Skip to content

[Triton/Gluon] [Feature] Fused all-reduce + RMSNorm + MXFP8 quant for TP decode on gfx950 - #7792

Merged
vgokhale merged 20 commits into
mainfrom
vinayak/fused-ar-rmsnorm-mxfp8
Nov 26, 2026
Merged

vgokhale merged 20 commits into
mainfrom
vinayak/fused-ar-rmsnorm-mxfp8

Conversation

@vgokhale

@vgokhale vgokhale commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR adds fused_all_reduce_rmsnorm_mxfp8 for TP decode on gfx950. One Gluon kernel does the bf16 all-reduce over 2, 4 or 8 ranks, the residual add, the RMSNorm and the MXFP8 quant. Before, these steps were an all-reduce kernel and a norm + quant kernel.

The all-reduce is a reduce-scatter, then an all-gather of the bf16 sum. The owner rank adds the ranks in rank order in fp32, as the AITER custom all-reduce does. Then each rank adds the residual and quantizes all rows, so all ranks get the same bits.

API

  • comm = AllReduceRmsnormMxfp8(cpu_group, max_tokens, hidden, config=None) makes the IPC inboxes (collective). It uses IpcCommBuffers from aiter/ops/triton/comms/ipc_buffers.py, which builds on IPCBufferPool from aiter/dist. config replaces keys of the tuned config (BLOCKS, num_warps).
  • x_q, x_scale, residual_out = fused_all_reduce_rmsnorm_mxfp8(x, residual, weight, eps, comm, gemma=False).
  • gemma=True uses 1 + weight (Gemma norm). gemma=False uses weight.
  • x_q is float8_e4m3fn. x_scale is uint8 E8M0 from mx_e8m0_scale, one scale for each 32 values. All outputs have all rows on each rank.
  • comm.error() and comm.reset() find and clear a timed-out wait.

Results

MI355X, hidden 6144, Gemma norm. The value is the time in us for each layer: the maximum of the ranks, then the median of 3 runs. A HIP graph has 8 calls. A small all-reduce before each replay starts the GPUs together.

Before: the AITER custom all-reduce, then one fused add + RMSNorm + MXFP8 kernel (gemma_fused_add_rmsnorm_mxfp8 from vLLM). After: this op.

tokens TP2 TP4 TP8
24 12.4 -> 10.9 (-12%) 10.8 -> 9.3 (-13%) 10.3 -> 11.4 (+11%)
48 17.9 -> 16.1 (-10%) 13.3 -> 11.6 (-13%) 12.0 -> 12.1 (+0%)
64 21.4 -> 19.4 (-9%) 14.9 -> 13.1 (-12%) 13.0 -> 12.7 (-3%)
96 28.8 -> 26.4 (-8%) 19.2 -> 16.9 (-12%) 15.4 -> 14.1 (-8%)
128 35.8 -> 33.4 (-7%) 22.9 -> 20.5 (-11%) 17.7 -> 15.4 (-13%)
160 43.0 -> 40.4 (-6%) 26.6 -> 23.8 (-10%) 19.5 -> 17.1 (-13%)
192 51.5 -> 47.5 (-8%) 30.1 -> 27.5 (-9%) 21.4 -> 18.7 (-13%)
256 64.4 -> 61.6 (-4%) 38.0 -> 34.6 (-9%) 25.2 -> 22.1 (-12%)

Tests

  • New multi-GPU test op_tests/multigpu_tests/triton_test/test_all_reduce_rmsnorm_mxfp8.py. It passes at 2, 4 and 8 ranks on MI355X.
  • At head 68890e6, the test passes at 2, 4 and 8 ranks. At 8 ranks it runs only the first shape, the sentinel check and the time-out check, because each other kernel variant compiles on all 8 ranks and took most of the CI time. 2 and 4 ranks run all checks.
  • The test computes the expected MXFP8 scale in fp64 with frexp, not with the kernel code. One case sets the group maxima in the tiny range (2.6e-36 to 5.3e-36), at exactly 1.75 x 2^k and up to the largest bf16 value. The old kernel fails this case.
  • The test compares all 3 outputs with a CPU reference. The reference adds the ranks in rank order in fp32 and uses the sum-of-squares order of the kernel. A bf16 or e4m3 value can be one rounding step from the reference, in at most 1 of 10,000 values (at least 8). The scale bytes must be equal. A failure gives the output, the number of values that differ and the largest step.
  • It covers hidden 6144, 7168, 2880 and 4096, both norms, token counts that are not a multiple of the world size, and a zero row.
  • It also covers 2 launches with no barrier, a HIP graph with 3 token counts, a 0xFFFF value in the data, and a forced time-out followed by reset.
  • Negative controls fail as expected: an eps 100 times larger (one-step changes in more than 1 of 10,000 values), a two-step change in one residual_out value, a changed scale byte, and an inverted time-out check.
  • New benchmark op_tests/op_benchmarks/triton/bench_all_reduce_rmsnorm_mxfp8.py. It uses the test's input generator. --sweep KEY=V1,V2 times other config values.

Shared code

This PR adds the shared code of the gfx950 comms ops. #7771 and #7832 build on it.

  • aiter/ops/triton/_gluon_kernels/common/comms_gfx950.py: polls, error records, 16-byte loads and stores, bf16 and e4m3 packing, the rank-order row sum, the RMSNorm and the MXFP8 store.
  • aiter/ops/triton/comms/ipc_buffers.py: IpcCommBuffers, the IPC buffers, colours, error, reset and close of a comm.

The mx_e8m0_scale helper (_gluon_kernels/common/utils.py) now uses only integer operations: it adds 0x200000 to the fp32 bits of amax and subtracts EXP_OFFSET from the exponent field. This removes v_log_f32 and the float-to-integer conversion, and each scale now uses 8 instructions, not 15. For all 2^32 fp32 inputs, NaN included, the scale byte is the same as before (exhaustive GPU test), so the other callers (the Gluon MXFP4/MXFP8 quant kernels) do not change.

Limitations

  • gfx950, 2, 4 or 8 ranks and bf16 only. hidden must be a multiple of 64, up to 8192.
  • max_tokens is 256 or less: one CTA owns or receives each row, and all CTAs must run at the same time.
  • At 8 ranks and 24 tokens, the op is 1 us slower than the old path.
  • The IPC buffer of each rank is 2 x 2 x world x ceil(max_tokens / world) x hidden x 2 bytes (12.6 MB at 256 tokens and hidden 6144).
  • The quant numbers can differ from other RMSNorm kernels by one code step, because the sum of squares has another order.
  • The gfx1250 op all_reduce_rmsnorm_quant uses fp8 with one fp32 scale for each 128 values, and 4 ranks. This op is for gfx950 and MXFP8.

PR Self-Review

Reviewed revision

14665de

Behavior and intent

This PR adds a new op, fused_all_reduce_rmsnorm_mxfp8, for TP decode on gfx950. One Gluon kernel does the bf16 all-reduce, the residual add, the RMSNorm and the MXFP8 quant. Before, these steps were an all-reduce kernel and a norm + quant kernel. The PR also adds the shared code of the gfx950 comms ops (_gluon_kernels/common/comms_gfx950.py and comms/ipc_buffers.py), which #7771 and #7832 use. No existing op changes.

