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) –Inference mesh (axis 0 replicates, axis 1 shards), common to every
-
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
¶
Inference mesh (axis 0 replicates, axis 1 shards), common to every
parameter; defaults to (num_workers, 1).
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 on every trainer rank, rendezvous with the workers,
__init__(*, client, source, is_sender, rank=0)
¶
Hold the client and source; trainer_init fills in the group.
_agree_destination_plan()
¶
Join the workers' first-update placement and complete-plan agreement.
_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_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 on every trainer rank, rendezvous with the workers, and run the initial sync that agrees destination placements. Rank 0 also drives the worker control plane.