Repository navigation
[HIP] [Perf] gfx1250 ar2s: MXFP8 output and sequence-parallel residual ops - #8428
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: |
|
Update: pushed 63b9540, ar2s kernel 2, on top of this branch. It is the base for the MoE-front mode PR that stacks on this one.
|
63b9540 to
4d96b11
Compare
…duce + RMSNorm At prefill sizes on gfx1250 TP > 1 (one PP stage, no TBO, every layer on the bf16 or native-MXFP8 AR + norm), the decoder's all-reduce + Gemma RMSNorm run aiter's sequence-parallel residual ops (ROCm/aiter#8428): reduce-scatter, norm of this rank's owner rows only, all-gather of the (MXFP8) normed output. The normed outputs are bit-identical; the residual stream stays valid on the owner rows only and is gathered by the final add. aiter falls back to the replicated ops for sizes or configurations its kernel does not take. Co-Authored-By: Claude Opus 5.5 <[email protected]>
4d96b11 to
7c7986e
Compare
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]>
…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]>
7c7986e to
f000c5e
Compare
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]>
f000c5e to
93c6e8d
Compare
No behavior change. - op_tests/multigpu_tests/test_ar2s_rms_gfx1250.py and test_ar2s_mxfp8_zero_group.py (from ROCm#8428's earlier head): no shebang on a non-executable file (EXE001), the timed lambdas bind their loop variables through functools.partial (B023), unused unpacked values are _-prefixed (RUF059), one combined `with` (SIM117), imports sorted with aiter first-party (I001). Co-Authored-By: Claude Opus 5.5 <[email protected]>
No behavior change. - op_tests/multigpu_tests/test_ar2s_rms_gfx1250.py and test_ar2s_mxfp8_zero_group.py (from ROCm#8428's earlier head): no shebang on a non-executable file (EXE001), the timed lambdas bind their loop variables through functools.partial (B023), unused unpacked values are _-prefixed (RUF059), one combined `with` (SIM117), imports sorted with aiter first-party (I001). - aiter/tuned_gemm.py: the unused row count of A is _m (RUF059). Co-Authored-By: Claude Opus 5.5 <[email protected]>
No behavior change. - op_tests/multigpu_tests/test_ar2s_rms_gfx1250.py and test_ar2s_mxfp8_zero_group.py (from ROCm#8428's earlier head): no shebang on a non-executable file (EXE001), the timed lambdas bind their loop variables through functools.partial (B023), unused unpacked values are _-prefixed (RUF059), one combined `with` (SIM117), imports sorted with aiter first-party (I001). - moe_deferred_tail.py: __all__ and __slots__ sorted (RUF022, RUF023; nothing reads the slots' order), and materialize's imports sorted (I001). - communicator_cuda.py: the deferred-tail imports one aliased name a statement (I001), and the three `# noqa: E731` dropped (RUF100: E731 is not enabled). - custom_all_reduce.py: the k5 tail entry's imports sorted (I001). Co-Authored-By: Claude Opus 5.5 <[email protected]>
What
Extends the gfx1250 pushed two-shot AR + RMSNorm (
ar2s_rms_gfx1250, #8427) withar2s_rms_exand three modes. They are exposed as sequence-parallel ops for prefill:tensor_model_parallel_sp_fused_allreduce_rmsnorm{,_mxfp8_quant}andtensor_model_parallel_sp_allreduce_add_residual(mutates_args=[]).per_1x32_mx_quant_hipgives for the bf16 output. The group max is floored atkAmaxFloor, so an all-zero group gets scale 85.all_reduce(x) + residualon every rank.The SP ops take the SP path at the ar2s sizes and run the replicated ops below them, so every call of a forward takes the same branch.
Why
In MiniMax-M3.1 TP4 prefill, the two AR + RMSNorm (+ MXFP8) calls of a layer were about 31% of a 14K-token prefill forward on a 100K-token cached prefix. With a sequence-parallel residual, each rank needs only its own rows, and the all-gather can carry the 8-bit activations the next GEMM consumes.
Evidence
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).
14336 / 32768 rows with [HIP] [JIT] [Perf] gfx1250 custom AR: pushed two-shot AR + RMSNorm for 32-288 MiB #8427's pipelined kernel, bit-exact:
In the model (with perf(minimax-m3): sequence-parallel residual for prefill-sized all-reduce + RMSNorm ATOM#3683): a 14336-token prefill on a 99968-token cached prefix drops from 165.7 to 152.7 ms a forward. The serving gate passes, and greedy outputs are identical on 16K-token prompts.
The times were measured on an earlier aiter base (
576d3f0); this rebase was checked for correctness on GPU (below), not re-timed.Gated on
_AR2S_RMS_HIDDEN, 4096-7168), in whole 512-element groups, which the MXFP8 output needs.AITER_CUSTOM_AR_AR2S_RMS_MAX_SIZEoverrides it, and 0 turns ar2s (and so the SP modes) off.fused_allreduce_rmsnorm_group_quant(..., "mxfp8")) keeps ar2s + the separate quant (measured level: 318.7 vs 317.7 us).PR Self-Review
Reviewed revision
93c6e8d
Behavior and intent
New SP / FP8 / AUX modes of ar2s behind explicit SP ops; the replicated path is unchanged.
Validation and unverified scope
Stacking. Rebased onto #8427's review head
0c78341fb(#8310 is on main now). The top commit is this PR. Adaptations:fused_allreduce_rmsnorm_group_quant(..., "mxfp8")([Triton/Gluon] [HIP] [Perf] Fuse gfx1250 AR RMSNorm native MXFP8 #8310 renamed it);test_ar2s_rms_ex_gfx1250.py(see below), on main's public MXFP8 op.On 4x MI455X at
f000c5e33, which differs from this head only in the import order of the two new test files (aiter JIT module rebuilt from that tree):tests/test_ar_rmsnorm_routing.py: 87 passed (CPU).op_tests/multigpu_tests/test_ar2s_rms_gfx1250.py([HIP] [JIT] [Perf] gfx1250 custom AR: pushed two-shot AR + RMSNorm for 32-288 MiB #8427's replicated-route test, here with the 192 MiB cap): all passed. At the default cap and at 48 MiB, 24 routed calls each matched the fp32 rank-order reference; at 0, none.test_ar2s_rms_ex_gfx1250.py --checkat 4 / 2752 / 6144 / 12288 / 14336 / 16384 rows: every check is True — fp8, sp, sp_fp8, aux, the public SP ops (api), and rank agreement. 16384 rows run in one launch.test_ar2s_mxfp8_zero_group.py: pass, replicated and SP. The E4M3 / E8M0 bytes equalper_1x32_mx_quant_hip's, and the all-zero row's scale is 85.Lint. black and ruff 0.16.0 (main's
pyproject.toml) are clean on every changed Python file.Unverified. Re-timing on this base, TP2, and an in-model run on this base.
PR-specific question
Stacked on #8427 (the bottom two commits); please review only the top commit.
Changed op tests
op_tests/multigpu_tests/test_ar2s_rms_ex_gfx1250.py(new) checks every mode and the public SP ops, bit for bit, against ar2s +per_1x32_mx_quant_hip, at 4-32768 rows:op_tests/multigpu_tests/test_ar2s_mxfp8_zero_group.py(new) checks an all-zero row's E4M3 / E8M0 bytes (scale 85), replicated and SP.🤖 Generated with Claude Code