Validation and unverified scope

  • op_tests/multigpu_tests/triton_test/test_all_reduce_rmsnorm_mxfp8.py at head 68890e6 (MI355X): passed at 2, 4 and 8 ranks. 14665de merges main. On Triton 3.9.0 (the CI wheel 3.9.0+amd.rocm7.2.0.git24d5394c, after the main bump [Triton/Gluon] [CI] [Build] Bump triton 7cb7b059 -> 24d5394c (3.9.0) with gfx950 fixes and config retune #8266), test_all_reduce_rmsnorm_mxfp8.py and test_all_reduce_rmsnorm_moe_route.py pass at 2, 4 and 8 ranks at 2143c23 of [Triton/Gluon] [Feature] Fused all-reduce + RMSNorm + MoE router + top-k + moe_sorting for TP decode on gfx950 #7832, which contains 14665de (MI355X). At 74c83bc, op_tests/triton_tests/utils/test_gluon_mx_e8m0_scale.py also passed. With the local image, all 3 outputs are bitwise equal to the CPU reference (the byte-exact test passed at a1f8263. The later commits change only the test and merge main, which adds only gfx1250 helpers to _gluon_kernels/common/utils.py).
  • The CI image has other Triton and PyTorch builds. There, 1 or 2 bf16 or e4m3 values of 1.5M were one rounding step from the reference, and the byte-exact test failed. No scale byte changed. c58e694 allows one rounding step in at most 1 of 10,000 values and keeps the scale bytes exact.
  • The CI 8-GPU job then failed in the time-out check at 8 ranks: the launch after reset timed out on all ranks. The check made a comm with another max_tokens, so it launched a new kernel variant. The rank that skipped the first launch loaded this variant only after reset, and the other ranks waited only 50 ms for it. In 68890e6 the check uses the kernel of the first shape, and the launch after reset has the default limit. When the last rank waits 0.3 s after reset, the old test fails and the new test passes. From an empty kernel cache, the 8-rank run takes 71 s, not 123 s.
  • Compared with the previous head, only these scale groups change: a maximum of exactly 1.75 x 2^k (one step higher), the tiny range (the bug) and a maximum of 1.75 x 2^127 or more. With random data at hidden 6144, about 0.45% of the groups change. residual_out does not change.
  • Time at hidden 6144, 4 ranks, 1 to 256 tokens: 0.98 to 1.01 of the previous head, in the run-to-run spread.
  • Unverified: architectures other than gfx950, and hidden sizes other than 6144, 7168, 2880 and 4096.

PR-specific question

Only the new op reads the new config configs/gfx950/gluon/fusions/all_reduce_rmsnorm_mxfp8/DEFAULT.json. Its keys are the hidden size: N_LEQ_4096 (4 warps) and any (8 warps), both with 256 CTAs. No existing op reads this file, so other ops and shapes keep their previous selection. Only the gfx950 comms ops import comms_gfx950.py and ipc_buffers.py. mx_e8m0_scale gives the same byte as before for every fp32 input, so its other callers keep their outputs.

Changed op tests

  • op_tests/multigpu_tests/triton_test/test_all_reduce_rmsnorm_mxfp8.py: new. It tests the op at 2, 4 and 8 ranks (at 8 ranks, the first shape and the sentinel and time-out checks) against a CPU reference: one rounding step in at most 1 of 10,000 bf16 or e4m3 values, and equal scale bytes. No other test covers this op.
  • op_tests/op_benchmarks/triton/bench_all_reduce_rmsnorm_mxfp8.py: new. It is the benchmark that the AITER Triton rules require for a new op.
  • op_tests/op_benchmarks/triton/utils/argparse.py: two new helpers, add_sweep_argument and get_sweep_configs, for --sweep. The existing functions do not change.
  • op_tests/triton_tests/utils/test_gluon_mx_e8m0_scale.py: new. It checks mx_e8m0_scale at 40 edge values (zero, denormals, 1.75 x 2^k, the largest value, inf and NaN) for EXP_OFFSET 2 and 8 against an independent frexp reference. No other test covers this helper.

… TP decode on gfx950

Add fused_all_reduce_rmsnorm_mxfp8 and its buffer class AllReduceRmsnormMxfp8.
One Gluon kernel does the bf16 all-reduce of the partial sums over 2, 4 or 8
ranks, the residual add, the RMSNorm (standard or Gemma) and the MXFP8 quant
(e4m3 values, E8M0 scale for each 32 values).

The all-reduce is a reduce-scatter into Lamport inboxes, then an all-gather of
the bf16 sum. The owner adds the ranks in rank order in fp32, as the AITER
custom all-reduce does. Each rank then norms and quantizes all rows, so all
ranks get the same bits. The sum of squares has a fixed order, and the test
checks all outputs bitwise against a CPU reference.

Each wait has a time limit. A wait that times out writes an error record into
the buffer of each rank, and reset() clears it. HIP graphs are supported.

Add a multi-GPU test (2, 4 and 8 ranks) and a benchmark.

Signed-off-by: Vinayak Gokhale <[email protected]>
@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 7792 --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.

vgokhale added a commit to vgokhale/vllm that referenced this pull request Nov 11, 2026
…MXFP8

Fills the post-MoE TODO of the decode glue. When the installed AITER has
fused_all_reduce_rmsnorm_mxfp8 (ROCm/aiter#7792, feature-detected), the
all-reduce after a decode-glue MoE half also adds the residual, applies
the next layer's Gemma RMSNorm and quantizes to MXFP8, in one launch,
and hands the next decoder layer an Mxfp8Carry (codes, E8M0 scales and
the new residual of every row on every rank); that layer then skips its
input norm. It applies when the next layer is a MoE layer taking MXFP8
attention input, no drafter hidden state is taken between the two
layers, no specialized decode kernel can take the next layer's place,
and the step has at most 256 rows (the op's limit; the glue's widths go
to 192). Otherwise the stock all-reduce runs, as before.

No env vars. The op's buffers are set up with the glue's own, at the
first eager forward (the profile run), agreed across ranks: an AITER
without the op, or a failed setup on any rank, keeps the stock path on
all of them. Its error record (set when a peer wait times out) is
checked with the glue's error word in the device-side health check
after each glue forward, the periodic epoch reset also resets its
inboxes, colours and error record (a separate collective phase), and
close() frees its buffers.

glue/carry.py and the decoder layer's Mxfp8Carry input are the same as
on the SP prefill branch (vinayak/m31-prefill-comms).

Checked on MI355X, TP4, one M3.1 MoE layer with random weights (4
GPUs), with vllm-project#7792's files installed: the carry's MXFP8 codes and scales
and the residual are bitwise equal to the stock all-reduce + fused Gemma
norm + MXFP8 quant on the same MoE rows at 24, 64, 96, 128 and 192
rows, also under a CUDA graph and after a forced timeout (error record
set on every rank, then the collective reset); the next layer's glue on
the carried residual matches it on the stock one. Without them, the
stock all-reduce runs. The post-MoE step (us a layer, CUDA graph, max
over ranks), stock all-reduce + fused norm vs the fused op: 24 rows
11.0 vs 9.0, 64 16.0 vs 13.1, 96 19.4 vs 16.5, 128 22.6 vs 20.2, 192
29.4 vs 27.1.

Signed-off-by: Vinayak Gokhale <[email protected]>
vgokhale added a commit to vgokhale/vllm that referenced this pull request Nov 11, 2026
…MXFP8

Fills the post-MoE TODO of the decode glue. When the installed AITER has
fused_all_reduce_rmsnorm_mxfp8 (ROCm/aiter#7792, feature-detected), the
all-reduce after a decode-glue MoE half also adds the residual, applies
the next layer's Gemma RMSNorm and quantizes to MXFP8, in one launch,
and hands the next decoder layer an Mxfp8Carry (codes, E8M0 scales and
the new residual of every row on every rank); that layer then skips its
input norm. It applies when the next layer is a MoE layer taking MXFP8
attention input, no drafter hidden state is taken between the two
layers, no specialized decode kernel can take the next layer's place,
and the step has at most 256 rows (the op's limit; the glue's widths go
to 192). Otherwise the stock all-reduce runs, as before.

No env vars. The op's buffers are set up with the glue's own, at the
first eager forward (the profile run), agreed across ranks: an AITER
without the op, or a failed setup on any rank, keeps the stock path on
all of them. Its error record (set when a peer wait times out) is
checked with the glue's error word in the device-side health check
after each glue forward, the periodic epoch reset also resets its
inboxes, colours and error record (a separate collective phase), and
close() frees its buffers.

glue/carry.py and the decoder layer's Mxfp8Carry input are the same as
on the SP prefill branch (vinayak/m31-prefill-comms).

Checked on MI355X, TP4, one M3.1 MoE layer with random weights (4
GPUs), with vllm-project#7792's files installed: the carry's MXFP8 codes and scales
and the residual are bitwise equal to the stock all-reduce + fused Gemma
norm + MXFP8 quant on the same MoE rows at 24, 64, 96, 128 and 192
rows, also under a CUDA graph and after a forced timeout (error record
set on every rank, then the collective reset); the next layer's glue on
the carried residual matches it on the stock one. Without them, the
stock all-reduce runs. The post-MoE step (us a layer, CUDA graph, max
over ranks), stock all-reduce + fused norm vs the fused op: 24 rows
11.0 vs 9.0, 64 16.0 vs 13.1, 96 19.4 vs 16.5, 128 22.6 vs 20.2, 192
29.4 vs 27.1.

Signed-off-by: Vinayak Gokhale <[email protected]>
@vgokhale
vgokhale marked this pull request as ready for review November 18, 2026 20:32
@vgokhale
vgokhale requested a review from a team November 18, 2026 20:32
@aiter-bot

aiter-bot commented Nov 18, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 14665de1e0fb · 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

This PR adds a new op, `fused_all_reduce_rmsnorm_mxfp8`, for TP decode on gfx950. One Gluon kernel does the bf16 all-reduce, the residual add, the RMSNorm and the MXFP8 quant. Before, these steps were an all-reduce kernel and a norm + quant kernel. The PR also adds the shared code of the gfx950 comms ops (`_gluon_kernels/common/comms_gfx950.py` and `comms/ipc_buffers.py`), which #7771 and #7832 use. No existing op changes.

Validation and unverified scope

- `op_tests/multigpu_tests/triton_test/test_all_reduce_rmsnorm_mxfp8.py` at head 68890e647 (MI355X): passed at 2, 4 and 8 ranks. 14665de1e merges main. On Triton 3.9.0 (the CI wheel `3.9.0+amd.rocm7.2.0.git24d5394c`, after the main bump #8266), `test_all_reduce_rmsnorm_mxfp8.py` and `test_all_reduce_rmsnorm_moe_route.py` pass at 2, 4 and 8 ranks at 2143c2345 of #7832, which contains 14665de1e (MI355X). At 74c83bc6a, `op_tests/triton_tests/utils/test_gluon_mx_e8m0_scale.py` also passed. With the local image, all 3 outputs are bitwise equal to the CPU reference (the byte-exact test passed at a1f8263be. The later commits change only the test and merge main, which adds only gfx1250 helpers to `_gluon_kernels/common/utils.py`).
- The CI image has other Triton and PyTorch builds. There, 1 or 2 bf16 or e4m3 values of 1.5M were one rounding step from the reference, and the byte-exact test failed. No scale byte changed. c58e694f3 allows one rounding step in at most 1 of 10,000 values and keeps the scale bytes exact.
- The CI 8-GPU job then failed in the time-out check at 8 ranks: the launch after `reset` timed out on all ranks. The check made a comm with another `max_tokens`, so it launched a new kernel variant. The rank that skipped the first launch loaded this variant only after `reset`, and the other ranks waited only 50 ms for it. In 68890e647 the check uses the kernel of the first shape, and the launch after `reset` has the default limit. When the last rank waits 0.3 s after `reset`, the old test fails and the new test passes. From an empty kernel cache, the 8-rank run takes 71 s, not 123 s.
- Compared with the previous head, only these scale groups change: a maximum of exactly 1.75 x 2^k (one step higher), the tiny range (the bug) and a maximum of 1.75 x 2^127 or more. With random data at hidden 6144, about 0.45% of the groups change. `residual_out` does not change.
- Time at hidden 6144, 4 ranks, 1 to 256 tokens: 0.98 to 1.01 of the previous head, in the run-to-run spread.
- Unverified: architectures other than gfx950, and hidden sizes other than 6144, 7168, 2880 and 4096.

PR-specific question

Only the new op reads the new config `configs/gfx950/gluon/fusions/all_reduce_rmsnorm_mxfp8/DEFAULT.json`. Its keys are the hidden size: `N_LEQ_4096` (4 warps) and `any` (8 warps), both with 256 CTAs. No existing op reads this file, so other ops and shapes keep their previous selection. Only the gfx950 comms ops import `comms_gfx950.py` and `ipc_buffers.py`. `mx_e8m0_scale` gives the same byte as before for every fp32 input, so its other callers keep their outputs.

Changed op tests

- `op_tests/multigpu_tests/triton_test/test_all_reduce_rmsnorm_mxfp8.py`: new. It tests the op at 2, 4 and 8 ranks (at 8 ranks, the first shape and the sentinel and time-out checks) against a CPU reference: one rounding step in at most 1 of 10,000 bf16 or e4m3 values, and equal scale bytes. No other test covers this op.
- `op_tests/op_benchmarks/triton/bench_all_reduce_rmsnorm_mxfp8.py`: new. It is the benchmark that the AITER Triton rules require for a new op.
- `op_tests/op_benchmarks/triton/utils/argparse.py`: two new helpers, `add_sweep_argument` and `get_sweep_configs`, for `--sweep`. The existing functions do not change.
- `op_tests/triton_tests/utils/test_gluon_mx_e8m0_scale.py`: new. It checks `mx_e8m0_scale` at 40 edge values (zero, denormals, 1.75 x 2^k, the largest value, inf and NaN) for EXP_OFFSET 2 and 8 against an independent `frexp` reference. No other test covers this helper.

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.

Move the Gluon device helpers of the gfx950 comms kernels into one
module, aiter/ops/triton/_gluon_kernels/gfx950/comms/common.py: the
Lamport poll (_lpoll, _poll_slots), the error record (_errec,
_fail_record), the 16-byte vector loads and stores, the bf16 and e4m3
packing, the lane butterfly and the quad exchange. The kernel imports
them from there. The fused all-reduce + MoE route kernel uses the same
module.

Two helpers get the names of the shared copies: _poll is _poll_slots,
and _bfly_sum(x) is _bfly_op(x, _BFLY_ADD). _st4 gets an optional CACHE
argument. Its default ("") gives the same store as before.

The kernel name (repr), the wrapper and the AMDGCN of the kernel do not
change.

Signed-off-by: Vinayak Gokhale <[email protected]>
vgokhale added a commit that referenced this pull request Nov 18, 2026
Use the shared gfx950 comms helpers (common.py, the same file as in #7792 and
#7832) for _pack_bf16, _bf_lo, _bf_hi, _errec_asm and _errec_cons. The error
record asm and constraints are the same strings for 1 to 8 buffers.
_fail_record and _drain stay here: their arguments differ.

Signed-off-by: Vinayak Gokhale <[email protected]>
@Boss2002n
Boss2002n requested a balanced review from Copilot November 18, 2026 22:33

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 scale calculation mishandles subnormal ratios, producing scale 0 and an FP8 input of 512 above the 448 maximum, while the test oracle repeats the same error.

1 open issue
What changed in this PR

Adds a fused Gluon operation for tensor-parallel decode on gfx950. It combines bf16 all-reduce, residual addition, RMSNorm, and MXFP8 quantization in one kernel for 2, 4, or 8 ranks.

Changes:

  • Adds the public wrapper, collective IPC buffer management, and fused kernel.
  • Introduces shared communication helpers and hidden-size-based launch configs.
  • Adds bitwise multi-GPU tests and a synchronized graph benchmark.
File Description
op_tests/​op_benchmarks/​triton/​bench_all_reduce_rmsnorm_mxfp8.py Benchmarks graph execution across ranks.
op_tests/​multigpu_tests/​triton_test/​test_all_reduce_rmsnorm_mxfp8.py Tests numerical results, graph replay, and timeout recovery.
aiter/​ops/​triton/​configs/​gfx950/​gluon/​fusions/​all_reduce_rmsnorm_mxfp8/​DEFAULT.json Selects launch settings by hidden size.
aiter/​ops/​triton/​comms/​fused/​all_reduce_rmsnorm_mxfp8.py Provides the public API and IPC buffer lifecycle.
aiter/​ops/​triton/​_gluon_kernels/​gfx950/​comms/​fused/​all_reduce_rmsnorm_mxfp8.py Implements fused communication, normalization, and quantization.
aiter/​ops/​triton/​_gluon_kernels/​gfx950/​comms/​common.py Supplies shared polling, packing, and lane-exchange helpers.

Review effort: Balanced

@zufayu
zufayu requested review from a team, Boss2002n and azaidy November 19, 2026 01:13
@Boss2002n Boss2002n assigned vgokhale and unassigned azaidy Nov 19, 2026

@Boss2002n Boss2002n 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.

Must fix before merge

  1. Very small values get a wrong scale (kernel): when the largest value in a group of 32 is between 2.6e-36 and 5.3e-36, the scale becomes 0, and values up to 896 go into fp8, which holds at most 448. The scale rule also differs from the other aiter MXFP8 ops: at 1.75 × 2^k it gives a scale one step lower. The test does not catch this because its reference uses the same code. Fix: use mx_e8m0_scale(am, 8) from _gluon_kernels/common/utils.py, and compute the expected scale in the test in a different way.
  2. The same code is in #7832 and #7771 (kernel): the sum, norm and quant code is the same as _row_sum, _norm_row and _store_rest in #7832, and the IPC class methods are copied in all three PRs. Fix: keep one copy and share it.
  3. The kernel is not in the tuner (DEFAULT.json): the tuner cannot try values for BLOCKS or num_warps. Fix: add an @kernel(...) entry, and add BLOCKS to SEARCH_SPACE.

Nice to fix

  • Add GMAX and PMAX to the repr keys (kernel), and make the docstrings shorter.
  • Put common.py in one place, _gluon_kernels/common/, and build #7771 and #7832 on it (common.py).
  • Remove token counts 24, 96, 128 and 192 at hidden 6144, and run the graph check for only one shape (test).
  • Use one input generator for both the test and the benchmark (bench).

…FP8 scale

The scale of a group whose amax was 2.6e-36 to 5.3e-36 was 2^-127. Then
values up to 896 went into e4m3, which holds at most 448. At an amax of
exactly 1.75 x 2^k, the scale was one step lower than the scale of the
other AITER MXFP8 ops.

The kernel now gets the scale from mx_e8m0_scale(amax, 8) in
_gluon_kernels/common/utils.py. It divides by the scale with ldexp,
because 2^-127 (scale byte 254) is not a normal fp32 value.

The test reference does not copy the kernel code: it rounds the amax
with frexp and computes in fp64. A new case has groups at the edges of
the rule (tiny amax, 1.75 x 2^k, the largest bf16 values) and checks
the reference against hand-computed scale bytes.

Signed-off-by: Vinayak Gokhale <[email protected]>
…luon_kernels/common

Move _gluon_kernels/gfx950/comms/common.py to
_gluon_kernels/common/comms_gfx950.py, next to the other shared Gluon
helpers. The module docstring says that the helpers are for gfx950 only.

The helpers that kernels import get names without a leading underscore,
for example poll_slots, fail_record, st4, bf_lo. _k4 is now dword_idx:
the kernels use k4 as a variable name. The asm builders stay private.

The README table of shared helpers and the Copilot reuse rule list the
module. The AMDGCN of the kernel does not change.

Signed-off-by: Vinayak Gokhale <[email protected]>
…t steps

The rank sum, the RMSNorm and the MXFP8 quant of a row are now shared
helpers in _gluon_kernels/common/comms_gfx950.py: row_sum, rmsnorm_row
and store_rmsnorm_row. They have the arguments of _row_sum, _norm_row
and _store_rest of the fused all-reduce + MoE route kernel (#7832), so
that kernel can call them without other changes. HAS_RES and QUANT
select the residual add and the quant.

One builder, _poll, now makes the Lamport poll and the tagged-word poll
of #7832 (_tpoll). For each poll size and scope, its asm and its
constraints are the same strings as before. poll_tags is the tagged
poll of #7832.

The kernel calls the shared helpers. The AMDGCN has the same
instructions in a different order (3 or 4 fewer s_nop) and the same
register counts. The outputs do not change.

Signed-off-by: Vinayak Gokhale <[email protected]>
The comm classes of the three gfx950 Gluon multi-GPU ops had copies of
the same methods: the IPC buffer pool, the peer buffers, _clear, error,
reset and close. These are now in one base class, IpcCommBuffers, in
aiter/ops/triton/comms/ipc_buffers.py. It uses IPCBufferPool of
aiter.dist, as before.

A subclass calls __init__ (gfx950 and group size checks, the time limit,
rank, device and CU count), sets its layout, then calls _open (buffers,
peers, colours, clear, barrier). _open takes the fill byte and the
number of bytes that a clear fills, so an op with zeroed flags (the MoE
combine + reduce-scatter) can use it. ERROR_BYTES is shared.

AllReduceRmsnormMxfp8 is now a subclass. Its constructor arguments and
its attributes (peers, device, max_tokens, blocks, config) do not
change.

Signed-off-by: Vinayak Gokhale <[email protected]>
…ut generator

The test no longer runs 24, 96, 128 and 192 tokens at hidden 6144: 1,
3, 64 and 256 test the same paths. The HIP graph check runs for the
first shape only.

generate_all_reduce_rmsnorm_mxfp8_inputs in the test makes the inputs of
the test and of the benchmark. The benchmark imports it, as the
benchmark rules ask.

Signed-off-by: Vinayak Gokhale <[email protected]>
…sweep

AllReduceRmsnormMxfp8 takes an optional config: BLOCKS and num_warps in
place of the tuned DEFAULT.json values. The config is an argument of
the comm, not of a call: all launches on one comm must use the same
CTAs, because each CTA keeps its own launch colour. The constructor
checks that num_warps is large enough for hidden.

The benchmark times the tuned config and each pair of --blocks and
--num-warps, with one comm for each config.

The AITER tuner cannot time this kernel: its workers time candidates
one GPU at a time, and all ranks must launch a collective together.

Signed-off-by: Vinayak Gokhale <[email protected]>
Compute the e8m0 scale byte with integer operations only. The helper adds
0x200000 to the fp32 bits of |amax| and takes the exponent field. Then it
subtracts EXP_OFFSET and clamps the result at 0. Inf and NaN give 254.

The old helper used log2, floor and a float-to-int conversion. On gfx950
this is v_log_f32 and approximately 15 instructions for each scale.

The new helper gives the same byte as the old helper for all 2^32 fp32
inputs that are not NaN, for EXP_OFFSET 0 to 15 (exhaustive check on
gfx950). This includes negative inputs: they give 254, or 0 when they
round to -0. A NaN amax now always gives 254. The old helper gave 254 or
0, as a function of the NaN payload.

Add a unit test with edge values for EXP_OFFSET 2 and 8.

Signed-off-by: Vinayak Gokhale <[email protected]>
Make the integer helper give the same byte as the former log2 formula for
all 2^32 fp32 inputs, NaN included. Then no caller output changes. The
callers are the comms kernels and the gfx950 and gfx1250 Gluon quant
kernels.

The helper now adds 0x200000 to the raw bits (mod 2^32), as the log2
formula did. For some NaNs this add sets the sign bit or wraps to an
exponent field of 0. These NaNs give 0, and the other NaNs give 254.

An exhaustive check on gfx950 finds no difference for all 2^32 inputs,
for EXP_OFFSET 0 to 15. The unit test checks NaNs on both sides of the
wrap and passes with the log2 formula and with the integer helper.

Signed-off-by: Vinayak Gokhale <[email protected]>
vgokhale added a commit that referenced this pull request Nov 20, 2026
…catter

Bring in the integer-only mx_e8m0_scale of #7792 (9f2d547). This op
does not use the helper. The merge keeps the stack on the #7792 head.

Signed-off-by: Vinayak Gokhale <[email protected]>
vgokhale added a commit that referenced this pull request Nov 20, 2026
…orm-router-topk-sort

Stack this PR on #7792. #7792 adds the shared gfx950 comms Gluon helpers
(_gluon_kernels/common/comms_gfx950.py), the IPC buffer base class
(comms/ipc_buffers.py) and the benchmark --sweep helpers. The next commits
switch this op to them.

Signed-off-by: Vinayak Gokhale <[email protected]>
vgokhale added a commit that referenced this pull request Nov 20, 2026
…duce-scatter

Bring in a1f8263 of #7792. This op does not use mx_e8m0_scale. The
merge keeps the stack on the #7792 head.

Signed-off-by: Vinayak Gokhale <[email protected]>
vgokhale added a commit that referenced this pull request Nov 20, 2026
…e MXFP8 scale

The kernel set the E8M0 scale to ceil(log2(amax / 448)) and used 0 when
amax / 448 was not a normal fp32 value. For a group amax from 2.6e-36 to
5.3e-36, the scale was 2^-127 and the scaled values went up to 896, but
e4m3 holds at most 448.

The kernel now uses mx_e8m0_scale(amax, 8), as #7792 and the other AITER
MXFP8 ops do, and scales the values with ldexp. The scale changes only for
these groups:

- amax from 1.75 x 2^-119 to 1.75 x 2^-118 (the bug above).
- amax exactly 1.75 x 2^k: the scale is 2^(k - 7), not 2^(k - 8).
- amax from 1.75 x 2^127: the scale is 2^127.

The test reference is now a copy of the #7792 reference (_mxfp8). It does
not use the formula of the kernel. A new case checks groups with an amax at
the edges of the rule, as in the #7792 test.

Signed-off-by: Vinayak Gokhale <[email protected]>
vgokhale added a commit that referenced this pull request Nov 20, 2026
…pers

The kernel had copies of code that #7792 and main already have. It now
uses the shared helpers:

- _gluon_kernels/common/comms_gfx950.py: the polls (poll_slots, and
  poll_tags in place of _tpoll and _poll_tags), the error records, the
  16-byte loads and stores, the lane exchanges, and the rank sum, RMSNorm
  and MXFP8 store of a row (row_sum, rmsnorm_row and store_rmsnorm_row in
  place of _row_sum, _norm_row and _store_rest).
- _gluon_kernels/common/utils.py: sum_combine in place of _add_i32, and
  fast_sigmoid in place of _sigmoid.

The own helper module _gluon_kernels/gfx950/comms/common.py is deleted.
The unused _top2 is deleted. The benchmark uses the shared --sweep helpers
(add_sweep_argument, get_sweep_configs) in place of its own copy.

The shared helpers have the same code as the deleted copies (the same
inline asm and the same operations), so the outputs do not change.
fast_sigmoid uses the same v_exp_f32 and v_rcp_f32 as _sigmoid. The
compiler can now pack its multiply and add into v_pk_mul_f32 and
v_pk_add_f32. The results are the same.

Signed-off-by: Vinayak Gokhale <[email protected]>
vgokhale added a commit that referenced this pull request Nov 20, 2026
AllReduceRmsnormMoeRoute had its own copy of the IPC buffer code of #7792:
the group checks, the buffer and peer mapping, the colours, the clear,
error(), reset() and close(). It is now a subclass of IpcCommBuffers
(comms/ipc_buffers.py). The constructor calls super().__init__, plans the
layout, allocates the scratch and calls _open. _clear also clears the
scratch. The class docstring now lists the error sites and the reset rule.

The layout, the buffer contents after a clear and the public API do not
change.

Signed-off-by: Vinayak Gokhale <[email protected]>
vgokhale added a commit that referenced this pull request Nov 20, 2026
…-topk-sort

Bring in the integer-only mx_e8m0_scale of #7792 (9f2d547). The shared
store_rmsnorm_row calls it for the MXFP8 output of this op. The scale
bytes do not change for inputs that are not NaN.

Signed-off-by: Vinayak Gokhale <[email protected]>
vgokhale added a commit that referenced this pull request Nov 20, 2026
…router-topk-sort

Bring in a1f8263 of #7792. The integer mx_e8m0_scale now gives the same
byte as the former log2 formula for every fp32 input, NaN included. The
outputs of this op do not change.

Signed-off-by: Vinayak Gokhale <[email protected]>
@vgokhale

Copy link
Copy Markdown
Contributor Author

Follow-up in 9f2d547 and a1f8263: mx_e8m0_scale (_gluon_kernels/common/utils.py) now uses only integer operations. It adds 0x200000 to the fp32 bits of amax and subtracts EXP_OFFSET from the exponent field. This removes v_log_f32 and the float-to-integer conversion: each scale uses 8 instructions, not 15. With the log2 version, #7832 was about 1% slower at 192 to 256 tokens; now it is not. For all 2^32 fp32 inputs, NaN included, the scale byte is the same as before (exhaustive GPU test for EXP_OFFSET 0 to 15), so the other callers do not change. The new test op_tests/triton_tests/utils/test_gluon_mx_e8m0_scale.py checks 40 edge values for EXP_OFFSET 2 and 8.

The test compared all output bytes. In the CI image (other Triton and
PyTorch builds) 1 or 2 bf16 or e4m3 values of 1.5M changed by one
rounding step, and the test failed.

Now a bf16 or e4m3 value can be one rounding step from the reference,
in at most 1 of 10,000 values (at least 8). The scale bytes must be
equal. A failure gives the output name, the number of values that
differ and the largest step.

Signed-off-by: Vinayak Gokhale <[email protected]>
vgokhale added a commit that referenced this pull request Nov 20, 2026
…m-router-topk-sort

Bring in c58e694 of #7792. Its multi-GPU test now allows a bf16 or
e4m3 value one rounding step from the reference. The kernels do not
change.

Signed-off-by: Vinayak Gokhale <[email protected]>
vgokhale added a commit that referenced this pull request Nov 20, 2026
…reduce-scatter

Bring in c58e694 of #7792. Its multi-GPU test now allows a bf16 or
e4m3 value one rounding step from the reference. The kernels do not
change.

Signed-off-by: Vinayak Gokhale <[email protected]>
Bring in main 008d53c. It has #8313, the fix of
tests/test_ar_rmsnorm_routing.py that failed in the 1-GPU CI job.
There are no conflicts.

Signed-off-by: Vinayak Gokhale <[email protected]>
vgokhale added a commit that referenced this pull request Nov 20, 2026
Bring in 74c83bc of #7792, which merges main 008d53c. Main has #8313, the
fix of tests/test_ar_rmsnorm_routing.py that failed in the 1-GPU CI
job. There are no conflicts.

Signed-off-by: Vinayak Gokhale <[email protected]>
vgokhale added a commit that referenced this pull request Nov 20, 2026
Bring in 74c83bc of #7792, which merges main 008d53c. Main has #8313, the
fix of tests/test_ar_rmsnorm_routing.py that failed in the 1-GPU CI
job. There are no conflicts.

Signed-off-by: Vinayak Gokhale <[email protected]>
Boss2002n
Boss2002n previously approved these changes Nov 21, 2026

@Boss2002n Boss2002n 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

Boss2002n and others added 2 commits November 21, 2026 04:24
…trim 8 ranks

In the CI 8-GPU job, the launch after reset timed out on all ranks at 8
ranks. The time-out check made a comm with another max_tokens, so it
launched a new kernel variant. The rank that skipped the first launch
loaded this variant only after reset, and the other ranks waited only
50 ms for it.

Now the sentinel and time-out checks use the comm size of the first
shape, so they launch a kernel that each rank has already compiled. The
50 ms limit applies only to the launch that the last rank skips. The
launch after reset has the default limit.

At 8 ranks the test runs only the first shape, the sentinel check and
the time-out check. Each other kernel variant compiles on all 8 ranks,
which took most of the CI time. 2 and 4 ranks run all checks.
At 8 ranks a run from an empty kernel cache takes 71 s, not 123 s
(MI355X).

Signed-off-by: Vinayak Gokhale <[email protected]>
vgokhale added a commit that referenced this pull request Nov 24, 2026
…router-topk-sort

Bring in 68890e6 of #7792. Its multi-GPU test reuses the first shape's
kernel in the time-out check and runs less at 8 ranks. The kernels do
not change.

Signed-off-by: Vinayak Gokhale <[email protected]>
vgokhale added a commit that referenced this pull request Nov 24, 2026
…duce-scatter

Bring in 68890e6 of #7792. Its multi-GPU test reuses the first shape's
kernel in the time-out check and runs less at 8 ranks. The kernels do
not change.

Signed-off-by: Vinayak Gokhale <[email protected]>
Bring in main 35df6ef. It has the Triton 3.9.0 bump (#8266), whose
fp4_utils.py fix the 1-GPU CI job needs: that job installs Triton 3.9.0.

Signed-off-by: Vinayak Gokhale <[email protected]>
vgokhale added a commit that referenced this pull request Nov 25, 2026
Bring in 14665de of #7792, which merges main 35df6ef. Main has the Triton 3.9.0
bump (#8266), whose fp4_utils.py fix the 1-GPU CI job needs.

Signed-off-by: Vinayak Gokhale <[email protected]>
azaidy added a commit that referenced this pull request Nov 25, 2026
… gfx950 (#7771)

* [Triton/Gluon] [Feature] Fused MoE top-k combine + reduce-scatter (gfx950)

Add fused_moe_combine_reduce_scatter: one Gluon kernel for gfx950 does
the MoE top-k combine and the reduce-scatter over 4 ranks (push mode).
Each rank combines the top-k rows of a token as mxfp4_moe_scatter_reduce
does and writes the row into the IPC inbox of the owner rank. The owner
adds the 4 ranks in rank order in fp32 and rounds once to bf16. The
combined [M, hidden] tensor is not written to memory.

Add the stage-2 keyword scatter_intermediate to _mxfp4_a4w4_stage2_fw
and _flydsl_v2_stage2_wrapper. With a dict and the bf16 scatter
epilogue, stage 2 returns the intermediate, reverse_sorted and
sorted_weights instead of the combine. With None, nothing changes.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] Support 2, 4 and 8 ranks in the MoE combine + reduce-scatter

Make the world size a constexpr (WORLD in 2, 4, 8). The peer buffers come
as a tuple and the per-peer code uses static loops. The inbox and the
flags are (WORLD - 1) x ceil(max_rows / WORLD) rows.

Add PARTS: PARTS CTAs share a row, one column part each, with a flag for
each (row, part). At 8 ranks the prefetch of 7 peer rows spills
registers with one CTA a row; PARTS 3 (hidden 6144) and 2 (hidden 3072,
5120) keep it in registers. The JSON config selects BLOCKS and PARTS by
world size and hidden size.

The 4-rank build (PARTS 1) has the same gfx950 instruction stream as
before (2779 instructions). The multi-GPU test runs at 2, 4 and 8 ranks.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] [Feature] Fused all-reduce + RMSNorm + MXFP8 quant for TP decode on gfx950

Add fused_all_reduce_rmsnorm_mxfp8 and its buffer class AllReduceRmsnormMxfp8.
One Gluon kernel does the bf16 all-reduce of the partial sums over 2, 4 or 8
ranks, the residual add, the RMSNorm (standard or Gemma) and the MXFP8 quant
(e4m3 values, E8M0 scale for each 32 values).

The all-reduce is a reduce-scatter into Lamport inboxes, then an all-gather of
the bf16 sum. The owner adds the ranks in rank order in fp32, as the AITER
custom all-reduce does. Each rank then norms and quantizes all rows, so all
ranks get the same bits. The sum of squares has a fixed order, and the test
checks all outputs bitwise against a CPU reference.

Each wait has a time limit. A wait that times out writes an error record into
the buffer of each rank, and reset() clears it. HIP graphs are supported.

Add a multi-GPU test (2, 4 and 8 ranks) and a benchmark.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] MoE combine + reduce-scatter: clear the stage-2 dict, reject empty weights

- _mxfp4_a4w4_stage2_fw and _flydsl_v2_stage2_wrapper clear the
  scatter_intermediate dict first. Before, a dict from an earlier scatter
  call kept its items when a later call wrote the complete output with
  another epilogue.
- fused_moe_combine_reduce_scatter rejects an empty sorted_weights. The
  kernel loads a weight for each (token, k), also for a skipped position.
- Test: one dict for a scatter call and then a reduce call, and the
  empty sorted_weights check.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] Share gfx950 comms Gluon helpers

Move the Gluon device helpers of the gfx950 comms kernels into one
module, aiter/ops/triton/_gluon_kernels/gfx950/comms/common.py: the
Lamport poll (_lpoll, _poll_slots), the error record (_errec,
_fail_record), the 16-byte vector loads and stores, the bf16 and e4m3
packing, the lane butterfly and the quad exchange. The kernel imports
them from there. The fused all-reduce + MoE route kernel uses the same
module.

Two helpers get the names of the shared copies: _poll is _poll_slots,
and _bfly_sum(x) is _bfly_op(x, _BFLY_ADD). _st4 gets an optional CACHE
argument. Its default ("") gives the same store as before.

The kernel name (repr), the wrapper and the AMDGCN of the kernel do not
change.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] Share gfx950 comms Gluon helpers

Use the shared gfx950 comms helpers (common.py, the same file as in #7792 and
#7832) for _pack_bf16, _bf_lo, _bf_hi, _errec_asm and _errec_cons. The error
record asm and constraints are the same strings for 1 to 8 buffers.
_fail_record and _drain stay here: their arguments differ.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_mxfp8: use mx_e8m0_scale for the MXFP8 scale

The scale of a group whose amax was 2.6e-36 to 5.3e-36 was 2^-127. Then
values up to 896 went into e4m3, which holds at most 448. At an amax of
exactly 1.75 x 2^k, the scale was one step lower than the scale of the
other AITER MXFP8 ops.

The kernel now gets the scale from mx_e8m0_scale(amax, 8) in
_gluon_kernels/common/utils.py. It divides by the scale with ldexp,
because 2^-127 (scale byte 254) is not a normal fp32 value.

The test reference does not copy the kernel code: it rounds the amax
with frexp and computes in fp64. A new case has groups at the edges of
the rule (tiny amax, 1.75 x 2^k, the largest bf16 values) and checks
the reference against hand-computed scale bytes.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_mxfp8: move the comms helpers to _gluon_kernels/common

Move _gluon_kernels/gfx950/comms/common.py to
_gluon_kernels/common/comms_gfx950.py, next to the other shared Gluon
helpers. The module docstring says that the helpers are for gfx950 only.

The helpers that kernels import get names without a leading underscore,
for example poll_slots, fail_record, st4, bf_lo. _k4 is now dword_idx:
the kernels use k4 as a variable name. The asm builders stay private.

The README table of shared helpers and the Copilot reuse rule list the
module. The AMDGCN of the kernel does not change.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_mxfp8: share the sum, norm and quant steps

The rank sum, the RMSNorm and the MXFP8 quant of a row are now shared
helpers in _gluon_kernels/common/comms_gfx950.py: row_sum, rmsnorm_row
and store_rmsnorm_row. They have the arguments of _row_sum, _norm_row
and _store_rest of the fused all-reduce + MoE route kernel (#7832), so
that kernel can call them without other changes. HAS_RES and QUANT
select the residual add and the quant.

One builder, _poll, now makes the Lamport poll and the tagged-word poll
of #7832 (_tpoll). For each poll size and scope, its asm and its
constraints are the same strings as before. poll_tags is the tagged
poll of #7832.

The kernel calls the shared helpers. The AMDGCN has the same
instructions in a different order (3 or 4 fewer s_nop) and the same
register counts. The outputs do not change.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_mxfp8: share the IPC buffer code

The comm classes of the three gfx950 Gluon multi-GPU ops had copies of
the same methods: the IPC buffer pool, the peer buffers, _clear, error,
reset and close. These are now in one base class, IpcCommBuffers, in
aiter/ops/triton/comms/ipc_buffers.py. It uses IPCBufferPool of
aiter.dist, as before.

A subclass calls __init__ (gfx950 and group size checks, the time limit,
rank, device and CU count), sets its layout, then calls _open (buffers,
peers, colours, clear, barrier). _open takes the fill byte and the
number of bytes that a clear fills, so an op with zeroed flags (the MoE
combine + reduce-scatter) can use it. ERROR_BYTES is shared.

AllReduceRmsnormMxfp8 is now a subclass. Its constructor arguments and
its attributes (peers, device, max_tokens, blocks, config) do not
change.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_mxfp8: trim the test, share its input generator

The test no longer runs 24, 96, 128 and 192 tokens at hidden 6144: 1,
3, 64 and 256 test the same paths. The HIP graph check runs for the
first shape only.

generate_all_reduce_rmsnorm_mxfp8_inputs in the test makes the inputs of
the test and of the benchmark. The benchmark imports it, as the
benchmark rules ask.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_mxfp8: add config= and a benchmark sweep

AllReduceRmsnormMxfp8 takes an optional config: BLOCKS and num_warps in
place of the tuned DEFAULT.json values. The config is an argument of
the comm, not of a call: all launches on one comm must use the same
CTAs, because each CTA keeps its own launch colour. The constructor
checks that num_warps is large enough for hidden.

The benchmark times the tuned config and each pair of --blocks and
--num-warps, with one comm for each config.

The AITER tuner cannot time this kernel: its workers time candidates
one GPU at a time, and all ranks must launch a collective together.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_mxfp8: shorter docstrings

Shorten the docstrings of the kernel module, the kernel, the comm class
and the wrapper. The detail of the sum of squares and of the Lamport
slots is now in the docstrings of the shared helpers.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_mxfp8: config keys and --sweep as in #7832

Make config= and the benchmark sweep the same as in the fused all-reduce +
MoE route op (#7832), so that the comms ops have one interface:

- config holds values that replace the values of the tuned config. An
  unknown key is an error.
- The benchmark takes --sweep KEY=V1,V2 (repeat for more keys) and times
  each combination as one line. A config that the constructor rejects is
  skipped with a warning.

add_sweep_argument and get_sweep_configs are new shared helpers in
op_tests/op_benchmarks/triton/utils/argparse.py, for the benchmarks of
the three comms ops.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] Keep the Copilot instructions unchanged

The README's shared-helpers table lists the new modules. Leave .github out of
this PR.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] moe_combine_reduce_scatter: use the shared gfx950 comms helpers

Use the device helpers of #7792 in
_gluon_kernels/common/comms_gfx950.py: bf_lo, bf_hi, pack_bf16 and
fail_record. Delete the copy of these helpers in
_gluon_kernels/gfx950/comms/common.py, and the local copy of
_fail_record in the kernel file (review: "_fail_record is defined
twice"). Also delete the stale comment above _thread_ids.

The shared fail_record broadcasts the buffer pointers to the lanes
(+ z) before the inline asm. The AMDGCN of
_moe_combine_reduce_scatter_kernel does not change.

The kernel keeps _drain, _thread_ids and its flag poll _poll local:
their semantics are different from the shared helpers.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] moe_combine_reduce_scatter: subclass IpcCommBuffers

MoeCombineReduceScatter is now a subclass of IpcCommBuffers (#7792).
The base class does the gfx950, group size and time limit checks, makes
the IPC buffers and the colours, and has error, reset and close.

Small differences:
- The constructor zeroes [0, inbox) of the buffer (the error record,
  the row flags and the done words) and then does a barrier.
- reset zeroes the error record one more time.
- The error sites are in the class docstring.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] moe_combine_reduce_scatter: limit BLOCKS to the CU count

All CTAs of a launch must run at the same time, because they wait for
each other. The comm now uses min(BLOCKS, CU count) CTAs, rounded down
to a multiple of PARTS, as in #7792. The comm keeps the value in
comm.blocks. The done words, the colours, the grid and the BLOCKS
constexpr of the kernel all use it.

On a 256-CU gfx950 the value is the same as before (256, or 255 with
PARTS 3), so the kernel and the buffers do not change there.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] moe_combine_reduce_scatter: add config= and a benchmark sweep

MoeCombineReduceScatter takes an optional config, as in #7792: values
that replace the values of the tuned DEFAULT.json config (BLOCKS, PARTS,
LAG, num_warps). An unknown key is an error. The config is an argument
of the comm, not of a call: the buffer layout and the colours depend on
BLOCKS and PARTS. The constructor checks the limits of the kernel (PARTS
divides hidden / 2, LAG >= 2, num_warps a power of 2 that is large
enough for the done words), so that a sweep skips a bad config.

The benchmark takes --sweep KEY=V1,V2 (the shared helpers of #7792) and
times each combination as one line. A config that the constructor
rejects is skipped with a warning.

The AITER tuner cannot time this kernel: each tuner worker times
candidates alone on one GPU, and all ranks must launch a collective
together.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] moe_combine_reduce_scatter: test fewer token counts

Remove the token counts 5857, 8192 and 14394 from the test. They test
the same paths as 2343 and 4096 (padding rows, more than LAG rows for
each CTA). Only the number of loop steps is larger. 16383 stays as the
largest count, so the buffer layout of the test does not change. The
benchmark still times 5857 and 14394.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] mx_e8m0_scale: integer-only scale byte

Compute the e8m0 scale byte with integer operations only. The helper adds
0x200000 to the fp32 bits of |amax| and takes the exponent field. Then it
subtracts EXP_OFFSET and clamps the result at 0. Inf and NaN give 254.

The old helper used log2, floor and a float-to-int conversion. On gfx950
this is v_log_f32 and approximately 15 instructions for each scale.

The new helper gives the same byte as the old helper for all 2^32 fp32
inputs that are not NaN, for EXP_OFFSET 0 to 15 (exhaustive check on
gfx950). This includes negative inputs: they give 254, or 0 when they
round to -0. A NaN amax now always gives 254. The old helper gave 254 or
0, as a function of the NaN payload.

Add a unit test with edge values for EXP_OFFSET 2 and 8.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] mx_e8m0_scale: same byte as the log2 formula for NaN

Make the integer helper give the same byte as the former log2 formula for
all 2^32 fp32 inputs, NaN included. Then no caller output changes. The
callers are the comms kernels and the gfx950 and gfx1250 Gluon quant
kernels.

The helper now adds 0x200000 to the raw bits (mod 2^32), as the log2
formula did. For some NaNs this add sets the sign bit or wraps to an
exponent field of 0. These NaNs give 0, and the other NaNs give 254.

An exhaustive check on gfx950 finds no difference for all 2^32 inputs,
for EXP_OFFSET 0 to 15. The unit test checks NaNs on both sides of the
wrap and passes with the log2 formula and with the integer helper.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_mxfp8 test: allow one rounding step

The test compared all output bytes. In the CI image (other Triton and
PyTorch builds) 1 or 2 bf16 or e4m3 values of 1.5M changed by one
rounding step, and the test failed.

Now a bf16 or e4m3 value can be one rounding step from the reference,
in at most 1 of 10,000 values (at least 8). The scale bytes must be
equal. A failure gives the output name, the number of values that
differ and the largest step.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_mxfp8 test: fix the time-out race, trim 8 ranks

In the CI 8-GPU job, the launch after reset timed out on all ranks at 8
ranks. The time-out check made a comm with another max_tokens, so it
launched a new kernel variant. The rank that skipped the first launch
loaded this variant only after reset, and the other ranks waited only
50 ms for it.

Now the sentinel and time-out checks use the comm size of the first
shape, so they launch a kernel that each rank has already compiled. The
50 ms limit applies only to the launch that the last rank skips. The
launch after reset has the default limit.

At 8 ranks the test runs only the first shape, the sentinel check and
the time-out check. Each other kernel variant compiles on all 8 ranks,
which took most of the CI time. 2 and 4 ranks run all checks.
At 8 ranks a run from an empty kernel cache takes 71 s, not 123 s
(MI355X).

Signed-off-by: Vinayak Gokhale <[email protected]>

---------

Signed-off-by: Vinayak Gokhale <[email protected]>
Co-authored-by: Satya Nikhil Kodukula <[email protected]>
Co-authored-by: azaidy <[email protected]>
@vgokhale
vgokhale merged commit 5564589 into main Nov 26, 2026
72 of 80 checks passed
@vgokhale
vgokhale deleted the vinayak/fused-ar-rmsnorm-mxfp8 branch November 26, 2026 18:28
vgokhale added a commit that referenced this pull request Nov 26, 2026
…p-k + moe_sorting for TP decode on gfx950 (#7832)

* [Triton/Gluon] [Feature] Fused all-reduce + RMSNorm + MXFP8 quant for TP decode on gfx950

Add fused_all_reduce_rmsnorm_mxfp8 and its buffer class AllReduceRmsnormMxfp8.
One Gluon kernel does the bf16 all-reduce of the partial sums over 2, 4 or 8
ranks, the residual add, the RMSNorm (standard or Gemma) and the MXFP8 quant
(e4m3 values, E8M0 scale for each 32 values).

The all-reduce is a reduce-scatter into Lamport inboxes, then an all-gather of
the bf16 sum. The owner adds the ranks in rank order in fp32, as the AITER
custom all-reduce does. Each rank then norms and quantizes all rows, so all
ranks get the same bits. The sum of squares has a fixed order, and the test
checks all outputs bitwise against a CPU reference.

Each wait has a time limit. A wait that times out writes an error record into
the buffer of each rank, and reset() clears it. HIP graphs are supported.

Add a multi-GPU test (2, 4 and 8 ranks) and a benchmark.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] [Feature] Fused all-reduce + RMSNorm + MoE router + top-k + moe_sorting for TP decode on gfx950

Add fused_all_reduce_rmsnorm_moe_route and its buffer class AllReduceRmsnormMoeRoute.
One persistent Gluon kernel goes from the partial sums of a row-parallel layer to the
inputs of the routed MoE: the all-reduce over 2, 4 or 8 ranks, the residual add, the
RMSNorm (standard or Gemma) and its optional MXFP8 copy, the router GEMM (fp32 or bf16
weights, fp32 logits), the top-k (sigmoid + correction bias or softmax, optional group
limit, renormalization, routed scaling factor), the moe_sorting outputs (any block size)
and the zeroed moe_buf.

The all-reduce is a one-shot push for small calls and a reduce-scatter + all-gather
above, chosen by the bytes a rank sends. The ranks are added in rank order in fp32
with one bf16 rounding, as the AITER custom all-reduce does. In the two-shot protocol
each rank routes its own rows and the top-k picks go to every rank. All ranks get the
same bits. The sort keeps the tokens of each expert in ascending order, as moe_sorting.

The row count is a runtime value; the kernel variants are power-of-2 row buckets.
Experts, top-k, hidden size and the router layout are compile-time values.

Each wait has a time limit. A wait that times out writes an error record into the
buffer of each rank, and reset() clears it. HIP graphs are supported.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] Share gfx950 comms Gluon helpers

Move the Gluon device helpers of the gfx950 comms kernels into one
module, aiter/ops/triton/_gluon_kernels/gfx950/comms/common.py: the
Lamport poll (_lpoll, _poll_slots), the error record (_errec,
_fail_record), the 16-byte vector loads and stores, the bf16 and e4m3
packing, the lane butterfly and the quad exchange. The kernel imports
them from there. The fused all-reduce + RMSNorm + MXFP8 kernel uses the
same module.

Use triton.next_power_of_2 in place of the local _next_pow2 (kernel)
and _pow2 (wrapper). They are equal for all n >= 1, and the kernel and
the wrapper give them no other values. Remove _BFLY_MAX and _BFLY_MINI,
which nothing used.

The kernel name (repr), the wrapper results and the AMDGCN of the kernel
do not change.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] Share gfx950 comms Gluon helpers

