[RFC] Two-stage relay for cross-node weight sync, priced by a calibrated cost model

Đang mở
#9,026 25 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@LiRunGuo đang làm issue này rồi.

Từ ngày 10/11/2026.

  • #9045 của @LiRunGuo — đang mở
  • #9074 của @LiRunGuo — đang mở
  • #9149 của @jinyouzhi — đang mở

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python, pytorch

Hướng nghiên cứu

Read the referenced issues #8885, #8519, #8623, #8809, #8966 and #8967, then follow the RFC sections on relay planning, cost modeling and delta transfer. The proposal depends on substantial planner, executor and transport work, and the body is truncated before all options are described. Done means implementing and validating the selected design, including transfer correctness and cost predictions against the reported measurements.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Refs #8252, #8935, #8936, #9027. Builds on #8885 (ZeRO storage maps), #8519 (AutoTP layer maps), #8623 (plan_transfer), #8809 (executor, merged), #8966 / #8967 (calibration and plan analysis, merged).

Status (2026-11-24)

  • Merged: schedule_transfers (#9027), the region alias check (#9093, open question 1), flat shards at the parameter's own strides (#9070) and one map for a weight held in several layouts (#9052, open question 8), calibration and plan analysis (#8966, #8967), and the cost model (#9145): it estimates each candidate plan's time from its schedule and keeps the cheapest. On 4× A100 and 4× H200, its choice was within 1.4% of the fastest measured candidate in all 5 moves on both machines, where the default was up to 76% slower.
  • In review: prepared transfers (#9094, approved), fused copies and the symmetric-memory window on top of it (#9118, draft), the weight sync (#9045, draft) and the training-state move (#9074, draft, with ZeRO-3's checks over the partition group in #9076).
  • Left: relay_map and the serial relay (§5, PR 2), flat relay and adjacency-based direct rounds, pipelining, and the cost-aware policy on #8936 that uses #9145 to choose between direct, relay and spread. A user-facing entry point (what a user turns on, what is chosen by default) is to be proposed separately.

Summary

When weights move from trainers on one node to rollout engines on another, the cheapest plan is often not a direct one. Two examples:

  • Sending every byte across the network once, into the target node, and then spreading it over NVLink beats every direct plan.
  • On 2 × 4 GH200 over Slingshot, the pipelined two-stage plan moves 8 GiB to four engines in about 93 ms. Direct plans take 374–502 ms, and relaying through a single GPU takes 366 ms.

This RFC proposes four things:

  1. Express the relay as two ordinary plan_transfer plans through an intermediate relay map. No new IR concept is needed, and exactness follows from the existing argument, stage by stage.
  2. Choose between direct and relay plans with a calibrated cost model:
    t ≈ max over resources r (bytes through r / capacity of r) + rounds · α_round + segments · α_seg.
    • The capacities come from calibrate_links / fit_links (#8966).
    • The per-resource bytes come from analyze_transfers (#8967).
    • One-time setup is priced separately, as a prepare cost spread over the syncs a plan serves.
  3. State the memory, coalescing and delta options the executor needs to make relay practical.
  4. Keep fabric differences out of the planner (§6):
    • the plan says what moves;
    • the cost model chooses among plans;
    • each transport declares what it can do.

The model was tested against measurements on four machines (GH200 + Slingshot, B300 + NVSwitch, B70 + PCIe, H100 + InfiniBand). It predicted the pipelined relay at about 93 ms before it was run, and the run measured 92.7 / 94.3 ms.

1. Relay as two plans

Let M_s be the source maps (for example the trainers' #8885 storage maps) and M_t the engines' target maps.

The relay map. M_r is any map onto relay GPUs on the target node that has one holder per element.

  • Rename (special case). When the source already has one holder per element and the relay locations line up, as with ZeRO-3 partitions and one relay per trainer rank, M_r is M_s with each source rank i renamed to relay(i): the same pieces, the same shard shapes, new locations.
  • Split (general case). Otherwise a rename either multiplies the traffic or is refused, so M_r splits the parameter along axis 0 instead. This is relay_map(source_map, relay_locations, min_split_bytes=...) in @0z5a's design (§5).

@0z5a's CPU check: one 4,096-element parameter, four relays, four engines that each hold it whole. Both stages were run by applying the plans' segments directly, and every accepted case was exact.

Source Relay map Stage 1 bytes / model Largest relay shard / model Sent from
ZeRO-3 partition rename 1.00 0.25 all four, evenly
ZeRO-1/2 replicas rename 4.00 1.00 rank 0 only
ZeRO-1/2 replicas split, default selector 1.00 0.25 rank 0 only
ZeRO-1/2 replicas split, selector picks the matching rank 1.00 0.25 all four, evenly
8 ZeRO-3 trainers, 4 relays rename i % 4 refused (InvalidMapError)
8 ZeRO-3 trainers, 4 relays split 1.00 0.25 all eight, evenly

The two stages:

  • Stage 1 = plan_transfer(M_r, M_s, replica_selector=...). With a one-holder M_r spread evenly over the relays, the model crosses the network exactly once, and with rail-aligned NICs each rail carries 1/W of it. Which source replica feeds each relay piece is the #8936 policy's choice. The table shows that this choice decides whether the load is spread.
  • Stage 2 = plan_transfer(M_t, M_r). An intra-node plan from the relay buffers into the engines' target maps, over NVLink. When every engine needs the whole model, this is an all-gather.

Both are ordinary plans, cached per layout like any other. Nothing in the planner changes for the basic version.

Exactness. Exactness does not depend on the rename: any M_r that passes the map checks works. A rename preserves every condition a map must satisfy: well-formedness, the destination partition, coverage, homogeneity and exact scaling. A split relay map is checked like any other map.

  • The correctness note's plan theorem ("any consistent plan is exact, for every replica choice, as long as the replicas agree") applies to each stage.
  • Stage 1 therefore writes exactly extract_r(F). Its replicas agree because they are copies of agreeing source replicas.
  • So stage 2 writes exactly extract_t(F). This is the parallelism-invariance corollary applied to M_s → M_r → M_t.

Where each condition is checked:

Condition Checked by When
Map conditions (tiling of every shard by address, full coverage, consistent holders, scale 1) plan_transfer's metadata checks, in O(pieces²), never per element at plan time, once per layout
Every element written exactly once, for any stride ParamAffineMap.validate_coverage() (O(numel) in Python) in tests only
The data itself: replicas agree, and the target matches the source a runtime digest of the moved tensors, compared after stage 2 after every sync

No check on a map can catch a map that is self-consistent but describes the wrong memory. That is the job of the digest.

The digest also catches the transport. On @LiRunGuo's two H100 nodes (torch 2.13, NCCL 2.29.7, InfiniBand with GPUDirect), a bare all_to_all_single, with no DeepSpeed code, misplaced one 128 KiB block about once per 60 TB when calls of 0.4–1.7 GiB per peer were in the mix (comment; reported as NVIDIA/nccl#2608). Each wrong block held bytes from 512 KiB or 1 MiB away in the same message. The plans replayed on CPU were exact. So the digest stays on at run time, and a weight whose digest fails is sent again and checked again. Its cost is part of the price (§4).

2. Relay memory

A separate relay buffer costs model / W per relay GPU: 2 GiB per GPU for the 8 GiB example above, and about 17.5 GB per GPU for a 70B bf16 model over 8. Two ways to avoid it:

  • Borrow idle memory (near term). The contract is that during a sync the engine lends one idle, contiguous region at a fixed address, at least model / W in size, and does not read it until stage 2 has finished. The KV cache between rollout rounds is the natural candidate.
    • One instance, measured by @0z5a: a vLLM engine paused at sleep level 0 lent 44 of its 45 GiB KV allocation. After a prefix-cache reset and resume, greedy outputs were identical token for token, and pause, lend and resume took 0.09 s.
    • At sleep level 1 the memory is released, and re-creating it took about 9 s on GH200. So only an engine paused at level 0 should lend.
    • That test covers the lender only. In the same experiment the borrower was a trainer allocating from the lent region, and that was not safe.
      • Step-0 gradient norms had relative errors of 1.0e-3 and 4.5e-3 in two runs, and 2.3% by step 1 in the first, against 1.4e-4 run-to-run noise.
      • The cause is not known (a reuse race is one guess), and that integration was dropped.
      • A relay only copies bytes and doesn't go through autograd, so it may not hit this. But writing relay data into a lent region has not been tested.
  • Write stage 1 straight into the engines' weights (long term). Each block lands in one engine that needs it, and stage 2 becomes an in-place all-gather among engines.
    • This needs no extra memory, but it needs plan_transfer to accept a target map whose pieces fill only part of each shard.
    • Today _shards_tile refuses such a target, by design.

3. Cost model

t ≈ max over resources r ( bytes through r / capacity of r )  +  rounds · α_round  +  segments · α_seg

Resources are everything a byte occupies on its way:

  • each GPU's network send and receive;
  • each NVLink link;
  • any shared link, such as a PCIe root port or a cross-socket hop.

They are separate resources: on GH200, a GPU receiving over NVLink and over the network at once is bound by whichever is slower, not by their sum (see the mixed incast rows below).

Pipelined stages cost the slowest resource's stage 1 plus the last stage-2 round, not t1 + t2.

Collectives such as NCCL's ring all-gather get their own calibrated cost per participant count, because ring efficiency varies with the GPU count (below).

Prepare and run. The formula is the cost of one run. A plan also has a one-time prepare cost:

  • validation;
  • the schedule digest;
  • staging allocation;
  • the transport's own setup, such as communicators or registered windows.

Today #8809 repeats the first three on every call. On a prepared handle, the staging arenas stay resident by default, so their allocation stays in t_prepare. A staged-only transport may release them explicitly, and its next run then pays allocation and view rebuilding again, so the policy prices that run with them added (@jinyouzhi).

A plan lives until either side's placement, parallel sizes or ZeRO partitioning changes (spec §10.5). So for a plan that serves n syncs, the policy compares t_prepare / n + t_run. A transport with a cheaper run and a costlier prepare wins only once that cost is spread over enough syncs.

Both costs are visible in the measurements:

  • On B300, a first call's setup was about 150–250 ms per ordered GPU pair (below).
  • #8809 also repeats its validation, schedule build, digest agreement and arena allocation on every warm call, so part of each warm call is prepare work as well (below and §5).
  • @jinyouzhi's symmetric-memory window paid about 1 ms of control plane per call until the transfer was prepared once (jinyouzhi/DeepSpeed#8).
  • Measured prepare and run (@jinyouzhi; fit in this comment). Qwen3-4B rebuild, row split to column split over N = 2 / 4 / 8 processes, staged prepared transfers (jinyouzhi/DeepSpeed#8):
    • Prepare grows with total segments: about 7.8 µs per segment on 8× B70 and 11.9 µs on 8× L20 from N = 4 to 8.
    • What prepare spends (breakdown), at N = 8 on B70 / L20: build_operations 42 / 76 ms and plan_digest 15 / 24 ms per plan, _validate_buffers 23 / 38 ms per request, _validate_aliases 7.5 / 11.6 ms, and the agreement all-gather 1.5–2.5 / 0.6–1 ms. So the fixed part is host-side Python, not a collective, and t_prepare is a per-segment term plus a per-tensor term.
      • Garbage collection adds a full collection to about every other prepare (each creates about 18k operation objects).
      • The 398 tensors have 8 distinct shapes, so a caller that shares plans across same-shape tensors removes most of the per-plan part.
    • Run on L20, refit with each process's regions (received, sent and local: about 1.6k / 2.2k / 4.2k at N = 2 / 4 / 8; fit): bytes per process plus a per-region term fits all three N within 4%, at 20.4 GB/s + 4.7 µs per region with 8 MiB staging and 23.4 GB/s + 9.3 µs with 64 MiB. A fourth N pinned it down (@jinyouzhi): fitted on N = 2, 4 and 8 at 8 MiB, the same model predicts N = 3, 5, 6 and 7 within 5.5%, at 4.8 µs per region.
      • At 64 MiB the larger constant is not a per-region cost: from N = 3 on, both budgets touch the same number of regions within 2%. The N = 8 / 64 MiB outlier is the host rebuilding about 2k views per round with only two rounds to hide it behind; caching the views brings it from 78 to 64 ms.
      • The per-region term is host time, the copy_ launches in _run, and it overlaps the bytes rather than adding to them: the final wait is 59–85 ms of the run at N = 2, and the device has already finished when the host reaches it at N = 8.
      • Fused copies (a prototype Triton kernel that copies each round's pack, each round's unpack and the local copies as one table of tiles per launch, with the tables built at prepare): the run is 15–18 ms plus the bytes at about 23 GB/s per process, within 5.5% at both budgets, and 1.5% faster than one copy_ per region at N = 2 and 17–32% at N = 8. Building the tables takes 70–230 ms in prepare. With fused copies, the regions term leaves t_run and joins t_prepare.
    • Run on B70 stays at 121–138 ms (64 MiB) while each process's bytes fall from 2.0 to 0.9 GB, which points to a shared link rather than each process's own.
    • Releasing the arenas, re-allocating them and running took 0.6–6.8 s on B70 at 8 × 64 MiB, against about 120 ms for a resident run.
  • A whole training-state move (@jinyouzhi), Qwen3-0.6B, ZeRO-1 DP4 → ZeRO-3 DP4 on 4× L20, 1.2 GB of bf16 weights plus 7.2 GB of fp32 master weights and Adam moments: maps 0.06 + plans 0.25 + prepare 0.08 + first run 0.23 = 0.62 s in the running processes, and 0.12 s for a repeated run once prepared. Through a universal checkpoint the same move took 27.4 s, plus a 10.1 s relaunch.

Inputs:

  • fit_links (#8966) gives the policy:

    • per-pair fits, one way and both ways at once;
    • relay fits keyed by (receive path, send path), for a process that receives while it sends;
    • fan completion rates keyed by peer set.

    The policy derives per-resource capacities from them. Colocated resharding and the all-gather stage use the both-ways fits; the relay GPUs of a pipelined relay use the relay fit.

  • analyze_transfers (#8967) gives each process's sent and received bytes, per-path bytes, and rounds.

  • The topology: each process's node, or #8966's link classes. A #8936 ReplicaRequest carries processes and bytes but not where a process sits, and a policy can be any callable object, so the cost-aware policy takes the topology when it is built. The planner needs nothing new.

  • Segments come from the plan.

Evidence

Fits use the medians from @0z5a's raw timings. Bold cases were not used to fit any parameter.

GH200, 2 nodes × 4 GPUs, Slingshot (one NIC per GPU), 8 GiB bf16 to 4 engines.
Capacities: 23.4 GB/s receive per rail, 52.1 GB/s per NVLink pair, 68.4 GB/s network send per GPU (fitted from the direct case).

Case Model (ms) Measured (ms)
Direct: each engine pulls everything from one trainer GPU 502 (fit) 502
Relay through one target GPU, 64 MiB pieces 367 366
Sharded direct: each trainer rank sends its shard to every engine 367 374
Two crossed flows (A0→B0, A0→B1, A1→B0) 91.7 91.7
Mixed incast, 50% NVLink + 50% network 45.8 46.0
Mixed incast, 80% NVLink + 20% network 33.0 33.4
Two-stage relay (sharded into node B, then all-gather), serial 91.7 + 19.9 = 111.6 112.4 / 113.5
Same, pipelined with 64 MiB buckets ≈ 93 (predicted before the run) 92.7 / 94.3
  • Incast is flat: 1, 2 and 4 senders into one GPU reach 23.4 / 22.7 / 23.4 GB/s, so on this fabric the policy should not cap inflow.
  • Rounds cost almost nothing on the network stage (1 vs 32 rounds: 93.4 vs 92.9 ms) and about 34 µs each on the NVLink all-gather.
  • Across the 16, 64 and 256 MiB bucket sizes, in both orders, "stage 1 + the last all-gather round" is within 3.3% of every pipelined run.

H100, 2 nodes × 4 GPUs, InfiniBand (one NDR200 NIC per GPU), @LiRunGuo's 54 transfers of Qwen3-8B and 32B: syncs from a ZeRO-3 trainer on node 0 into replicas on node 1, and replicas growing onto node 0, shrinking back, or changing TP size, each as flat, relay + pipe, and relay + pipe + spread (fit).

  • Capacities: 24.2 GB/s per NIC plus 20.4 ms, from the three 32B flat syncs (within 0.4%; 97% of NDR200's 25 GB/s), and 82 GB/s per GPU inside a node, from six 8B moves on node 1. The GPUs are H100 SXM, so this is low for NVLink, and which intra-node transport NCCL uses is still to be checked.
  • Held out (33 transfers): network-only moves within −7% to +8% for 8B, and relay + pipe + spread within −1.3% to +4.0% at two replicas per node.
  • Not priced yet:
    • relay + pipe and relay + pipe + spread move the same bytes per rank, yet spread is 1.11–1.58× faster. The difference sits in the all-to-alls that carry embed_tokens and lm_head (per-step data), so the pipelined term needs each rank's inter- and intra-node bytes per all-to-all. It then becomes a sum over the all-to-alls of the slowest rank's step, which reduces to stage 1 plus the last stage-2 round when the buckets are even;
    • the 32B reconfigures, 16–18% over the network term. All of it is in the first all-to-all, 156–166 ms longer than its bytes take at the later steps' rate. Building the new layout without a barrier before the move probably counts the ranks' allocation wait as move time; without that wait they sit 4–7% under the network term;
    • a replica grown onto the trainer's GPUs, whose first all-to-all carries the same wait. These rows are to be rerun with a barrier, with per-rank local bytes and regions.
  • The choice: with two or more replicas per node, flat is 1.9–3.3× slower than the best relay, and the model picks a relay every time. Where plans move the same bytes the model ties; breaking ties toward spread, it picks the fastest plan or one within 1.3% of it in 13 of the 14 cases (the exception is +14.7%).
  • The source matters as much as the plan: reading from both the old replica and the trainer's partitions, a replica grows onto the trainer's node 4.7–5.3× faster, because nothing crosses the network. That choice needs holders in two layouts (#9052, and #9070 for column cuts).

B300, one node, 8 GPUs on NVSwitch.

  • Capacities: 699 GB/s receive and 716 GB/s send per GPU, flat from 1 to 7 peers.
  • NCCL ring all-gather of 8 GiB: 9.7 / 10.8 / 11.2 / 12.4 ms on 2 / 3 / 4 / 8 GPUs. That is 1.58× to 1.15× the bytes/capacity bound, so collectives are calibrated separately.
  • NVLS was slower than ring at 2–4 GPUs, and NCCL's default chose ring at every size tried.
  • The #8809 executor is linear in rounds at 8 GPUs: 35.2 / 67.0 / 371.0 ms at 4 / 16 / 128 rounds, i.e. 2.71 ms per round with 64 segments. The warm Qwen3-4B calls below split that into a round cost and a chunk cost. At 2 GPUs the cost per round grows from 0.16 to 0.30 ms as the staging shrinks.

Segments dominate a real model. Rebuilding Qwen3-4B (398 bf16 tensors, 8.0 GB) on B300 with the #8809 executor (64 MiB staging) makes one plan per tensor. @0z5a timed a first call and a second call in the same process, with the same plan and communicators:

GPUs Segments Rounds First call (ms) Second call (ms)
2 1,592 78 471 / 394 66.9 / 66.7
4 6,368 32 1,939 132.8
8 25,472 16 10,476 611.4

(Two launches at 2 GPUs. Earlier one-shot first calls on other days took 449 ms at 2 GPUs and 14.5 s at 8.)

  • Most of a first call is one-time setup: communicators, allocator growth and first-use paths, not broken down. The second call is 6–7× faster at 2 GPUs and 17× faster at 8.
    • The setup grows roughly with the number of ordered GPU pairs, about 150–250 ms per pair. The per-launch values are 151, 164, 176 and 202 ms here, and 191 and 248 ms for the earlier one-shot calls.
    • So it belongs in a prepare cost, paid once per plan and process, not in the cost of every sync.
  • Even warm, 8 GPUs take 611 ms against about 10 ms of bytes/capacity. Much of that may be prepare work that #8809 repeats on every call.
    • @0z5a's CPU prototype (gloo, the same segment counts, Qwen3-4B shapes divided by 16) caches that work once. At 8 ranks, a warm call took 701 ms on that machine, 546 ms of it before the first byte moved. Caching the prepare work brought it to 144 ms, and caching the region views as well to 72 ms.
    • That is a laptop CPU with no GPU launches, so the numbers don't transfer to B300 directly. The prediction for B300 at 8 GPUs is ≤ 350 ms with prepare cached. If it lands above 450 ms, prepare isn't the main term there, and coalescing goes first.
    • So the order is: cache the prepare work first, then measure what coalescing still buys.
  • Round and chunk costs. These fits combine the warm calls with the staging sweep above. A chunk is a segment, or a staging-sized piece of one.
    • At 8 GPUs: 24.0 ms + 1.29 ms · rounds + 0.178 ms · chunks per process fits all four points (errors −0.9, +0.5, 0 and 0%). That's three parameters on four points, so one more staging size would be a useful check.
      • The 24 ms term is equivalent to the bytes at an effective ~310 GB/s, well below the 699 GB/s the links carry.
      • With bytes/capacity at 699 GB/s (10.75 ms) instead, about 13 ms per call is unexplained.
    • At 2 GPUs: about 0.06 ms per chunk per process, with the round cost bending as staging shrinks (above).
    • Across GPU counts: one set of constants for all GPU counts misses some points by more than 2×. Before calibrating per GPU count, try @0z5a's split of the chunk term:
      • α_schedule · total chunks for prepare, which grows with the GPU count;
      • α_copy · regions this process touches for run (5,970 at 8 GPUs: 2,786 packs, 2,786 unpacks, 398 local copies).

B70, one node, 8 GPUs on PCIe (from @jinyouzhi on #8966).

  • Pair bandwidth ranges from 3.6 to 54 GB/s depending on sender and direction.
  • At width 2, fan-in completion ranges from 12.6 to 55.2 GB/s depending on which senders feed the receiver.
  • This is why resources include shared links and why fit_links keys fans by peer set: each of the three cases discussed there is bound by a different resource (a sender's link, the receiver, the cross-socket link).

4. Delta transfer

Between GRPO steps, only about 1–2% of bf16 weight elements change. An element changes only when its fp32 master moves past half a bf16 ulp. A lossless sparse delta (indices and values) through the affine path sends just those.

Measured end to end (@0z5a):

  • Setup: a trainer on one B300 GPU behind a 10 Gb/s NIC, and rollout on two GH200 nodes, each receiving over a 1 GbE link.
  • Transport: plain TCP over ssh (an int32 index and a bf16 value per change), not #8809 or NCCL.
  • Over 7 GRPO steps of Qwen3-4B, 0.90–1.37% of elements changed per step, i.e. 0.43–0.66 GB per step to the two receivers combined.
  • The delta sync took 3.4–6.3 s per step (median 4.1 s), not counting the per-sync digest check. A full 8 GB push would take about 70 s per receiver at that link rate.
  • Digests over all 796 regions matched, at step 0 and at the end.
  • Pricing each receiver's delta bytes against its link gave 2–3.5 s, below the measured time. The gap is the sender's copy, not the network.
    • The sender copies each target's payload GPU → host → bytes, one target after the other, before any send starts.
    • That takes about 0.53 s per 332 MB target, 23–25% of the sender's communication time.
    • Without it, each receiver got 0.092–0.106 GB/s (median 0.098), its single-pair rate.
  • The shared 10 Gb/s sender port was not the limit at two receivers (about 0.2 GB/s, ~16% of the port). Each receiver's 1 GbE link was.
    • A single-receiver decomposition confirms the cap. The real sender and wire format reach 0.102 GB/s, the same as a raw ssh pipe (0.103). Two flows into one receiver total 0.104–0.111 GB/s.
  • So the model prices this sync as delta bytes / 0.10 GB/s per 1 GbE receiver, plus a sender-side copy term.
    • The copy term is about 0.6 GB/s per target, serial in the current code. A chunked double buffer would overlap it.
    • Two runs are still to do: a direct fan run (both receivers at once) and a 1-vs-2-sender split test. Both need a GH200 node that is down, so there is no date yet. Until then, the fan factor of 1.0 is unmeasured.
  • Over NVLink, delta does not pay: 1.19 s against 0.39 s for the full transfer.
    • About 0.8 s of the 1.19 s isn't in any timer yet.
    • The same run's break-even bandwidth, about 32 GB/s, is the better number. It is an overestimate if part of that 0.8 s is specific to delta.
    • That run changed 1.6–2.2% of elements.

The policy prices delta and full the same way: encode/decode and copy time, plus bytes / capacity, plus the digest (below).

Correctness condition: both sides must start from the same previous version, bit for bit. So the digest has to run after every delta, and any mismatch falls back to a full sync.

  • This matters in practice. In a dry run that dropped one index on one receiver, a digest checked only at the end passed, because a later delta happened to rewrite that element.
  • A digest after every sync caught it at the first sync.

The digest needs its own term in the price. The sync times above exclude it.

  • As coded (sha256, serial, after resume), one check took 29.3 s at step 0 and 14.7 s at the end. Checking every step would add about 15 s to a 3.4–6.3 s sync.
  • That cost isn't inherent. A GPU-side region checksum should be far cheaper (@0z5a has a prototype tested on CPU).
  • The check could also run during rollout, at the price of finding a bad delta one step later.

5. Planner and executor

(@0z5a)

  • Planning: two plan_transfer calls, cached per layout. The policy evaluates the model for direct, relay, sharded and sharded + gather, and keeps the cheapest.
  • Execution: #8809's bounded peer staging runs both stages.
    • Stage 2 starts on bucket k as soon as stage 1 has landed it.
    • 64 MiB buckets were best on Slingshot. On NVSwitch, larger staging keeps paying (8 / 64 / 256 MiB: 371 / 67 / 35 ms).
  • Coalescing: in the schedule, not in a map. Per-tensor plans keep the exactness argument per plan, and merging only changes how a round's regions are addressed.

The full design is in @0z5a's comment: https://github.com/deepspeedai/DeepSpeed/issues/9026#issuecomment-6708313633

  • prepared transfers, with schedule state on a handle;
  • relay_map;
  • coalescing and adjacency-based direct rounds;
  • pipelining through a gate table computed at prepare.

The proposed order of PRs, each useful alone:

  1. staged prepare/run: #9094 by @0z5a (approved), on #9027 (merged), with the structure of jinyouzhi/DeepSpeed#8; the fused copy and window transport follow as #9118 by @jinyouzhi;
  2. relay_map and the serial relay;
  3. flat relay and adjacency-based direct rounds;
  4. pipelining;
  5. small tensors, and the receive side, as the numbers from step 1 direct.

Training-state moves (#9074, @LiRunGuo). The split proposed there for upstream, each piece after this RFC:

  1. ZeRO-3's rank-agreement checks and barriers over the partition group (#9076);
  2. the training-state move on plan_transfers + execute_transfers, with DP4 → DP2 → DP4 as its test. @jinyouzhi suggests it cover the wider matrix of DeepSpeedExamples#1021 (ZeRO stage, AutoTP and AutoEP size changes);
  3. the relay as two plan_transfers calls through a relay map (open question 1);
  4. the pipelined execution, after #9027.

The rectangle planner and NativeRollout stay out. A move across TP or EP sizes inside the same processes also needs each engine to hold its own parallel groups (#9081).

6. Layers, and where the fabric enters

Fabric differences touch three layers differently. Examples: GPUDirect or not, host staging, one-sided windows. (Prompted by @delock's question; the current-state details are from @0z5a.)

Layer Decides Where it lives today Sees the fabric?
Plan which source region feeds each target region, from which replica; merging adjacent segments plan_transfer (#8623): replica_selector, _coalesce; batch policy plan_transfers (#8936) No. Exactness lives here, so the fabric changes how fast a plan runs, never what it writes
Plan choice direct vs relay vs sharded, bucket size, transport proposed in this RFC. #8966 and #8967 measure and report only; #9027's schedule_transfers exposes the executor's rounds, directness and arena sizes per process, which can feed the round term without mirroring executor logic. Nothing chooses today Only through calibrated numbers
Transport how bytes move the #8809 executor Yes

The executor today (#8809):

  • Schedule agreement: before anything moves, all ranks agree on a digest of the schedule. If any rank rejects it, nothing moves.
  • Ordering: each round posts all receives before any sends, in one batch_isend_irecv.
  • Messages: one packed message per peer per round.
    • A round goes in place only when it has exactly one region and that region is contiguous; each side decides separately.
    • Otherwise the round is packed through a per-peer staging arena bounded by StagingBudget (default 8 MiB per peer, per direction).
    • Large regions are split into budget-sized rounds.
  • Buffers: they must be on the current accelerator device when distributed is initialized (CPU otherwise), contiguous, and all of one dtype.
  • Rank numbering: source and target ranks are mapped separately (TransferEndpoints). Copies within one process skip the transport.
  • Limits: the call is synchronous (no CUDA graphs, no overlap with compute), and only scale == 1 is planned.

Transport capabilities. Fabric-specific code stays in the transport. It declares what it can do, detected by capability rather than by device name, so the planner never branches on the fabric. A declaration states three properties for a pair of processes (on the same host, or across hosts), not for a device (@jinyouzhi):

  • What one transfer can address on each side: packed, one contiguous run per peer per message (which is why staging exists); regions, a list of (offset, length) or strided regions in registered memory, as with RDMA scatter/gather; or mapped, peer memory that this process can load from and store to directly.
  • Who moves the bytes: two-sided, where both ends post and the receives are armed first; or one-sided, where one end moves the bytes and signals the other (pull, push or put). Completion is either stream-ordered signals or a group fence.
  • Which memory and registration it needs: device or pinned host memory (host staging is the device → host case), and whether the buffers must lie in a registered window, which is collective, has fixed addresses and outlives the prepared handle.

In these terms, #8809's staged path is packed, two-sided, device memory, no registration; the window path of jinyouzhi/DeepSpeed#7 is mapped and one-sided within a host, registered; the put path of jinyouzhi/DeepSpeed#9 is packed on both sides and one-sided across hosts, registered. The executor picks each operation's path per pair from these properties, as jinyouzhi/DeepSpeed#9 does in _mapped_direction, and finds the capabilities by probing. NCCL M2N sits outside this per-operation scheme, as a whole-request path (open question 6).

Each declared path is calibrated like any other resource, and the cost model chooses among paths, prepare and run included (§3). Candidates:

  • host staging, for accelerators without a device-to-device path;
  • GPUDirect RDMA scatter/gather. The #8809 docstring notes that it changes the per-peer message contract.
  • @jinyouzhi's prototypes: symmetric-memory windows within a node and NCCL put/signal across hosts (jinyouzhi/DeepSpeed#7, jinyouzhi/DeepSpeed#9).

PXN is not the relay. NCCL may route an inter-node send through an NVLink peer nearer the NIC (PXN). That is NCCL's own choice, made with or without staging, per message and invisible to the planner. The relay in §1 is planned explicitly and priced by the model.

PXN matters for calibration: a "direct" network sample may already include a PXN hop. So calibration should record the NCCL PXN settings (NCCL_PXN_DISABLE, NCCL_P2P_PXN_LEVEL) and the transport lines from NCCL_DEBUG=INFO with each fit (@0z5a).

Related work: NCCL M2N

NCCL M2N (NVIDIA, arXiv:2610.07516; nccl_m2n in NVIDIA/nccl-extensions) reshards a tensor between two disjoint process groups, each described by a DTensor-style mesh with Shard/Replicate placements.

What it shares with this RFC. Its hierarchical schedule is the relay idea: each unique source contribution crosses the network once per destination NVLink domain, and leaders forward it to replicas over NVLink. Its speed-of-light bound, max(T_network, T_NVLink), has the same max-over-resources form as the cost model above.

The differences that matter for DeepSpeed:

  • Layouts. M2N's local tiles are contiguous and equal-sized per rank. DeepSpeed's often are not: uneven head-aligned AutoTP splits, fused and interleaved QKV, replicated blocks inside a sharded tensor, ZeRO flat partitions. The affine maps describe all of these.
  • Groups. M2N requires disjoint source and destination groups. Colocated resharding on the same GPUs is in scope here.
  • Exactness. Here, the correctness argument's conditions are checked at plan time, and the data is digested after each sync. The M2N paper validates its output bitwise in its benchmarks.
  • Choosing plans. M2N derives its schedule from the two layouts. Here, a calibrated model chooses among direct, relay and sharded plans per fabric, which matters on non-uniform fabrics such as the B70 PCIe tree above.

Where it helps. M2N is a native NCCL transport, and per-call and per-segment overhead is the main overhead this RFC measures. Using M2N, or its approach, as an execution backend for the affine plans it can describe is worth evaluating. So far (open question 6), it fits as a whole-request path rather than as a backend for a plan's segments.

Open questions

  1. Partial targets in plan_transfer (for in-place relay): an explicit flag, or a separate entry point, so the default keeps refusing a target that does not tile its shards?
    • @LiRunGuo's alternative (comment): each relay shard is the band of its holder's own destination, so it is a view of the engine's weights and a whole shard, and no partial target is needed. Stage 2 then copies each band onto itself, which is skipped, but #8809's _validate_aliases refuses the stage because a relay rank's source lies inside its own target. The executor would have to allow that when no segment reads what another one writes.
    • #9074 implements this formulation (affine_plan.py). @LiRunGuo's proposal for the executor (comment): drop a local segment whose source and target are the same memory with the same strides, and check overlap only on what the remaining segments read and write.
    • Answered by @0z5a (comment): #9093 makes that change. The whole-buffer check stays the fast path; when buffers overlap, the executor checks the regions each process reads and writes, and drops a local copy whose source and target are the same memory at the same strides, counting its region as read. relay_map takes the bands as its definition, so no partial-target flag is needed, and min_split_bytes only decides which weights are relayed.
  2. Coalescing across tensors: @0z5a proposes doing it in the schedule rather than in a map. On the receive side, a tensor's rows come from different senders, so what helps there: unpacking with cached views, or gathering into a sender-ordered buffer and then assembling?
    • @jinyouzhi's answer on 8× L20 (comment): gather into the sender-ordered arena and assemble with one copy kernel per round, prepared once. Cached views change the run by less than 1% up to N = 6 at 8 MiB; the fused kernel is the fastest at every N and budget (§3). Open: a kernel that also covers XPU (the Triton XPU backend or a SYCL kernel), with copy_ kept for views it cannot describe as rows of contiguous columns.
    • Order, from @0z5a (comment): the fused copy comes after the prepared transfers, as its own PR, with copy_ as the default path. #9094 keeps each round's pack and unpack copies in one list on the handle, so a per-round table can replace that list without changing prepare or run.
  3. Candidate plans: is enumerating direct / relay / sharded / sharded + gather enough at first, or should the policy search?
  4. Round and chunk costs: fitted on B300 at 2 and 8 GPUs, from the staging sweep plus warm calls. Does the prepare/run split (α_schedule · total chunks + α_copy · regions touched) explain the dependence on GPU count? Prepared-transfer timings on B70 and L20, with a breakdown of prepare and per-process region counts, now exist (above). On L20, a fourth N and fused copies pinned the run term (§3): about 5 µs of host time per region, overlapping the bytes, and nothing per region once the copies are fused. Still needed: rows on B300 and GH200.
  5. Other fabrics: multi-node InfiniBand, measured by @LiRunGuo (comment): 2 nodes × 4 H100 with 4 × NDR200 per node, a ZeRO-3 trainer on node 0 syncing into rollout replicas on node 1, every sync digest-checked.
    • A "flat" sync, where every replica pulls its own copy, takes 1.04–1.08× of its inter-node bytes over the node's four NICs at 25 GB/s, for Qwen3-8B and 32B at 1, 2 and 4 replicas. The network term alone prices it.
    • With 2 and 4 replicas, relay + pipelining + spreading large weights over the ranks takes 1.11–1.30× of one model over the NICs, and the remainder grows with the replica count.
    • His 54 transfers are fitted in §3. Open: per-step bytes for the stage-2 term, a rerun of the reconfigures and grows with a barrier before the move, and the intra-node topology and NCCL transport.
  6. NCCL M2N as a backend: for plans whose layouts M2N can describe, how does it compare with #8809 on the same hardware, and can a plan's segments be handed to it?
    • One data point (@0z5a, B300, 2→2 with Qwen3-4B shapes, all bit-exact, median of five warm calls), to TP2 (8.05 GB) / to two TP1 (16.09 GB):
      • nccl_m2n PACK, one reshard per tensor: 24.8 / 36.0 ms;
      • #8809 at 128 MiB staging: 39.3 / 43.6 ms;
      • #8809 at the default 8 MiB: 66.6 / 101.5 ms;
      • NCCL, one message per GPU pair: 6.0 / 11.6 ms.
    • M2N's Group API and DIRECT mode hung at the first call in that setup.
    • The #8809 rows include the prepare work it repeats on every call, so this is to be repeated with prepared transfers before reading anything into the gap.
    • With prepared transfers (@jinyouzhi, comment), on 8× L20 (PCIe, no NVLink), 4 → 4 over disjoint groups, every Qwen3-4B weight (8.04 GB), all bit-exact, medians of five warm runs: M2N PACK, one reshard per tensor, 259.1 ms; prepared #8809 113.9 / 119.8 ms at 8 / 64 MiB, and 112.4 / 115.7 ms with fused copies. The gap is bandwidth, not per-call overhead: on the 778 MB embedding alone M2N reaches 31 GB/s. DIRECT and PIPE need GPU-initiated networking and did not run there, the Group API failed in ncclDevCommCreate, and M2N's first call costs about 850 ms.
    • On handing it a plan's segments: not as segments. M2N takes a whole tensor per call, described by a mesh and Shard/Replicate placements with equal tiles. So it fits as a whole-request path: the policy chooses it when both maps can be written as M2N placements and the groups are disjoint, and calibrates it like any other path.
    • On @LiRunGuo's InfiniBand setup (Qwen3-8B, 2 nodes): his relay plans were 3–13% faster than M2N's default PACK transport, and both were exact. M2N's beta PIPE transport returned wrong values in 3 of 4 layouts. That comparison uses his bucketed all_to_all_single, not #8809, and is to be repeated with prepared #8809 transfers.
  7. The transport declaration: what is the smallest set of capabilities that covers host staging, RDMA scatter/gather and one-sided windows? For prepared state, @0z5a's answer is that schedule state lives on the prepared handle, and transport state such as windows hangs off it.
    • For the capabilities, @jinyouzhi's answer (comment): three properties per pair of processes, now in §6: what one transfer addresses on each side, who moves the bytes, and which memory and registration it needs.
    • For staging, @jinyouzhi's answer (comment):
      • run checks the handle by default, on all three paths (staged, direct and window): the buffers a caller passes are views of the old storage, so even staged copies don't follow a moved buffer (correction). jinyouzhi/DeepSpeed#8 (a8c34e3) compares each buffer's data_ptr, size, dtype and device with what prepare recorded and combines the result with a one-element all-reduce, so if a buffer moved on any rank, for example after reload_states(), every rank raises before data moves;
      • arenas stay resident on the handle, sized from what the schedule needs (#9027 reports it per process) rather than budget × peers;
      • prepare may take caller-provided storage, such as the lent region of §2, under its fixed-address contract;
      • a rank-uniform release_staging() frees them for staged-only transports, while window transports keep them pinned.
  8. One weight held in two layouts (from @LiRunGuo: a surviving TP shard and the trainer's ZeRO-3 partitions). plan_transfer refuses it, since two source regions must be equal or disjoint. Cutting each layout's pieces at the other's boundaries, with the union of holders on each piece, makes it plannable without a planner change.
    • On CPU, over 300 random small cases (uneven TP sizes, any subset of surviving ranks, 1–6 ZeRO-3 partitions), every row-split case was accepted and exact (137 of 137).
    • For a column split, a cut ZeRO-3 box that spans several rows is no longer a dense run of the flat partition, and the planner refuses it (84 of 163). One piece per row is accepted, but exceeds max_pieces_per_map for large weights.
    • Done: #9052 and #9070 are merged. Agreed answer: the constructor is #9052, row case first. For the column case, @0z5a's planner change, #9070, accepts a flat shard whose pieces sit at the parameter's own row-major strides, with one shift for the whole shard. With #9052 on top of #9070, every random two-layout case on CPU plans exactly into both a row-split and a column-split target, including the 82 column cuts per target that #9052 alone refuses (comment). The correctness note gets the matching tiling lemma.

Who does what

Part Owner
Exactness argument, cost model (#9145; prepare/run and the choice of transport), a weight held in several layouts (#9052), and the cost-aware policy on #8936 @Achyuthan-S
Two-stage planning (relay_map), executor staging, prepared transfers (#9094) and pipelining, the region alias check (#9093), coalescing in the schedule, schedule_transfers (#9027) @0z5a
Calibration and plan analysis (#8966, #8967) @jinyouzhi
Transport prototypes as transport state on the prepared handle: symmetric-memory windows and NCCL put/signal (jinyouzhi/DeepSpeed#7, jinyouzhi/DeepSpeed#9), fused copies and the window on prepared transfers (#9118); prepared-versus-staged numbers on B70 @jinyouzhi
InfiniBand measurements; the rollout's shard-to-shard path on plan_transfer; ZeRO-3 over a subgroup (#9076) and the training-state move (#9074); a layout-independent digest kernel (offered) @LiRunGuo

Measurements: GH200 and B300 by @0z5a; B70 by @jinyouzhi; InfiniBand (H100, NDR200) by @LiRunGuo. Feedback welcome, especially from @delock.

Ngôn ngữ chính
Python
Star
43.3k
Fork
5.1k
Merge trung bình
5 ngày 10 giờ
Pull request đã merge (30 ngày)
85

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của deepspeedai/DeepSpeed

Tất cả issue của deepspeedai/DeepSpeed

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.