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. The transport uses local shards without requiring a trainer-side gather; a WeightSource may still gather internally.

Destinations come from the shared load plan: each name receives directly into live memory, into a staging box, or as a full tensor for load_weights.

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.

The shared load plan determines direct writes, staged copies and loader fallbacks. Every update uses the shared direct-reload lifecycle.

Methods:

  • finish_weight_update –

    Finish the reload and release the staging buffer.

  • init_transfer_engine –

    Agree on source and local readiness before constructing NCCL.

  • receive_weights –

    Stream the agreed destinations, yielding only fallbacks to the loader.

  • shutdown –

    Finish pending GPU work and release M2N communication state.

  • start_weight_update –

    Reset checkpoint views and completeness for every full update.

_agree_destination_plan(local_error=None)

Plan destinations against the reloading model and agree them with every participant; state is committed only once all ranks accept.

_prepare_source_plan(wire_params, num_trainer_ranks)

Validate worker-visible source metadata without constructing NCCL.

_requested_indices(update_info)

Resolve the update's names to their declared order.

_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 the reload and release the staging buffer.

init_transfer_engine(init_info)

Agree on source and local readiness before constructing NCCL.

The model is untouched; destinations are planned by the first update.

receive_weights(update_info)

Stream the agreed destinations, yielding only fallbacks to the loader.

shutdown()

Finish pending GPU work and release M2N communication state.

start_weight_update()

Reset checkpoint views and completeness for every full update.

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 session-wide inference mesh, starting at rank_offset.

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.