Skip to content

[Triton/Gluon] [HIP] gfx1250 all-reduce + RMSNorm + per-token FP8 in one kernel - #8022

Merged
TennyWang1223 merged 3 commits into
ROCm:mainfrom
lirui927:fuse/ar-norm-fp8
Nov 19, 2026
Merged

TennyWang1223 merged 3 commits into
ROCm:mainfrom
lirui927:fuse/ar-norm-fp8

Conversation

@lirui927

@lirui927 lirui927 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What it does

On gfx1250, all-reduce + residual add + RMSNorm + per-token FP8 quant becomes one kernel launch instead of two. Two kernels do it:

  • HIP Lamport one-shot (lamport_ar_rmsnorm_gfx1250, the default path, TP2 and TP4). The epilogue can now also do the per-token FP8 quant, with one fp32 scale per row and optionally the bf16 output (emit_bf16). fused_allreduce_rmsnorm_quant(quant_type="per_token") uses it wherever should_lamport_ar_rms accepts the call: hidden a multiple of 256 up to 8192, TP4 up to 8 MiB, TP2 up to 16 MiB. Before, main ran Lamport bf16 followed by a separate quant kernel up to 4 MiB, and custom_fused_ar_rms_quant above that. The quant steps are those of ar_rmsnorm_gfx1250, so the FP8 output and scales match custom_fused_ar_rms_quant bit for bit. The new arguments go at the end of the kernel's argument list. Its bf16/fp16 instantiations therefore compile to the same instructions as on main, and so do the module's other 407 kernels; only the kernarg segment grows.
  • Gluon all_reduce_rmsnorm_per_token_quant (TP4 with AITER_GLUON_FUSED_AR=1). It is the plain Gluon all-reduce plus an epilogue: residual add, RMSNorm (plain or Gemma) and optionally per-token FP8. It runs as its own kernel, _all_reduce_rmsnorm_kernel, on the inboxes of the plain all-reduce. It takes any hidden size that is a multiple of 8, up to 24576. The communicator sends it calls of up to 128 rows where Lamport could take the call (Lamport is faster past that), and calls of up to 4 MiB where Lamport can't (for example hidden 6152). Its per-token FP8 uses the steps of the HIP quant dynamic_per_token_scaled_quant takes at each width: at hidden 32/64/128 (the per-group kernel) the amax is floored at 1e-10 and the scale inverted with an IEEE divide; elsewhere amax from 0 and v_rcp_f32. _all_reduce_kernel compiles to the same ISA as on main.

all_reduce_rmsnorm_quant (Gluon, power-of-2 hidden, one scale per 128 values) keeps the bf16 calls it takes today. It is not extended: it holds a row as a [HIDDEN / 4, 4] block and packs rows into its inboxes for a single hidden size, so supporting hidden 6144 would mean replacing its layout and protocol with those of the plain all-reduce, which is what the new op is.

Benefit

Measured on MI455X x4 (rocm/fw-bringup:gfx1250-minimax-m3-20261112) in HIP graph replay: 10 calls per graph, median of 20 replays, slowest rank. The baseline is the unfused route that main takes for the same call, timed in the same process with scripts/bench_ar_norm.py. Values are the median of 4 rounds interleaved with the PR head; spread ≤ 0.5 µs. µs per call, TP4, hidden 6144:

M FP8: main route (Lamport bf16 + per-token quant) FP8: Lamport fused FP8: Gluon fused bf16: main route (Lamport) bf16: Gluon fused
1 9.22 7.83 (-15%) 5.80 (-37%) 7.02 5.51 (-22%)
16 10.24 9.01 (-12%) 6.80 (-34%) 7.81 6.50 (-17%)
64 11.70 10.16 (-13%) 8.48 (-28%) 8.96 7.98 (-11%)
128 14.53 13.24 (-9%) 11.67 (-20%) 12.23 11.31 (-8%)
256 19.75 17.02 (-14%) – (Lamport takes it) 16.79 – (Lamport takes it)

The Gluon columns need AITER_GLUON_FUSED_AR=1. The Lamport FP8 kernel is the default.

  • FP8 Lamport fused vs Lamport bf16 + quant, from the op test's own table (TP2 and TP4, hidden 2048–8192, M 1–1024, 62 sizes): 6–18% faster at every size.
  • FP8 between 4 and 8 MiB at TP4, where main uses custom_fused_ar_rms_quant: hidden 7168 M=512 64.1 → 30.5 µs, hidden 8192 M=512 65.8 → 34.0 µs, hidden 4096 M=1024 45.9 → 33.0 µs.
  • bf16 Lamport on its own: the kernel keeps main's instructions, and its time matches main within noise for every size of the op test. The PR's first version passed the peer pointers as scalar kernel arguments, which was 10–20% slower than main at TP2 from 256 rows of hidden ≥ 7168 (for example 512×8192 took 20.65 µs vs 17.15 µs). That version was not faster on FP8 either, so this branch keeps main's argument layout.

Testing