Move the Gluon device helpers of the gfx950 comms kernels into one
module, aiter/ops/triton/_gluon_kernels/gfx950/comms/common.py: the
Lamport poll (_lpoll, _poll_slots), the error record (_errec,
_fail_record), the 16-byte vector loads and stores, the bf16 and e4m3
packing, the lane butterfly and the quad exchange. The kernel imports
them from there. The fused all-reduce + MoE route kernel uses the same
module.

Two helpers get the names of the shared copies: _poll is _poll_slots,
and _bfly_sum(x) is _bfly_op(x, _BFLY_ADD). _st4 gets an optional CACHE
argument. Its default ("") gives the same store as before.

The kernel name (repr), the wrapper and the AMDGCN of the kernel do not
change.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_moe_route: reject a max_tokens with no free CTA

A call takes one reduce CTA for each row of its power-of-2 routed bucket, and
the pushes need a free CTA. At 2 ranks and 256 CTAs, max_tokens 257 to 510
passed the constructor, but a call with more than 256 tokens (a 512-row bucket,
256 reduce CTAs) failed with ZeroDivisionError in _constexprs. The
constructor now rejects such a max_tokens. The test checks max_tokens 300 and
512: a rejected value, or a correct call with that many tokens.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_moe_route: reject shapes that need too much LDS

