vllm.distributed.weight_transfer.nccl_engine
¶
NCCL-based (dense) weight transfer engine.
Classes:
-
NCCLTrainerInitInfo–Trainer-side init info for the dense NCCL weight transfer backend.
-
NCCLTrainerWeightTransferEngine–Trainer-side NCCL weight transfer engine.
-
NCCLWeightTransferEngine–Weight transfer engine using NCCL for communication between trainer and workers.
-
NCCLWeightTransferInitInfo–Worker-side initialization info for NCCL-based weight transfer backends.
-
NCCLWeightTransferUpdateInfo–Per-round update info for the dense NCCL weight transfer backend.
NCCLTrainerInitInfo
dataclass
¶
Bases: TrainerInitInfo
Trainer-side init info for the dense NCCL weight transfer backend.
The sender opens its endpoint as NCCL rank 0, so it needs no rank_offset.
rank (from TrainerInitInfo) identifies this trainer process.
The trainer joins over a TCPStore rendezvous (master_address +
master_port). Torch-free trainers (e.g. JAX) that cannot join a TCPStore
mint an ncclUniqueId themselves and drive rank 0 out of band; they ship a
nccl_unique_id_b64 payload straight to the inference workers'
init_weight_transfer_engine (see NCCLWeightTransferInitInfo) rather than
going through this engine.
packed / buffer sizes are the transfer's wire params. The trainer
propagates them to the worker at trainer_init so the two sides cannot
disagree. Note this defaults to packed, unlike the worker-side
NCCLWeightTransferInitInfo, whose default only applies when no trainer
ships a value. backend is the factory dispatch key.
Attributes:
-
use_load_plan(bool) –Have the workers write received tensors of the target model through a
-
world_size(int) –Transfer group size: rank 0 and each distinct
ParamMeta.owners[0], plus
Source code in vllm/distributed/weight_transfer/nccl_engine.py
use_load_plan = False
class-attribute
instance-attribute
¶
Have the workers write received tensors of the target model through a
load plan instead of load_weights where the plan allows (off by default).
The workers get source.metadata at init and plan from it at the first
weight update, inside start_weight_update, so that call takes longer by
the plan's trace time (with HTTPVLLMWeightSyncClient, raise its
timeout for a very large model). Every update must send a subset of that
metadata with the same dtypes and shapes; send_weights checks this on
every trainer rank before contacting the workers. The check stays until
re-init, even if planning failed and the workers fell back to
load_weights. The inference server
must run with VLLM_RELOAD_MODE=direct and without EPLB; the workers
refuse otherwise at init.
world_size
instance-attribute
¶
Transfer group size: rank 0 and each distinct ParamMeta.owners[0], plus
the inference workers (1 + num_workers for a single sender).
NCCLTrainerWeightTransferEngine
¶
Bases: TrainerWeightTransferEngine[NCCLTrainerInitInfo]
Trainer-side NCCL weight transfer engine.
Each parameter is broadcast by its first owner (rank 0 when unset); rank 0
also drives the client RPCs. See "Broadcasting ranks" in nccl.md.
Other trainer ranks hold no communicator and only drive iter_full() to
stay in the trainer-side gathers (e.g. FSDP full_tensor()).
packed / buffer sizes come from NCCLTrainerInitInfo; the sender
propagates them to the worker at trainer_init (on the worker-side init
info), so per-round payloads carry only parameter metadata.
Source code in vllm/distributed/weight_transfer/nccl_engine.py
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 | |
_broadcast(meta, src)
¶
Broadcast meta from group rank src: that rank sends from
iter_full(), every other group member receives and discards.
Source code in vllm/distributed/weight_transfer/nccl_engine.py
_broadcast_plan(meta)
staticmethod
¶
The transfer group's trainer ranks, in group-rank order, and each broadcaster's parameters (in metadata order), in broadcaster order.
Source code in vllm/distributed/weight_transfer/nccl_engine.py
_build_worker_init_payload(init_info, *, metadata=None)
classmethod
¶
metadata: what the workers plan from; passed only with
use_load_plan, so overrides without it keep working otherwise.
Source code in vllm/distributed/weight_transfer/nccl_engine.py
_checked_iter(source, meta)
staticmethod
¶
Yield the sender's pairs, checking each against what the worker was told to expect.
The worker sizes its receive buffers — and in packed mode cuts its chunk
boundaries — from the update info, which is built from metadata. If
iteration disagrees with it, the two sides split the stream differently
and the transfer hangs in NCCL or loads garbage. Checking here costs one
comparison per parameter and turns that into an error naming the first
divergent parameter.
Source code in vllm/distributed/weight_transfer/nccl_engine.py
_discard(meta, src)
¶
Receive another broadcaster's parameters and drop them.
Source code in vllm/distributed/weight_transfer/nccl_engine.py
_post_send_sync()
¶
Wait for this rank's transfer work to land before returning.
Broadcasts are only enqueued by send_weights: the unpacked path on
the current stream, the packed path on the producer's own streams (which
it drains itself). Waiting here lets a caller mutate parameters, or
start the next step on another stream, as soon as send_weights
returns, instead of silently depending on same-stream ordering. Every
rank waits: a non-sender's full_tensor() gathers feed the sender's
broadcast, so they must have landed before it may touch its shards.
Unlike IPC there is no cross-rank barrier here. Nothing in this backend outlives the collective it travelled in (IPC's barrier keeps shared buffers alive until every consumer has opened them), so a barrier would only add a dependency on the default process group that this backend otherwise does not have.
Source code in vllm/distributed/weight_transfer/nccl_engine.py
_send_update(meta, src, reuse)
¶
Rank 0's part of one broadcaster's turn: run its update_weights
concurrently with _broadcast.
Source code in vllm/distributed/weight_transfer/nccl_engine.py
NCCLWeightTransferEngine
¶
Bases: WeightTransferEngine[NCCLWeightTransferInitInfo, NCCLWeightTransferUpdateInfo]
Weight transfer engine using NCCL for communication between trainer and workers.
Receives dense checkpoint-format weights broadcast from the trainer ranks
below rank_offset and loads them with the layerwise reload lifecycle.
Methods:
-
finish_weight_update–Finish reloading after all weights have been received.
-
init_transfer_engine–Initialize NCCL process group with the trainer and record the
-
receive_weights–Receive weights from trainer via NCCL broadcast.
-
start_weight_update–Begin reloading the incoming checkpoint weights; with
Source code in vllm/distributed/weight_transfer/nccl_engine.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
finish_weight_update()
¶
Finish reloading after all weights have been received.
Source code in vllm/distributed/weight_transfer/nccl_engine.py
init_transfer_engine(init_info)
¶
Initialize NCCL process group with the trainer and record the trainer-supplied wire params so the worker decodes exactly as the trainer encodes.
Parameters:
-
(init_info¶NCCLWeightTransferInitInfo) –NCCL initialization info containing master address, port, rank offset, world size, the packed wire params and, with
use_load_plan, the trainer's metadata
Raises:
-
ValueError–use_load_planwithout metadata. -
RuntimeError–use_load_planwith a configuration no load plan supports (check_plannable).
Source code in vllm/distributed/weight_transfer/nccl_engine.py
receive_weights(update_info)
¶
Receive weights from trainer via NCCL broadcast.
Whether to use packed broadcasting (and the buffer geometry) is read
from self.packed / self.packed_*, set at the init handshake from the
trainer's init info, so it is guaranteed to match how the trainer
encoded.
With a load plan, a target update checks the update against the
metadata sent at init (_check_manifest) and writes through
load_planned; draft updates use load_weights.
Parameters:
-
(update_info¶NCCLWeightTransferUpdateInfo) –Parameter names, dtypes, shapes and
src; empty lists reuse the previous call's from the samesrc
Source code in vllm/distributed/weight_transfer/nccl_engine.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |
start_weight_update()
¶
Begin reloading the incoming checkpoint weights; with
use_load_plan, the first target update also builds the load plan,
reused by every later one.
Source code in vllm/distributed/weight_transfer/nccl_engine.py
NCCLWeightTransferInitInfo
dataclass
¶
Bases: WeightTransferInitInfo
Worker-side initialization info for NCCL-based weight transfer backends.
Keyword-only (kw_only): adding the optional nccl_unique_id_b64 field
means the rendezvous fields can no longer keep a fixed positional slot, so a
stale positional call fails loudly instead of silently swapping arguments.
Provide exactly one rendezvous mode:
master_address+master_port-- TCPStore /StatelessProcessGrouprendezvous (requires torch on every rank, including the trainer), ornccl_unique_id_b64-- standard (RFC 4648, not URL-safe) base64 of the 128 raw bytes fromncclGetUniqueId, for torch-free trainers (e.g. JAX) that mint the unique id out of band and share it (over HTTP, etc.). Note a JAX peer must usebase64.b64encode, noturlsafe_b64encode.
On the unique-id path all ranks must enter init concurrently (there is no
store barrier), and every peer must honor the warm-up handshake: the
worker's communicator issues a one-element all_reduce immediately after
ncclCommInitRank (see PyNcclCommunicator.from_unique_id_bytes), so a
foreign peer must issue a matching one-element all_reduce before any
other collective or all ranks deadlock.
Attributes:
-
metadata(list[tuple[str, str, list[int]]] | None) –(name, dtype name, shape) of every tensor the trainer sends; required
-
use_load_plan(bool) –Dense backend only: write received tensors of the target model through a
Source code in vllm/distributed/weight_transfer/nccl_common.py
metadata = None
class-attribute
instance-attribute
¶
(name, dtype name, shape) of every tensor the trainer sends; required
with use_load_plan.
use_load_plan = False
class-attribute
instance-attribute
¶
Dense backend only: write received tensors of the target model through a
load plan built from metadata at the first weight update (see
NCCLTrainerInitInfo.use_load_plan). The server must run with
VLLM_RELOAD_MODE=direct and without EPLB; init refuses otherwise.
NCCLWeightTransferUpdateInfo
dataclass
¶
Bases: WeightTransferUpdateInfo
Per-round update info for the dense NCCL weight transfer backend.
Carries the parameter metadata and src, the broadcasting group rank; the
packed wire params live on the init info.
Empty lists reuse the previous update's metadata for the same model and src.
Methods:
-
__post_init__–Validate that all lists have the same length.
Source code in vllm/distributed/weight_transfer/nccl_engine.py
__post_init__()
¶
Validate that all lists have the same length.
Source code in vllm/distributed/weight_transfer/nccl_engine.py
_check_manifest(manifest, sent)
¶
Every sent (name, dtype, shape) must be in the manifest sent at init; a subset is fine (a broadcaster sends only its own). The trainer checks before an update; the worker checks again for trainers that drive it out of band.