MI455X x4, same image; main, the PR head and this branch were each run on the same GPUs in one session.

  • op_tests/multigpu_tests/test_fused_ar_rms_lamport.py -t 2 4, run twice on each tree:
    • a row fails on a bit difference or when any candidate's error ratio against the torch reference reaches 5% (worst: 0.0044, rccl+norm);
    • every output is bit for bit equal to custom_fused_ar_rms(_quant), including FP8 out, scale and the emit_bf16 output, and to Lamport bf16 + the per-token quant;
    • the mixed bf16/FP8 sequence (70 calls per TP: unaligned operands on odd ranks, graph replay between eager calls) has 0 differing bits;
    • main passes its bf16-only version (51 calls, 0 bits).
  • op_tests/multigpu_tests/triton_test/test_all_reduce_rmsnorm_quant.py (TP4): 3 passed, under pytest and as a script.
    • The new test_all_reduce_rmsnorm_per_token_quant checks the Gluon output at hidden 6144 bit for bit against the Gluon all-reduce + rmsnorm2d_fwd_with_add + the HIP per-token quant.
    • At hidden 2048/6152/16384 it checks against an fp32 reference, within 1 bf16 ulp / 1 FP8 code.
    • With quant, at every hidden size that is a multiple of 16, the FP8 out and scale must also be the bits of the HIP per-token quant applied to the op's own bf16 out. Hidden 6152 is excluded from this check: there the HIP per-token quant leaves the last 4 FP8 bytes of each row unwritten. This happens whenever hidden % 16 == 8 and hidden > 2048, also on main.
    • It also covers edge rows (a zero row among them, at hidden 6144 and at 32/64/128, where the HIP quant takes its per-group kernel), the call-counter wrap, partial chunks and graph replay. With the Gluon kernel from before 1aef2c8, the edge rows at 32/64/128 fail on all 4 ranks.
    • The dispatch test checks that the public ops take the new op.
    • The PR head's version of these tests also passes (3 passed).
  • triton_test/test_all_reduce.py (plain Gluon all-reduce): passes on main and on this branch.
  • test_fused_ar_rms.py (pytest): 12 passed; test_fused_ar_gemma_rmsnorm_case errors at setup (it is a script-mode function with a tp_size argument, not a pytest test).
  • test_ag_lamport.py passes. test_ar_add_lamport.py gives the same result on main and on this branch: every bit-difference column is identical, and no Lamport call has a differing bit. Its TP4 mixed sequence reports 1217950 differing bits (52 calls) on both trees. They come from the one call past the Lamport cap, which goes to RCCL and does not sum in rank order; the RCCL column differs the same way. The test does not fail on this.
  • tests/test_ar_rmsnorm_routing.py (CPU): 30 passed.
  • CPU ISA checks:
    • the plain Gluon kernel compiles to the same ISA as on main (ranks 0–3);
    • the HIP module's bf16/fp16 Lamport kernels and its 407 other kernels compile to the same instructions as on main.
  • Lint: ruff clean. black clean on the changed lines (black 26.5 would reformat one line of communicator_cuda.py that main already has).

Not covered

  • Gluon is TP4 only: the plain Gluon all-reduce exists only for TP4.
  • The 128-row cap of the Gluon path is kept as tuned. At M=128 Lamport is slightly faster for FP8 at hidden 4096 (10.27 vs 10.76 µs) and for bf16 at hidden 7168 (13.64 vs 14.54 µs); at M ≤ 64 Gluon is faster everywhere measured.
  • End-to-end model A/B.

Dependencies

None. Based on main. Supersedes #7396 (closed), which was stacked on #7082. Independent of #7082 and #7445, and merges cleanly with #7445.

PR Self-Review

Reviewed revision

1aef2c8

Behavior and intent

  • On gfx1250, all-reduce + residual add + RMSNorm + per-token FP8 quant becomes one kernel launch instead of two.
  • HIP Lamport one-shot (lamport_ar_rmsnorm_gfx1250, default, TP2/TP4): epilogue can now do per-token FP8 quant (one fp32 scale per row, optional bf16 output via emit_bf16). fused_allreduce_rmsnorm_quant(quant_type="per_token") uses it wherever should_lamport_ar_rms accepts the call (hidden multiple of 256 up to 8192; TP4 up to 8 MiB, TP2 up to 16 MiB). main ran Lamport bf16 plus a separate quant up to 4 MiB and custom_fused_ar_rms_quant above that. FP8 outputs and scales match custom_fused_ar_rms_quant bit for bit.
  • Gluon all_reduce_rmsnorm_per_token_quant (TP4, AITER_GLUON_FUSED_AR=1): plain Gluon all-reduce plus a residual/RMSNorm/optional per-token FP8 epilogue, any hidden multiple of 8 up to 24576; used up to 128 rows where Lamport could take the call, and up to 4 MiB where it can't.
  • Why: the extra launch costs time; TP4 hidden 6144 FP8 goes from 9.22-19.75 us on main's route to 7.83-17.02 us with Lamport fused (description table, HIP graph replay, MI455X x4).
  • Unchanged ISA: bf16/fp16 Lamport instantiations, the module's other 407 kernels and _all_reduce_kernel compile to the same instructions as main.

