Skip to content

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 –

    ParamMeta with its m2n source layout spelled out, as the engines plan

  • M2NWireParam –

    JSON-safe source metadata for one parameter in the init handshake.

Functions:

M2NLayout dataclass

A tensor's mesh and placement on one side of a transfer.

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.

M2NParamMeta dataclass

Bases: ParamMeta

ParamMeta with its m2n source layout spelled out, as the engines plan reshards from it. Built from a source's ParamMeta by m2n_param_meta.

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.

from_dict(value) classmethod

Parse one strict wire record from its JSON-decoded mapping.

to_dict()

Serialize this record using only JSON-compatible values.

_max_partition_overlaps(extent, partitions, other_partitions)

Return the maximum other partitions intersected by any one partition.

check_complete_plan_agreement(group, source_digest, dst_mesh, dst_placements, local_error=None)

Require every rank to accept the same complete transfer plan.

check_data_plane_agreement(group, unique_id_bytes, local_error=None)

Agree on the NCCL rendezvous identity before NCCL init.

check_placements(placements, context='placements')

Reject placement pairs nccl_m2n cannot express.

check_plan_limits(src, dst, name, shape)

Reject plans whose per-shard fan-in or fan-out exceeds M2N capacity.

check_runtime_ready_agreement(group, local_error)

Require every rank to prepare local resources before NCCL init.

check_source_plan_agreement(group, params, expected_digest=None, local_error=None)

Verify every participant entered with the same source plan.

check_transferable(name, dtype, shape)

Reject parameters nccl_m2n cannot transfer.

complete_plan_digest(source_digest, dst_mesh, dst_placements)

Return a digest of the agreed source and destination plan.

create_m2n_communicator(nccl, group, unique_id_bytes)

Create the M2N data-plane communicator through NCCL4Py.

expected_local_shape(meta)

Validate a parameter's source layout and return its local shape.

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.

m2n_param_meta(meta, num_trainer_ranks)

The m2n source layout of meta, which must be owned by every trainer rank in rank order (or by default).

A 1-D mesh gains a size-1 second axis; a replicated parameter keeps REPLICATED. Placements m2n cannot express (both axes sharded, more than two axes) are left for validate_transfer_plan to reject.

prepare_m2n_local_runtime(m2n, max_cta)

Prepare rank-local resources before any rank enters NCCL init.

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.

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_plan_digest(params)

Return a rank-independent digest of the ordered source wire plan.

validate_layout(mesh, placements, shape, context)

Validate one resolved layout and return its required local shape.

validate_transfer_plan(metas, dst_mesh, dst_placements)

Validate the complete ordered source-to-destination transfer plan.