Skip to content

[FlyDSL] [Bugfix] gfx1250 TDM C store: read C back from LDS in the grouped MXFP4 MoE GEMMs - #8466

Closed
XiaobingSuper wants to merge 5 commits into
ROCm:mainfrom
XiaobingSuper:xiaobingsuper/gfx1250-tdm-c-lds-readback
Closed

XiaobingSuper wants to merge 5 commits into
ROCm:mainfrom
XiaobingSuper:xiaobingsuper/gfx1250-tdm-c-lds-readback

Conversation

@XiaobingSuper

@XiaobingSuper XiaobingSuper commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What

The gfx1250 grouped MXFP4 MoE GEMMs (launch_gemm_a8w4_tdm) no longer write their C tile with a per-wave TDM store (tensor_store_from_lds). The tile is read back from LDS with ds_load behind the existing barrier and written with buffer_store_b128.

  • GEMM2 (bf16 C). This is the c_lds_store read-back that [FlyDSL] [Perf] gfx1250 MoE: fold a shared MXFP8 expert into the routed MXFP4 GEMMs #8430 added for the shared-fold GEMM2, now also on the plain routed launcher.
  • Quantized stage-1 GEMM (FP4 / FP8 payload). A new cq_lds_store epilogue writes the payload rows the same way (kernel name _cqldsst). Where its 16-byte chunking does not divide the block (tile_m * payload_row_bytes / 16 not a multiple of the thread count, e.g. 16x128 tiles with 2 waves), the TDM store is kept. This is a known remaining exposure, the same as in the validated stack.
  • Default and opt-out. flydsl_grouped_gemm_a8w4_masked turns this on by default (_c_lds_store). EP scatter keeps its own store, and AITER_TDM_C_LDS_STORE=0 restores the TDM store.

The same change for the native MXFP8 GEMM (gemm_a8w8_gfx1250, gemm_a8w8_256x256_gfx1250) is in #8273. The tp_gather GEMM1 of #8461 gets it there as one more commit.

Why

This fixes the stray token-0 bug we hit in MiniMax-M3.1 TP4 decode on 4x MI455X. With dual-stream MoE (the shared MLP beside the routed MoE on the other HIP queue of a captured graph), now and then a decode row's logits were all zero and argmax picked token 0.

Root cause, proven byte for byte. At a bad step (rank 0, layer 45):

  • The shared expert's down_proj output (an MXFP8 GEMM with the same epilogue) was corrupt only in rows 6-7 of N tile 51, columns 56-63.
  • Those two 16-byte chunks are bit-identical to the FP8 activation bytes of k-tile 4, at the LDS offsets the C tile overlays.
  • FP8 bytes read as bf16 are 1e25-1e38, never NaN. The residual is poisoned, RMSNorm then outputs 0, and the logits row is all zero.

Why the MoE GEMMs are covered too. The routed MoE GEMMs store their C tiles the same way and run in the same concurrent window:

  • in GEMM2 a stale piece is a 1e25-1e38 bf16 value;
  • in GEMM1 it is a garbage FP4 activation or E8M0 scale that GEMM2 then multiplies by.

The shared-fold GEMM2 showed the same race before (#8430).

Hardware / compiler note

On gfx1250, the LDS read of a TDM store (tensor_store_from_lds) is not ordered behind ds_stores issued by the other waves of the workgroup, even after every wave has done s_wait_dscnt 0 and passed s_barrier_signal / s_barrier_wait.

  • What we see. Each wave's TDM box covers whole rows, i.e. columns other waves wrote. A 16-byte piece of the box can leave with the bytes LDS held before those ds_stores: the last k-tile's operands that the C tile overlays.
  • What does work. A ds_load issued after the same barrier always sees the new data (0 bad in 84,000 launches in the [FlyDSL] [Perf] gfx1250 MoE: fold a shared MXFP8 expert into the routed MXFP4 GEMMs #8430 stress test).
  • Conditions. It shows up mostly when another queue's kernels share the CUs.
  • Ask. We could not find a documented fence that orders the TDM engine's LDS read behind other waves' DS writes. If one exists (or a required s_wait / cache-control bit), the TDM store could come back. Until then this read-back is the workaround.

The first occurrence (the shared-fold GEMM2) and its rates are summarized in #8430; a write-up with the ISA sequence and bad-byte provenance has been written up separately for the compiler / hardware team.

Correctness and performance

MiniMax-M3.1 TP4 on 4x MI455X, with this change and the MXFP8 GEMM one (#8273) together:

  • Zero-row events (token 0): 8 of 40 greedy passes without the fix. With it: 0 of 40, 0 of 12 high-concurrency passes (384-row batches), 0 over full GSM8K, and 0 of 25 with the default token-graph buckets.
  • Accuracy: our serving gate passes, and GSM8K (1319, 5-shot) scores 0.9545 / 0.9538.
  • Decode step: unchanged within the ±2% noise. The measured pairs were bs1 4.838 vs 4.797 ms, bs4 6.286 vs 6.257, bs10 7.557 vs 7.608, bs16 8.494 vs 8.657.
  • Reproduces without our stack: the bug also reproduces on the plain integration image, so it is not caused by our other changes.

Dependencies

Validation status

🤖 Generated with Claude Code

ruili and others added 5 commits November 21, 2026 14:14
…n the same pass

A shared expert run beside the routed MXFP4 MoE (MiniMax-M3.1) quantizes the
same bf16 rows to MXFP8 in its own launch. The routed A1 quant already reads
each row and reduces every 32-block's amax, so it can write that copy too:
fused_moe / flydsl_moe_fused_quant_preshuffle take `mxfp8_copy_out=(payload,
scale)`, row-major (M, K) E4M3 + (M, K/32) E8M0, the bytes of
per_1x32_mx_quant_hip(quant_dtype=fp8, scale_type=fp8_e8m0) (amax floored at
kAmaxFloor, RoundUp exponent against 448, v_cvt_scalef32_pk8_fp8_bf16).

The three quant builds the M3.1 grouped MoE dispatches take a `mxfp8_copy`
build flag (`_mx8cp` builds with two more pointers): token-multidest (plain
and K-split), the compact-scale quant, and the route-indexed quant (each
source row's first route writes it, mapped or not). Any other A1 path, or a
non-grouped MoE / FHMoE, fills the copy with the HIP quant instead. Without
the flag every build is unchanged: the kernel bodies moved into a @flyc.jit
body inlined into either signature.

fused_moe's plugin contract moves to version 3 (two more outputs a v2
provider would leave unwritten, so v2 is not superseded);
tests/plugin_contracts.json records it.

op_tests/test_moe_quant_shared_mxfp8.py: routed outputs bitwise unchanged and
the copy bitwise the split quant (and a torch model of the rule) for every
variant at 8..32768 tokens, the public fused_moe path, and timing of the fused
launch against routed quant + split quant.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…shared-expert add

Add an optional output epilogue to the grouped MoE gather-reduce:
out = bf16(bf16(bf16(sum_k w * rows) * scale) + addend), each step rounded
like the separate torch ops it replaces (the multiply is skipped at scale
1.0), so the bytes are unchanged.

moe_output_epilogue(addend, scale, before=None) is a context manager that
hands the pending epilogue to the next _grouped_a8w4_tdm_moe call in the
block; `before` runs right before the gather-reduce launch (e.g. a wait for
the stream that produced addend) and `consumed` tells the caller whether a
gather-reduce took it. EP calls and other MoE paths leave it unconsumed and
the caller applies the scale and add itself. Python-side state: for eager
callers, not torch.compile tracing.

MiniMax-M3.1 TP4 shape (hidden 6144, E128 top-4, bf16), 4x MI455X, us:
  T                       64    128   192   256
  gather-reduce+mul+add  5.41  5.61  6.09  6.50
  fused gather-reduce    1.84  1.91  2.19  2.21
Output bitwise identical to the separate ops (eager and Inductor).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed MXFP4 GEMM launches

moe_shared_expert_fold(weights, scale) runs a dense shared expert inside the
next grouped MoE call (_grouped_a8w4_tdm_moe), as one more expert every
token routes to with weight 1:

- GEMM1: launch_gemm_a8w4_tdm_shared_fold puts the shared gate/up tiles in
  the routed GEMM1 launch (leading workgroups, FP8 x FP8 on the MXFP8 copy of
  the input the A1 quant writes, SwiGLU and MXFP8 quant in the same
  epilogue), the routed tiles unchanged behind them;
- GEMM2: the shared down tiles in the routed GEMM2 launch (BF16 rows);
- the shared rows are added after the routed scale in the gather-reduce
  (moe_output_epilogue).

The MXFP4 TDM GEMM gains b_fp8 (row-major FP8 B, staged like the FP8
activation), inline_task, dense_rows and c_stage_apart knobs for the dense
tiles; the routed tiles compile as before. prepare_shared_fold_weights()
lays the weights out once (gate/up interleaved, n32k4 scales) into storage
it owns, so a caller may shuffle its own parameters in place afterwards. The
fold is taken only for unclustered decode tiles without EP, compact or
prequantized A1; elsewhere `consumed` stays False and the caller runs the
shared expert itself.

MiniMax-M3.1 TP4 MoE layer (E128 top-4 MXFP4 routed + MXFP8 shared,
hidden 6144), 4x MI455X, us per layer:
  T                         64    128   192   256
  routed + shared (2 streams) 69.1  78.4  81.7  82.6
  fold                       65.6  72.7  78.0  81.0
Shared-expert rel-L2 vs fp32: 2.0e-3 (separate MLP: 1.7e-2, which rounds the
gate/up and SwiGLU outputs to BF16 before its quant). Not bitwise the
separate MLP for that reason; MoE output rel-L2 vs the current path 1.4e-5.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…stores, not a TDM store

On gfx1250 a TDM store (tensor_store_from_lds) can read LDS bytes that
predate ds_stores the workgroup issued before `s_wait_dscnt 0` and
`s_barrier`. In the shared-fold GEMM2 (routed 16x128 with the 64x64 /
32x64 dense tiles), the C pieces of each wave's last ds_store, in the
first rows of its 8-row TDM box, sometimes came out as the input stage's
older A/B bytes. That happened in 0.2-10% of launches at T 48-80 under
hot-expert routing on MI455X. A ds_load after the same barrier always sees
the new data.

New build option c_lds_store (bf16/f16 C without EP scatter): after the
barrier that follows the C restage, the waves read the tile back from LDS
in whole-row 16-byte chunks and write it with buffer_store_b128. Rows past
mn_oob are dropped, as the TDM store's row extent drops them.
launch_gemm_a8w4_tdm_shared_fold turns it on for GEMM2. The kernel name
gains `_cldsst`.

MI455X, T 48-256, hot-expert routing: 0 bad launches in 84,000 (the TDM
store: up to 10%), bitwise the clean output, +0.0-0.6 us per GEMM2.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…m LDS instead of TDM-storing it

On gfx1250, a TDM store's (tensor_store_from_lds) read of LDS is not
ordered behind the other waves' ds_stores, even after `s_wait_dscnt 0` and a
workgroup barrier. A 16-byte piece of a wave's TDM box can then leave as the
bytes LDS held before the C tile: the input stage's FP4 / FP8 operands. ROCm#8430
fixed this for the shared-fold GEMM2. The same store pattern runs in the plain
routed MoE GEMMs:
- GEMM2's bf16 tile, where stale operand bytes read as bf16 are 1e25-1e38;
- a stage-1 GEMM's quantized FP4 / FP8 tile (with its E8M0 scales), which
  GEMM2 then dequantizes.

Both now leave LDS through a ds_load read-back behind the existing barrier,
then buffer stores:
- launch_gemm_a8w4_tdm takes `c_lds_store`. For GEMM2 it is the bf16
  read-back ROCm#8430 added for the fold (`c_lds_store`). For a quantized stage-1
  GEMM it is a new `cq_lds_store` epilogue that writes the payload rows the
  same way (kernel name `_cqldsst`), kept on the TDM store where its 16-byte
  chunking does not divide the block.
- flydsl_grouped_gemm_a8w4_masked turns it on by default
  (`_c_lds_store`). EP scatter keeps its own store, and
  AITER_TDM_C_LDS_STORE=0 restores the TDM store.

The race fires when another queue's kernels share the CUs, e.g. MiniMax-M3's
shared MLP running beside the routed MoE on the other stream of a captured
graph. On MiniMax-M3.1 TP4 (4x MI455X), together with the same change in the
MXFP8 GEMM, all-zero logit rows (decoded as token 0) went from 8 of 40 greedy
passes to 0 of 40, 0 of 12 high-concurrency passes and 0 over full GSM8K.
The decode step is unchanged within noise; GSM8K 0.9545 / 0.9538.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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 8466 --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

Copy link
Copy Markdown
Contributor Author

Closing: per the scope decision, only the gemm_a8w8_gfx1250 read-back ships (in #8273); the grouped MXFP4 MoE read-back costs ~4% of prefill time with no observed failure, and stays as a latent-risk note in #8273.

XiaobingSuper added a commit to XiaobingSuper/aiter that referenced this pull request Nov 23, 2026
…e2e9)

Scope decision for the stray token-0 fix: only the read-back in
gemm_a8w8_gfx1250 ships (ROCm#8273); the grouped MoE PR (ROCm#8466) is
closed. This reverts both commits that brought it here:
- f3c9c30, the `cq_lds_store` wiring for launch_gemm_a8w4_tdm_tpg;
- the merge 77be2e9 of the grouped GEMM1 / GEMM2 read-back
  (`_c_lds_store`, `cq_lds_store`).

The grouped MoE read-back cost about 4% of prefill time (uncached prefill
TTFT +3.7-4.5%, C64 P90 274.7 vs 281-283), and no failure was ever observed
in these kernels. They keep the TDM store, a latent risk recorded in
ROCm#8273's hardware / compiler note. This branch's tree is again that of
9baf599.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants