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. Each parameter owns its source mesh and placements because dense and
expert weights can use different factorizations over the same source-group
ranks. A source topology separately routes each parameter to its owning rank
group, including pipeline-parallel producers.
Classes:
-
DTensorModuleSource–M2NWeightSourceovermodule.named_parameters(). -
M2NManifestEntry–One immutable source descriptor with a lazy rank-local tensor view.
-
M2NSourceTopology–Ordered source rank groups and each parameter's owning group.
-
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.
M2NSourceTopology
dataclass
¶
Ordered source rank groups and each parameter's owning group.
Rank ids live in the global metadata-group namespace. Rank order within a
group defines route-local source-mesh coordinates, so callers must not sort
it. param_groups[i] selects the group that exports params[i].
Transfer-route identity is derived separately from this source ownership.
An empty topology represents an empty manifest and is also used as a
lifecycle sentinel. A usable non-empty plan must pass :meth:validate.
Source groups are non-empty, pairwise disjoint, and equal-sized, so a
trainer rank belongs to at most one group. Each parameter selects exactly
one canonical group.
Methods:
-
from_dict–Parse one strict JSON-decoded topology record.
-
single_group–Build the legacy topology: every trainer exports every parameter.
-
to_dict–Serialize this topology using JSON-compatible values.
-
validate–Validate this topology against one concrete source manifest.
Source code in vllm/distributed/weight_transfer/m2n_common.py
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 | |
from_dict(value)
classmethod
¶
Parse one strict JSON-decoded topology record.
Source code in vllm/distributed/weight_transfer/m2n_common.py
single_group(num_trainer_ranks, num_params)
classmethod
¶
Build the legacy topology: every trainer exports every parameter.
Source code in vllm/distributed/weight_transfer/m2n_common.py
to_dict()
¶
Serialize this topology using JSON-compatible values.
validate(*, num_trainer_ranks, num_params)
¶
Validate this topology against one concrete source manifest.
Source code in vllm/distributed/weight_transfer/m2n_common.py
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. -
iter_group–Iterate one source group in its global manifest subsequence order.
-
metadata–Name, dtype, full shape, and source layout for each parameter.
-
source_topology–Return explicit source groups, or
Nonefor the legacy single group.
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
iter_group(group_index)
¶
Iterate one source group in its global manifest subsequence order.
Legacy sources expose one group and keep their existing __iter__
implementation. Explicit multi-group sources must override this method
so ranks materialize only parameters belonging to the requested group.
Source code in vllm/distributed/weight_transfer/m2n_source.py
metadata()
¶
source_topology()
¶
Return explicit source groups, or None for the legacy single group.
Group ranks use global trainer-rank ids in source-mesh coordinate order.
The trainer engine converts None into one group containing every
trainer rank and assigning every parameter to it. Pipeline-parallel or
otherwise partitioned producers override this together with
:meth:iter_group; vLLM never infers trainer ownership from parameter
names or inference topology.
Source code in vllm/distributed/weight_transfer/m2n_source.py
ManifestM2NWeightSource
¶
Bases: M2NWeightSource
An ordered M2N source backed by lazy, rank-local manifest entries.
The provider callable is invoked on every iteration, so it can return a
current parameter view or perform rank-local conversion and LoRA merging.
Callable identities and tensors remain local and never enter the wire plan.
Callbacks run synchronously and must honor M2NWeightSource.__iter__'s
current-stream readiness contract.
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.
This adapter treats tensors without DeviceMesh metadata as replicated.
Implicitly sharded tensors, such as Megatron parameters, require a custom
M2NWeightSource with an explicit source layout.
Megatron integrations must use ManifestM2NWeightSource or another custom
M2NWeightSource that explicitly supplies TP/EP layouts. Megatron parameters
must not be passed to DTensorModuleSource.
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 so
vLLM has one canonical fully replicated representation. resolve_layout
later converts it to the equivalent size-1-axis encoding.