vllm.distributed.weight_transfer.m2n_source
¶
Trainer-side weight sources for the NCCL M2N backend.
m2n plans a transfer from both sides' layouts, so the trainer has to say how it
holds each parameter — which the base WeightSource / ParamMeta pair does not
express. This module supplies the m2n flavor of both, and the DTensor-backed
implementation that covers the common trainer. Each parameter owns its source
mesh and placements because dense and expert weights can use different
factorizations over the same trainer ranks.
Classes:
-
DTensorModuleSource–M2NWeightSourceovermodule.named_parameters(). -
M2NManifestEntry–One immutable source descriptor with a lazy rank-local tensor view.
-
M2NWeightSource–A
WeightSourcethat also describes how the trainer holds its weights. -
ManifestM2NWeightSource–An ordered M2N source backed by lazy, rank-local manifest entries.
Functions:
-
mesh_from_tensor–The mesh a parameter lives on, as an
M2NMesh. -
placements_from_tensor–How a parameter is placed over its mesh, or
REPLICATED.
DTensorModuleSource
¶
Bases: M2NWeightSource
M2NWeightSource over module.named_parameters().
Covers both the FSDP/DTensor trainer (placement read off each parameter,
local shard yielded via to_local()) and the plain replicated trainer, with
no special casing. Trainers with a custom producer (a Megatron export, MoE
re-fusing) subclass M2NWeightSource instead.
Methods:
-
__init__–Wrap
module;num_trainer_rankssizes the mesh for plain tensors. -
__iter__–Yield each parameter's local shard (
to_local()), or the tensor itself. -
metadata–Read each global shape and source layout without gathering shards.
Source code in vllm/distributed/weight_transfer/m2n_source.py
__init__(module, num_trainer_ranks)
¶
Wrap module; num_trainer_ranks sizes the mesh for plain tensors.
__iter__()
¶
Yield each parameter's local shard (to_local()), or the tensor itself.
Source code in vllm/distributed/weight_transfer/m2n_source.py
metadata()
¶
Read each global shape and source layout without gathering shards.
Source code in vllm/distributed/weight_transfer/m2n_source.py
M2NManifestEntry
dataclass
¶
One immutable source descriptor with a lazy rank-local tensor view.
Attributes:
-
metadata(M2NParamMeta) –Return the serializable portion consumed during initialization.
Source code in vllm/distributed/weight_transfer/m2n_source.py
metadata
property
¶
Return the serializable portion consumed during initialization.
M2NWeightSource
¶
Bases: WeightSource
A WeightSource that also describes how the trainer holds its weights.
Unlike ModuleSource, iteration yields each rank's local shard, not a
materialized full tensor: gathering is exactly the cost m2n removes.
Methods:
-
__iter__–Yield
(name, local buffer)pairs in metadata order. -
metadata–Name, dtype, full shape, and source layout for each parameter.
Source code in vllm/distributed/weight_transfer/m2n_source.py
__iter__()
¶
Yield (name, local buffer) pairs in metadata order.
Providers must enqueue materialization on the caller's current CUDA stream, or return a buffer whose writes are already visible to it. Buffers may be torch tensors, CUDA Array Interface objects, or raw device pointers accepted by nccl4py. Providers own correct communicator-device placement. Raw-pointer providers additionally own allocation lifetime, dtype, and shape correctness.
Source code in vllm/distributed/weight_transfer/m2n_source.py
metadata()
¶
ManifestM2NWeightSource
¶
Bases: M2NWeightSource
An ordered M2N source backed by lazy, rank-local manifest entries.
Methods:
-
__iter__–Materialize one rank-local buffer at a time.
-
metadata–Return a fresh list while preserving the immutable manifest order.
Source code in vllm/distributed/weight_transfer/m2n_source.py
_placement_code(placement)
¶
Map a torch.distributed placement onto an m2n placement code.
Source code in vllm/distributed/weight_transfer/m2n_source.py
mesh_from_tensor(tensor, num_trainer_ranks)
¶
The mesh a parameter lives on, as an M2NMesh.
Tensors without DeviceMesh metadata are treated as replicated. Implicitly sharded tensors require a custom source with an explicit layout.
Source code in vllm/distributed/weight_transfer/m2n_source.py
placements_from_tensor(tensor)
¶
How a parameter is placed over its mesh, or REPLICATED.
REPLICATED is returned rather than a (REPLICATE, REPLICATE) pair: m2n
cannot express that, and the size-1-axis encoding it needs instead is
applied later by resolve_layout, which owns that workaround.