Repository navigation
[Triton/Gluon] [Bugfix] gfx1250 a8w4 MoE decode: store the output tile from registers, not LDS + TDM store - #7202
Conversation
…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]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
There was a problem hiding this comment.
🟡 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]>
|
@ROCm/team_aiter @ROCm/triton_kernels_team Please take a look. Head |
|
@azaidy Tagging you as a Gluon owner for the gfx1250 a8w4 MoE decode register-store change in this PR. |
|
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? |
|
Done at https://github.com/AMD-Triton/triton-tickets/issues/2164. @lburzawa.
|
|
@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]>


Summary
_moe_gemm_a8w4_decode(gfx1250 Gluon) stores its output tile with a maskedbuffer_storefrom registers instead of staging it in LDS fortdm.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'sw2_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_loadand stored from registers: 0 (so the TDM store is the faulty step);s_sleep 2right before the TDM store: 0; at most 2 workgroups per WGP: 0. What does not:s_nops ors_wait_tensorcnt 0after 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_storeneeds 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'ss_wait_dscnt 0afters_barrier_signalat 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 ads_readof 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 LLVM941a04e69ee8(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
_moe_gemm_a8w4_decode: maskedgl.amd.gfx1250.buffer_storefrom the accumulator's WMMA layout.Yis rebased to the tile inindex_typeand the voffset is only the in-tile offset, becausebuffer_storeoffsets are 32-bit. No LDS round trip, no TDM store; LDS allocation unchanged.ds_store-> TDM store pattern and were not exercised here.Performance
The ±0.5 % bracket is the
gl.storeepilogue. Thebuffer_storerevision 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):
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.storeepilogue. Thebuffer_storerevision 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 byds_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
4699230dc21d0e075a973c01390eca68c57648c5Behavior and intent
_moe_gemm_a8w4_decodeon gfx1250 ended the non-scatter path withds_storeintow_bufferslot 0 (the output tile aliases that slot),s_wait_dscnt 0, a workgroup barrier, thentensor_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'sw2_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_storefrom its WMMA layout (rowtile_m + in_m < M, columntile_n + in_n < yN).buffer_storeoffsets are 32-bit bytes, soYis advanced to this tile inindex_type(start_m + tile_mrows,tile_ncolumns, 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, Triton76940adplus 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:
ds_loadand a register store: 0. Theds_storelanded; the TDM store is the step that misses it.s_sleep 2immediately before the TDM store: 0. At most 2 workgroups per WGP: 0.s_nops ors_wait_tensorcnt 0after 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_storerevision that replaced the measuredgl.storeepilogue is not re-run on gfx1250.PR-specific question
The new store is a masked
gl.amd.gfx1250.buffer_storeof 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 pastY. Clean runs of the previousgl.storeepilogue 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. Thisbuffer_storerevision uses that same mask and layout and is not re-run on gfx1250.The scope boundary is the other epilogues. The
async_scatterbranch directly above thiselse, the persistent decode kernel, and the prefill kernel still dods_storethen a TDM store. They were not exercised. gpt-oss Gluon decode below 384 tokens (sglang#47398) takes the path this PR changes. Theasync_waitremoved with the old store waited on that store; nothing after the epilogue consumed it.Changed op tests
None.
🤖 Generated with Claude Code