Skip to content

vllm.distributed.weight_transfer.nccl_engine

NCCL-based (dense) weight transfer engine.

Classes:

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

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 reload directly (the default with weight updates) and run 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.

_broadcast(meta, src)

Broadcast meta from group rank src: that rank sends from iter_full(), every other group member receives and discards.

_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.

_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.

_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.

_discard(meta, src)

Receive another broadcaster's parameters and drop them.

_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.

_send_update(meta, src, reuse)

Rank 0's part of one broadcaster's turn: run its update_weights concurrently with _broadcast.

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(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_plan without metadata.

  • RuntimeError –

    use_load_plan with a configuration no load plan supports (check_plannable).

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:

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.

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 / StatelessProcessGroup rendezvous (requires torch on every rank, including the trainer), or
  • nccl_unique_id_b64 -- standard (RFC 4648, not URL-safe) base64 of the 128 raw bytes from ncclGetUniqueId, 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 use base64.b64encode, not urlsafe_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 = 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 reload directly (the default with weight updates) and run 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.

__post_init__()

Validate that all lists have the same length.

_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.