Repository navigation
[HIP] fea: impl gfx1250 lamport allreduce - #7927
Conversation
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
Route the gfx1250 plain all-reduce through Lamport kernels on the shared Lamport inbox: a one-shot up to 1.25 MiB at TP4 and 9 MiB at TP2, and a new two-shot (pushed reduce-scatter + all-gather) above it, up to world_size x the Lamport cap (32 MiB at TP2/TP4). fp16/bf16 only; same bits as the custom all-reduce (rank-order fp32 sum). The plain all-reduce cutoff of CudaCommunicator.all_reduce (#7432, 4 MiB at TP2/TP4, RCCL above) no longer applies to the inputs the Lamport kernels take: they stay ahead of RCCL up to world_size x the cap. Other inputs keep the cutoff. The two-shot's all-gather gets a private inbox of world_size x cap after the escape inbox (per-rank Lamport buffer 120 -> 152 MiB at TP2/TP4); the shared inbox, the cap and the other Lamport ops are unchanged. Signed-off-by: TennyWang1223 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
ab0efca to
f11d1be
Compare
|
aiter-bot — queued behind 1 review(s); expect to start in about 22 min. The box reviews one PR at a time. |
|
Review ownership / next action:
I will wait for the communication primary review rather than approve ahead of it. |
aiter-bot
left a comment
There was a problem hiding this comment.
ROCm/aiter PR #7927 — [HIP] fea: impl gfx1250 lamport allreduce
Review (advisory):
Validation (deterministic): NOT RUN — auto-validation disabled (REVIEW_AUTO_VALIDATE=0) and no gfx1250 GPU on this review box (8x gfx942); the target op_tests/multigpu_tests/gfx1250_poc/test_gfx1250_lamport_allreduce.py exists but cannot run here (the CPU-only gate test test_custom_allreduce_size_env.py was run by hand against the head files: 16 passed; the gfx1250 kernel tests were not run)
Perf (advisory): NOT RUN — the perf stage has no entry point for the target (no --scenario bench / perftest harness) and this gfx942 box cannot run the gfx1250-only timing harness; the PR's tables (TP2 1.43–6.73x, TP4 1.02–3.30x vs main) are author-run on one 4x gfx1250 box
Size: 1047 lines / 9 files — over the review bar
Design (advisory): SPLIT — (1) the ADD template-param refactor of lamport_ar_1shot_gfx1250 with the AR+add path re-verified, (2) the lamport_ar_2shot_gfx1250 kernel with its private all-gather inbox plus the C++ entry, pybind and op plumbing, (3) the Python routing (select_lamport_ar, should_lamport_ar, the should_custom_plain_ar / custom_all_reduce gates) with its three test files
Human: recommend valarLip review whether PR #7927 rerouting every gfx1250 TP2/TP4 fp16/bf16 plain all-reduce up to 32 MiB off the LL kernels and RCCL onto the one-shot/two-shot lamport_ar_2shot_gfx1250 split (and growing the per-rank Lamport inbox 120 -> 152 MiB for it) is the right default for all TP model families
car candidate with the Lamport cap forced to 0) before merging the new default route.
📝 The PR carries an AI-attribution footer and two structural checks fired (the NaN-bits asymmetry above and the "same bits" claim it contradicts), so this is elevated-AI-code risk despite an unusually thorough self-review: the re-arm-safety argument for the private all-gather inbox is author-authored and only its consequences are tested. Reviewer should ask for thorough manual verification of the two-shot dispatch logic and the routing gates (select_lamport_ar, should_custom_plain_ar) before merge.
1 finding(s) posted inline, on the lines they are about:
csrc/include/custom_all_reduce_gfx1250.cuh:1690-1698— lamport_ar_2shot_gfx1250 canonicalizes its output (0xffff → 0x7fff,…
…lit norm where it wins fused_allreduce_rmsnorm now runs the Lamport two-shot all-reduce (#7927) followed by the split add + RMSNorm instead of a fused kernel: - above the Lamport one-shot AR + RMSNorm cap (8 MiB) up to the two-shot's 4 x cap (32 MiB), where the fused kernel syncs through the barrier; - for hidden 6144, also in (2, 4] MiB and (6, 8] MiB, where the fused one-shot steps up past 256 and past 512 rows. TP4, hidden 6144 bf16, CUDA graph replay on 4 x MI455X, us per call (slowest rank's median), before -> after: rows 192 (2.2 MiB) 15.7 -> 13.2 rows 683 (8 MiB) 38.8 -> 29.3 rows 256 (3 MiB) 16.5 -> 13.9 rows 1365 (16 MiB) 59.1 -> 42.7 rows 341 (4 MiB) 22.2 -> 15.1 rows 2048 (24 MiB) 77.3 -> 56.5 rows 544 (6.4 MiB) 33.4 -> 27.5 rows 2730 (32 MiB) 96.1 -> 72.9 Unchanged outside these ranges (24 / 128 / 512 / 2731 rows). residual_out keeps its bits; out differs in the last bf16 bit of about 1 value in 1e5 (the norm is the split kernel's). The decision uses shapes, dtypes and the cap only. AITER_LAMPORT_SPLIT_AR_NORM=0 restores the old routing. Only TP4 and (under the cap) hidden 6144 were measured, so only those are routed. Co-Authored-By: Claude Fable 5.2 <[email protected]>
#8012 @ c3b4113, head 2026-11-16T06:45:00Z) Applied as the PR diff onto the rebased 1116 tree; PR state: draft. Conflicts resolved by keeping both sides (both PRs add different opt-in routes next to each other): communicator_cuda.py (#8015 Lamport one-shot check, then this PR's INT4 two-shot check), custom_all_reduce.py (constants, both symm_mem inits, both init methods), custom_all_reduce_gfx1250.h / pybind (main's #7927 allreduce_lamport and fused AR+RMS+quant declarations kept next to this PR's q4 declarations). (cherry picked from commit 1bb791e) Rebase onto main 12-03: #8015 (one-shot + symm_mem inbox) is not carried: main's #7937 final builds the Lamport inbox on every transport and routes plain all-reduce itself (should_lamport_ar(inp, two_shot)). So _LAMPORT_AR_MAX_SIZE / _init_lamport_symm / should_lamport_ar / lamport_all_reduce and the communicator's one-shot branch from #8015 are left out; the symm_mem init calls main's _init_lamport_ar_rms, then this PR's _init_lamport_q4_2s(symm=True). pybind keeps main's allreduce_lamport(split=False) next to the q4 bindings.
Summary
Route the gfx1250 plain all-reduce through Lamport kernels. On TP2/TP4, fp16/bf16 inputs up to world_size x the Lamport cap (32 MiB at both) now run one of two kernels:
Both entries (
tensor_model_parallel_all_reduceandCudaCommunicator.all_reduce) reach it throughCustomAllreduce.custom_all_reduce. The plain all-reduce cutoff from #7432 (4 MiB at TP2/TP4, RCCL above) no longer applies to the inputs the Lamport kernels take: they are faster than RCCL up to 32 MiB. The result has the same bits as the custom all-reduce: a rank-order fp32 sum, rounded once. The one exception is the NaN payload: a 0xffff half-word is the Lamport "not arrived" sentinel, so it is sent as 0x7fff (still a NaN), and the two-shot also does this to the sum it hands to its peers. A NaN stays a NaN on every path, and every rank writes the same bits. fp32, larger inputs, TP6/TP8 and other archs keep their current route.Motivation
On main, the gfx1250 plain all-reduce at TP2/TP4 runs the LL one-shot
ar_ll_gfx1250, at TP4 the LL two-shotar_2s_ll_gfx1250from 1 MiB (#7432), and RCCL above 4 MiB (_GFX1250_PLAIN_AR_MAX_SIZE). The Lamport protocol from #7499 needs no barrier, no registered input and no copy-in. #7499 and #7861 already use it for the AR + RMSNorm, AR + add and all-gather, and it now covers the plain all-reduce too. On 4x gfx1250 it is faster than the LL kernels and RCCL at every size from 1 KiB to 32 MiB (tables below).A one-shot alone stops at the cap (8 MiB at TP4), because every rank pushes the whole message into each peer's slot. The two-shot pushes only
1/world_sizeof the message per peer in each of its two steps. So it fitsworld_sizex the cap in the same shared inbox, and it is also faster than the one-shot from about 1.3 MiB at TP4.Changes
custom_all_reduce_gfx1250.cuh):lamport_ar_1shot_gfx1250: the Lamport AR + add kernel with abool ADDtemplate parameter.ADD=falseis the plain all-reduce. The AR + add (ADD=true) is unchanged.lamport_ar_2shot_gfx1250(new): threadtowns packtof each rank's chunk.tof chunkgto rankgthrough the shared inbox, taking one round of the per-wave round counters as every Lamport op does. So it interleaves freely with the other Lamport ops.world_size x cap, armed with0xff) is appended after the escape inbox of [HIP] fea: impl gfx1250 lamport allgather #7861. The shared data inbox, the escape inbox, their offsets and the cap are unchanged. The other Lamport ops keep their size ranges.allreduce_lamport_gfx1250(fa, inp, out, two_shot). It checks the size against the cap for the one-shot, and againstworld_sizex the cap for the two-shot.custom_all_reduce.py):custom_all_reducefirst asksselect_lamport_ar. That requires fp16/bf16, a contiguous input, and at mostworld_sizex the Lamport cap. It picks the one-shot up to_LAMPORT_AR_1SHOT_MAX_BYTES(TP2 9 MiB, TP4 1.25 MiB, the measured crossovers), and the two-shot above that.should_custom_plain_ar(the gate ofCudaCommunicator.all_reduce) also passes an input thatselect_lamport_artakes, above the plain all-reduce cutoff. Everything else keeps the cutoff, so fp32 and inputs above 32 MiB still go to RCCL above 4 MiB.should_custom_ar, soAITER_CUSTOM_AR_MAX_SIZE/AITER_CUSTOM_AR_MIN_SIZEstill bound them._lamport_aligned), as for the other Lamport ops.should_lamport_ar(inp, two_shot)andlamport_all_reduce(inp, two_shot): the gate and the direct entry.op_tests/multigpu_tests/gfx1250_poc/test_gfx1250_lamport_allreduce.py(new): performance, correctness and a routing check.op_tests/multigpu_tests/test_custom_allreduce.py: the gfx1250 LL mixed-size regression now sets the Lamport cap to 0, so that its bf16 sizes keep exercising the LL kernel.op_tests/multigpu_tests/test_custom_allreduce_size_env.py: a CPU test of the plain all-reduce gate with the Lamport cap.Performance (if applicable)
Setup: 4x gfx1250 (256 CU), ROCm 10.1, RCCL 2.30.7, IPC transport, bf16, CUDA graph (43 calls × 20 replays, median per rank, slowest rank reported).
tensor_model_parallel_all_reducewith this PR.TL;DR: Over the cases this PR routes (sizes 1 KiB–32 MiB plus
[M, 7168]with M 1–2048), TP2 is 1.43–6.73x faster than main (median 1.78x) and TP4 1.02–3.30x (median 1.55x). Against the fastest of the LL one-shot, the LL two-shot, the barrier kernel and RCCL (default and with #7432'sRCCL_DDA_LL_*settings) at each size, TP2 is 1.30–2.37x faster (median 1.75x) and TP4 1.02–3.30x (median 1.48x). No case is slower. The smallest gains are at TP4 5–8 MiB (1.02–1.08x, see the note under the tables).Rows of hidden 7168, bf16 (the shapes of #7432)
By size, bf16, against each kernel
us per all-reduce. LL is what the custom all-reduce runs without Lamport (
ar_ll_gfx1250, at TP4ar_2s_ll_gfx1250from 1 MiB; the barrier kernel where noted). "RCCL tuned" setsRCCL_DDA_LL_ONESHOT_THRESHOLD=2097152andRCCL_DDA_LL_TWOSHOT_THRESHOLD=134217728, as in #7432. Bold is main's route.At TP4 the Lamport two-shot slows down between 3.5 and 4.4 MiB (12.5 → 21.9 us) and is only 2–8% ahead of RCCL at 5–8 MiB. Its register use (49 VGPRs, no LDS) does not limit occupancy; the cause is not known yet and is left to a follow-up. In 4.4–6 MiB the one-shot is 1–6% faster than the two-shot; the two-shot is kept there so that the split stays a single size, and it is still ahead of RCCL and the LL two-shot.
The one-shot / two-shot crossover
bf16 and fp16 cross at the same sizes. Above the cap only the two-shot fits, so it runs there.
Why the private all-gather inbox is world_size x the cap
With a private inbox of only 1x the cap, the two-shot could reach only the cap. The private inbox costs 32 MiB per rank. What the extra range buys at TP4 (bf16, us):
RCCL 2.30 slows down sharply between 16 and 20 MiB at TP4, and between 8 and 10 MiB at TP2, with or without the tuned settings.
Growing the cap itself instead would grow the shared inbox (3.75 x world_size x the cap per rank: 120 MiB at TP4, 240 MiB with the cap doubled), and with it the range of every Lamport op.
Testing
Documentation
This is an internal routing change with no new knob. The one-shot / two-shot split and the inbox layout are documented next to
_LAMPORT_AR_1SHOT_MAX_BYTESand_LAMPORT_AR_RMS_MAX_BYTES, and in the kernel comments.Dependencies
Breaking Changes
None. Some notes on behavior:
AITER_CUSTOM_AR_LAMPORT_RMS_MAX_SIZEnow also bounds the Lamport all-reduce: the one-shot up to it, the two-shot up to world_size x it. Setting it to0turns the Lamport all-reduce off too, and the plain all-reduce cutoff then applies to every input again.PR Self-Review
Reviewed revision
f11d1be
Behavior and intent
On gfx1250 TP2/TP4, a plain fp16/bf16 all-reduce of a contiguous input up to 32 MiB now runs a single Lamport kernel, the one-shot or the two-shot, instead of the LL kernels (up to 4 MiB) or RCCL (above). The output bits are unchanged against the custom all-reduce: both sum in fp32 in rank order and round once. The only exception is the NaN payload, since a 0xffff half-word is canonicalized to 0x7fff (still a NaN) so it never reads as the Lamport sentinel. fp32, non-contiguous inputs, inputs above 32 MiB, TP6/TP8, multi-node groups, other archs and the RCCL path behave as before. The other Lamport ops keep their kernels and size ranges.
Validation and unverified scope
All runs are on 4x gfx1250, TP2 and TP4, on this branch rebased onto main (after #7432 and #7861).
python op_tests/multigpu_tests/gfx1250_poc/test_gfx1250_lamport_allreduce.py -t 4 2 -d bf16 fp16 fp32 --size 1k 64k 1m 1280k 1408k 2m 4m 5m 8m 9m 9728k 16m 32m 33m 64m 65m, and the same file with its default[M, 7168]sweep:torch.profiler: fp16/bf16 up to 32 MiB on the Lamport kernels; fp32 on the LL one-shot / LL two-shot up to 4 MiB and RCCL above; everything above 32 MiB on RCCL.python op_tests/multigpu_tests/test_custom_allreduce.py --regression, at-t 4with--transport autoand--transport symm, and at-t 2: all pass (tail, LL128, gfx1250 LL mixed sizes, LL two-shot mixed sizes, LL in place, plain all-reduce cutoff).python op_tests/multigpu_tests/test_custom_allreduce.py --op all_reduce, run with-t 4 -m graph,-t 4 -m eager,-t 2 -m graphand-t 4 -d fp16: all pass.errcolumn is up to 4.9e-4, from its reference, which accumulates in bf16; the values are the same as before the rebase. TP2 and fp16 show 0.--op all_reducethe file also runsall_gather_lastdim_add([HIP] Addall_gather_lastdim_addto the custom all-reduce #6960), which is not wired on gfx1250 and raises there, on main as well.python op_tests/multigpu_tests/test_ar_add_lamport.py,test_fused_ar_rms_lamport.py,test_ag_lamport.pyandgfx1250_poc/test_gfx1250_allgather.py: all bit for bit, and the all-gather routes are unchanged.python op_tests/multigpu_tests/test_custom_ar_fused_interleave.py --tp 4andtest_custom_allreduce_rank_order.py: pass.pytest op_tests/multigpu_tests/test_custom_allreduce_size_env.py: 16 passed, including the newtest_gfx1250_plain_ar_gate_lamport, which fails on the gate without this change.black --checkandruff checkare clean on the changed Python files.PR-specific question
Boundaries. A plain all-reduce takes a Lamport kernel only when
CustomAllreduce.select_lamport_arpicks one, that is whenshould_lamport_ar(inp, two_shot=True)holds. All of the following must be true:_lamport_max_bytesis non-zero only after_init_lamport_ar_rmshas set up the Lamport inbox._init_ipccalls it, and only on gfx1250.AITER_CUSTOM_AR_LAMPORT_RMS_MAX_SIZEsets a size.select_lamport_arreturns None, andshould_custom_plain_aris the [HIP] perf(custom_ar): gfx1250 LL two-shot all-reduce for 1 MiB+ messages #7432 cutoff unchanged.AITER_CUSTOM_AR_MAX_SIZE/AITER_CUSTOM_AR_MIN_SIZEwindow, becauseshould_custom_arruns first._LAMPORT_AR_1SHOT_MAX_BYTES(TP4 1.25 MiB, TP2 9 MiB), the two-shot the rest.custom_all_reduce, which bothtensor_model_parallel_all_reduceandCudaCommunicator.all_reducereach.should_custom_plain_arlets these inputs past the 4 MiB plain cutoff; every other input keeps it.Invariants.
should_lamport_arandselect_lamport_arread the dtype, contiguity, byte count and cap only, never the address, and the cap and the one-shot split are the same on every rank. This matters because the kernels wait for every peer, so a split group would hang. An unaligned input is copied rank-locally (_lamport_aligned) instead of being rerouted.allreduce_lamportrejects a non-contiguous input, an output that does not match it, any dtype but fp16/bf16, and a communicator without an inbox.ar_packsrejects an input that is not whole 16B packs, and one larger than the slot (one-shot) or world_size x the slot (two-shot), the sizes the shared inbox and the private all-gather inbox are built for.static_asserta 2-byte dtype.DISPATCH_NGPUS_1250), and the inbox exists only within one node.Changed op tests
op_tests/multigpu_tests/gfx1250_poc/test_gfx1250_lamport_allreduce.py(new): the production all-reduce route on gfx1250.op_tests/multigpu_tests/test_custom_allreduce.py: the gfx1250 LL mixed-size regression now setsAITER_CUSTOM_AR_LAMPORT_RMS_MAX_SIZE=0. Without it, its bf16 sizes would take the Lamport one-shot, and the test would no longer cover the LL kernel it guards. The LL two-shot and in-place regressions from [HIP] perf(custom_ar): gfx1250 LL two-shot all-reduce for 1 MiB+ messages #7432 run fp32 or callall_reducedirectly, so the Lamport kernels do not take them.op_tests/multigpu_tests/test_custom_allreduce_size_env.py: the stub communicator gets the Lamport cap (0, the inbox off, unless a test sets it), which the plain all-reduce gate now reads.test_gfx1250_plain_ar_gate_lamport(new) checks that fp16/bf16 inputs up to world_size x the cap pass the gate above the plain cutoff, and that fp32, strided inputs, inputs above that, a cap of 0 andAITER_CUSTOM_AR_MAX_SIZEstill keep it. It runs on CPU, so CI covers the gate.🤖 Generated with Claude Code