Skip to content

[Triton/Gluon] [Bugfix] gfx1250 a8w4 MoE decode: store the output tile from registers, not LDS + TDM store - #7202

Merged
azaidy merged 4 commits into
ROCm:mainfrom
akao-amd:pr-gfx1250-moe-a8w4-decode-gstore
Nov 16, 2026
Merged

azaidy merged 4 commits into
ROCm:mainfrom
akao-amd:pr-gfx1250-moe-a8w4-decode-gstore

Conversation

@akao-amd

@akao-amd akao-amd commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

_moe_gemm_a8w4_decode (gfx1250 Gluon) stores its output tile with a masked buffer_store from registers instead of staging it in LDS for tdm.async_store. On gfx1250 that TDM store occasionally writes stale LDS into the MoE output.

Motivation

The decode kernel's epilogue is ds_store (into w_buffer slot 0, which the output tile aliases) -> s_wait_dscnt 0 -> s_barrier -> tensor_store_from_lds. Under decode load, with 3-4 of these workgroups per WGP, the TDM store sometimes ships what the slot held before: 16-byte chunks of the weight tile last TDM-loaded into it (byte-exact in the layer's w2_weight: same N tile, k-iteration 4, W row 0), values up to ~1e38. The compiled code has the expected waits; none of the documented ones closes it.

Rate: in a gpt-oss-120b W4A8 server (TP2, 8192/1024 c16 load, GEMM2 recomputed inside the CUDA graph and compared bitwise) 820-2441 wrong output elements per million calls; offline, one GPU, 1083-3583 per million. One bad chunk becomes a NaN row after the next RMSNorm; in SGLang (sgl-project/sglang#47398, Gluon decode below 384 tokens) GSM8K after load failed in 9 of 14 TP2 runs. Reproduced on main as well.

What removes it, offline (384k calls each): this change: 0; the same LDS staging read back with ds_load and stored from registers: 0 (so the TDM store is the faulty step); s_sleep 2 right before the TDM store: 0; at most 2 workgroups per WGP: 0. What does not: s_nops or s_wait_tensorcnt 0 after every TDM op, a 2 KB LDS gap between workgroups, 3 buffers.

Context (the same paragraph in the three companion gfx1250 PRs). Three defects and a compiler bug hit gpt-oss-120b on gfx1250 together and hid one another. (1) The TDM store of an LDS-staged output tile can ship stale LDS: the a8w4 MoE decode and unified attention 2D register-store PRs. The rule for when a TDM store may read LDS written by ds_store needs an answer from the LLVM AMDGPU / hardware side. (2) The Gluon 2D attention turns one NaN in a KV page tail into NaN for every query that reads the page: the V-masking PR. (3) LLVM placed the workgroup release's s_wait_dscnt 0 after s_barrier_signal at the top of a loop. That made attention extend non-deterministic and looked like (1). It is fixed by llvm/llvm-project#220357, which is in Triton main's LLVM and known to the compiler team (ROCm/rocm-libraries#10893). In serving, (1) in the MoE made one token's row NaN and (2) spread it to the whole batch. GSM8K failed only at TP2 and only after load. At TP1 the same race stayed finite and passed every gate. Related gfx1250 TDM/LDS ordering reports: #5712 (a TDM load racing a ds_read of the slot it overwrites), #4537 (TDM ring wait counts), the note in #4894's gfx1250 quant kernel ("fp8 TDM async_store corrupted data in tiles wider than 1024"), and LLVM 941a04e69ee8 (keep the TDM counter low), which lowers (1)'s rate to ~0.6x but not to 0. Other gfx1250 users of the Gluon MoE decode kernel may be exposed to (1): vLLM's gpt-oss Gluon MoE path (ROCm/vllm#1327) and ATOM's FlyDSL-prefill + Gluon-decode split.

Changes

  • Non-scatter epilogue of _moe_gemm_a8w4_decode: masked gl.amd.gfx1250.buffer_store from the accumulator's WMMA layout. Y is rebased to the tile in index_type and the voffset is only the in-tile offset, because buffer_store offsets are 32-bit. No LDS round trip, no TDM store; LDS allocation unchanged.
  • Not changed: the EP-scatter branch, the persistent decode kernel and the prefill kernel. They use the same ds_store -> TDM store pattern and were not exercised here.

Performance

Hardware Workload/configuration Before After Change
gfx1250 (MI450X, one DPX partition pair) gpt-oss-120b W4A8, SGLang TP2, InferenceX fixed-seq 1k/1k and 8k/1k, c4-c64; control / fix / control, both orders, two GPU pairs control tok/s fix tok/s within ±0.5 %

The ±0.5 % bracket is the gl.store epilogue. The buffer_store revision is not re-measured.

Test

gfx1250 only (the kernel is gfx1250-only). Offline repro: 16 tokens, the same input 64x per CUDA graph, every output compared bitwise with an eager call: 0 differences in 384k calls (before: 1083-3583 per million). Serving (gpt-oss-120b W4A8, GSM8K 1319 after 8k/1k + 1k/1k load, in-graph GEMM2 pair counters):

GSM8K counters
before, TP2 9 of 14 runs failed (0.34-0.92) 820-2441 per million calls
after, TP2 with counters 6 of 6 pass (0.9591-0.9629) 0 in ~1M calls per rank
after, TP2 without debug hooks 4 of 4 pass (0.9583-0.9621) –
after, TP1 2 of 2 pass (0.9606, 0.9621) 0 in 988k

Validated on the AITER tree of a gpt-oss gfx1250 recipe (base 2bb5491) with the image's Triton (76940ad + revert); this commit is the same change rebased onto main, where the offline repro also fails and the change is bitwise equal to the original on clean runs. Those runs are the gl.store epilogue. The buffer_store revision is not re-run on gfx1250. Not run: AITER's op tests on gfx1250, the persistent decode and prefill kernels (same pattern), other models' shapes. The root rule (when may a TDM store read LDS written by ds_store?) is a question for the LLVM AMDGPU / hardware side.

CI shard 4 on the MI35X runner is the same 26 files, in the same order, as #7201 and #7203. This PR's run of that shard finished in 79.4 min against a 90 min cap. The TSV estimates the shard at 37 min, so the cap is close on every revision that still has this split. This PR does not change those files.

PR Self-Review

Reviewed revision

4699230dc21d0e075a973c01390eca68c57648c5

Behavior and intent

_moe_gemm_a8w4_decode on gfx1250 ended the non-scatter path with ds_store into w_buffer slot 0 (the output tile aliases that slot), s_wait_dscnt 0, a workgroup barrier, then tensor_store_from_lds. Under decode load, with 3–4 of these workgroups on one WGP, that TDM store sometimes writes the weight tile last loaded into the slot: 16-byte chunks, byte-exact in the layer's w2_weight (same N tile, k-iteration 4, W row 0), values up to about 1e38. The compiled waits are the documented ones. None of them closes it. One bad chunk becomes a NaN row at the next RMSNorm.

The non-scatter epilogue now stores the accumulator with a masked gl.amd.gfx1250.buffer_store from its WMMA layout (row tile_m + in_m < M, column tile_n + in_n < yN). buffer_store offsets are 32-bit bytes, so Y is advanced to this tile in index_type (start_m + tile_m rows, tile_n columns, both widened before the add) and the voffset is only the in-tile offset. A tile past 2**31 elements does not wrap. There is no LDS round trip and no TDM store. LDS allocation is unchanged. The EP-scatter branch, the persistent decode kernel, and the prefill kernel are not touched.

Validation and unverified scope

gfx1250 only (the kernel is gfx1250-only). Recipe AITER 2bb549102, Triton 76940ad plus its revert. The same change rebased onto main: the offline repro still fails on main's old epilogue, and the new store matches the old one bitwise on clean runs.

Offline, 16 tokens, the same input 64 times per CUDA graph, every output compared bitwise with an eager call. 384k calls each:

  • This change: 0 differences (before: 1083–3583 per million).
  • Same LDS staging, then ds_load and a register store: 0. The ds_store landed; the TDM store is the step that misses it.
  • s_sleep 2 immediately before the TDM store: 0. At most 2 workgroups per WGP: 0.
  • What does not remove it: s_nops or s_wait_tensorcnt 0 after every TDM op, a 2 KB LDS gap between workgroups, 3 buffers.

Serving, gpt-oss-120b W4A8, SGLang, GSM8K 1319 after an 8k/1k plus 1k/1k load. GEMM2 recomputed inside the CUDA graph and compared bitwise (TP2, 8192/1024 c16): 820–2441 wrong elements per million calls before. After: 0 in about 1M calls per rank (TP2, counters on, 6 of 6 GSM8K pass, 0.9591–0.9629) and 0 in 988k at TP1 (2 of 2 pass, 0.9606 and 0.9621). TP2 without the debug hooks: 4 of 4 pass (0.9583–0.9621). Before, 9 of 14 TP2 GSM8K runs failed (0.34–0.92). Throughput on a control/fix/control bracket, both orders, two GPU pairs, 1k/1k and 8k/1k at c4–c64: within ±0.5%.

Not run: AITER's op tests on gfx1250, the persistent decode kernel, the prefill kernel, the EP-scatter branch, other models' shapes. The buffer_store revision that replaced the measured gl.store epilogue is not re-run on gfx1250.

PR-specific question

The new store is a masked gl.amd.gfx1250.buffer_store of the WMMA accumulator, masked with (offs_y_m < M) & (offs_y_n < yN). The failure mode that adds is a mask or a layout that does not match the old tensor-descriptor store, or a voffset that still holds the tile origin and wraps past 2**31 bytes. The pointer rebase keeps that origin in the 64-bit base. On a partial M or N tile a wrong mask would drop a live element or write past Y. Clean runs of the previous gl.store epilogue are bitwise equal to the original kernel, on the recipe tree and again after the rebase onto main, which is the check that the predicate and the WMMA layout describe the same tile the descriptor stored. This buffer_store revision uses that same mask and layout and is not re-run on gfx1250.

The scope boundary is the other epilogues. The async_scatter branch directly above this else, the persistent decode kernel, and the prefill kernel still do ds_store then a TDM store. They were not exercised. gpt-oss Gluon decode below 384 tokens (sglang#47398) takes the path this PR changes. The async_wait removed with the old store waited on that store; nothing after the epilogue consumed it.

Changed op tests

None.

🤖 Generated with Claude Code

…not via LDS + TDM store

The decode kernel wrote its output tile registers -> LDS (ds_store, into
w_buffer slot 0, which it aliases) -> tensor_store_from_lds. Under decode
load, with 3-4 of these workgroups resident per WGP, the TDM store
occasionally reads stale LDS: 16-byte chunks of the weight tile last
loaded into that slot end up in the output (bf16 garbage up to ~1e38),
although the compiled code has s_wait_dscnt 0 + s_barrier between the
ds_stores and the TDM store. On gpt-oss-120b W4A8 TP2 this broke GSM8K
after load (TP2).

Measured (offline repro, 16 tokens, same input 64x per CUDA graph, 384k
MoE calls, bitwise against eager): 1083-2411 differing elements per
million calls before, 0 after. Each of these also removes it: launching
with <= 2 workgroups per WGP, an s_sleep 2 before the TDM store, or
reading the tile back with ds_load and storing from registers.

Masked global stores from the WMMA layout (4 x global_store_b128 per
lane) replace the LDS round trip and the TDM store; LDS use unchanged.

Co-Authored-By: Claude <[email protected]>
@akao-amd
akao-amd requested a review from a team October 30, 2026 07:04
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
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 gfx1201 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 7202 --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.

@aiter-bot

aiter-bot commented Oct 30, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 4699230dc21d · 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

`_moe_gemm_a8w4_decode` on gfx1250 ended the non-scatter path with `ds_store` into `w_buffer` slot 0 (the output tile aliases that slot), `s_wait_dscnt 0`, a workgroup barrier, then `tensor_store_from_lds`. Under decode load, with 3–4 of these workgroups on one WGP, that TDM store sometimes writes the weight tile last loaded into the slot: 16-byte chunks, byte-exact in the layer's `w2_weight` (same N tile, k-iteration 4, W row 0), values up to about 1e38. The compiled waits are the documented ones. None of them closes it. One bad chunk becomes a NaN row at the next RMSNorm.

The non-scatter epilogue now stores the accumulator with a masked `gl.amd.gfx1250.buffer_store` from its WMMA layout (row `tile_m + in_m < M`, column `tile_n + in_n < yN`). `buffer_store` offsets are 32-bit bytes, so `Y` is advanced to this tile in `index_type` (`start_m + tile_m` rows, `tile_n` columns, both widened before the add) and the voffset is only the in-tile offset. A tile past 2**31 elements does not wrap. There is no LDS round trip and no TDM store. LDS allocation is unchanged. The EP-scatter branch, the persistent decode kernel, and the prefill kernel are not touched.

Validation and unverified scope

gfx1250 only (the kernel is gfx1250-only). Recipe AITER `2bb549102`, Triton `76940ad` plus its revert. The same change rebased onto main: the offline repro still fails on main's old epilogue, and the new store matches the old one bitwise on clean runs.

Offline, 16 tokens, the same input 64 times per CUDA graph, every output compared bitwise with an eager call. 384k calls each:

- This change: 0 differences (before: 1083–3583 per million).
- Same LDS staging, then `ds_load` and a register store: 0. The `ds_store` landed; the TDM store is the step that misses it.
- `s_sleep 2` immediately before the TDM store: 0. At most 2 workgroups per WGP: 0.
- What does not remove it: `s_nop`s or `s_wait_tensorcnt 0` after every TDM op, a 2 KB LDS gap between workgroups, 3 buffers.

Serving, gpt-oss-120b W4A8, SGLang, GSM8K 1319 after an 8k/1k plus 1k/1k load. GEMM2 recomputed inside the CUDA graph and compared bitwise (TP2, 8192/1024 c16): 820–2441 wrong elements per million calls before. After: 0 in about 1M calls per rank (TP2, counters on, 6 of 6 GSM8K pass, 0.9591–0.9629) and 0 in 988k at TP1 (2 of 2 pass, 0.9606 and 0.9621). TP2 without the debug hooks: 4 of 4 pass (0.9583–0.9621). Before, 9 of 14 TP2 GSM8K runs failed (0.34–0.92). Throughput on a control/fix/control bracket, both orders, two GPU pairs, 1k/1k and 8k/1k at c4–c64: within ±0.5%.

Not run: AITER's op tests on gfx1250, the persistent decode kernel, the prefill kernel, the EP-scatter branch, other models' shapes. The `buffer_store` revision that replaced the measured `gl.store` epilogue is not re-run on gfx1250.

PR-specific question

The new store is a masked `gl.amd.gfx1250.buffer_store` of the WMMA accumulator, masked with `(offs_y_m < M) & (offs_y_n < yN)`. The failure mode that adds is a mask or a layout that does not match the old tensor-descriptor store, or a voffset that still holds the tile origin and wraps past 2**31 bytes. The pointer rebase keeps that origin in the 64-bit base. On a partial M or N tile a wrong mask would drop a live element or write past `Y`. Clean runs of the previous `gl.store` epilogue are bitwise equal to the original kernel, on the recipe tree and again after the rebase onto main, which is the check that the predicate and the WMMA layout describe the same tile the descriptor stored. This `buffer_store` revision uses that same mask and layout and is not re-run on gfx1250.

The scope boundary is the other epilogues. The `async_scatter` branch directly above this `else`, the persistent decode kernel, and the prefill kernel still do `ds_store` then a TDM store. They were not exercised. gpt-oss Gluon decode below 384 tokens (sglang#47398) takes the path this PR changes. The `async_wait` removed with the old store waited on that store; nothing after the epilogue consumed it.

Changed op tests

None.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

PR state

  • PASS — pull request is marked ready for review

Copilot findings

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

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

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

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The non-persistent decode path still permits int32 stride overflow that writes before Y, and the reported graph-replay failure lacks automated regression coverage.

2 open issues
What changed in this PR

This PR changes the gfx1250 Gluon a8w4 MoE decode output store to avoid the reported stale-LDS corruption during decode workloads.

Changes:

  • Replaces LDS staging and TDM output stores with masked stores directly from registers.
  • Adds explicit output row and column bounds checks.
  • Leaves EP-scatter, persistent decode, and prefill paths unchanged.
File Description
aiter/​ops/​triton/​_gluon_kernels/​gfx1250/​moe/​moe_op_gemm_a8w4.py Updates the non-scatter decode epilogue to store output directly from registers.

Review effort: Balanced

…dex_type

The new gl.store multiplied the tile row and column by the strides in int32.
start_m was already cast to index_type, so UPCAST_INDICES did not cover that
product. Row 65536 with stride 32768 is 2**31 and wraps to a store before Y.

Co-authored-by: Cursor <[email protected]>
@akao-amd

akao-amd commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

@ROCm/team_aiter @ROCm/triton_kernels_team Please take a look. Head b7cc853 is green, including Aiter Test: https://github.com/ROCm/aiter/actions/runs/41571090713. That head widens the register-store offsets to int64, which is the overflow note on the first commit.

@akao-amd

akao-amd commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

@azaidy Tagging you as a Gluon owner for the gfx1250 a8w4 MoE decode register-store change in this PR.

@lburzawa

lburzawa commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

TDM store giving incorrect results seems like a compiler issue rather than kernel issue. Can you file a compiler ticket instead and include a repro for failing accuracy/UTs?

@akao-amd

akao-amd commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Done at https://github.com/AMD-Triton/triton-tickets/issues/2164. @lburzawa.

TDM store giving incorrect results seems like a compiler issue rather than kernel issue. Can you file a compiler ticket instead and include a repro for failing accuracy/UTs?

@lburzawa

Copy link
Copy Markdown
Contributor

@akao-amd This seems to be some hw/fw issue. We can accept temporary change away from TDM store. I left one change request and otherwise we should be good to go.

gl.store lowered to a 64-bit global store. buffer_store keeps the base in
the descriptor. Its voffset is 32-bit, so Y is rebased to the tile in
index_type and only the in-tile offsets are stored.

Co-authored-by: Cursor <[email protected]>
Advance Y by the tile origin (start_m + tile_m rows, tile_n columns) in
index_type and pass only the in-tile rows and columns as the buffer_store
offset. The voffset is 32-bit bytes, so the row-within-expert offset
cannot go there for large experts; this drops the add-then-subtract.

Co-authored-by: Cursor <[email protected]>
@zufayu
zufayu requested review from a team and removed request for a team November 13, 2026 01:49
@akao-amd

Copy link
Copy Markdown
Contributor Author

@lburzawa @zufayu Any suggest on how to bring this PR miving forward?

@azaidy azaidy 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!

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.

7 participants