Skip to content

[HIP] [JIT] [Perf] gfx1250 custom AR: pushed two-shot AR + RMSNorm for 32-288 MiB - #8427

Open
XiaobingSuper wants to merge 3 commits into
ROCm:mainfrom
XiaobingSuper:xiaobingsuper/gfx1250-ar2s-prefill-ar-rmsnorm
Open

XiaobingSuper wants to merge 3 commits into
ROCm:mainfrom
XiaobingSuper:xiaobingsuper/gfx1250-ar2s-prefill-ar-rmsnorm

Conversation

@XiaobingSuper

@XiaobingSuper XiaobingSuper commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What

This PR adds a pushed two-shot all-reduce + residual add + (Gemma) RMSNorm kernel for gfx1250 (ar_2shot_rms_gfx1250, CustomAllreduce.ar2s_fused_ar_rms).

fused_allreduce_rmsnorm routes to it bf16 inputs of 32-288 MiB whose hidden size is 4096-7168. On main, those sizes take the 2-stage custom fused AR + RMSNorm up to 64 MiB, and RCCL + a separate add + RMSNorm above that.

  • Data flow.
    • Phase 1 pushes each row chunk to its owner's reduce-scatter inbox.
    • Phase 2 sums the rank's own chunk in fp32 in rank order, rounds it once to bf16, pushes it to every peer's all-gather inbox, and normalizes it.
    • Phase 3 normalizes the peers' rows.
  • Synchronization. Block b waits only for block b of its peers, through a flag per phase, sender and block, with epoch counters. There is no barrier at either end, eager or in a CUDA graph.
    • Flag polls are bounded. A poll that runs out counts the error and traps, so a peer that never arrives fails the launch instead of producing wrong output.
  • Numerics. out and residual_out follow the Lamport fused kernel step by step.
  • Off switch. AITER_CUSTOM_AR_AR2S_RMS_MAX_SIZE overrides the per-launch cap (default 160 MiB at TP4). 0 turns the route off and allocates no inbox.

Evidence

Hidden 6144 (MiniMax-M3), TP4, bf16, Gemma norm, 4x MI455X, image rocm/fw-bringup:gfx1250-minimax-m3-20261201, aiter main 2770d86d4 + this kernel.

  • Times are us per call. A run is 10 calls on distinct inputs; each cell is the max over ranks of the median of 15 alternating rounds.
  • "main" is the same process with the ar2s branch switched off, which leaves main's routing. A main-only tree gives the same times within 0.5% at 2752, 8192 and 24576 tokens, and two runs of the main arm agree within 1% at every size.
tokens MiB main's route main, eager this PR, eager speedup main, graph this PR, graph speedup
2752 32.3 2-stage fused 107.2 72.1 1.49x 87.8 69.2 1.27x
4096 48 2-stage fused 138.7 91.3 1.52x 116.8 88.4 1.32x
5440 63.8 2-stage fused 174.0 119.6 1.46x 146.4 116.5 1.26x
5504 64.5 RCCL + norm 146.7 119.7 1.23x 144.2 117.0 1.23x
6144 72 RCCL + norm 151.6 126.1 1.20x 148.7 123.6 1.20x
8192 96 RCCL + norm 194.5 159.2 1.22x 190.8 157.3 1.21x
10240 120 RCCL + norm 212.5 194.6 1.09x 209.1 192.2 1.09x
12288 144 RCCL + norm 297.6 227.3 1.31x n/a 224.9
14336 168 RCCL + norm 323.6 282.1 1.15x n/a 279.2
16384 192 RCCL + norm 351.0 315.1 1.11x n/a 312.3
20480 240 RCCL + norm 428.0 385.5 1.11x n/a 382.4
24576 288 RCCL + norm 506.6 451.8 1.12x n/a 448.3
  • n/a: in this harness, capturing main's RCCL + norm in a CUDA graph fails from 144 MiB (hipErrorInvalidValue at capture). This PR captures and replays at every size.
  • An earlier version of this table compared against RCCL + norm measured on an older aiter base (576d3f0) and image. Main's route is faster now (8192 tokens: 299.7 -> 194.5 us), so the gain is 1.09-1.52x rather than 1.2-2.1x. This PR's own times did not change (8192 tokens: 159.2 us both times).
  • Outside 32-288 MiB the route is unchanged. At 384 MiB both sides run RCCL + norm: 617 us.

Hidden sizes and the gate. Same harness and process, on 0c78341fb's kernel build. Each cell is main's route time / this PR's time, eager, with graph in parentheses where main's route can be captured. Main's route is the 2-stage fused kernel at 32 MiB and RCCL + norm from 64.5 MiB.

hidden 32 MiB 64.5 MiB 96 MiB 160 MiB 288 MiB route
2048 1.99x (1.59x) 1.03x (1.01x) 1.01x (1.00x) 1.00x 0.92x main's
4096 1.60x (1.46x) 1.12x (1.12x) 1.17x (1.16x) 1.16x 1.06x ar2s
5120 1.84x (1.48x) 1.22x (1.21x) 1.18x (1.18x) 1.21x 1.09x ar2s
6144 1.49x (1.28x) 1.22x (1.23x) 1.24x (1.23x) 1.13x 1.12x ar2s
7168 1.41x (1.21x) 1.26x (1.25x) 1.24x (1.23x) 1.17x 1.13x ar2s
8192 1.13x (0.94x) 1.03x (1.02x) 1.05x (1.04x) 1.09x 1.00x main's
  • The gate takes 4096-7168 (_AR2S_RMS_HIDDEN); the kernel itself takes up to 8192.
  • 8192 is left out because its 160 KiB of dynamic LDS a block leaves one block per CU (so half of the 2-per-CU grid starts late). In a graph it is slower than the 2-stage kernel at 32 MiB, and at most 1.09x elsewhere.
  • 2048 is left out because, although it is 2.0x at 32 MiB, it is even with RCCL + norm from 64 MiB and 0.92x at 288 MiB.

Numerics.

  • Against main's 2-stage fused kernel (32-64 MiB), out and residual_out are bit-identical.
  • Against RCCL + norm, residual_out differs in 27.6% of the values, because RCCL sums in a different order.
  • Against an fp32 rank-order reference, residual_out is bit-exact on all 4 ranks, and out is within 1 bf16 ulp for all but at most 3.4e-8 of the values at hidden 6144 (this comment). The op test below checks the same at 4096 / 6144 / 7168.

Scope

  • gfx1250, TP4, bf16 contiguous 2-D operands.
  • Hidden a multiple of 256 in 4096-7168: one 16-byte pack a thread, one row a block.
  • 32-288 MiB, at most 160 MiB a launch (AITER_CUSTOM_AR_AR2S_RMS_MAX_SIZE); larger inputs are split into balanced launches.
  • Cost: a 2 x 160 MiB IPC inbox per rank at TP4 on gfx1250; none when the env cap is 0.

Everything else keeps its route.

PR Self-Review

Reviewed revision

0c78341

Behavior and intent

This is the new default route for 32-288 MiB bf16 fused AR + RMSNorm at gfx1250 TP4 with hidden 4096-7168. Against main's route it is:

  • 1.06-1.84x faster eager across 4096 / 5120 / 6144 / 7168;
  • 1.12-1.48x in a CUDA graph up to 96 MiB, where main's route can be captured.

Every other size, hidden, dtype, world size and arch is unchanged. Setting AITER_CUSTOM_AR_AR2S_RMS_MAX_SIZE=0 restores main's route and allocates nothing.

Validation and unverified scope

  • Head and branch. Two commits on main 4fb090db3. 290d8d0 is the kernel and route. 0c78341fb holds the review fixes: the trap on a flag timeout, the env cap, the hidden gate, the op test and updated comments.
  • op_tests/multigpu_tests/test_ar2s_rms_gfx1250.py, 4x MI455X at 0c78341fb: all passed.
    • At the default cap and at a 48 MiB cap, 24 routed calls each were checked against the fp32 rank-order reference.
    • At a cap of 0 there were no routed calls and no inbox.
    • Hidden 2048 and 8192 stayed on main's route.
    • An earlier run of the same test on the same node stalled in its second pass (48 MiB cap) and was stopped after 14 minutes, while the node was being handed to other work. The cause was not captured. On idle GPUs, each of the three passes alone and the whole test pass.
  • Times.
    • The hidden-size table above ran on this head's kernel build.
    • The hidden 6144 table ran on 290d8d0's kernel. At 6144 the two agree within 2% where both measured a size (32 / 64.5 / 96 / 288 MiB: 1.49 / 1.22 / 1.24 / 1.12x against 1.49 / 1.23 / 1.22 / 1.12x).
  • CPU. tests/test_ar_rmsnorm_routing.py passes (87). It covers the env cap, a cap of 0 allocating and routing nothing, and the hidden gate. black and ruff are clean on the changed Python files.
  • Kernel build.
    • VGPRs with the trap: TP4 61, TP2 48; no scratch, occupancy 16.
    • The file compiled for gfx942, gfx950 and gfx1250 (hipcc -c) at 290d8d0; at this head only the gfx1250 JIT module was built.
  • Unverified. TP2 (instantiated but not routed), and an in-model run.

PR-specific question

Boundaries.

  • Only gfx1250 sets up the inbox (_init_ar2s_rms, world size 4 only, and not with the env cap at 0), so on other archs, world sizes and with the cap at 0, should_ar2s_rms is False.
  • It then takes only bf16, 2-D, contiguous operands, with hidden % 256 == 0 and 4096 <= hidden <= 7168, of at least 32 MiB. The caller caps the total at 288 MiB.
  • The decision reads only shapes, dtypes and sizes, so every rank takes the same path.
  • The C++ entry re-checks hidden, 16-byte alignment, the inbox size and 32-bit indexing, and throws instead of launching.

Changed op tests

op_tests/multigpu_tests/test_ar2s_rms_gfx1250.py (new, moved from #8428). Through tensor_model_parallel_fused_allreduce_rmsnorm, on 4 x gfx1250, it checks:

  • the route window and hidden gate;
  • values against an fp32 rank-order reference;
  • that every rank's outputs agree;
  • that sizes can change between calls;
  • CUDA-graph replay.

It runs with the default cap, a 48 MiB cap and a cap of 0, and skips elsewhere.

🤖 Generated with Claude Code

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

@XiaobingSuper

XiaobingSuper commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

GPU check of 8782dc2 on 4x MI455X (gfx1250), TP4: this PR's own tree (main bf59948 + this commit), every module JIT-built from it, flydsl 0.5.3. tensor_model_parallel_fused_allreduce_rmsnorm (hidden 6144 bf16, 32-288 MiB, so the ar2s route) against an fp32 rank-order reference (all_gather, sum in rank order, one bf16 round, + residual, RMSNorm):

tokens 2752 4096 6144 8192 12288 14336 24576
residual_out bit-exact (4 ranks) yes yes yes yes yes yes yes
out > 1 bf16 ulp (fraction) 0 0 0 0 2.7e-8 3.4e-8 2.0e-8
ar2s, eager, us 69.7 88.3 124.9 159.2 228.0 282.6 454.5

Against RCCL's own sum, residual_out is equal or within 1-2 bf16 ulps (different fp32 order). One thing to know: at interpreter exit each rank prints Exception ignored in IPCBuffer.__del__ ... no attribute 'free_meta_buffer' (the inbox's raw buffer is freed after aiter's ops are gone). A MiniMax-M3.1 server on aiter main shows the same kind of exit-time IPCBuffer.__del__ error, so it is not specific to this PR. Outputs are not affected.

@XiaobingSuper
XiaobingSuper marked this pull request as ready for review November 24, 2026 06:04
@XiaobingSuper
XiaobingSuper requested review from a team and a balanced review from Copilot November 24, 2026 06:04

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions github-actions Bot changed the title [HIP] [Perf] gfx1250 custom AR: pushed two-shot AR + RMSNorm for 32-288 MiB [HIP] [JIT] [Perf] gfx1250 custom AR: pushed two-shot AR + RMSNorm for 32-288 MiB Nov 24, 2026
@aiter-bot

aiter-bot commented Nov 24, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 37760c4c6d6a · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA

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

Copilot AI balanced review requested due to automatic review settings November 26, 2026 03:07

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 26, 2026 05:14

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@XiaobingSuper
XiaobingSuper force-pushed the xiaobingsuper/gfx1250-ar2s-prefill-ar-rmsnorm branch from e657a79 to a42aed0 Compare November 30, 2026 05:36
Copilot AI balanced review requested due to automatic review settings November 30, 2026 05:36

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@XiaobingSuper

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (6f8df0a08) as one commit (a42aed0cf). The only conflict was in custom_all_reduce.py, where main (#7937) reworked the Lamport constants and added _alloc_lamport_inbox. The ar2s constant and methods now follow main's code unchanged, and the route is recorded as ar2s under main's route trace, like the other fused routes. The ar2s inbox is still set up on the IPC transport only. The three HIP files are byte-identical to before. The module builds for gfx942, gfx950 and gfx1250, and tests/test_ar_rmsnorm_routing.py passes (30). The 4-GPU check was not rerun after the rebase.

fused_allreduce_rmsnorm on gfx1250 fell back to RCCL + a separate add +
RMSNorm above the Lamport kernels' range. Add a pushed two-shot all-reduce +
residual add + (Gemma) RMSNorm kernel (ar2s_rms_gfx1250) and route bf16
inputs of 32-288 MiB to it at TP4:

- phase 1 pushes each row chunk to its owner's RS inbox, phase 2 sums the own
  chunk in fp32 in rank order, rounds once to bf16, pushes it to every peer's
  AG inbox and normalizes it, phase 3 normalizes the peers' rows;
- block b only waits for block b of its peers (a flag per phase, sender and
  block, epoch counters), so no barrier is needed, eager or in a CUDA graph;
- row-local barriers are LDS-only and only a flag waits for the store drain;
  the three phases are pipelined per step; phase 2 prefetches the next row's
  summands into LDS asynchronously; flag polls are bounded (no hang);
- out / residual_out follow the Lamport fused kernel step by step;
- the kernel body is compiled only for gfx1250 (as mega_mhc_gfx1250.cu), so
  the gfx942 / gfx950 wheel builds do not see the gfx1250 async builtins.

The inbox is set up on the IPC transport only; the route is traced as "ar2s"
under AITER_AR_ROUTE_TRACE like the other fused AR + RMSNorm routes.

TP4, hidden 6144 bf16, Gemma norm, 4x MI455X, eager, us per call, measured
with the first, unpipelined version of this kernel (same layout, flags and
arithmetic, so the same outputs):
  tokens   2752  4096  6144  8192  12288  24576
  before  108.1 147.9 258.2 299.7  368.1  537.4
  after    85.3 104.9 145.5 182.7  256.1  502.4

residual_out matches an fp32 reference bit for bit, out is within 1 bf16 ulp
for < 1e-5 of the values (4 ranks, eager and graph, 13 row counts including
non-multiples of 4 and a split launch). Gated on gfx1250, TP4 (the measured
world size), bf16, hidden a multiple of 256 up to 8192, 32-288 MiB.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@XiaobingSuper
XiaobingSuper force-pushed the xiaobingsuper/gfx1250-ar2s-prefill-ar-rmsnorm branch from a42aed0 to 290d8d0 Compare December 2, 2026 08:10
Copilot AI balanced review requested due to automatic review settings December 2, 2026 08:10

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@TennyWang1223 TennyWang1223 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review summary (advisory)

What it does: adds a gfx1250-only pushed two-shot AR + residual add + RMSNorm kernel (ar_2shot_rms_gfx1250) and makes it the default fused_allreduce_rmsnorm route for bf16, TP4, 32–288 MiB inputs.

Verdict: needs work before approval. I found no correctness bug in the kernel's sync protocol, its 32-bit indexing, or the rank-consistent routing decision. The issues below are about failure visibility, test coverage, and how wide the new default route is.

Reviewed at head 290d8d0.

Should fix

1. A timed-out flag poll silently produces wrong output.
wait_flag_bounded gives up after kMaxPolls (20M) loads. It bumps Flags::err and the callers continue straight into the inbox reads (L355, L437). Nothing reads err: there is no getter in the header or pybind, no reader in Python, and none in #8428.

If one rank reaches the call that many polls behind its peers, that call's out/residual_out are wrong on every rank. The inbox-reuse argument in the header comment (L31-L35) also stops holding for the next call. The existing gfx1250 barriers (custom_all_reduce_gfx1250.cuh L427, L449) spin without a bound, so a stall there at least shows up.

Could you make the timeout observable? For example, read and reset err on the host and raise or log, or trap in the kernel instead of continuing.

2. The new default route has no test.
This PR adds no test, and no existing test reaches the route. op_tests/multigpu_tests/test_fused_ar_rms.py defaults to at most 19 rows at TP8, and the other TP4 tests stay under 32 MiB. CI has no gfx1250 runner, and the Multi-GPU job was skipped. Could op_tests/multigpu_tests/test_ar2s_rms_gfx1250.py move from #8428 into this PR?

3. The gate admits every hidden size up to 8192, but only 6144 was measured.
should_ar2s_rms takes any hidden that is a multiple of 256 and at most 8192.

At hidden 8192 the dynamic LDS is 2 × (4 + 1) × 1024 × 16 = 160 KiB per block, plus 260 B of static LDS. Two blocks need 328,200 B, which is more than the 327,680 B available, so only one block fits per CU. That breaks the grid = 2 × CU design in _init_ar2s_rms. The kernel comment itself notes that one block per CU made half the grid start 150–190 µs late. Hidden sizes below 6144 (2048, 4096) are also unmeasured.

Could you post numbers for 4096, 7168 and 8192, or narrow the gate to the hidden sizes you measured?

4. There is no dedicated off switch, and about 324 MiB per GPU is allocated unconditionally.
_AR2S_RMS_MAX_BYTES is a constant. _init_ar2s_rms always allocates a 2 × 160 MiB inbox plus a 4 MiB flag buffer on gfx1250 TP4 with IPC transport, decode-only instances included.

Today the only ways to turn the route off are switching the whole custom-AR transport (AITER_CUSTOM_AR_FORCE_VMM=1 / AITER_CUSTOM_AR_USE_SYMM_MEM=1) or disabling custom AR. Could you add an env cap like AITER_CUSTOM_AR_LAMPORT_RMS_MAX_SIZE, where 0 turns the route off and skips the allocation?

Nit

5. Stale comments.

  • communicator_cuda.py L112-L116 still says 1.3–1.9x vs RCCL + norm, and 624.6 vs 686.2 µs at 384 MiB. The re-measured table in the PR body says 1.09–1.52x vs main, and 617 µs on both sides at 384 MiB.
  • The kernel header (L4-L6) still says "RCCL is 2x off the link".

Notes

  • CI is green, but it runs only on MI35X (gfx950), where this route is never taken. It says nothing about the new kernel.
  • The diff still applies cleanly to current main (e50914dd7).
  • Not reproduced: I had no gfx1250 hardware. The numerics and perf figures referenced here are the PR's own.

Advisory review, AI-assisted (Claude Code). It does not block the merge.

…gate, op test

Review follow-ups for the pushed two-shot AR + RMSNorm:

- A flag poll that runs out of kMaxPolls now traps instead of reading an
  inbox the peer never filled: the call's output would be wrong on every
  rank and the next call's inbox reuse would no longer hold.
- AITER_CUSTOM_AR_AR2S_RMS_MAX_SIZE overrides the per-launch cap (default
  160 MiB at TP4, rounded down to whole MiB); 0 turns the route off and
  allocates no inbox.
- The route takes hidden 4096-7168 only. Measured at TP4 against main's
  route, 32-288 MiB: 4096, 6144 and 7168 are 1.06-1.60x faster; 2048 is
  even above 64 MiB and 0.92x at 288 MiB; 8192 is 0.94-1.13x, as its
  160 KiB of dynamic LDS a block leaves one block a CU.
- op_tests/multigpu_tests/test_ar2s_rms_gfx1250.py (moved here from
  ROCm#8428): route window and hidden gate, values against an fp32 rank-order
  reference, ranks agree, CUDA-graph replay, with the default cap, 48 MiB
  and 0.
- Stale comments updated to the re-measured numbers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings December 3, 2026 12:20

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@XiaobingSuper

Copy link
Copy Markdown
Contributor Author

@TennyWang1223 thanks for the review. All five points are addressed in 0c78341fb, one commit on top of 290d8d0, so the diff from what you reviewed is that commit alone.

1. A timed-out flag poll. When kMaxPolls runs out, wait_flag_bounded still bumps Flags::err, but it then calls __builtin_trap() instead of returning.

  • The launch now fails before any rank reads an inbox the peer never filled.
  • No later call can run on an inbox whose reuse argument no longer holds.
  • A host-side read of err would need either a sync per call or a check deferred past the wrong output, so I chose the trap.
  • VGPRs: TP4 59 -> 61, TP2 46 -> 48, still no scratch.

2. A test for the route. op_tests/multigpu_tests/test_ar2s_rms_gfx1250.py has moved here from #8428 and was extended. Through tensor_model_parallel_fused_allreduce_rmsnorm on 4 GPUs, with Gemma on and off, it checks:

  • the route: ar2s takes a call exactly inside (32, 288] MiB and for hidden 4096-7168, and not just outside the window or for 2048 / 8192;
  • the values against an fp32 rank-order reference: residual_out bit-exact; out within 1 bf16 ulp except at most 1e-6 of the values, and at most 4 ulps;
  • that every rank's outputs are the same;
  • sizes changing from call to call on one workspace;
  • a CUDA graph captured in graph_capture() and replayed on new inputs.

It runs with the default cap, with a 48 MiB cap, and with a cap of 0 (no inbox, no route). It also asserts that the inbox was set up, so it cannot pass with the route silently off.

Result on 4x MI455X at 0c78341fb: all passed in 24 s. At the default cap and at 48 MiB, 24 routed calls each were checked against the reference (4096 / 6144 / 7168, Gemma on and off, four sizes inside the window); at 0, none, with no inbox. 2048 and 8192 stayed on main's route throughout. It skips on fewer than 4 GPUs or on archs other than gfx1250. #8428 will drop its own copy.

3. The hidden-size gate. I measured 2048 / 4096 / 5120 / 6144 / 7168 / 8192 at TP4 and narrowed the gate to 4096-7168 (_AR2S_RMS_HIDDEN; the kernel itself still takes up to 8192). The table is main's route time / this PR's time, in the same process, eager (graph in parentheses where main's route can be captured):

hidden 32 MiB 64.5 MiB 96 MiB 160 MiB 288 MiB route
2048 1.99x (1.59x) 1.03x (1.01x) 1.01x (1.00x) 1.00x 0.92x main's
4096 1.60x (1.46x) 1.12x (1.12x) 1.17x (1.16x) 1.16x 1.06x ar2s
5120 1.84x (1.48x) 1.22x (1.21x) 1.18x (1.18x) 1.21x 1.09x ar2s
6144 1.49x (1.28x) 1.22x (1.23x) 1.24x (1.23x) 1.13x 1.12x ar2s
7168 1.41x (1.21x) 1.26x (1.25x) 1.24x (1.23x) 1.17x 1.13x ar2s
8192 1.13x (0.94x) 1.03x (1.02x) 1.05x (1.04x) 1.09x 1.00x main's
  • 8192 matches your LDS arithmetic. One block a CU fits, and in a graph the route is slower than the 2-stage kernel at 32 MiB, with at most 1.09x elsewhere, so it is out.
  • 2048 is 2.0x against the 2-stage kernel at 32 MiB, but about even with RCCL + norm from 64 MiB and 0.92x at 288 MiB, so it is out too.
  • 5120, a size inside the gate that is not a multiple of 2048, gains at every size like its neighbors (1.09-1.84x).

4. An off switch. AITER_CUSTOM_AR_AR2S_RMS_MAX_SIZE overrides the per-launch cap (default 160 MiB at TP4, rounded down to whole MiB).

  • 0, or anything under 1 MiB, turns the route off, and _init_ar2s_rms then allocates neither the inbox nor the flags.
  • An invalid value logs a warning and keeps the default.
  • I named it after this route rather than reusing AITER_CUSTOM_AR_LAMPORT_RMS_MAX_SIZE, which already caps the Lamport route.
  • CPU tests: test_the_ar2s_cap_env and test_an_ar2s_cap_of_0_allocates_and_routes_nothing, plus test_ar2s_takes_the_measured_hidden_sizes for the gate. tests/test_ar_rmsnorm_routing.py: 87 passed.

5. Stale comments. Both are updated. The comment above _AR2S_RMS_MIN_BYTES gives the re-measured range for 4096-7168, and the kernel header no longer says RCCL is 2x off the link.

XiaobingSuper added a commit to XiaobingSuper/aiter that referenced this pull request Dec 3, 2026
Extend the pushed two-shot AR + RMSNorm (ar2s_rms_gfx1250) with ar2s_rms_ex
and three modes, exposed as sequence-parallel tensor_model_parallel_sp_* ops
for prefill:

- FP8: the norm output is written as MXFP8 (E4M3 + row-major E8M0 per 32),
  the bytes per_1x32_mx_quant_hip gives for the bf16 out (the group max is
  floored at kAmaxFloor as there, so an all-zero group gets scale 85).
- SP: each rank keeps the residual of its own row chunk only; the owner
  normalizes (and quantizes) its rows and pushes the result, so the
  all-gather moves MXFP8 and phase 3 is a copy. The normed output is whole
  on every rank and bit-identical to the replicated path.
- AUX (with SP): no norm, the whole all_reduce(x) + residual on every rank.

tensor_model_parallel_sp_fused_allreduce_rmsnorm{,_mxfp8_quant} and
tensor_model_parallel_sp_allreduce_add_residual take the SP path at the ar2s
sizes and are the replicated ops below it, so every call of a forward takes
the same branch (mutates_args=[]).

The TP4 per-launch cap is 192 MiB, one launch for a 14336-token chunk of
hidden 6144.

TP4, hidden 6144, Gemma norm, 4x MI455X: AR + RMSNorm + MXFP8 at 14336 rows
347 -> 226 us a call (SP + MXFP8 all-gather vs ar2s + separate quant);
sp_fp8 at 14336 / 32768 rows 189.0 / 401.2 us, bit-exact.

On top of ROCm#8427 at 0c78341 (the review round there), adapted as follows:

- The SP gate (ar2s_sp_eligible) takes the replicated route's measured
  hidden range (_AR2S_RMS_HIDDEN, 4096-7168) in whole 512-element groups,
  which the MXFP8 output needs.
- The replicated MXFP8 fallback calls main's
  fused_allreduce_rmsnorm_group_quant(..., "mxfp8") (ROCm#8310 renamed it).
- The 192 MiB cap keeps ROCm#8427's AITER_CUSTOM_AR_AR2S_RMS_MAX_SIZE
  override; the routing test's default is 192 MiB.
- ROCm#8427 now carries op_tests/multigpu_tests/test_ar2s_rms_gfx1250.py (the
  replicated route); this PR's test and benchmark of the ex modes moves to
  test_ar2s_rms_ex_gfx1250.py, on main's public MXFP8 op
  (tensor_model_parallel_fused_allreduce_rmsnorm_quant with
  quant_type="per_1x32", quant_dtype=fp8), ruff-clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
XiaobingSuper added a commit to XiaobingSuper/aiter that referenced this pull request Dec 4, 2026
Extend the pushed two-shot AR + RMSNorm (ar2s_rms_gfx1250) with ar2s_rms_ex
and three modes, exposed as sequence-parallel tensor_model_parallel_sp_* ops
for prefill:

- FP8: the norm output is written as MXFP8 (E4M3 + row-major E8M0 per 32),
  the bytes per_1x32_mx_quant_hip gives for the bf16 out (the group max is
  floored at kAmaxFloor as there, so an all-zero group gets scale 85).
- SP: each rank keeps the residual of its own row chunk only; the owner
  normalizes (and quantizes) its rows and pushes the result, so the
  all-gather moves MXFP8 and phase 3 is a copy. The normed output is whole
  on every rank and bit-identical to the replicated path.
- AUX (with SP): no norm, the whole all_reduce(x) + residual on every rank.

tensor_model_parallel_sp_fused_allreduce_rmsnorm{,_mxfp8_quant} and
tensor_model_parallel_sp_allreduce_add_residual take the SP path at the ar2s
sizes and are the replicated ops below it, so every call of a forward takes
the same branch (mutates_args=[]).

The TP4 per-launch cap is 192 MiB, one launch for a 14336-token chunk of
hidden 6144.

TP4, hidden 6144, Gemma norm, 4x MI455X: AR + RMSNorm + MXFP8 at 14336 rows
347 -> 226 us a call (SP + MXFP8 all-gather vs ar2s + separate quant);
sp_fp8 at 14336 / 32768 rows 189.0 / 401.2 us, bit-exact.

On top of ROCm#8427 at 0c78341 (the review round there), adapted as follows:

- The SP gate (ar2s_sp_eligible) takes the replicated route's measured
  hidden range (_AR2S_RMS_HIDDEN, 4096-7168) in whole 512-element groups,
  which the MXFP8 output needs.
- The replicated MXFP8 fallback calls main's
  fused_allreduce_rmsnorm_group_quant(..., "mxfp8") (ROCm#8310 renamed it).
- The 192 MiB cap keeps ROCm#8427's AITER_CUSTOM_AR_AR2S_RMS_MAX_SIZE
  override; the routing test's default is 192 MiB.
- ROCm#8427 now carries op_tests/multigpu_tests/test_ar2s_rms_gfx1250.py (the
  replicated route); this PR's test and benchmark of the ex modes moves to
  test_ar2s_rms_ex_gfx1250.py, on main's public MXFP8 op
  (tensor_model_parallel_fused_allreduce_rmsnorm_quant with
  quant_type="per_1x32", quant_dtype=fp8), ruff-clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings December 4, 2026 02:53

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants