Repository navigation
[HIP] [JIT] [Perf] gfx1250 custom AR: pushed two-shot AR + RMSNorm for 32-288 MiB - #8427
XiaobingSuper wants to merge 3 commits into
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
57971b7 to
8782dc2
Compare
|
GPU check of 8782dc2 on 4x MI455X (gfx1250), TP4: this PR's own tree (main bf59948 + this commit), every module JIT-built from it, flydsl 0.5.3.
Against RCCL's own sum, residual_out is equal or within 1-2 bf16 ulps (different fp32 order). One thing to know: at interpreter exit each rank prints |
WAITING ON AUTHORPR Self-ReviewRevision Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision. Questions to answer in the PR description
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
e657a79 to
a42aed0
Compare
|
Rebased onto current main ( |
fused_allreduce_rmsnorm on gfx1250 fell back to RCCL + a separate add + RMSNorm above the Lamport kernels' range. Add a pushed two-shot all-reduce + residual add + (Gemma) RMSNorm kernel (ar2s_rms_gfx1250) and route bf16 inputs of 32-288 MiB to it at TP4: - phase 1 pushes each row chunk to its owner's RS inbox, phase 2 sums the own chunk in fp32 in rank order, rounds once to bf16, pushes it to every peer's AG inbox and normalizes it, phase 3 normalizes the peers' rows; - block b only waits for block b of its peers (a flag per phase, sender and block, epoch counters), so no barrier is needed, eager or in a CUDA graph; - row-local barriers are LDS-only and only a flag waits for the store drain; the three phases are pipelined per step; phase 2 prefetches the next row's summands into LDS asynchronously; flag polls are bounded (no hang); - out / residual_out follow the Lamport fused kernel step by step; - the kernel body is compiled only for gfx1250 (as mega_mhc_gfx1250.cu), so the gfx942 / gfx950 wheel builds do not see the gfx1250 async builtins. The inbox is set up on the IPC transport only; the route is traced as "ar2s" under AITER_AR_ROUTE_TRACE like the other fused AR + RMSNorm routes. TP4, hidden 6144 bf16, Gemma norm, 4x MI455X, eager, us per call, measured with the first, unpipelined version of this kernel (same layout, flags and arithmetic, so the same outputs): tokens 2752 4096 6144 8192 12288 24576 before 108.1 147.9 258.2 299.7 368.1 537.4 after 85.3 104.9 145.5 182.7 256.1 502.4 residual_out matches an fp32 reference bit for bit, out is within 1 bf16 ulp for < 1e-5 of the values (4 ranks, eager and graph, 13 row counts including non-multiples of 4 and a split launch). Gated on gfx1250, TP4 (the measured world size), bf16, hidden a multiple of 256 up to 8192, 32-288 MiB. Co-Authored-By: Claude Opus 5.5 <[email protected]>
a42aed0 to
290d8d0
Compare
TennyWang1223
left a comment
There was a problem hiding this comment.
Review summary (advisory)
What it does: adds a gfx1250-only pushed two-shot AR + residual add + RMSNorm kernel (ar_2shot_rms_gfx1250) and makes it the default fused_allreduce_rmsnorm route for bf16, TP4, 32–288 MiB inputs.
Verdict: needs work before approval. I found no correctness bug in the kernel's sync protocol, its 32-bit indexing, or the rank-consistent routing decision. The issues below are about failure visibility, test coverage, and how wide the new default route is.
Reviewed at head 290d8d0.
Should fix
1. A timed-out flag poll silently produces wrong output.
wait_flag_bounded gives up after kMaxPolls (20M) loads. It bumps Flags::err and the callers continue straight into the inbox reads (L355, L437). Nothing reads err: there is no getter in the header or pybind, no reader in Python, and none in #8428.
If one rank reaches the call that many polls behind its peers, that call's out/residual_out are wrong on every rank. The inbox-reuse argument in the header comment (L31-L35) also stops holding for the next call. The existing gfx1250 barriers (custom_all_reduce_gfx1250.cuh L427, L449) spin without a bound, so a stall there at least shows up.
Could you make the timeout observable? For example, read and reset err on the host and raise or log, or trap in the kernel instead of continuing.
2. The new default route has no test.
This PR adds no test, and no existing test reaches the route. op_tests/multigpu_tests/test_fused_ar_rms.py defaults to at most 19 rows at TP8, and the other TP4 tests stay under 32 MiB. CI has no gfx1250 runner, and the Multi-GPU job was skipped. Could op_tests/multigpu_tests/test_ar2s_rms_gfx1250.py move from #8428 into this PR?
3. The gate admits every hidden size up to 8192, but only 6144 was measured.
should_ar2s_rms takes any hidden that is a multiple of 256 and at most 8192.
At hidden 8192 the dynamic LDS is 2 × (4 + 1) × 1024 × 16 = 160 KiB per block, plus 260 B of static LDS. Two blocks need 328,200 B, which is more than the 327,680 B available, so only one block fits per CU. That breaks the grid = 2 × CU design in _init_ar2s_rms. The kernel comment itself notes that one block per CU made half the grid start 150–190 µs late. Hidden sizes below 6144 (2048, 4096) are also unmeasured.
Could you post numbers for 4096, 7168 and 8192, or narrow the gate to the hidden sizes you measured?
4. There is no dedicated off switch, and about 324 MiB per GPU is allocated unconditionally.
_AR2S_RMS_MAX_BYTES is a constant. _init_ar2s_rms always allocates a 2 × 160 MiB inbox plus a 4 MiB flag buffer on gfx1250 TP4 with IPC transport, decode-only instances included.
Today the only ways to turn the route off are switching the whole custom-AR transport (AITER_CUSTOM_AR_FORCE_VMM=1 / AITER_CUSTOM_AR_USE_SYMM_MEM=1) or disabling custom AR. Could you add an env cap like AITER_CUSTOM_AR_LAMPORT_RMS_MAX_SIZE, where 0 turns the route off and skips the allocation?
Nit
5. Stale comments.
communicator_cuda.pyL112-L116 still says 1.3–1.9x vs RCCL + norm, and 624.6 vs 686.2 µs at 384 MiB. The re-measured table in the PR body says 1.09–1.52x vs main, and 617 µs on both sides at 384 MiB.- The kernel header (L4-L6) still says "RCCL is 2x off the link".
Notes
- CI is green, but it runs only on MI35X (gfx950), where this route is never taken. It says nothing about the new kernel.
- The diff still applies cleanly to current main (
e50914dd7). - Not reproduced: I had no gfx1250 hardware. The numerics and perf figures referenced here are the PR's own.
Advisory review, AI-assisted (Claude Code). It does not block the merge.
…gate, op test Review follow-ups for the pushed two-shot AR + RMSNorm: - A flag poll that runs out of kMaxPolls now traps instead of reading an inbox the peer never filled: the call's output would be wrong on every rank and the next call's inbox reuse would no longer hold. - AITER_CUSTOM_AR_AR2S_RMS_MAX_SIZE overrides the per-launch cap (default 160 MiB at TP4, rounded down to whole MiB); 0 turns the route off and allocates no inbox. - The route takes hidden 4096-7168 only. Measured at TP4 against main's route, 32-288 MiB: 4096, 6144 and 7168 are 1.06-1.60x faster; 2048 is even above 64 MiB and 0.92x at 288 MiB; 8192 is 0.94-1.13x, as its 160 KiB of dynamic LDS a block leaves one block a CU. - op_tests/multigpu_tests/test_ar2s_rms_gfx1250.py (moved here from ROCm#8428): route window and hidden gate, values against an fp32 rank-order reference, ranks agree, CUDA-graph replay, with the default cap, 48 MiB and 0. - Stale comments updated to the re-measured numbers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@TennyWang1223 thanks for the review. All five points are addressed in 1. A timed-out flag poll. When
2. A test for the route.
It runs with the default cap, with a 48 MiB cap, and with a cap of 0 (no inbox, no route). It also asserts that the inbox was set up, so it cannot pass with the route silently off. Result on 4x MI455X at 3. The hidden-size gate. I measured 2048 / 4096 / 5120 / 6144 / 7168 / 8192 at TP4 and narrowed the gate to 4096-7168 (
4. An off switch.
5. Stale comments. Both are updated. The comment above |
Extend the pushed two-shot AR + RMSNorm (ar2s_rms_gfx1250) with ar2s_rms_ex
and three modes, exposed as sequence-parallel tensor_model_parallel_sp_* ops
for prefill:
- FP8: the norm output is written as MXFP8 (E4M3 + row-major E8M0 per 32),
the bytes per_1x32_mx_quant_hip gives for the bf16 out (the group max is
floored at kAmaxFloor as there, so an all-zero group gets scale 85).
- SP: each rank keeps the residual of its own row chunk only; the owner
normalizes (and quantizes) its rows and pushes the result, so the
all-gather moves MXFP8 and phase 3 is a copy. The normed output is whole
on every rank and bit-identical to the replicated path.
- AUX (with SP): no norm, the whole all_reduce(x) + residual on every rank.
tensor_model_parallel_sp_fused_allreduce_rmsnorm{,_mxfp8_quant} and
tensor_model_parallel_sp_allreduce_add_residual take the SP path at the ar2s
sizes and are the replicated ops below it, so every call of a forward takes
the same branch (mutates_args=[]).
The TP4 per-launch cap is 192 MiB, one launch for a 14336-token chunk of
hidden 6144.
TP4, hidden 6144, Gemma norm, 4x MI455X: AR + RMSNorm + MXFP8 at 14336 rows
347 -> 226 us a call (SP + MXFP8 all-gather vs ar2s + separate quant);
sp_fp8 at 14336 / 32768 rows 189.0 / 401.2 us, bit-exact.
On top of ROCm#8427 at 0c78341 (the review round there), adapted as follows:
- The SP gate (ar2s_sp_eligible) takes the replicated route's measured
hidden range (_AR2S_RMS_HIDDEN, 4096-7168) in whole 512-element groups,
which the MXFP8 output needs.
- The replicated MXFP8 fallback calls main's
fused_allreduce_rmsnorm_group_quant(..., "mxfp8") (ROCm#8310 renamed it).
- The 192 MiB cap keeps ROCm#8427's AITER_CUSTOM_AR_AR2S_RMS_MAX_SIZE
override; the routing test's default is 192 MiB.
- ROCm#8427 now carries op_tests/multigpu_tests/test_ar2s_rms_gfx1250.py (the
replicated route); this PR's test and benchmark of the ex modes moves to
test_ar2s_rms_ex_gfx1250.py, on main's public MXFP8 op
(tensor_model_parallel_fused_allreduce_rmsnorm_quant with
quant_type="per_1x32", quant_dtype=fp8), ruff-clean.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Extend the pushed two-shot AR + RMSNorm (ar2s_rms_gfx1250) with ar2s_rms_ex
and three modes, exposed as sequence-parallel tensor_model_parallel_sp_* ops
for prefill:
- FP8: the norm output is written as MXFP8 (E4M3 + row-major E8M0 per 32),
the bytes per_1x32_mx_quant_hip gives for the bf16 out (the group max is
floored at kAmaxFloor as there, so an all-zero group gets scale 85).
- SP: each rank keeps the residual of its own row chunk only; the owner
normalizes (and quantizes) its rows and pushes the result, so the
all-gather moves MXFP8 and phase 3 is a copy. The normed output is whole
on every rank and bit-identical to the replicated path.
- AUX (with SP): no norm, the whole all_reduce(x) + residual on every rank.
tensor_model_parallel_sp_fused_allreduce_rmsnorm{,_mxfp8_quant} and
tensor_model_parallel_sp_allreduce_add_residual take the SP path at the ar2s
sizes and are the replicated ops below it, so every call of a forward takes
the same branch (mutates_args=[]).
The TP4 per-launch cap is 192 MiB, one launch for a 14336-token chunk of
hidden 6144.
TP4, hidden 6144, Gemma norm, 4x MI455X: AR + RMSNorm + MXFP8 at 14336 rows
347 -> 226 us a call (SP + MXFP8 all-gather vs ar2s + separate quant);
sp_fp8 at 14336 / 32768 rows 189.0 / 401.2 us, bit-exact.
On top of ROCm#8427 at 0c78341 (the review round there), adapted as follows:
- The SP gate (ar2s_sp_eligible) takes the replicated route's measured
hidden range (_AR2S_RMS_HIDDEN, 4096-7168) in whole 512-element groups,
which the MXFP8 output needs.
- The replicated MXFP8 fallback calls main's
fused_allreduce_rmsnorm_group_quant(..., "mxfp8") (ROCm#8310 renamed it).
- The 192 MiB cap keeps ROCm#8427's AITER_CUSTOM_AR_AR2S_RMS_MAX_SIZE
override; the routing test's default is 192 MiB.
- ROCm#8427 now carries op_tests/multigpu_tests/test_ar2s_rms_gfx1250.py (the
replicated route); this PR's test and benchmark of the ex modes moves to
test_ar2s_rms_ex_gfx1250.py, on main's public MXFP8 op
(tensor_model_parallel_fused_allreduce_rmsnorm_quant with
quant_type="per_1x32", quant_dtype=fp8), ruff-clean.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
What
This PR adds a pushed two-shot all-reduce + residual add + (Gemma) RMSNorm kernel for gfx1250 (
ar_2shot_rms_gfx1250,CustomAllreduce.ar2s_fused_ar_rms).fused_allreduce_rmsnormroutes to it bf16 inputs of 32-288 MiB whose hidden size is 4096-7168. On main, those sizes take the 2-stage custom fused AR + RMSNorm up to 64 MiB, and RCCL + a separate add + RMSNorm above that.outandresidual_outfollow the Lamport fused kernel step by step.AITER_CUSTOM_AR_AR2S_RMS_MAX_SIZEoverrides the per-launch cap (default 160 MiB at TP4). 0 turns the route off and allocates no inbox.Evidence
Hidden 6144 (MiniMax-M3), TP4, bf16, Gemma norm, 4x MI455X, image
rocm/fw-bringup:gfx1250-minimax-m3-20261201, aiter main2770d86d4+ this kernel.hipErrorInvalidValueat capture). This PR captures and replays at every size.576d3f0) and image. Main's route is faster now (8192 tokens: 299.7 -> 194.5 us), so the gain is 1.09-1.52x rather than 1.2-2.1x. This PR's own times did not change (8192 tokens: 159.2 us both times).Hidden sizes and the gate. Same harness and process, on
0c78341fb's kernel build. Each cell is main's route time / this PR's time, eager, with graph in parentheses where main's route can be captured. Main's route is the 2-stage fused kernel at 32 MiB and RCCL + norm from 64.5 MiB._AR2S_RMS_HIDDEN); the kernel itself takes up to 8192.Numerics.
outandresidual_outare bit-identical.residual_outdiffers in 27.6% of the values, because RCCL sums in a different order.residual_outis bit-exact on all 4 ranks, andoutis within 1 bf16 ulp for all but at most 3.4e-8 of the values at hidden 6144 (this comment). The op test below checks the same at 4096 / 6144 / 7168.Scope
AITER_CUSTOM_AR_AR2S_RMS_MAX_SIZE); larger inputs are split into balanced launches.Everything else keeps its route.
PR Self-Review
Reviewed revision
0c78341
Behavior and intent
This is the new default route for 32-288 MiB bf16 fused AR + RMSNorm at gfx1250 TP4 with hidden 4096-7168. Against main's route it is:
Every other size, hidden, dtype, world size and arch is unchanged. Setting
AITER_CUSTOM_AR_AR2S_RMS_MAX_SIZE=0restores main's route and allocates nothing.Validation and unverified scope
4fb090db3.290d8d0is the kernel and route.0c78341fbholds the review fixes: the trap on a flag timeout, the env cap, the hidden gate, the op test and updated comments.op_tests/multigpu_tests/test_ar2s_rms_gfx1250.py, 4x MI455X at0c78341fb: all passed.290d8d0's kernel. At 6144 the two agree within 2% where both measured a size (32 / 64.5 / 96 / 288 MiB: 1.49 / 1.22 / 1.24 / 1.12x against 1.49 / 1.23 / 1.22 / 1.12x).tests/test_ar_rmsnorm_routing.pypasses (87). It covers the env cap, a cap of 0 allocating and routing nothing, and the hidden gate. black and ruff are clean on the changed Python files.hipcc -c) at290d8d0; at this head only the gfx1250 JIT module was built.PR-specific question
Boundaries.
_init_ar2s_rms, world size 4 only, and not with the env cap at 0), so on other archs, world sizes and with the cap at 0,should_ar2s_rmsis False.Changed op tests
op_tests/multigpu_tests/test_ar2s_rms_gfx1250.py(new, moved from #8428). Throughtensor_model_parallel_fused_allreduce_rmsnorm, on 4 x gfx1250, it checks:It runs with the default cap, a 48 MiB cap and a cap of 0, and skips elsewhere.
🤖 Generated with Claude Code