Validation and unverified scope

  • MI455X x4, rocm/fw-bringup:gfx1250-minimax-m3-20261112:
    • op_tests/multigpu_tests/test_fused_ar_rms_lamport.py -t 2 4 twice: every output bitwise equal to custom_fused_ar_rms(_quant) and to Lamport bf16 + per-token quant; mixed bf16/FP8 sequence (70 calls per TP, unaligned operands, graph replay) has 0 differing bits.
    • op_tests/multigpu_tests/triton_test/test_all_reduce_rmsnorm_quant.py (TP4): 3 passed under pytest and as a script.
    • triton_test/test_all_reduce.py, test_fused_ar_rms.py (12 passed), test_ag_lamport.py pass; tests/test_ar_rmsnorm_routing.py (CPU) 30 passed; CPU ISA checks as above.
  • Unverified: end-to-end model A/B; Gluon path at TP2/TP8 (Gluon all-reduce is TP4 only); the 128-row Gluon cap is kept as tuned, and at M=128 Lamport is slightly faster for some hidden sizes.

PR-specific question

Can the new routing send a per-token FP8 call to a kernel that cannot take it, or change results for bf16 callers?

  • Lamport is chosen only where should_lamport_ar_rms already accepts the call; Gluon only at TP4 with AITER_GLUON_FUSED_AR=1, hidden a multiple of 8 up to 24576, within the row/byte caps above. Everything else keeps the existing route. tests/test_ar_rmsnorm_routing.py and the dispatch test check which op the public entry points take.
  • bf16 callers: new kernel arguments are appended at the end, so bf16/fp16 Lamport kernels keep main's instructions and timing within noise; all_reduce_rmsnorm_quant keeps the bf16 calls it takes today.
  • test_ar_add_lamport.py at TP4 reports a bit difference for the one call past the Lamport cap, which goes to RCCL (non-rank-order sum). main reports the same numbers, so this PR does not cause it.
  • Per-token FP8 at hidden 32/64/128 follows the HIP per-group kernel dynamic_per_token_scaled_quant uses there: the amax is floored at 1e-10 and the reciprocal is an IEEE divide, so a zero row gets scale 1e-10/448 instead of 0.

Changed op tests

  • op_tests/multigpu_tests/test_fused_ar_rms_lamport.py
    • Covers: rows now also fail on an error ratio ≥ 5% against the torch reference; Lamport per-token FP8 output, scales and emit_bf16 output, bit for bit against custom_fused_ar_rms(_quant) and Lamport bf16 + per-token quant; a mixed bf16/FP8 shape sequence on one inbox, eager and in graph replay.
    • Before this PR: the FP8 calls fail, since Lamport has no per-token quant epilogue or emit_bf16; main passes only its bf16-only version.
    • Not redundant: extends the canonical Lamport test with a quant dimension instead of a new file.
  • op_tests/multigpu_tests/triton_test/test_all_reduce_rmsnorm_quant.py
    • Covers: new test_all_reduce_rmsnorm_per_token_quant (hidden 6144 bitwise vs Gluon all-reduce + rmsnorm2d_fwd_with_add + HIP per-token quant; hidden 2048/6152/16384 vs fp32 reference within 1 bf16 ulp / 1 FP8 code; FP8 bits vs the HIP per-token quant of its own bf16 out at hidden multiples of 16; edge rows incl. hidden 32/64/128, call-counter wrap, partial chunks, graph replay) and a dispatch test that the public ops take the new op.
    • Before this PR: fails, all_reduce_rmsnorm_per_token_quant does not exist.
    • Not redundant: the existing tests there cover all_reduce_rmsnorm_quant (power-of-2 hidden, per-128 scales), not per-token FP8 or non-power-of-2 hidden.

@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter standard tests on MI35X
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the Radeon R9700 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 8022 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

lirui927 pushed a commit that referenced this pull request Nov 16, 2026
This reverts commit 3e1ba30. #8022 replaces #7396 and is applied after the main all-reduce commits it builds on.
lirui927 and others added 2 commits November 16, 2026 10:44
On gfx1250, fused_allreduce_rmsnorm_quant (per-token FP8) ran the Lamport
one-shot AR + RMSNorm and then a separate per-token quant kernel up to
4 MiB, and custom_fused_ar_rms_quant above that. lamport_ar_rmsnorm_gfx1250
now also takes an FP8 output type: its epilogue then does the per-token
quant of ar_rmsnorm_gfx1250 (amax of the rounded bf16/fp16 output,
scale = amax / FP8 max, rcp, clamp, cvt_pk), so the call is one launch and
the FP8 out and scales are bit for bit those of custom_fused_ar_rms_quant.
In cluster mode the row amax goes through the cluster partials after a
second cluster barrier. With emit_bf16 the kernel also writes the
bf16/fp16 output.

fused_allreduce_rmsnorm_quant takes it wherever should_lamport_ar_rms
does (hidden a multiple of 256 up to 8192; TP4 up to 8 MiB, TP2 up to
16 MiB). Other calls keep their route.

The kernel keeps its argument layout, with scale_out and bf16_output
last, so its bf16/fp16 instantiations keep main's instructions byte for
byte (only the kernarg segment grows), and so do the other kernels of
the module. The FP8 instantiations use the registers of the bf16 ones.

test_fused_ar_rms_lamport.py checks the FP8 out, scale and emit_bf16
output bit for bit against custom_fused_ar_rms_quant and against Lamport
bf16 + the per-token quant, also in its mixed sequence, and now fails on
any bit difference.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…one launch

all_reduce_rmsnorm_per_token_quant runs the plain Gluon all-reduce
(_all_reduce_kernel, set up on TP4 with AITER_GLUON_FUSED_AR=1) with an
epilogue: residual add, RMSNorm (plain or Gemma) and optionally the
per-token FP8 quant, in one launch of _all_reduce_rmsnorm_kernel. Rows go
through the chunks and inboxes of the plain all-reduce, so any hidden
that is a multiple of 8 up to 24576 works and plain and fused calls share
the inboxes. At hidden 6144 the outputs are bit for bit those of the
plain all-reduce followed by add_rmsnorm (and the per-token quant of its
bf16 out); other sizes are within 1 bf16 ulp or 1 FP8 code of an fp32
reference. _all_reduce_kernel is unchanged, to the byte of its ISA.

Unlike all_reduce_rmsnorm_quant (power-of-2 hidden, one scale for each
128 values, inboxes for one hidden size), the scale is one value a row,
the (tokens, 1) of fused_allreduce_rmsnorm_quant(quant_type="per_token").

CudaCommunicator, TP4, bf16 in: the op takes calls up to the 4 MiB of
the plain all-reduce, but only up to _GLUON_AR_NORM_MAX_TOKENS (128) rows
where the Lamport one-shot could take them, as Lamport is faster past
that. The gate does not look at operand addresses, so all ranks take the
same kernel; an unaligned operand is copied. all_reduce_rmsnorm_quant
keeps its bf16 sizes (power-of-2 hidden), and emit_bf16 stays on Lamport.

Tests: the kernel cases go into test_all_reduce_rmsnorm_quant.py next to
those of the other Gluon AR + RMSNorm op, with its dispatch test checking
the new route; the routing runs on the CPU in tests/, which CI runs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lirui927
lirui927 marked this pull request as ready for review November 16, 2026 14:40
@lirui927
lirui927 requested a review from a team November 16, 2026 14:40
@github-actions github-actions Bot changed the title [HIP][Triton/Gluon] gfx1250 all-reduce + RMSNorm + per-token FP8 in one kernel [Triton/Gluon] [HIP] gfx1250 all-reduce + RMSNorm + per-token FP8 in one kernel Nov 16, 2026
@aiter-bot

aiter-bot commented Nov 16, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 1aef2c832437 · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

- On gfx1250, all-reduce + residual add + RMSNorm + per-token FP8 quant becomes one kernel launch instead of two.
- HIP Lamport one-shot (`lamport_ar_rmsnorm_gfx1250`, default, TP2/TP4): epilogue can now do per-token FP8 quant (one fp32 scale per row, optional bf16 output via `emit_bf16`). `fused_allreduce_rmsnorm_quant(quant_type="per_token")` uses it wherever `should_lamport_ar_rms` accepts the call (hidden multiple of 256 up to 8192; TP4 up to 8 MiB, TP2 up to 16 MiB). `main` ran Lamport bf16 plus a separate quant up to 4 MiB and `custom_fused_ar_rms_quant` above that. FP8 outputs and scales match `custom_fused_ar_rms_quant` bit for bit.
- Gluon `all_reduce_rmsnorm_per_token_quant` (TP4, `AITER_GLUON_FUSED_AR=1`): plain Gluon all-reduce plus a residual/RMSNorm/optional per-token FP8 epilogue, any hidden multiple of 8 up to 24576; used up to 128 rows where Lamport could take the call, and up to 4 MiB where it can't.
- Why: the extra launch costs time; TP4 hidden 6144 FP8 goes from 9.22-19.75 us on `main`'s route to 7.83-17.02 us with Lamport fused (description table, HIP graph replay, MI455X x4).
- Unchanged ISA: bf16/fp16 Lamport instantiations, the module's other 407 kernels and `_all_reduce_kernel` compile to the same instructions as `main`.

Validation and unverified scope

