Skip to content

[Triton/Gluon] [Bugfix] gfx1250 a4w4 MoE decode: store the output tile without the TDM store - #7632

Open
hubertlu-tw wants to merge 3 commits into
ROCm:mainfrom
hubertlu-tw:fix/gfx1250-gluon-a4w4-decode-regstore
Open

hubertlu-tw wants to merge 3 commits into
ROCm:mainfrom
hubertlu-tw:fix/gfx1250-gluon-a4w4-decode-regstore

Conversation

@hubertlu-tw

@hubertlu-tw hubertlu-tw commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

_moe_gemm_a4w4_decode on gfx1250 writes its output tile to LDS and then ships it with tensor_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_layout so lanes run along a row, then written with a masked gl.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 the HAS_MX_OUT epilogue, 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_a4w4 call 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:

  • 586 new bad values in 20 min, 1–17 per affected call, different on each rank, in ~375k GEMM2 calls per rank.
  • Values like -5.8e25 or 2.4e6, i.e. bf16 garbage, not a numerical overflow. Rerunning the same inputs is clean.
  • The first hit is always in a captured bs-512 decode graph, after the grouped reduce, 1–5 bad values inside one 16-byte chunk.

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 calls tdm.async_store gets stale chunks in about 7e-7 of tile stores on gfx1250. Every bad 16-byte chunk holds exactly what that LDS address held before the ds_store. The same kernel with the TDM store swapped for ds_load + gl.store, or for gl.store straight 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_layout to a BlockedLayout([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 at OUT_BLOCK_N = 256 (two 256-byte row pieces at 128).
  • Masked gl.store with offsets in that layout (offs_y_m < M, offs_y_n < yN), widened to index_type before the stride multiply, as in [Triton/Gluon] [Bugfix] gfx1250 a8w4 MoE decode: store the output tile from registers, not LDS + TDM store #7202.
  • 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 LDS stays at 74480 / 78832 bytes for the two DeepSeek-V4-Pro decode configs. Occupancy is unchanged.
  • Storing straight from the WMMA layout also works, but each global_store_b128 then writes 16 rows x 32 B, and GEMM2 at 512 tokens gets 6–9% slower. The re-layout avoids that.
  • ISA at the DeepSeek-V4-Pro decode configs: no tensor_store_from_lds; 2–4 global_store_b128 per lane, row-contiguous.
  • Not touched: the EP_SCATTER async_scatter branch and _moe_gemm_a4w4_prefill. Both use the same ds_store → TDM pattern but aren't on this decode path.

op_tests/triton_tests/moe/test_moe_gemm_a4w4.py

  • DeepSeek-V4-Pro TP4 decode cases (384 experts, top-6): GEMM1 (N=1536, K=7168) and GEMM2 (N=7168, K=768) at 37 and 512 tokens.
  • test_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 contains tensor_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_decode from torch.profiler (100 calls each, no host overhead), DeepSeek-V4-Pro TP4 shapes with ATOM's call arguments. main and this PR ran on two GPUs at once, then again with the GPUs swapped. Run 1 / run 2:

Hardware Tokens GEMM2 (N=7168, K=768) GEMM1 bf16 (N=1536, K=7168)
gfx1250 1 +4.4% / -11.6% +1.0% / -0.1%
gfx1250 16 -1.9% / +6.0% +5.4% / -7.0%
gfx1250 64 -0.0% / +1.4% +2.6% / -3.7%
gfx1250 256 -0.7% / +1.1% +1.7% / -2.0%
gfx1250 512 -0.5% / +1.7% +1.6% / -2.3%

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

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

gfx1250, change loaded into the aiter in the ATOM image below:

  • Bitwise vs 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.
  • Kernel timing, table above.
  • 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 gluon with main'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 all apply_swiglu=True, which is what [Triton/Gluon] fixed a moe bug related to swiglu on gfx1250 #7417 fixes.
  • Stress loop: 8 GEMM2 calls at 512 tokens in one CUDA graph, replayed while other MoE GEMMs and a bf16 matmul run on a second stream, every output checked against an eager run. 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.
  • gfx950 CI. The kernel is gfx1250-only.

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_tokens 256, with #7550, #7601 and #7605 applied:

Without this PR With this PR
New bad values in decode GEMM2 output (check from Motivation) 586 in 20 min 0 in 20 min
Decode GEMM2 calls whose output changes when the call is repeated on the same inputs (15 min) 22 / 22 / 23 / 30 per rank, out of ~207k 0 on every rank, out of ~210k
Throughput / accuracy, 20 min 28.7 req/s, 0.955 28.8 req/s, 0.965

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_a batched 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

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Kernel-internal change, no interface or behavior change.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None. Output is bitwise identical to main.

Follow-ups (not in this PR)

  • _moe_gemm_a4w4_prefill and the EP_SCATTER branch still use the LDS + TDM store epilogue.
  • The other kernel on this model that writes wrong data the same way is the OPUS sparse prefill attention code object (separate issue). The FlyDSL dense FP8 GEMM (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

e465d24e1

Behavior 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 masked gl.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 main bit 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 with main'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_stored fails on main's kernel and passes here. The rest of test_moe_gemm_a4w4.py -k gluon gives 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_stored fails before this PR. At the DeepSeek-V4-Pro decode shapes, main's compiled _moe_gemm_a4w4_decode still contains tensor_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_op cases 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.py gets two additions:

  • test_decode_output_not_tdm_stored runs 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 with tensor_store_from_lds.
  • Three cases are added to the existing correctness test: GEMM1 (N=1536, K=7168) and GEMM2 (N=7168, K=768) at 37 tokens, and GEMM2 at 512 tokens, all with 384 experts and top-6.

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.

…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]>
@hubertlu-tw
hubertlu-tw requested a review from a team November 8, 2026 21:42
@github-actions

github-actions Bot commented Nov 8, 2026

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 7632 --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.

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

Comment on lines +375 to +378
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"
@hubertlu-tw
hubertlu-tw requested a review from valarLip November 8, 2026 22:49
…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]>
@aiter-bot

aiter-bot commented Nov 8, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 759e22c386ee · 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. What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?
  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.

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]>
@hubertlu-tw
hubertlu-tw requested a review from lburzawa November 10, 2026 20:30
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)

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.

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?

@zufayu
zufayu requested review from a team and Boss2002n and removed request for valarLip November 11, 2026 05:49
@github-actions

Copy link
Copy Markdown
Contributor

No activity for 15 days, so this is now labelled stale. A push or a comment clears it; keep-open exempts it. Nothing is closed automatically.

@github-actions github-actions Bot added the stale The PR hasn't been updated in 2 weeks label Nov 27, 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. 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 in 759e22c3. 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_layout question 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).

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

Labels

stale The PR hasn't been updated in 2 weeks Triton/Gluon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants