Repository navigation
[Triton/Gluon] [Bugfix] gfx1250 a4w4 MoE decode: store the output tile without the TDM store - #7632
hubertlu-tw wants to merge 3 commits into
Conversation
…e without the TDM store `_moe_gemm_a4w4_decode` (gfx1250 Gluon) wrote its non-scatter output tile as registers -> LDS (ds_store) -> s_wait_dscnt 0 -> s_barrier -> tensor_store_from_lds. On gfx1250 that TDM store can ship stale LDS (16-byte chunks of the weight tile last loaded into the aliased buffer) despite the waits. ROCm#7202 replaces the same pattern in `_moe_gemm_a8w4_decode`, and ROCm#7605 in the FlyDSL grouped MoE GEMM. Under ATOM's gfx1250 decode this kernel is GEMM2 of the a4w4 MoE (GEMM1 emits MXFP4 through the HAS_MX_OUT epilogue, which already stores from registers). The tile is now re-laid with gl.convert_layout into a BlockedLayout whose lanes run along N (8 bf16 each, warps across rows) and stored with a masked gl.store: offsets in that layout, masked with offs_y_m < M and offs_y_n < yN, widened to index_type before the stride multiply. A warp writes 512 contiguous bytes of one row per store at OUT_BLOCK_N = 256 and two 256-byte row pieces at 128. Storing straight from the WMMA layout instead writes 16 rows x 32 bytes per store and costs 6-9% kernel time at 512 decode tokens on the DeepSeek-V4-Pro GEMM2 shape. convert_layout goes through LDS with ds_store -> barrier -> ds_load and no TDM. Its scratch reuses the start of w_buffer after the final TDM wait and a workgroup barrier, so the kernel's LDS size is unchanged (74480 / 78832 bytes for the two DeepSeek-V4-Pro decode configs). Not changed: the EP_SCATTER async_scatter branch and `_moe_gemm_a4w4_prefill`, which use the same ds_store -> TDM pattern but are not on this decode path. The op test gains DeepSeek-V4-Pro TP4 decode cases (384 experts, top-6) for the GEMM1 and GEMM2 shapes, and test_decode_output_not_tdm_stored, which runs the decode kernel at those shapes and fails if the compiled kernel contains tensor_store_from_lds. The corruption itself only shows up under serving load (about one GEMM2 call in 5k with ATOM's decode graphs, about one in a million from an op-level stress loop), so the test checks the store path rather than the output. Signed-off-by: Hubert Lu <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
There was a problem hiding this comment.
🟡 Changes recommended
The test can falsely pass by matching a cached decode specialization from an earlier case rather than verifying that this call used the expected non-scatter decode kernel.
1 open issue
What changed in this PR
This PR replaces the gfx1250 Gluon a4w4 MoE decode kernel’s non-scatter TDM output store to address intermittent stale-data corruption. It follows the related a8w4 decode and FlyDSL grouped MoE fixes without changing the public API.
Changes:
- Converts the output tile to a row-contiguous layout and writes it with masked register stores.
- Adds DeepSeek-V4-Pro TP4 correctness cases and a compiled-assembly regression check.
- Leaves prefill and EP-scatter paths unchanged.
| File | Description |
|---|---|
op_tests/triton_tests/moe/test_moe_gemm_a4w4.py |
Adds decode shapes and a check for unwanted TDM output stores. |
aiter/ops/triton/_gluon_kernels/gfx1250/moe/moe_op_gemm_a4w4.py |
Replaces the non-scatter decode TDM store with layout conversion and masked global stores. |
Review effort: Balanced
| if not compiled: | ||
| # Already compiled by an earlier case in this process: check those. | ||
| compiled = _compiled_kernels(gluon_a4w4._moe_gemm_a4w4_decode) | ||
| assert compiled, "the decode kernel did not run for this shape" |
…is call launched The test used to diff the decode kernel's JIT cache before and after the call, and fell back to checking every cached specialization when the call compiled nothing new. That fallback could pass on a specialization left by an earlier case even if this call never launched the decode kernel. Empty the decode kernel's in-memory JIT cache before the call instead, so what's in it afterwards is exactly what this call launched (reloaded from the on-disk cache when it was compiled before). Assert that something was launched, that it is the non-scatter specialization (EP_SCATTER_0), and that its AMDGCN has no tensor_store_from_lds. Signed-off-by: Hubert Lu <[email protected]>
WAITING ON AUTHORPR Self-ReviewRevision 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
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
Review follow-up. The non-scatter decode epilogue now writes the re-laid output tile with gl.amd.gfx1250.buffer_store instead of gl.store. buffer_store offsets are int32, so the base pointer moves to the tile's first row and column in index_type first, and only the tile-local offsets (at most BLOCK_M x OUT_BLOCK_N) go through int32. Large outputs still don't wrap, and the bounds mask is now relative to the tile. Drop test_decode_output_not_tdm_stored. test_op already checks the decode kernel's output against the reference at the DeepSeek-V4-Pro TP4 decode shapes, and the corruption the TDM store caused is too rare to hit from an op test, so the ISA check added little. gfx1250 (MI455): test_op -k "gluon and 384" 48 passed. DeepSeek-V4-Pro TP4 + MTP3 on ATOM with this change and ROCm#7605: 10 min with 600 GSM8K requests in flight did not trigger the ADO 4171957 collapse (41,935 requests), GSM8K 0.948, and no compiled decode kernel contains tensor_store_from_lds. Signed-off-by: Hubert Lu <[email protected]>
| OUT_LAYOUT: gl.constexpr = gl.BlockedLayout( | ||
| [1, 8], [32 // OUT_TPW_N, OUT_TPW_N], [gl.num_warps(), 1], [1, 0] | ||
| ) | ||
| out = gl.convert_layout(out, OUT_LAYOUT) |
There was a problem hiding this comment.
Given we are using transposed WMMA layout where we already have 8 contiguous fp32 elements per thread I wonder how relevant/necessary is to use convert_layout here. Could we run a quick performance comparison with and without?
|
No activity for 15 days, so this is now labelled |
There was a problem hiding this comment.
Must fix before merge
- No test fails without the fix (
test_moe_gemm_a4w4.py:160-164): the three new cases also pass with main's kernel. The assembly check that failed on main was removed in759e22c3. So no test stops a later change from bringing back the TDM store. Fix: add an output test that fails on main, or explain in the PR why no test can do this and get a maintainer's approval. Also update the description, which still names the removed test.
Nice to fix
- Reply to the
convert_layoutquestion with the timing with and without the re-layout. The description has 6–9% at 512 tokens. - Replace the three new cases (48 runs, no new path) with one decode case that has a column tail, for example N 2880. Then the new column mask is tested (test).
- Shorten each of the two new comment blocks to one or two sentences: what the code does and why, without the history (kernel).

Summary
_moe_gemm_a4w4_decodeon gfx1250 writes its output tile to LDS and then ships it withtensor_store_from_lds. Under serving load that TDM store sometimes picks up stale LDS, so a 16-byte chunk of an output row holds old weight bytes instead of the result. #7202 fixes the same pattern in the a8w4 decode kernel, and #7605 in the FlyDSL grouped MoE GEMM.This drops the TDM store from the non-scatter path. The tile is re-laid with
gl.convert_layoutso lanes run along a row, then written with a maskedgl.store. Output is bitwise identical and kernel time is unchanged.Motivation
DeepSeek-V4-Pro on ATOM, 4 x gfx1250 B0,
ATOM_USE_TRITON_MOE_DECODE=1. Decode MoE runs on the Gluon a4w4 kernels. GEMM1 emits MXFP4 through theHAS_MX_OUTepilogue, which already stores from registers; GEMM2 is this kernel with bf16 output.To see what GEMM2 produces under load, we wrapped ATOM's
moe_gemm_a4w4call with a few device-side counters that also run inside the captured decode graphs. Each GEMM2 output row is checked for values that are non-finite or above 1e5 (normal values stay under ~1.5e3). A row that is entirely bad came in already NaN and is counted separately. Only rows with a few bad values count as new corruption.At 600 concurrent GSM8K requests on TP4:
Same signature as #7202 and #7605.
The store itself is the problem, and that holds outside this kernel too. A standalone Gluon kernel that writes a bf16 tile to LDS with
ds_store, waits (s_wait_dscnt 0+ barrier, same as here) and then callstdm.async_storegets stale chunks in about 7e-7 of tile stores on gfx1250. Every bad 16-byte chunk holds exactly what that LDS address held before theds_store. The same kernel with the TDM store swapped fords_load+gl.store, or forgl.storestraight from registers, was clean over the same 5.5e9 tile stores. It also happens when the output buffer doesn't overlap anything a TDM load wrote; the stale data is then an earlier workgroup's tile.Changes
aiter/ops/triton/_gluon_kernels/gfx1250/moe/moe_op_gemm_a4w4.py,_moe_gemm_a4w4_decode, non-scatter epilogue:gl.convert_layoutto aBlockedLayout([1, 8], [32 // TPW_N, TPW_N], [num_warps, 1], [1, 0]), so each lane holds 8 bf16 of one row and a warp covers 512 contiguous bytes of a row atOUT_BLOCK_N = 256(two 256-byte row pieces at 128).gl.storewith offsets in that layout (offs_y_m < M,offs_y_n < yN), widened toindex_typebefore the stride multiply, as in [Triton/Gluon] [Bugfix] gfx1250 a8w4 MoE decode: store the output tile from registers, not LDS + TDM store #7202.convert_layoutgoes through LDS withds_store→ barrier →ds_loadand no TDM. Its scratch reuses the start ofw_bufferafter the final TDM wait and a workgroup barrier, so LDS stays at 74480 / 78832 bytes for the two DeepSeek-V4-Pro decode configs. Occupancy is unchanged.global_store_b128then writes 16 rows x 32 B, and GEMM2 at 512 tokens gets 6–9% slower. The re-layout avoids that.tensor_store_from_lds; 2–4global_store_b128per lane, row-contiguous.EP_SCATTERasync_scatterbranch and_moe_gemm_a4w4_prefill. Both use the sameds_store→ TDM pattern but aren't on this decode path.op_tests/triton_tests/moe/test_moe_gemm_a4w4.pytest_decode_output_not_tdm_stored: runs the decode kernel at those shapes with its in-memory JIT cache emptied first, so it checks exactly the specialization that call launched. It fails if nothing was launched, if the launched kernel isn't the non-scatter specialization, or if its AMDGCN containstensor_store_from_lds. The corruption only shows up under serving load (about one GEMM2 call in 8k in ATOM's decode graphs, about one in a million from an op-level stress loop), so the test checks the store path instead of the output.Performance (if applicable)
Kernel device time of
_moe_gemm_a4w4_decodefromtorch.profiler(100 calls each, no host overhead), DeepSeek-V4-Pro TP4 shapes with ATOM's call arguments.mainand this PR ran on two GPUs at once, then again with the GPUs swapped. Run 1 / run 2:The GEMM1 MXFP4 path, which this PR doesn't change, moves by the same amounts (+1.6% / +1.2% at 1 token, +2.3% / -3.0% at 512), so that's the noise floor. Server throughput is unchanged: 34,533 vs 34,398 requests in 20 min.
Testing
gfx1250, change loaded into the aiter in the ATOM image below:
main: GEMM2 raw and with ATOM's gammas + scatter reduce, GEMM1 bf16 + SwiGLU, GEMM1 MXFP4, at 1/16/64/256/512 tokens. 20/20 outputs equal.pytest op_tests/triton_tests/moe/test_moe_gemm_a4w4.py -k not_tdm_stored:main's kernel 3 failed (_moe_gemm_a4w4_decode_..._EP_SCATTER_0 stores its output tile with tensor_store_from_lds), this PR 3 passed.pytest op_tests/triton_tests/moe/test_moe_gemm_a4w4.py -k gluonwithmain's kernel and with this PR: the 48 new cases pass on both. The full gluon set gives 324 passed / 60 failed either way, and it's the same 60. They're allapply_swiglu=True, which is what [Triton/Gluon] fixed a moe bug related to swiglu on gfx1250 #7417 fixes.main's kernel got one bad call in ~1M (8 values, one 16-byte chunk). This PR got none. That's too rare to use as a test.End to end: DeepSeek-V4-Pro, ATOM TP4,
rocm/atom-dev:ub26-dcgpu-rk-10.2.0a20260922.bkc.20261002-pyt2.14.0-tri-main-15164f01-atomsrc-gfx1250-b1012, 600 GSM8K requests in flight,max_tokens256, with #7550, #7601 and #7605 applied:For the second row we ran every GEMM2 call twice and compared the two outputs bit for bit. The kernel is deterministic, so they should always match. We did the same to the FP8 linears, the
wo_abatched GEMM and the prefill attention in those runs (~2.9M calls per rank), and none of them ever differed. So it's the decode MoE kernel writing wrong data. Prefill attention ran on the Gluon kernel for these two runs, because the OPUS one has the same kind of problem (separate issue).Documentation
Kernel-internal change, no interface or behavior change.
Dependencies
Breaking Changes
None. Output is bitwise identical to
main.Follow-ups (not in this PR)
_moe_gemm_a4w4_prefilland theEP_SCATTERbranch still use the LDS + TDM store epilogue.gemm_a8w8_gfx1250.py) has the same epilogue, but it never differed in ~2.9M calls per rank under the same load.PR Self-Review
Reviewed revision
e465d24e1Behavior and intent
The gfx1250 Gluon a4w4 MoE decode kernel no longer writes its output with
tensor_store_from_lds. It re-lays the tile through LDS and writes it with a maskedgl.store, and the output is bitwise the same. Under concurrent decode the TDM store sometimes wrote stale LDS into a 16-byte chunk of an output row, which put garbage into DeepSeek-V4-Pro's MoE output.Validation and unverified scope
All on gfx1250, with the change loaded into the aiter in the ATOM image. Outputs match
mainbit for bit (20/20, GEMM1 and GEMM2, 1–512 tokens), and kernel time stays within the noise of a path this PR doesn't touch. On a DeepSeek-V4-Pro TP4 server with 600 GSM8K requests in flight, repeating each decode GEMM2 call and comparing the outputs turns up 22–30 mismatched calls per rank in 15 min withmain's kernel and none with this change. Other kernels checked the same way never mismatch. The output-buffer check goes from 586 bad values to 0 in 20 min, and throughput and accuracy don't move.test_decode_output_not_tdm_storedfails onmain's kernel and passes here. The rest oftest_moe_gemm_a4w4.py -k gluongives the same result either way.Still unverified: the EP-scatter and prefill paths (not touched), other architectures (the kernel is gfx1250-only), and a test that reproduces the bad output itself. Our stress loop hit it only once in ~1M calls on
main's kernel, which is too rare for CI.PR-specific question
test_decode_output_not_tdm_storedfails before this PR. At the DeepSeek-V4-Pro decode shapes,main's compiled_moe_gemm_a4w4_decodestill containstensor_store_from_lds, and that's what the test looks for. We couldn't write a test that catches the bad output itself. It only shows up under sustained serving load: about one GEMM2 call in 8k in ATOM's decode graphs, and about one in a million from an op-level stress loop. So the test pins the store that causes it instead.The three new
test_opcases pass before and after. They exist so the new epilogue's masks and offsets get checked against the reference with 384 experts and top-6, at a ragged 37 tokens and a full 512. No existing test looks at how the decode kernel writes its output, and the existing a4w4 cases only use 8 or 256 experts with top-4 or top-8.Changed op tests
op_tests/triton_tests/moe/test_moe_gemm_a4w4.pygets two additions:test_decode_output_not_tdm_storedruns the decode kernel at the DeepSeek-V4-Pro GEMM1 and GEMM2 shapes and checks the specialization each call launched. It fails if that kernel writes its output withtensor_store_from_lds.Neither overlaps with what's already there. No existing test checks how the decode kernel writes its output, and none runs it with 384 experts and top-6.