Skip to content

[FlyDSL] [Bugfix] gfx1250 grouped MoE GEMM: store the output tile without the TDM store - #7605

Open
hubertlu-tw wants to merge 1 commit into
ROCm:mainfrom
hubertlu-tw:fix/gfx1250-flydsl-moe-tdm-regstore
Open

hubertlu-tw wants to merge 1 commit into
ROCm:mainfrom
hubertlu-tw:fix/gfx1250-flydsl-moe-tdm-regstore

Conversation

@hubertlu-tw

Copy link
Copy Markdown
Contributor

Summary

On gfx1250 the grouped MoE GEMM in mxfp4_preshuffle_gfx1250_tdm.py writes its output by staging the tile in LDS (ds_store) and then shipping it with tensor_store_from_lds. Under load the TDM store sometimes picks up stale LDS, and a 16-byte chunk of an output row ends up holding old weight bytes. #7202 hit the same thing in the Gluon a8w4 decode kernel.

This keeps the LDS staging but reads the tile back with ds_load and writes it out with plain buffer_stores, one contiguous row segment per store. No more TDM store on the non-scatter path. Output is bitwise identical and kernel time is unchanged.

Motivation

DeepSeek-V4-Pro on ATOM, 4 x gfx1250 B0. Prefill MoE runs through fused_moe and this kernel. Every few minutes one token's MoE output on one TP rank comes back with 5 of its 7168 columns set to things like 1.6e30, -2.2e17 or NaN, from finite inputs. Rerunning the same inputs is clean. Before #7550 / #7601 that NaN could take the whole server down via the compressor; now it only ruins one request, but it still happens.

Filling the MoE output buffers with a fixed pattern before each prefill call (0xA5 for GEMM1's quantized output, bf16 0x7F7F for GEMM2's output and the gather-reduce output) and flagging any final output that's non-finite or above 1e5 (normal values stay under ~1.5e3) gives a pretty clear picture:

Changes

aiter/ops/flydsl/kernels/mxfp4_preshuffle_gfx1250_tdm.py

  • AITER_FLYDSL_TDM_REGSTORE picks the epilogue: lds (default), tdm or reg.
  • lds: stage in LDS as before, ds_load_b128 it back, then buffer_store contiguous row segments (512 B, two full lines, for the bf16 GEMM2 tile). Rows past the expert's end are masked with the same bound the TDM store used.
  • Applies to GEMM2's bf16 output and to GEMM1's outputs (fused act + MX requant with fp4/fp8 payload, row-major or preshuffled, and the bf16 fallback). They all had the same ds_store → TDM store sequence.
  • tdm is the old path, ISA byte-identical to main.
  • reg stores straight from the accumulators. It's correct, but each lane only holds 8 bf16 of a row in the WMMA layout, so every buffer_store_b128 scatters 32 B into 16 rows and GEMM2 is 24–54% slower at 2048–8192 tokens. Kept for A/B only.
  • Each mode compiles under its own name (_ldsst, _regst, unchanged for tdm) and cache key.
  • EP-scatter TDM gather-store, e8m0 scale stores and the split-K reduction are untouched.

op_tests/flydsl_tests/test_flydsl_grouped_gemm.py

  • test_grouped_output_epilogue_matches_tdm_store: same grouped MoE call under lds, reg and tdm in separate processes, outputs must match bitwise. a4w4/a8w4, requant on/off, 37/300/4096 tokens (ragged tails and the 128-row tiles).

Performance (if applicable)

test_flydsl_grouped_gemm.py --scenario kernel --data-format a4w4 --experts 384 --topk 6 --model-dim 7168 --inter-dim 768 --act silu --no-bias, gfx1250, lds vs tdm on two GPUs at once, then repeated with the GPUs swapped. Numbers are run 1 / run 2 for uniform and constant weight init:

Hardware Workload/configuration GEMM2 change GEMM1 + GEMM2 change
gfx1250 16 tokens, uniform / constant init -0.8% / +2.5%, +1.3% / -4.2% +0.1% / +1.4%, +6.1% / -6.9%
gfx1250 128 tokens +1.2% / +2.6%, +3.5% / -2.5% +1.4% / +2.3%, +1.5% / -0.1%
gfx1250 512 tokens -0.1% / +1.9%, +1.7% / -1.0% +0.8% / +1.4%, +0.1% / -0.2%
gfx1250 2048 tokens +4.0% / +0.2%, +1.2% / +3.0% +1.6% / -0.3%, +2.0% / +1.1%
gfx1250 8192 tokens +3.2% / -2.0%, +2.8% / -2.0% +3.6% / -3.6%, +2.4% / -2.6%

Noise is about ±4% and the sign flips between runs. No measurable difference.

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:

  • lds and reg vs tdm, bitwise: 8 shapes (a4w4/a8w4 at 37, 300, 4096 tokens, DeepSeek-V4-Pro shapes at 16 and 2048) × requant on/off. 80/80 outputs match. Rel. error vs the torch reference 0.0027–0.0032 in every mode.
  • Kernel timing, table above.
  • pytest op_tests/flydsl_tests/test_flydsl_grouped_gemm.py -k epilogue on a full aiter build. Doesn't run in the ATOM image (aiter.fused_topk fails to JIT-build there, missing ck_tile/core.hpp), so the bitwise check above calls the same _run_grouped_via_fused_moe with torch top-k routing.
  • gfx950 CI. The file 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, #7550 and #7601 applied:

Run TDM store This PR
Output-buffer check (see Motivation), every prefill MoE call 28 hits in 4.5 min 0 hits in ~26k calls per rank (5.5 min)
Poisoned requests (fresh NaN episodes), 20 min 1.5–3.2 per 10 min 1.5 per 10 min (3 requests, each contained)
Throughput / accuracy, 20 min ~28.5 req/s, 0.95 28.5 req/s, 0.955

The first row is what this PR fixes. The poisoned-request rate doesn't drop much because what's left starts in decode, and decode MoE here runs on the Gluon a4w4 kernels, not this one.

Documentation

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

The env var is only for A/B and debugging; nobody needs to set it.

Dependencies

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

Breaking Changes

None. Output is bitwise identical to the TDM-store path.

Follow-ups (not in this PR)

PR Self-Review

Reviewed revision

4dcd0aef8

Behavior and intent

The non-scatter epilogue of the gfx1250 grouped MoE GEMM stops using tensor_store_from_lds. It still stages the tile in LDS, then reads it back and writes rows with regular buffer stores, so the output is bitwise the same. The TDM store occasionally wrote stale LDS into a 16-byte chunk of an output row under load, which gave garbage MoE outputs and, combined with the compressor bug, collapsed DeepSeek-V4-Pro accuracy across the whole server.

Validation and unverified scope

On gfx1250 with the change loaded into the ATOM image's aiter: lds and reg match tdm bit for bit on all 80 outputs (8 shapes incl. 4096 tokens and DeepSeek-V4-Pro shapes, a4w4/a8w4, requant on/off), and test_flydsl_grouped_gemm.py --scenario kernel timing is within ±4% of tdm from 16 to 8192 tokens. On a DeepSeek-V4-Pro TP4 server at 600 concurrent GSM8K requests, the output-buffer check from Motivation goes from 28 hits in 4.5 min to 0 in ~26k prefill MoE calls per rank, and over 20 min throughput stays at 28.5 req/s with 0.955 accuracy. Still unverified: the pytest itself (it can't JIT-build aiter.fused_topk in that image; a torch-routing script ran the same comparison), the EP-scatter path, the decode path where the remaining NaN episodes start (not touched here), and other architectures (the file is gfx1250-only).

PR-specific question

The new test can't fail before this PR since lds and reg don't exist yet. It pins the new default to the TDM-store path bitwise across a4w4/a8w4, requant on/off and 37/300/4096 tokens, including the 128-row tiles. The corruption itself is nondeterministic and only shows up under concurrent serving load, so a single-process op test won't reproduce it. The existing tests compare each kernel to a reference once, which doesn't hit the race, and none of them compares two epilogues of the same kernel.

Changed op tests

op_tests/flydsl_tests/test_flydsl_grouped_gemm.py adds test_grouped_output_epilogue_matches_tdm_store, which runs one grouped MoE call under the lds, reg and tdm epilogues in separate processes and requires bitwise-equal output across a4w4/a8w4, requant on/off and 37/300/4096 tokens. Not redundant: the existing tests check each config against a reference, but nothing ties the new epilogue to the old one.

@hubertlu-tw
hubertlu-tw requested a review from a team November 7, 2026 08:09
@github-actions

github-actions Bot commented Nov 7, 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 7605 --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 Nov 7, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision d08faf0eabe4 · 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.

…TDM store

The gfx1250 grouped MoE TDM GEMM (mxfp4_preshuffle_gfx1250_tdm.py) ended
every non-scatter epilogue with ds_store of the output tile into the input
arena -> s_wait_dscnt 0 -> s_barrier -> tensor_store_from_lds. That TDM
store occasionally ships stale LDS: under DeepSeek-V4-Pro prefill load
(TP4, GEMM2 t16x512x128 b2 K768 e384) one 16-byte chunk of one expert's
GEMM2 output row holds fp4 weight bytes read as bf16 (1e16..1e36 / NaN),
always the last ds_store_b128 slot of a warp (col % 128 in 112..127). The
bad bytes are in memory: with the output pre-filled with a sentinel, no
sentinel survives, and the garbage is foreign data rather than the
buffer's previous contents. The ISA already has the documented waits;
s_nops before the epilogue do not help. aiter ROCm#7202 found the same in the
Gluon a8w4 MoE decode kernel: the TDM store of an LDS-staged tile can ship
the weight tile last loaded into the aliased slot, while staging in LDS
and reading back with ds_load is clean, i.e. the TDM store is the faulty
step.

The non-scatter epilogue now keeps the LDS staging but replaces the TDM
store with the same transfer done by the waves: after the existing
barrier every lane ds_loads 16 bytes of the staged tile and
buffer_stores them, consecutive lanes along a row, so a store instruction
writes whole row segments (512 contiguous bytes of a 1 KB bf16 row). It
mirrors the TDM store exactly: same LDS source (including the deferred
stage-1 staging), rows below the expert end (whole M16 slabs for the
preshuffled fp4 output), same global bytes. Lane coordinates are computed
once with shifts, per-pass offsets are immediates, and loads are issued in
batches of 16 ahead of their stores. This covers the bf16 GEMM2 output,
the fused activation + MX requant GEMM1 payload (fp4 or fp8; the e8m0
scale stores are unchanged) and the bf16 GEMM1 fallback.

AITER_FLYDSL_TDM_REGSTORE selects the epilogue per process:

- lds (default): LDS staging + ds_load readback + row-contiguous
  buffer_store; kernel name suffix "_ldsst".
- tdm: LDS staging + TDM store, the previous code (ISA byte-identical).
- reg: masked buffer stores straight from the accumulator registers, no
  LDS ("_regst"). Kept for A/B only: each store covers 16 rows x 32 bytes
  (the WMMA lane layout), which costs up to +54% GEMM2 time at large M.

The setting is in the kernel name, and each epilogue traces to different
IR, which FlyDSL 0.5.0 keys its cache on, so cached TDM-store kernels
are not reused. The EP-scatter TDM gather-store, the k_waves
partial-sum reduction and the e8m0 scale stores are unchanged; fp8
stage-1 output with preshuffled A (not produced by the dispatcher) keeps
the TDM store under reg.

Results on gfx1250 (DeepSeek-V4-Pro TP4 prefill, ATOM):
- Corruption detector (sentinel fill + check of every prefill MoE call):
  0 garbage chunks with the TDM store removed vs 28 in 4.5 min with the
  TDM store on the t16 config.
- Bitwise identical to the TDM-store epilogue in every case tried (80
  outputs: a4w4/a8w4, requant on/off, 16..4096 tokens, t16/t64/t128 tiles,
  DSV4 shape).
- Kernel time vs the TDM store at 16..8192 tokens: lds within noise (GEMM2
  -4..+4%, GEMM1 + GEMM2 -7..+6%).

test_grouped_output_epilogue_matches_tdm_store compares lds and reg
against tdm bitwise (one process per epilogue: FlyDSL folds the setting
into its cache key).

Signed-off-by: Hubert Lu <[email protected]>
@hubertlu-tw
hubertlu-tw force-pushed the fix/gfx1250-flydsl-moe-tdm-regstore branch from 4dcd0ae to d08faf0 Compare November 10, 2026 20:28
@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 26, 2026

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

FlyDSL stale The PR hasn't been updated in 2 weeks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants