Skip to content

vllm.distributed.weight_transfer.m2n_engine

Inference-side weight transfer engine built on NCCL M2N (nccl_m2n).

The trainer and the inference workers share one NCCL communicator: trainer ranks occupy [0, T), workers [T, T + N). Each parameter is moved with a single nccl.m2n.reshard, which redistributes it from the trainer's layout (FSDP / EP / arbitrary DTensor sharding) to the inference layout — so the trainer sends its local shards and never all-gathers a full tensor, which is what the broadcast NCCL backend forces it to do.

When an incoming checkpoint parameter maps directly to a live vLLM parameter, M2N reshards into that worker's local model storage. Parameters whose names or layouts cannot be resolved receive a full tensor and fall back to load_weights, preserving the existing backend's loading behavior.

Both meshes participate in every reshard, in the same order, so this backend has the same concurrency shape as the broadcast NCCL backend: the worker must be inside receive_weights while the trainer is sending. Driving that from the trainer is the trainer engine's job.

Classes:

M2NWeightTransferEngine

Bases: WeightTransferEngine[M2NWeightTransferInitInfo, M2NWeightTransferUpdateInfo]

Inference-side engine: receives each parameter with one reshard.

Resolvable parameters are resharded from the trainer layout directly into each worker's live local model storage. Unresolvable parameters receive a full tensor and use load_weights. In both cases, the trainer sends its local shards without materializing a full tensor.

Methods:

_prepare_destination_plan(init_info)

Resolve the merged-#51520 in-place/full-fallback destination plan.

_prepare_source_plan(wire_params, num_trainer_ranks)

Validate worker-visible source metadata without constructing NCCL.

_reshard(comm, stream, src_meta, dst_placements, dst_buffer)

Reshard one parameter from its trainer layout into a worker buffer.

dst_placements describes the buffer's logical placement over the worker mesh; dst_buffer is this rank's physical storage.

finish_weight_update()

Finish reloading when the plan uses fallback entries.

init_transfer_engine(init_info)

Agree on source and local readiness before constructing NCCL.

receive_weights(update_info)

Receive each requested parameter using its initialization-time plan.

shutdown()

Finish pending GPU work and release M2N communication state.

start_weight_update()

Begin reloading, but only if some parameter needs it.

Directly-resharded parameters are written in place and never go through load_weights, so a plan with no fallback entries has nothing to reload.

M2NWeightTransferInitInfo dataclass

Bases: WeightTransferInitInfo

Worker-side init info: the rendezvous plus the full transfer plan.

Layouts are static for the whole run, so they ride the one-time init handshake and the per-round update info stays a list of names. Everything is plain JSON so the HTTP control plane carries it unchanged.

Methods:

Attributes:

dst_mesh_dims instance-attribute

The inference mesh, starting at rank_offset. Declared rather than derived so both sides describe the destination identically.

params instance-attribute

Ordered per-parameter source metadata and layouts.

rank_offset instance-attribute

First worker rank, i.e. the number of trainer ranks.

source_digest instance-attribute

SHA-256 of the ordered, versioned source parameter plan.

world_size instance-attribute

Trainer ranks + all inference workers.

parse_wire_params()

Parse and authenticate the ordered source plan.

M2NWeightTransferUpdateInfo dataclass

Bases: WeightTransferUpdateInfo

Per-round update info: which parameters this chunk carries, in order.

Shapes, dtypes and layouts were fixed at init, so a round only needs to say what is coming and in what order — both sides must issue their reshards in exactly that order.