vllm.distributed.weight_transfer.m2n_common
¶
Shared helpers for the NCCL M2N (nccl_m2n) weight transfer backend.
M2N reshards a tensor between two disjoint meshes of ranks that live in one
communicator: the trainer occupies ranks [0, T) and the inference workers
[T, T + N). This module holds everything both sides need — the optional
runtime import, layout descriptors, and the conversion to nccl.m2n types —
so the engine module stays about the transfer itself.
Classes:
-
M2NLayout–A tensor's mesh and placement on one side of a transfer.
-
M2NMesh–One side's rank topology — pure topology, no tensor placement.
-
M2NParamMeta–ParamMetaextended with how the trainer places this tensor. -
M2NWireParam–JSON-safe source metadata for one parameter in the init handshake.
Functions:
-
check_complete_plan_agreement–Require every rank to accept the same complete transfer plan.
-
check_data_plane_agreement–Agree on the NCCL rendezvous identity before NCCL init.
-
check_placements–Reject placement pairs nccl_m2n cannot express.
-
check_plan_limits–Reject plans whose per-shard fan-in or fan-out exceeds M2N capacity.
-
check_runtime_ready_agreement–Require every rank to prepare local resources before NCCL init.
-
check_source_plan_agreement–Verify every participant entered with the same source plan.
-
check_transferable–Reject parameters nccl_m2n cannot transfer.
-
complete_plan_digest–Return a digest of the agreed source and destination plan.
-
create_m2n_communicator–Create the M2N data-plane communicator through NCCL4Py.
-
expected_local_shape–Validate a parameter's source layout and return its local shape.
-
import_m2n–Import
nccl.m2nlazily, with an actionable error when it is missing. -
prepare_m2n_local_runtime–Prepare rank-local resources before any rank enters NCCL init.
-
publish_destination_placements–Share the worker-side destination plan with every rank in the group.
-
resolve_layout–Pair one tensor's placement with the mesh m2n should see for it.
-
source_plan_digest–Return a rank-independent digest of the ordered source wire plan.
-
validate_layout–Validate one resolved layout and return its required local shape.
-
validate_local_buffer–Check source dtype/shape while delegating buffer validity to M2N.
-
validate_transfer_plan–Validate the complete ordered source-to-destination transfer plan.
M2NLayout
dataclass
¶
A tensor's mesh and placement on one side of a transfer.
Source code in vllm/distributed/weight_transfer/m2n_common.py
M2NMesh
dataclass
¶
One side's rank topology — pure topology, no tensor placement.
Mirrors ncclMesh_t: a 2-axis mesh owning the contiguous rank interval
[start_rank, start_rank + dims[0] * dims[1]). There is no 1-D mesh; a
single-axis topology is spelled with a second axis of size 1.
A model may use a different factorization for each tensor. For example, dense weights can use a DP x TP mesh while expert weights use EDP x EP.
Source code in vllm/distributed/weight_transfer/m2n_common.py
M2NParamMeta
dataclass
¶
Bases: ParamMeta
ParamMeta extended with how the trainer places this tensor.
The base class carries only name / dtype / full shape, which is not enough
to plan a reshard. source_layout carries both the per-parameter mesh and
its placement on that mesh.
Source code in vllm/distributed/weight_transfer/m2n_common.py
M2NWireParam
dataclass
¶
JSON-safe source metadata for one parameter in the init handshake.
Methods:
-
from_dict–Parse one strict wire record from its JSON-decoded mapping.
-
to_dict–Serialize this record using only JSON-compatible values.
Source code in vllm/distributed/weight_transfer/m2n_common.py
from_dict(value)
classmethod
¶
Parse one strict wire record from its JSON-decoded mapping.
Source code in vllm/distributed/weight_transfer/m2n_common.py
to_dict()
¶
Serialize this record using only JSON-compatible values.
Source code in vllm/distributed/weight_transfer/m2n_common.py
_max_partition_overlaps(extent, partitions, other_partitions)
¶
Return the maximum other partitions intersected by any one partition.
Source code in vllm/distributed/weight_transfer/m2n_common.py
check_complete_plan_agreement(group, source_digest, dst_mesh, dst_placements, local_error=None)
¶
Require every rank to accept the same complete transfer plan.
Source code in vllm/distributed/weight_transfer/m2n_common.py
check_data_plane_agreement(group, unique_id_bytes, local_error=None)
¶
Agree on the NCCL rendezvous identity before NCCL init.
Source code in vllm/distributed/weight_transfer/m2n_common.py
check_placements(placements, context='placements')
¶
Reject placement pairs nccl_m2n cannot express.
Source code in vllm/distributed/weight_transfer/m2n_common.py
check_plan_limits(src, dst, name, shape)
¶
Reject plans whose per-shard fan-in or fan-out exceeds M2N capacity.
Source code in vllm/distributed/weight_transfer/m2n_common.py
check_runtime_ready_agreement(group, local_error)
¶
Require every rank to prepare local resources before NCCL init.
Source code in vllm/distributed/weight_transfer/m2n_common.py
check_source_plan_agreement(group, params, expected_digest=None, local_error=None)
¶
Verify every participant entered with the same source plan.
Source code in vllm/distributed/weight_transfer/m2n_common.py
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 | |
check_transferable(name, dtype, shape)
¶
Reject parameters nccl_m2n cannot transfer.
Source code in vllm/distributed/weight_transfer/m2n_common.py
complete_plan_digest(source_digest, dst_mesh, dst_placements)
¶
Return a digest of the agreed source and destination plan.
Source code in vllm/distributed/weight_transfer/m2n_common.py
create_m2n_communicator(nccl, group, unique_id_bytes)
¶
Create the M2N data-plane communicator through NCCL4Py.
Source code in vllm/distributed/weight_transfer/m2n_common.py
expected_local_shape(meta)
¶
Validate a parameter's source layout and return its local shape.
Source code in vllm/distributed/weight_transfer/m2n_common.py
import_m2n()
¶
Import nccl.m2n lazily, with an actionable error when it is missing.
Deferred so that importing vLLM — or any other weight transfer backend — never requires the m2n runtime to be present.
Source code in vllm/distributed/weight_transfer/m2n_common.py
prepare_m2n_local_runtime(m2n, max_cta)
¶
Prepare rank-local resources before any rank enters NCCL init.
Source code in vllm/distributed/weight_transfer/m2n_common.py
publish_destination_placements(comm, device, stream, first_worker_rank, placements, num_parameters)
¶
Share the worker-side destination plan with every rank in the group.
The trainer must issue each reshard with the same destination the workers
use, but once destinations are per-parameter they depend on the inference
model, which only the workers can see. The first worker publishes them here,
over the shared NCCL communicator; trainer ranks pass None and receive
them, and the other workers pass their own so a disagreement is caught
rather than deadlocking later.
Only placements travel: the destination mesh is still derived from the rank split, identically on both sides. The plan is published on the data plane before any M2N reshard collective.
Source code in vllm/distributed/weight_transfer/m2n_common.py
resolve_layout(mesh, placements, context='placements')
¶
Pair one tensor's placement with the mesh m2n should see for it.
A replicated tensor needs a size-1 mesh axis to carry a no-op shard, since
m2n has no {REPLICATE, REPLICATE}. It is therefore described over the
same rank interval re-factored as (size, 1). That re-factoring is sound
precisely because replication is order-independent — every rank holds the
whole tensor, so it does not matter that (a, b) and (size, 1) walk the
interval in a different order. A sharded tensor keeps its side's own
factorization, where rank order decides who owns which shard.
Source code in vllm/distributed/weight_transfer/m2n_common.py
source_plan_digest(params)
¶
Return a rank-independent digest of the ordered source wire plan.
Source code in vllm/distributed/weight_transfer/m2n_common.py
validate_layout(mesh, placements, shape, context)
¶
Validate one resolved layout and return its required local shape.
Source code in vllm/distributed/weight_transfer/m2n_common.py
validate_local_buffer(m2n, meta, buffer)
¶
Check source dtype/shape while delegating buffer validity to M2N.
Source code in vllm/distributed/weight_transfer/m2n_common.py
validate_transfer_plan(metas, dst_mesh, dst_placements)
¶
Validate the complete ordered source-to-destination transfer plan.