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. Each transfer route places one ordered trainer source group at
[0, T) and an ordered destination group at [T, T + N). This module holds
everything both sides need — the optional runtime import, topology/layout
descriptors, and conversion to nccl.m2n types — so engine modules stay about
transfer execution.
Classes:
-
M2NDestinationMode–How one logical checkpoint tensor is installed on a worker.
-
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. -
M2NSourceTopology–Ordered source rank groups and each parameter's owning group.
-
M2NTransferRoute–One source and destination group in route-local communicator order.
-
M2NTransferWave–One deterministic bounded issue wave shared by senders and receivers.
-
M2NWireParam–JSON-safe source metadata for one parameter in the init handshake.
Functions:
-
build_m2n_param_routes–Map each manifest parameter to its canonical transfer-route index.
-
build_m2n_transfer_routes–Build canonical source-group-to-all-workers transfer routes.
-
build_m2n_transfer_waves–Plan bounded launches while preserving model-loader dependencies.
-
check_communicator_init_agreement–Agree once on the complete ordered communicator-init result.
-
check_data_plane_agreement–Agree on ordered NCCL route rendezvous identities before NCCL init.
-
check_multi_communicator_launch_order–Require NCCL's ordered multi-communicator launch mode when needed.
-
check_placements–Validate vLLM's canonical M2N placement representation.
-
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.
-
create_m2n_communicator–Create one 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. -
m2n_load_group–Return the ordered model-load group, or
Nonefor in-place loads. -
prepare_m2n_local_runtime–Prepare rank-local resources before any rank enters NCCL init.
-
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.
M2NDestinationMode
¶
How one logical checkpoint tensor is installed on a worker.
Source code in vllm/distributed/weight_transfer/m2n_common.py
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
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
M2NTransferRoute
dataclass
¶
One source and destination group in route-local communicator order.
dst_mesh describes the destination rank interval. Each parameter's
resolved destination layout is carried by its destination record.
Attributes:
-
source_ranks(tuple[int, ...]) –Global metadata ranks forming the ordered source mesh.
-
worker_ranks(tuple[int, ...]) –Global metadata ranks forming the ordered destination mesh.
Source code in vllm/distributed/weight_transfer/m2n_common.py
M2NTransferWave
dataclass
¶
One deterministic bounded issue wave shared by senders and receivers.
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
_legacy_source_topology(params)
¶
Infer the pre-PP single source group for compatibility callers.
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
build_m2n_param_routes(routes, num_params)
¶
Map each manifest parameter to its canonical transfer-route index.
Source code in vllm/distributed/weight_transfer/m2n_common.py
build_m2n_transfer_routes(topology, *, num_trainer_ranks, world_size, dst_mesh_dims)
¶
Build canonical source-group-to-all-workers transfer routes.
Source code in vllm/distributed/weight_transfer/m2n_common.py
build_m2n_transfer_waves(routes, load_groups, *, active_indices=None)
¶
Plan bounded launches while preserving model-loader dependencies.
None identifies an in-place destination. Equal integer values identify
callbacks that must run in manifest order. A wave launches at most one new
parameter on every unblocked route before consuming one ready result. Ready
results are drained before the next launch wave, so independent PP groups
advance together without reordering fused or fallback loader inputs.
Source code in vllm/distributed/weight_transfer/m2n_common.py
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 | |
check_communicator_init_agreement(group, local_errors)
¶
Agree once on the complete ordered communicator-init result.
Source code in vllm/distributed/weight_transfer/m2n_common.py
1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 | |
check_data_plane_agreement(group, unique_id_bytes, local_error=None)
¶
Agree on ordered NCCL route rendezvous identities before NCCL init.
A scalar preserves the single-communicator API. Multi-route callers pass one bytes-or-None entry per canonical transfer route.
Source code in vllm/distributed/weight_transfer/m2n_common.py
1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 | |
check_multi_communicator_launch_order(num_routes)
¶
Require NCCL's ordered multi-communicator launch mode when needed.
Pipeline transfers use one NCCL communicator and CUDA stream per route. NCCL requires implicit launch ordering for overlapping operations on independent communicators. This is process-global NCCL configuration, so callers must set it before starting the process rather than mutating the environment after NCCL may already have initialized.
Source code in vllm/distributed/weight_transfer/m2n_common.py
check_placements(placements, context='placements')
¶
Validate vLLM's canonical M2N placement representation.
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, *, topology=None)
¶
Verify every participant entered with the same source plan.
Source code in vllm/distributed/weight_transfer/m2n_common.py
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 | |
check_transferable(name, dtype, shape)
¶
Reject parameters nccl_m2n cannot transfer.
Source code in vllm/distributed/weight_transfer/m2n_common.py
create_m2n_communicator(nccl, group, unique_id_bytes, *, members=None)
¶
Create one M2N data-plane communicator through NCCL4Py.
members uses metadata-group ranks in communicator-local order. Every
metadata rank must call this helper for each route, including nonmembers, so
automatic UID bootstrap advances the shared control plane identically.
Nonmembers return None after that bootstrap.
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
m2n_load_group(mode, staging_group)
¶
Return the ordered model-load group, or None for in-place loads.
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
resolve_layout(mesh, placements, context='placements')
¶
Pair one tensor's placement with the mesh m2n should see for it.
vLLM canonically describes a replicated tensor over a (size, 1) mesh with
a no-op shard on the size-1 axis. NCCL M2N also accepts two replicated axes,
but keeping one representation makes plan agreement unambiguous. 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, topology=None)
¶
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, destination_layouts)
¶
Validate the complete ordered source-to-destination transfer plan.