- MI455X x4, `rocm/fw-bringup:gfx1250-minimax-m3-20261112`:
  - `op_tests/multigpu_tests/test_fused_ar_rms_lamport.py -t 2 4` twice: every output bitwise equal to `custom_fused_ar_rms(_quant)` and to Lamport bf16 + per-token quant; mixed bf16/FP8 sequence (70 calls per TP, unaligned operands, graph replay) has 0 differing bits.
  - `op_tests/multigpu_tests/triton_test/test_all_reduce_rmsnorm_quant.py` (TP4): 3 passed under pytest and as a script.
  - `triton_test/test_all_reduce.py`, `test_fused_ar_rms.py` (12 passed), `test_ag_lamport.py` pass; `tests/test_ar_rmsnorm_routing.py` (CPU) 30 passed; CPU ISA checks as above.
- Unverified: end-to-end model A/B; Gluon path at TP2/TP8 (Gluon all-reduce is TP4 only); the 128-row Gluon cap is kept as tuned, and at M=128 Lamport is slightly faster for some hidden sizes.

PR-specific question

Can the new routing send a per-token FP8 call to a kernel that cannot take it, or change results for bf16 callers?
- Lamport is chosen only where `should_lamport_ar_rms` already accepts the call; Gluon only at TP4 with `AITER_GLUON_FUSED_AR=1`, hidden a multiple of 8 up to 24576, within the row/byte caps above. Everything else keeps the existing route. `tests/test_ar_rmsnorm_routing.py` and the dispatch test check which op the public entry points take.
- bf16 callers: new kernel arguments are appended at the end, so bf16/fp16 Lamport kernels keep `main`'s instructions and timing within noise; `all_reduce_rmsnorm_quant` keeps the bf16 calls it takes today.
- `test_ar_add_lamport.py` at TP4 reports a bit difference for the one call past the Lamport cap, which goes to RCCL (non-rank-order sum). `main` reports the same numbers, so this PR does not cause it.
- Per-token FP8 at hidden 32/64/128 follows the HIP per-group kernel `dynamic_per_token_scaled_quant` uses there: the amax is floored at 1e-10 and the reciprocal is an IEEE divide, so a zero row gets scale 1e-10/448 instead of 0.

Changed op tests

- `op_tests/multigpu_tests/test_fused_ar_rms_lamport.py`
  - Covers: rows now also fail on an error ratio ≥ 5% against the torch reference; Lamport per-token FP8 output, scales and `emit_bf16` output, bit for bit against `custom_fused_ar_rms(_quant)` and Lamport bf16 + per-token quant; a mixed bf16/FP8 shape sequence on one inbox, eager and in graph replay.
  - Before this PR: the FP8 calls fail, since Lamport has no per-token quant epilogue or `emit_bf16`; `main` passes only its bf16-only version.
  - Not redundant: extends the canonical Lamport test with a `quant` dimension instead of a new file.
- `op_tests/multigpu_tests/triton_test/test_all_reduce_rmsnorm_quant.py`
  - Covers: new `test_all_reduce_rmsnorm_per_token_quant` (hidden 6144 bitwise vs Gluon all-reduce + `rmsnorm2d_fwd_with_add` + HIP per-token quant; hidden 2048/6152/16384 vs fp32 reference within 1 bf16 ulp / 1 FP8 code; FP8 bits vs the HIP per-token quant of its own bf16 out at hidden multiples of 16; edge rows incl. hidden 32/64/128, call-counter wrap, partial chunks, graph replay) and a dispatch test that the public ops take the new op.
  - Before this PR: fails, `all_reduce_rmsnorm_per_token_quant` does not exist.
  - Not redundant: the existing tests there cover `all_reduce_rmsnorm_quant` (power-of-2 hidden, per-128 scales), not per-token FP8 or non-power-of-2 hidden.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The fused FP8 path omits the required zero-row scale floor for widths 32, 64, and 128, and the new tests do not fail when reference errors exceed the accepted threshold.

2 open issues
What changed in this PR

This PR fuses all-reduce, residual addition, RMSNorm and per-token FP8 quantization on gfx1250, reducing kernel launches in AITER’s distributed communication paths.

Changes:

  • Extends HIP Lamport kernels with per-token FP8 output, row scales and optional bf16/fp16 output.
  • Adds a TP4 Gluon fused operation and routes supported calls through it.
  • Expands numerical, graph-replay and routing tests.
File Description
tests/​test_ar_rmsnorm_routing.py Adds CPU tests for dispatch limits and precedence.
op_tests/​multigpu_tests/​triton_test/​test_all_reduce_rmsnorm_quant.py Tests Gluon outputs, graph replay and public dispatch.
op_tests/​multigpu_tests/​test_fused_ar_rms_lamport.py Extends Lamport tests to FP8 and mixed-call sequences.
csrc/​pybind/​custom_all_reduce_gfx1250_pybind.cu Exposes the quantized Lamport binding.
csrc/​kernels/​custom_all_reduce_gfx1250.cu Adds output validation and quantized Lamport dispatch.
csrc/​include/​custom_all_reduce_gfx1250.h Declares the quantized Lamport entry point.
csrc/​include/​custom_all_reduce_gfx1250.cuh Implements FP8 quantization and scale reduction in Lamport.
aiter/​ops/​triton/​comms/​all_reduce.py Adds the public Gluon wrapper and capacity checks.
aiter/​ops/​triton/​_gluon_kernels/​gfx1250/​comms/​all_reduce.py Implements fused Gluon communication and normalization.
aiter/​ops/​custom_all_reduce.py Registers the quantized Lamport operation.
aiter/​dist/​device_communicators/​custom_all_reduce.py Allocates outputs and invokes quantized Lamport.
aiter/​dist/​device_communicators/​communicator_cuda.py Routes supported calls between Gluon, Lamport and fallbacks.

Review effort: Balanced

…h; tests fail off the reference

dynamic_per_token_scaled_quant takes the per-group kernel for hidden 32, 64
and 128: the amax is floored at kAmaxFloor (1e-10) and the scale inverted
with an IEEE divide. The Gluon fused op used the wide path's steps (amax
from 0, v_rcp_f32) at every width, so a zero row there got scale 0 instead
of 1e-10 / 448. Use the group path's steps at those three widths; other
widths compile to the same ISA as before.

test_all_reduce_rmsnorm_per_token_quant now also checks, at every hidden
size that is a multiple of 16, that the FP8 out and scale are the bits of
the HIP per-token quant of the op's own bf16 out, and runs the edge rows
(a zero row among them) at hidden 32, 64 and 128. Hidden 6152 keeps the
fp32-reference check only: there the HIP per-token quant leaves the last 4
FP8 bytes of each row unwritten (hidden % 16 == 8 above 2048, also on
main). test_fused_ar_rms_lamport.py fails when a candidate's error ratio
against the torch reference reaches checkAllclose's tol_err_ratio (5%),
not only on bit differences against car_fused.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zufayu
zufayu requested review from a team and Boss2002n November 17, 2026 13:29

@TennyWang1223 TennyWang1223 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@TennyWang1223
TennyWang1223 merged commit f7c728a into ROCm:main Nov 19, 2026
jhinpan pushed a commit to jonahbernard/aiter that referenced this pull request Nov 20, 2026
…e_rmsnorm

ROCm#5670 made fused_allreduce_rmsnorm ask each communicator
should_fly_allreduce_rmsnorm() before the paths this test checks. The
CustomAllreduce stand-in from ROCm#8022 binds only the other routing gates,
so the custom_fused case past the Gluon limit raised AttributeError.
ROCm#8022's last CI ran on a base without ROCm#5670.

Bind the real gate with _fly_rms=None, which is its value on gfx1250,
where the FlyDSL fused engine does not build.

(cherry picked from commit 06ae37f)
zufayu pushed a commit that referenced this pull request Nov 20, 2026
…e_rmsnorm (#8313)

#5670 made fused_allreduce_rmsnorm ask each communicator
should_fly_allreduce_rmsnorm() before the paths this test checks. The
CustomAllreduce stand-in from #8022 binds only the other routing gates,
so the custom_fused case past the Gluon limit raised AttributeError.
#8022's last CI ran on a base without #5670.

Bind the real gate with _fly_rms=None, which is its value on gfx1250,
where the FlyDSL fused engine does not build.
zufayu pushed a commit that referenced this pull request Dec 3, 2026
…e/prefill kernels (#6277)

* [ASM] [MLA] Fix and optimize the gfx942 MLA decode/prefill kernels

Replace 20 gfx942 MLA code objects with fixed and optimized builds and add
one new kernel (32 heads, qlen 1). Kernel names, kernargs and grids are
unchanged, so every existing caller dispatches as before.

Bugs fixed (stock behavior):
- KV loads above 4 GiB: buffer_load offsets were page_id * stride in 32 bits
  (some kernels also took a 24-bit page id), so pools over 4 GiB read other
  tokens' KV. KV now loads with 64-bit global addresses in every kernel.
- Other 32-bit offset overflows (output/split data, kv_indptr, LSE, Q).
- Missing s_waitcnt before using load results (prologue KV tile, V transpose
  LDS reads, fp8 descales) -> stale data under memory pressure.
- MFMA -> VALU read hazard in the softmax (nondeterministic results).
- LDS races and missing barriers in the a8w8 qseqlen 1/2/4 kernels.
- 32x1 / 64x1 kernels: S == 1 null split pointer fault; the 32-head kernel
  ran one token per workgroup and was not causal for qlen > 1.
- qseqlen-2 a8w8 causal mask, PS empty work items, kv_scale handling in the
  paged qseqlen-4 PS kernel, reads of unwritten splits for qlen >= 9.

Dispatch: gqa_ratio 32, bf16, non-persistent now selects the new
MLA_A16W16_1TG_4W_32mx1_16nx1_Coex0_Msk1_QH16_Q1 kernel when
max_seqlen_q == 1 (new mla_asm.csv row) and the causal any-qlen kernel
otherwise.

Performance matches or beats stock on most measured shapes (up to ~20%
faster); the 64-bit KV addressing costs up to ~1.5% on a few memory-bound
shapes of the a8w8 qseqlen-4 kernels.

Tested on MI300X against an fp32/fp64 reference and a bit-exact oracle,
including KV pools above 4 GiB, injected stalls and 1 h soak runs, and with
op_tests (test_mla.py incl. the CI invocations, test_mla_persistent.py,
test_mla_sparse.py and the other MLA op_tests): all pass.

Signed-off-by: Jonah Bernard <[email protected]>

* [MLA] Extend test_mla_ltx.py gfx942 coverage to every fixed kernel

The gfx942 kv_address check now covers each MLA .co this PR fixes,
except the page_size 64 ds32 kernel. GFX942_PRESETS maps each preset
to the modes (nps / ps / prefill) that reach its kernels. The default
gfx942 run sweeps all of them: 84 cases, 20 kernels.

- FP8 and A16W8 configs, qlen 1-8, 8/16/32/64/128 heads
- mla_prefill_fwd (causal prefill) mode
- causal reference for qlen > 1; FP8-Q tolerance 6e-2
- persistent metadata uses the real Q/KV dtypes on gfx942
  (gfx950 keeps BF16)

gfx950 defaults and presets are unchanged.

Signed-off-by: Jonah Bernard <[email protected]>

* test_mla_ltx: cover the gfx942 page-64 ds32 MLA kernel at 4 GiB

Add qh16_ds32_q1/q2/q4 presets (uint8 KV) for
mla_a16w8_qh16_m16x4_n16x1_coex0_mask1_ps_page64_ds32. The harness packs fp8
nope, fp32 block scales and bf16 rope into 64-token pages and runs the
kv_address cases on them: one page below, across and above the 4 GiB boundary
(page 102,300), plus a 65-page context the metadata splits in two.

Signed-off-by: Jonah Bernard <[email protected]>

* [MLA] Pick the bf16 32-head qSeqLen 1 kernel only on gfx942

asm_mla.cu set config_max_seqlen_q = 1 for bf16 32-head non-persistent
decode with max_seqlen_q == 1 on every arch, but only the gfx942
mla_asm.csv has a qSeqLen 1 row for that config. get_heuristic_kernel_mla
needs an exact match, so gfx950 failed with "cannot get heuristic kernel".
Gate it on arch_id == "gfx942"; other archs use qSeqLen 0 as before.

Signed-off-by: Jonah Bernard <[email protected]>

* [ASM] [MLA] Fix the gfx950 MLA kernels and test the fp8 msk0 kernel in CI

Rebuild 12 gfx950 MLA .co files from the same sources as the gfx942
kernels in this PR (the .text matches the gfx942 builds). KV is read with
64-bit global loads, so pools above 4 GiB no longer wrap, and the
nondeterminism, the non-causal 64-head kernel, the 1-split fault in the
64-head kernel and the bf16-Q/fp8-KV PS fault are fixed.
mla_a8w8_qh128_m32x4_n16x2_msk0 has no gfx942 counterpart: it is the
fp8 128-head msk1 source built with MASK = 0. Kernel names and
mla_asm.csv rows are unchanged.

aiter_test.sh: on gfx950, add a test_mla.py run of non-causal fp8 decode
with qlen 2 and 4 (128 heads), which is the only path that reaches the
msk0 kernel.

Signed-off-by: Jonah Bernard <[email protected]>

* [HIP] [MLA] Add the missing barrier in mla_reduce_v1's massive row loop

In mla_reduce_v1_impl_massive (4 or more splits), warp 0 writes the LSE
scales of a row to p_lds_lse_scale, and every warp then reads them to
scale its part of the output. The row loop had no barrier after the
output pass, so when a block reduces more than one row (qlen > 1, or
folded heads), warp 0 could overwrite the scales with the next row's
while warp 1 was still reading them. Warp 1's dims (256-511) of that
row were then combined with the wrong row's weights.

This is the remaining failure in #6731: with this PR's stage-1 kernels,
the issue's repro (32 heads, qlen 4, 5 splits) gave 167 wrong calls in
400,000 on MI300X, each one token and one head in dims 256-511 only.
With the barrier: 0 in 400,000.

Signed-off-by: Jonah Bernard <[email protected]>

* [MLA] Add a test_mla_reduce case for the row-loop barrier

The previous commit's race needs many splits, many rows per workgroup and
a full GPU; none of the existing cases has all three, so they pass with
or without the barrier. The new case (16 heads, dv 512, 32 tiles x 64
splits x 32 rows) failed on every run without the barrier on MI300X (50
of 50, plus both dtypes of the full test on two GPUs) and passes with it.

Signed-off-by: Jonah Bernard <[email protected]>

* [ASM] [MLA] Apply the causal mask in bf16 128-head decode with qlen > 1

The non-persistent bf16 128-head decode always ran
mla_dec_stage1_bf16_a16w16_subQ128_mqa128, which has no causal mask, so
causal decode with qlen > 1 attended to future tokens (#6733).

Run mla_pfl_bf16_a16w16_causal_subQ128_mqa128 for that case instead. It is
the masked build of the same kernel and takes the decode arguments
unchanged. It skips splits past a query's last token, so stage 2 now uses
the per-query split count for it.

gfx950 ships the same two kernels (identical .text), so the fix covers it
too; it was only tested on gfx942.

Signed-off-by: Jonah Bernard <[email protected]>

* [Test] test_ar_norm_precedence: give the stand-in should_fly_allreduce_rmsnorm

#5670 made fused_allreduce_rmsnorm ask each communicator
should_fly_allreduce_rmsnorm() before the paths this test checks. The
CustomAllreduce stand-in from #8022 binds only the other routing gates,
so the custom_fused case past the Gluon limit raised AttributeError.
#8022's last CI ran on a base without #5670.

Bind the real gate with _fly_rms=None, which is its value on gfx1250,
where the FlyDSL fused engine does not build.

(cherry picked from commit 06ae37f)

* [Test] test_moe_2stage: accept the gfx942 FlyDSL clamped SiLU route

#8178 sends a gfx942 per_Token FP8 SiLU with an active swiglu_limit and no
tuned CK row to the FlyDSL whole-graph backend, which applies the clamp, and
checks the CK limits only when no FlyDSL backend takes the call.
test_plain_fp8_swiglu_limit_dispatch still assumed CK stage 1: it read
md.stage1.keywords on a FlyDSL result (AttributeError on MI300X), and it
expected NotImplementedError for per_Token at inter_dim 192, which FlyDSL
now serves.

The first two hunks are #8294's change. The inter_dim 192 expectation is the
assertion that #8294's own MI300X run still fails on.

* Revert "[Test] test_moe_2stage: accept the gfx942 FlyDSL clamped SiLU route"

This reverts commit fdcd7bd.

* [fused_moe] Keep CK-capable clamped SiLU off the gfx942 FlyDSL default

The whole-graph batch-1 and decode kernels clamp BF16 activations, so a
per-token call that CK can clamp was missing the per-token reference and
crashing the dispatch test on stage1 being None.

Co-authored-by: Cursor <[email protected]>
(cherry picked from commit ca91b9f)

* [MLA] Route gfx950 128-head bf16 causal qlen>1 decode to the masked prefill kernel too

mla_asm_decode_remap only forced ps=0 (and thus the masked-prefill-kernel
selection for causal qlen>1) on gfx942, so gfx950 kept running the plain
persistent decode kernel for this case, which has no per-query causal mask.
Meanwhile mla.py's masked_qh128_bf16 (which drives CAUSAL_PER_QUERY for the
stage-2 reduction) was already set for both gfx942 and gfx950, so stage 2
believed splits past each query's causal horizon were skipped on gfx950 too,
even though stage 1 never skipped them there.

gfx950 already ships and dispatches mla_pfl_bf16_a16w16_causal_subQ128_mqa128.co
(hsa/gfx950/mla/mla_asm.csv) with the 64-bit KV addressing fix from this PR,
so extending the gate just routes to an existing, already-tested kernel.

* Revert "[MLA] Route gfx950 128-head bf16 causal qlen>1 decode to the masked prefill kernel too"

This reverts commit 2cd4f38.

Forcing ps=0 for gfx950 128-head bf16 decode breaks every persistent
128-head bf16 decode on gfx950. The gfx950 block at the end of
mla_asm_decode_remap still tests `persistent`, not `ps`, and remaps the
shape to gqa 32 / qSeqLen 4. The lookup then asks for (gqa 32, ps 0,
qSeqLen 4), which hsa/gfx950/mla/mla_asm.csv does not have, so
test_mla_persistent.py, test_mla_persistent_round_robin.py and
test_mla_sparse.py fail on MI35X with "cannot get heuristic kernel!
... gqa:32 ps:0 ... qseqlen:4".

The CAUSAL_PER_QUERY concern does not need this change.
masked_qh128_bf16 only feeds the stage-2 reduction in the
non-persistent branch of mla_decode_fwd. That branch passes
num_kv_splits_indptr, so persistent is false and ps is already 0 on
gfx950: causal qlen > 1 already selects
mla_pfl_bf16_a16w16_causal_subQ128_mqa128 there. Persistent decode
reduces with mla_reduce_v1 and runs the qh32_qseqlen4 *_ps kernels,
which have causal and msk0 variants.

* [CI] [MLA] Gate the gfx950-only msk0 test on the live GPU arch

get_gfx() returns the last GPU_ARCHS entry. With GPU_ARCHS="gfx950;gfx942"
the gate read gfx942 on a gfx950 GPU and skipped the test; with
"gfx942;gfx950" it would run the gfx950-only kernel on gfx942.
get_gfx_runtime() reads the arch from rocminfo and ignores GPU_ARCHS.

---------

Signed-off-by: Jonah Bernard <[email protected]>
Co-authored-by: amd-bartgips <[email protected]>
Co-authored-by: Jin Pan <[email protected]>
Co-authored-by: jatseng-ai <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Jin Pan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants