Skip to content

[HIP][Triton/Gluon] gfx1250 decode all-reduce + RMSNorm (+ FP8 quant) in one kernel - #7396

Closed
lirui927 wants to merge 3 commits into
ROCm:lirui927/stack-on-7082from
lirui927:fuse/f1a-ar-norm-quant
Closed

lirui927 wants to merge 3 commits into
ROCm:lirui927/stack-on-7082from
lirui927:fuse/f1a-ar-norm-quant

Conversation

@lirui927

@lirui927 lirui927 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #7082 (base branch lirui927/stack-on-7082 = current main + #7082). Once #7082 lands, this PR will be rebased onto main.

What this PR does

On gfx1250 TP4 decode (small M), each row-parallel output goes through all-reduce, residual add, RMSNorm, and, before an FP8 GEMM, a per-token FP8 quant. Today that takes 2–3 kernel launches. This PR reduces it to one.

  1. Use [HIP] Fuse gfx1250 LL all-reduce RMSNorm FP8 epilogue #7082's fused norm + FP8 quant when QuickReduce is enabled. fused_allreduce_rmsnorm_quant used to skip the LL all-reduce + add_rmsnorm_quant path whenever QuickReduce was enabled. It now skips that path only when QuickReduce would actually take the message. Decode sizes get the 2-kernel path; large prefill messages stay on QuickReduce.
  2. Fold RMSNorm (and the FP8 quant) into the gfx1250 Gluon all-reduce kernel. _all_reduce_kernel gains an optional epilogue (bf16 norm, or norm + per-token FP8), so the whole call is one launch. It works for any hidden size that is a multiple of 8, up to 24576. A row is split into cdiv(hidden, 384) chunks over a power-of-two number of waves, with the last chunk masked. The supported range comes from one helper, norm_waves(hidden), which the dispatch also uses.
    • At hidden 6144 (and other multiples of 768) the epilogue reduces in the same order as add_rmsnorm(_quant), so outputs are bitwise identical. Other sizes are within 1 bf16 ulp or 1 FP8 code of an fp32 reference.
    • With the epilogue off, the kernel compiles to the same instructions as before.
    • The fused path is used for M <= AITER_GLUON_AR_NORM_MAX_TOKENS (default 256). AITER_GLUON_AR_NORM=0 turns it off; larger M keeps the existing routes.

Benefit

Against the previous stack (hidden 6144, time per call in µs; MI455X x4, TP4, HIP graph replay, slowest rank, median of 4 rounds; A/A noise <= 0.13 µs):

M FP8 before FP8 after bf16 before bf16 after
1 8.90 5.47 (-39%) 6.66 5.32 (-20%)
16 10.31 6.41 (-38%) 7.60 5.99 (-21%)
64 12.21 8.06 (-34%) 9.24 7.95 (-14%)
128 16.17 10.46 (-35%) 13.52 10.43 (-23%)
256 24.92 16.23 (-35%) 19.98 15.88 (-21%)

"Before" was measured on the earlier gfx1250 perf stack (2c8902d), not on main + #7082.

  • Kernels per call: 3 -> 1 (FP8), 2 -> 1 (bf16).
  • Prefill sizes (M = 2517, 4536) stay on QuickReduce and are unchanged.

Other hidden sizes: fused vs unfused (Gluon all-reduce + add_rmsnorm(_quant)), µs, same setup, M16 / M64 / M256:

hidden bf16 fused / unfused FP8 fused / unfused
4096 6.24/7.56 · 7.30/8.40 · 14.44/16.40 6.70/7.84 · 7.75/8.73 · 14.44/16.75
6144 5.98/7.53 · 7.59/10.53 · 15.55/21.10 6.48/7.98 · 8.02/10.71 · 15.84/21.55
7168 7.07/8.04 · 8.89/11.09 · 19.16/23.83 7.65/8.33 · 9.52/11.35 · 20.14/24.18
8192 7.39/8.32 · 9.37/12.17 · 20.61/25.52 8.09/8.48 · 10.17/12.15 · 22.31/25.92

Fused is faster at every size and M measured (M 1–256): 2–23% faster than unfused. Supporting arbitrary hidden did not slow down 6144: A/B against the 6144-only version is within ±0.1 µs for bf16 and 0.1–0.4 µs faster for FP8.

Testing

  • Outputs (FP8 bytes, scales, residual, bf16 out) hash identically before and after, for every M; graph replay matches eager.
  • op_tests/multigpu_tests/triton_test/test_all_reduce_rmsnorm.py on TP4: hidden 6144 bitwise against all-reduce + add_rmsnorm(_quant); hidden 2048/4096/5120/6152/7168/8192/16384 at M 1/7/64 within 1 bf16 ulp / 1 FP8 code of an fp32 reference; graph replay mixing sizes into NaN-filled outputs.
  • op_tests/multigpu_tests/test_fused_ar_rms.py dispatch tests (20 passed): any supported hidden takes the fused path (including 4096); sizes it cannot serve do not.
  • Not measured: end-to-end model A/B; M 257–341 (these stay on the commit-1 path); hidden 16384–24576 performance (32-wave builds spill 12–48 bytes).

@lirui927 lirui927 changed the title [HIP] Allow gfx1250 LL quant with QuickReduce enabled [HIP][Triton/Gluon] gfx1250 decode all-reduce + RMSNorm (+ FP8 quant) in one kernel Nov 6, 2026
@lirui927
lirui927 force-pushed the xiaobingsuper/m3-mi455-perf-stack branch from 2c8902d to 3499407 Compare November 10, 2026 07:46
@lirui927
lirui927 force-pushed the fuse/f1a-ar-norm-quant branch 2 times, most recently from d2ac969 to 77aa016 Compare November 12, 2026 04:45
@lirui927
lirui927 changed the base branch from xiaobingsuper/m3-mi455-perf-stack to main November 12, 2026 04:45
lirui927 and others added 2 commits November 12, 2026 08:10
On gfx1250 decode, the LL path of fused_allreduce_rmsnorm[_quant] runs
the gluon plain all-reduce and then a separate HIP add_rmsnorm(_quant)
kernel. Fold residual add, Gemma/plain RMSNorm and the optional
per-token FP8 quant into the epilogue of the existing _all_reduce_kernel,
so each call is one launch:

- senders are unchanged in role; epilogue launches run 8 waves per
  program, one 384-value chunk per wave
- one receiver program owns a whole row, one wave per slab; the sum of
  squares and the row max are reduced through LDS in the HIP kernel's
  order, so outputs are bitwise equal to all-reduce + add_rmsnorm_quant
- without the epilogue the kernel compiles to the same instructions
- CudaCommunicator routes hidden 6144, M <= AITER_GLUON_AR_NORM_MAX_TOKENS
  (default 256) to it; AITER_GLUON_AR_NORM=0 keeps the previous path

TP4 MI455X, HIP graph replay, slowest rank, per call (M16 / M64 / M256):
FP8 path 7.84 / 9.54 / 19.92 -> 6.41 / 8.06 / 16.23 us, bf16 path
7.59 / 9.24 / 20.10 -> 5.99 / 7.95 / 15.88 us versus the LL quant
epilogue alone. Part of wuhuikx/LLM-Booster#393.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lirui927
lirui927 force-pushed the fuse/f1a-ar-norm-quant branch from 77aa016 to 980096b Compare November 12, 2026 08:11
@lirui927
lirui927 changed the base branch from main to lirui927/stack-on-7082 November 12, 2026 08:11
@lirui927
lirui927 marked this pull request as ready for review November 12, 2026 08:16
…pilogue

all_reduce_rmsnorm took only hidden 6144. A row is now cdiv(hidden, 384)
chunks with a partial last chunk; a program runs norm_waves(hidden) waves
(the next power of 2 of cdiv(hidden, 768), at most 32), 2 chunks a
receiver wave. Values past the row are masked: senders post every line
of a chunk (0 past the row, with the tag), receivers do not poll chunks
past the row. Hidden 6144 keeps its 8 waves, unmasked senders and the
HIP reduction order, so it stays bitwise equal to all-reduce +
add_rmsnorm(_quant). norm_waves is the one dispatch rule: hidden a
multiple of 8, 8 to 24576.

Tests grade the other sizes against an fp32 reference (residual_out
exact, out within 1 bf16 ulp or 1 FP8 code, scale within 1 bf16 ulp of
the row max) and replay a graph into NaN-filled outputs. The dispatch
mock gains the attributes the base branch now reads.

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

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ Action required before merge (5)

  1. Drop the bf16 fused_allreduce_rmsnorm branch, or show it beats Lamport on current main. aiter/dist/device_communicators/communicator_cuda.py:501-519 runs after the gfx1250 Lamport one-shot AR+RMSNorm (:420, custom_all_reduce.py:2273). Lamport is on by default for TP4 up to 8 MiB, hidden%256==0, hidden<=8192, so it takes 4096/6144/7168/8192 decode. The existing Gluon fused kernel (:388) takes power-of-2 hidden before Lamport does. Your dispatch tests only reach the new branch because they mock should_lamport_ar_rms=False and gluon_ar=None (test_fused_ar_rms.py:1473,1483). The bf16 "before" numbers come from 2c8902d, which predates #7499 (Lamport). Either remove the branch or post a TP4 A/B against Lamport for the sizes it is meant to serve.
  2. Extend the existing Gluon fused kernel instead of adding a second AR+RMSNorm(+FP8) op, or explain in the PR why you can't. aiter/ops/triton/comms/fused/all_reduce_rmsnorm_quant.py:19 (_all_reduce_rmsnorm_kernel) already fuses AR + residual + RMSNorm + FP8 on gfx1250. It is missing per-token scale and non-power-of-2 hidden. The new all_reduce_rmsnorm (aiter/ops/triton/comms/all_reduce.py:124) has the same signature and a different scale contract: (tokens,1) vs (tokens,hidden//128). Duplicates like this are what aiter/ops/triton/README.md:15 forbids. If two kernels really have to stay, give the new op a name that says per-token, and state the reason in the PR.
  3. Remove the getattr defense for test mocks. communicator_cuda.py:36 uses getattr(comm, "gluon_ar_norm", False), but __init__ and the reuse_from path always set the attribute. Use comm.gluon_ar_norm and add gluon_ar_norm=False to the SimpleNamespace comms in test_fused_ar_rms.py that don't set it (e.g. the one patched at :1329).
  4. Re-measure the FP8 path against its real base. The table compares against 2c8902d, not main + #7082. Post per-call µs for main+#7082 (LL AR + add_rmsnorm_quant) vs this PR at M 1/16/64/256, hidden 6144, plus at least one end-to-end decode number from the ATOM consumer (ATOM_ENABLE_GLUON_FUSED_AR, per-token fused_allreduce_rmsnorm_quant).
  5. Rebase on main after #7082 lands, get CI green, and fix the small items. The base is lirui927/stack-on-7082, so no CI has run on a65bc68b3. Small items: the comment at communicator_cuda.py:507 ("the HIP add_rmsnorm below") describes the fallback, not this branch. The _gluon_ar_norm_comm docstring says only transport is mocked, but all_reduce is a Mock. Pass quant= by keyword at both all_reduce_rmsnorm call sites.

Reviewed at a65bc68. Stacked on unmerged #7082. #7445 (HIP fused-AR barrier) touches a different kernel and merges cleanly with this PR.

@lirui927

Copy link
Copy Markdown
Contributor Author

Superseded by #8022, which is based on main and does not need #7082: it carries the Gluon all-reduce + RMSNorm (+ per-token FP8) epilogue from this PR, and adds per-token FP8 to the Lamport AR + RMSNorm kernel for the default path. The review items above are addressed there.

@lirui927 lirui927 closed this Nov 16, 2026
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 pushed a commit that referenced this pull request Nov 16, 2026
…launch

The all_reduce_rmsnorm epilogue of #7396, on main and without #7082. The
plain Gluon all-reduce (_all_reduce_kernel, set up on TP4 with
AITER_GLUON_FUSED_AR=1) gains an optional epilogue: residual add, RMSNorm
and optionally the per-token FP8 quant, so the call is one launch. Any
hidden that is a multiple of 8 up to 24576 works (norm_waves). At hidden
6144 the outputs are bit for bit those of the same 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. Without the
epilogue the kernel is unchanged.

CudaCommunicator, TP4, bf16 in: all_reduce_rmsnorm 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 #6923 Gluon AR + RMSNorm keeps its bf16 sizes
(power-of-2 hidden), and emit_bf16 stays on Lamport.
AITER_GLUON_AR_NORM=0 turns the new path off.

TP4 MI455X, HIP graph replay, slowest rank, hidden 6144, per call
(M1 / M16 / M64 / M128), against the Lamport kernels:
FP8 7.58 / 8.70 / 10.01 / 13.29 -> 5.74 / 6.68 / 8.09 / 11.42 us,
bf16 6.74 / 7.54 / 8.85 / 11.94 -> 5.54 / 6.24 / 7.72 / 11.10 us.
Part of wuhuikx/LLM-Booster#393.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit e0fe5ee)

Conflict: aiter/dist/device_communicators/communicator_cuda.py, the same
qr_comm line as in the previous commit; kept.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants