vllm.distributed.weight_transfer.m2n_trainer
¶
Trainer-side weight transfer engine for the NCCL M2N backend.
Symmetric to M2NWeightTransferEngine but in the training process. Every
trainer rank joins the shared communicator and runs every reshard, sending its
own local shard; only rank 0 touches the inference control plane.
Workers join the communicator during init and run reshard from inside
update_weights, so those two RPCs overlap with work on this side. Both run on
a helper thread and are joined afterwards, which keeps that overlap inside the
engine -- where the TrainerWeightTransferEngine contract puts it -- rather than
in every caller.
Classes:
-
M2NTrainerInitInfo–Trainer-side init info for nccl_m2n.
-
M2NTrainerWeightTransferEngine–Trainer-side engine: sends every rank's local shard, once per parameter.
M2NTrainerInitInfo
dataclass
¶
Bases: TrainerInitInfo
Trainer-side init info for nccl_m2n.
rank (from TrainerInitInfo) is this trainer process's rank; it is also
its rank in the shared communicator, since the trainer occupies
[0, num_trainer_ranks). Rank 0 drives the control plane.
Methods:
-
__post_init__–Reject rank counts or destination meshes that cannot form a group.
Attributes:
-
destination_mesh_dims(tuple[int, int]) –dst_mesh_dims, or a flat mesh over every inference worker. -
dst_mesh_dims(tuple[int, int] | None) –How the inference ranks are laid out: axis 0 replicates and axis 1
-
listen_socket(socket | None) –Optional rank-zero TCPStore reservation; never sent to workers.
-
nccl_unique_id_b64(str | None) –Optional UID for the NCCL data plane; TCP remains the metadata plane.
-
world_size(int) –Trainer ranks + all inference workers.
destination_mesh_dims
property
¶
dst_mesh_dims, or a flat mesh over every inference worker.
dst_mesh_dims = None
class-attribute
instance-attribute
¶
How the inference ranks are laid out: axis 0 replicates and axis 1
shards. The trainer declares it so both sides describe the destination
identically; defaults to a flat (num_workers, 1), which is all a
replicated destination needs.
Destination meshes remain common to every parameter; per-parameter destination meshes are intentionally future work.
listen_socket = field(default=None, repr=False, compare=False)
class-attribute
instance-attribute
¶
Optional rank-zero TCPStore reservation; never sent to workers.
nccl_unique_id_b64 = field(default=None, repr=False)
class-attribute
instance-attribute
¶
Optional UID for the NCCL data plane; TCP remains the metadata plane.
world_size
instance-attribute
¶
Trainer ranks + all inference workers.
__post_init__()
¶
Reject rank counts or destination meshes that cannot form a group.
M2NTrainerWeightTransferEngine
¶
Bases: TrainerWeightTransferEngine[M2NTrainerInitInfo]
Trainer-side engine: sends every rank's local shard, once per parameter.
Called on every trainer rank. All ranks join the communicator and run every
reshard; only rank 0 touches the control plane. The source's iter_local()
supplies the shards and its metadata the layouts; every parameter must be
owned by all trainer ranks, in rank order.
Methods:
-
__init__–Hold the client and source;
trainer_initfills in the group. -
send_weights–Drive one update round: start, reshard concurrently, then finish.
-
shutdown–Finish pending GPU work and release M2N communication state.
-
trainer_init–Build the engine and rendezvous with the inference side.
__init__(*, client, source, is_sender, rank=0)
¶
Hold the client and source; trainer_init fills in the group.
_initialize(init_info, source)
¶
Run source validation, metadata agreement, and NCCL rendezvous.
_prepare_source_plan(source, num_trainer_ranks)
¶
Build and validate this rank's immutable source plan.
_publish_round_outcome(failure)
¶
Tell non-sender trainer ranks whether worker finalization passed.
_receive_destination_plan(group, first_worker_rank, device)
¶
Receive the inference-side per-parameter placements.
_receive_round_outcome()
¶
Wait until trainer rank zero observed every worker's finish RPC.
_send()
¶
Reshard each local shard into its worker-planned destination.
_worker_init_info(init_info)
¶
Handshake payload: rendezvous, both meshes, and the transfer plan.
send_weights()
¶
Drive one update round: start, reshard concurrently, then finish.
shutdown()
¶
Finish pending GPU work and release M2N communication state.
trainer_init(init_info, *, client, source=None)
classmethod
¶
Build the engine and rendezvous with the inference side.
Runs on every trainer rank. Rank 0 additionally ships the transfer plan to the workers and drives the control plane; the other ranks only build local state and join the communicator. Every rank participates in every reshard and sends its local shard.
Build a local validation envelope, start the worker RPC without waiting, join the metadata rendezvous, and require unanimous source, data-plane, and runtime readiness before constructing NCCL.