Some shapes in the documented limits need more LDS than a gfx950 CU has
(160 KiB). For example, 2048 experts at hidden 8192 need 304 KiB (the
partial logits of the route step), and top-64 at 512 tokens needs 266 KiB
(the picks of the sort step). The constructor accepted these shapes, and the
launch failed.

The constructor now computes the LDS of each kernel variant (one for each
token bucket and protocol up to max_tokens) and rejects the shape when one
variant needs more than the LDS of a CU. The compiler reuses LDS between the
router, route and sort steps, so the largest step sets the size. The formula
assumes a correction bias. It gives the same size as the compiled kernels
(shared-memory size in the Triton metadata) for each variant of the shapes
that we compiled, and it is larger by the size of the bias buffer when a
call has no bias and more than 256 experts.

The test checks that the constructor rejects 2048 experts at hidden 8192.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_moe_route: reject a correction bias with softmax

With softmax scoring and a correction bias, the kernel ranked the experts by
logit + bias. vLLM ranks them by softmax(logit) + bias, so the picks were
different. Example: logits [0, 1] and bias [0.5, 0] give expert 1 in the
kernel and expert 0 in vLLM. The wrapper now rejects a correction bias with
softmax. Sigmoid with a bias does not change.

The same input could also give NaN weights. The renormalized softmax
subtracted the logit of the first pick, and with a bias the first pick does
not always have the largest logit. When a picked logit was 88.7 or more
above the first one, exp overflowed to inf and the weights were
inf / inf = NaN. The kernel now subtracts the largest picked logit. Without
a bias, this is the logit of the first pick, so the results do not change.

The test checks softmax routing (renormalized and not) with picked logits
up to 300 apart, and that the wrapper rejects softmax with a bias.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_moe_route: reject inputs that give a wrong top-k

Three inputs gave a wrong top-k with no error. The wrapper now rejects them:

- A strided correction bias. The kernel reads bias[e] at offset e.
- Kept groups with fewer experts than topk (topk_group * experts per group <
  topk). When no allowed expert was left, the kernel picked expert 0 for the
  remaining slots.
- Groups of one expert with a correction bias. The score of a group is the
  sum of its 2 best experts, so each group score was -inf, the kernel kept
  no group and picked expert 0 for every slot. vLLM's grouped_topk raises an
  error for this input.

The test checks that the wrapper rejects each of them.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_moe_route: test block sizes, 384 experts and no residual

The test used only block_size 16, at most 256 experts and a residual. Each
shape now has a block size and a residual flag:

- block_size 32, 64 and 128 on the second, third and fourth shapes. The
  test compares the sort with moe_sorting at the same block size.
- A new shape with 384 experts (selection values and bias in LDS), groups
  with 48 experts, a bias, Gemma and MXFP8.
- residual=None on the third shape and on the new shape.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_moe_route: config argument and benchmark sweep

The AITER tuner cannot time this kernel. It runs one worker on each GPU,
and each worker times one launch at a time. This kernel is a collective:
all ranks must launch it together, and each rank waits for the data of the
other ranks.

AllReduceRmsnormMoeRoute now takes an optional config dict. Its values
replace the values of the JSON config, and an unknown key is an error. The
benchmark uses it: --sweep KEY=V1,V2 (one or more keys) times each
combination of the values as one line, on all ranks together. A config that
the constructor rejects is skipped with a warning. Without --sweep, the
benchmark times the JSON config as before.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_mxfp8: use mx_e8m0_scale for the MXFP8 scale

The scale of a group whose amax was 2.6e-36 to 5.3e-36 was 2^-127. Then
values up to 896 went into e4m3, which holds at most 448. At an amax of
exactly 1.75 x 2^k, the scale was one step lower than the scale of the
other AITER MXFP8 ops.

The kernel now gets the scale from mx_e8m0_scale(amax, 8) in
_gluon_kernels/common/utils.py. It divides by the scale with ldexp,
because 2^-127 (scale byte 254) is not a normal fp32 value.

The test reference does not copy the kernel code: it rounds the amax
with frexp and computes in fp64. A new case has groups at the edges of
the rule (tiny amax, 1.75 x 2^k, the largest bf16 values) and checks
the reference against hand-computed scale bytes.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_mxfp8: move the comms helpers to _gluon_kernels/common

Move _gluon_kernels/gfx950/comms/common.py to
_gluon_kernels/common/comms_gfx950.py, next to the other shared Gluon
helpers. The module docstring says that the helpers are for gfx950 only.

The helpers that kernels import get names without a leading underscore,
for example poll_slots, fail_record, st4, bf_lo. _k4 is now dword_idx:
the kernels use k4 as a variable name. The asm builders stay private.

The README table of shared helpers and the Copilot reuse rule list the
module. The AMDGCN of the kernel does not change.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_mxfp8: share the sum, norm and quant steps

The rank sum, the RMSNorm and the MXFP8 quant of a row are now shared
helpers in _gluon_kernels/common/comms_gfx950.py: row_sum, rmsnorm_row
and store_rmsnorm_row. They have the arguments of _row_sum, _norm_row
and _store_rest of the fused all-reduce + MoE route kernel (#7832), so
that kernel can call them without other changes. HAS_RES and QUANT
select the residual add and the quant.

One builder, _poll, now makes the Lamport poll and the tagged-word poll
of #7832 (_tpoll). For each poll size and scope, its asm and its
constraints are the same strings as before. poll_tags is the tagged
poll of #7832.

The kernel calls the shared helpers. The AMDGCN has the same
instructions in a different order (3 or 4 fewer s_nop) and the same
register counts. The outputs do not change.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_mxfp8: share the IPC buffer code

The comm classes of the three gfx950 Gluon multi-GPU ops had copies of
the same methods: the IPC buffer pool, the peer buffers, _clear, error,
reset and close. These are now in one base class, IpcCommBuffers, in
aiter/ops/triton/comms/ipc_buffers.py. It uses IPCBufferPool of
aiter.dist, as before.

A subclass calls __init__ (gfx950 and group size checks, the time limit,
rank, device and CU count), sets its layout, then calls _open (buffers,
peers, colours, clear, barrier). _open takes the fill byte and the
number of bytes that a clear fills, so an op with zeroed flags (the MoE
combine + reduce-scatter) can use it. ERROR_BYTES is shared.

AllReduceRmsnormMxfp8 is now a subclass. Its constructor arguments and
its attributes (peers, device, max_tokens, blocks, config) do not
change.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_mxfp8: trim the test, share its input generator

The test no longer runs 24, 96, 128 and 192 tokens at hidden 6144: 1,
3, 64 and 256 test the same paths. The HIP graph check runs for the
first shape only.

generate_all_reduce_rmsnorm_mxfp8_inputs in the test makes the inputs of
the test and of the benchmark. The benchmark imports it, as the
benchmark rules ask.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_mxfp8: add config= and a benchmark sweep

AllReduceRmsnormMxfp8 takes an optional config: BLOCKS and num_warps in
place of the tuned DEFAULT.json values. The config is an argument of
the comm, not of a call: all launches on one comm must use the same
CTAs, because each CTA keeps its own launch colour. The constructor
checks that num_warps is large enough for hidden.

The benchmark times the tuned config and each pair of --blocks and
--num-warps, with one comm for each config.

The AITER tuner cannot time this kernel: its workers time candidates
one GPU at a time, and all ranks must launch a collective together.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_mxfp8: shorter docstrings

Shorten the docstrings of the kernel module, the kernel, the comm class
and the wrapper. The detail of the sum of squares and of the Lamport
slots is now in the docstrings of the shared helpers.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_mxfp8: config keys and --sweep as in #7832

Make config= and the benchmark sweep the same as in the fused all-reduce +
MoE route op (#7832), so that the comms ops have one interface:

- config holds values that replace the values of the tuned config. An
  unknown key is an error.
- The benchmark takes --sweep KEY=V1,V2 (repeat for more keys) and times
  each combination as one line. A config that the constructor rejects is
  skipped with a warning.

add_sweep_argument and get_sweep_configs are new shared helpers in
op_tests/op_benchmarks/triton/utils/argparse.py, for the benchmarks of
the three comms ops.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] Keep the Copilot instructions unchanged

The README's shared-helpers table lists the new modules. Leave .github out of
this PR.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_moe_route: use mx_e8m0_scale for the MXFP8 scale

The kernel set the E8M0 scale to ceil(log2(amax / 448)) and used 0 when
amax / 448 was not a normal fp32 value. For a group amax from 2.6e-36 to
5.3e-36, the scale was 2^-127 and the scaled values went up to 896, but
e4m3 holds at most 448.

The kernel now uses mx_e8m0_scale(amax, 8), as #7792 and the other AITER
MXFP8 ops do, and scales the values with ldexp. The scale changes only for
these groups:

- amax from 1.75 x 2^-119 to 1.75 x 2^-118 (the bug above).
- amax exactly 1.75 x 2^k: the scale is 2^(k - 7), not 2^(k - 8).
- amax from 1.75 x 2^127: the scale is 2^127.

The test reference is now a copy of the #7792 reference (_mxfp8). It does
not use the formula of the kernel. A new case checks groups with an amax at
the edges of the rule, as in the #7792 test.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_moe_route: use the shared comms helpers

The kernel had copies of code that #7792 and main already have. It now
uses the shared helpers:

- _gluon_kernels/common/comms_gfx950.py: the polls (poll_slots, and
  poll_tags in place of _tpoll and _poll_tags), the error records, the
  16-byte loads and stores, the lane exchanges, and the rank sum, RMSNorm
  and MXFP8 store of a row (row_sum, rmsnorm_row and store_rmsnorm_row in
  place of _row_sum, _norm_row and _store_rest).
- _gluon_kernels/common/utils.py: sum_combine in place of _add_i32, and
  fast_sigmoid in place of _sigmoid.

The own helper module _gluon_kernels/gfx950/comms/common.py is deleted.
The unused _top2 is deleted. The benchmark uses the shared --sweep helpers
(add_sweep_argument, get_sweep_configs) in place of its own copy.

The shared helpers have the same code as the deleted copies (the same
inline asm and the same operations), so the outputs do not change.
fast_sigmoid uses the same v_exp_f32 and v_rcp_f32 as _sigmoid. The
compiler can now pack its multiply and add into v_pk_mul_f32 and
v_pk_add_f32. The results are the same.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_moe_route: share the IPC buffer code

AllReduceRmsnormMoeRoute had its own copy of the IPC buffer code of #7792:
the group checks, the buffer and peer mapping, the colours, the clear,
error(), reset() and close(). It is now a subclass of IpcCommBuffers
(comms/ipc_buffers.py). The constructor calls super().__init__, plans the
layout, allocates the scratch and calls _open. _clear also clears the
scratch. The class docstring now lists the error sites and the reset rule.

The layout, the buffer contents after a clear and the public API do not
change.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_moe_route: shorter docstrings

Shorten the docstrings of the kernel module, the kernel, the comm class
and the wrapper. The detail of the sum of squares, the Lamport slots and
the MXFP8 scale is now in the docstrings of the shared helpers. The
sorted_ids format is the moe_sorting format.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] mx_e8m0_scale: integer-only scale byte

Compute the e8m0 scale byte with integer operations only. The helper adds
0x200000 to the fp32 bits of |amax| and takes the exponent field. Then it
subtracts EXP_OFFSET and clamps the result at 0. Inf and NaN give 254.

The old helper used log2, floor and a float-to-int conversion. On gfx950
this is v_log_f32 and approximately 15 instructions for each scale.

The new helper gives the same byte as the old helper for all 2^32 fp32
inputs that are not NaN, for EXP_OFFSET 0 to 15 (exhaustive check on
gfx950). This includes negative inputs: they give 254, or 0 when they
round to -0. A NaN amax now always gives 254. The old helper gave 254 or
0, as a function of the NaN payload.

Add a unit test with edge values for EXP_OFFSET 2 and 8.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] mx_e8m0_scale: same byte as the log2 formula for NaN

Make the integer helper give the same byte as the former log2 formula for
all 2^32 fp32 inputs, NaN included. Then no caller output changes. The
callers are the comms kernels and the gfx950 and gfx1250 Gluon quant
kernels.

The helper now adds 0x200000 to the raw bits (mod 2^32), as the log2
formula did. For some NaNs this add sets the sign bit or wraps to an
exponent field of 0. These NaNs give 0, and the other NaNs give 254.

An exhaustive check on gfx950 finds no difference for all 2^32 inputs,
for EXP_OFFSET 0 to 15. The unit test checks NaNs on both sides of the
wrap and passes with the log2 formula and with the integer helper.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_mxfp8 test: allow one rounding step

The test compared all output bytes. In the CI image (other Triton and
PyTorch builds) 1 or 2 bf16 or e4m3 values of 1.5M changed by one
rounding step, and the test failed.

Now a bf16 or e4m3 value can be one rounding step from the reference,
in at most 1 of 10,000 values (at least 8). The scale bytes must be
equal. A failure gives the output name, the number of values that
differ and the largest step.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_moe_route test: allow one rounding step

The test compared all bytes of the norm outputs, and it made the router
reference from the reference norm output. In the CI image (other Triton
and PyTorch builds) 1 to 3 bf16 values of a call changed by one rounding
step. Then the norm bytes and the top-k weights did not agree, and the
test failed.

Now residual_out and normed can be one rounding step from the
reference, in at most 1 of 10,000 values (at least 8). x_q, x_scale and
the routing are compared with a reference made from the normed output
of the kernel, which is the input of the router. These checks stay
exact (top-k ids, MXFP8 bytes) or tight (top-k weights). The edge-scale
check also compares x_scale with the expected bytes.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_mxfp8 test: fix the time-out race, trim 8 ranks

In the CI 8-GPU job, the launch after reset timed out on all ranks at 8
ranks. The time-out check made a comm with another max_tokens, so it
launched a new kernel variant. The rank that skipped the first launch
loaded this variant only after reset, and the other ranks waited only
50 ms for it.

Now the sentinel and time-out checks use the comm size of the first
shape, so they launch a kernel that each rank has already compiled. The
50 ms limit applies only to the launch that the last rank skips. The
launch after reset has the default limit.

At 8 ranks the test runs only the first shape, the sentinel check and
the time-out check. Each other kernel variant compiles on all 8 ranks,
which took most of the CI time. 2 and 4 ranks run all checks.
At 8 ranks a run from an empty kernel cache takes 71 s, not 123 s
(MI355X).

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Triton/Gluon] all_reduce_rmsnorm_moe_route test: fix the time-out race, trim 8 ranks

In the CI 8-GPU job, the launch after reset timed out on all ranks at 8
ranks. The time-out check made a comm with another max_tokens, so it
launched a new kernel variant. The rank that skipped the first launch
loaded this variant only after reset, and the other ranks waited only
50 ms for it.

Now the time-out check uses the comm size of the first shape, so it
launches kernels that each rank has already compiled. The 50 ms limit
applies only to the launch that the last rank skips. The launch after
reset has the default limit.

At 8 ranks the test runs only the first shape and the time-out check.
Each other kernel variant compiles on all 8 ranks, which took most of
the CI time. 2 and 4 ranks run all checks.
At 8 ranks a run from an empty kernel cache takes 82 s, not 230 s
(MI355X).

Signed-off-by: Vinayak Gokhale <[email protected]>

---------

Signed-off-by: Vinayak Gokhale <[email protected]>
Co-authored-by: Satya Nikhil Kodukula <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:multi-gpu Trigger multi-GPU op tests on PR Triton/Gluon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants