Repository navigation
[FlyDSL] [Bugfix] gfx1250 grouped MoE GEMM: store the output tile without the TDM store - #7605
hubertlu-tw wants to merge 1 commit into
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
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 |
…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]>
4dcd0ae to
d08faf0
Compare
|
No activity for 15 days, so this is now labelled |
Summary
On gfx1250 the grouped MoE GEMM in
mxfp4_preshuffle_gfx1250_tdm.pywrites its output by staging the tile in LDS (ds_store) and then shipping it withtensor_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_loadand writes it out with plainbuffer_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_moeand 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 (
0xA5for GEMM1's quantized output, bf160x7F7Ffor 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:t16x512x128(b2, K768), and only columns 112..127 of each 128-column block. That's the lastds_store_b128each lane issues before the TDM store.s_wait_dscnt 0x0and the barrier beforetensor_store_from_lds, and padding it withs_nops changes nothing. It's not a missing wait in this kernel. [Triton/Gluon] [Bugfix] gfx1250 a8w4 MoE decode: store the output tile from registers, not LDS + TDM store #7202 has the open question to LLVM / HW about when a TDM store can safely read freshlyds_stored LDS.Changes
aiter/ops/flydsl/kernels/mxfp4_preshuffle_gfx1250_tdm.pyAITER_FLYDSL_TDM_REGSTOREpicks the epilogue:lds(default),tdmorreg.lds: stage in LDS as before,ds_load_b128it back, thenbuffer_storecontiguous 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.ds_store→ TDM store sequence.tdmis the old path, ISA byte-identical tomain.regstores straight from the accumulators. It's correct, but each lane only holds 8 bf16 of a row in the WMMA layout, so everybuffer_store_b128scatters 32 B into 16 rows and GEMM2 is 24–54% slower at 2048–8192 tokens. Kept for A/B only._ldsst,_regst, unchanged fortdm) and cache key.op_tests/flydsl_tests/test_flydsl_grouped_gemm.pytest_grouped_output_epilogue_matches_tdm_store: same grouped MoE call underlds,regandtdmin 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,ldsvstdmon two GPUs at once, then repeated with the GPUs swapped. Numbers are run 1 / run 2 for uniform and constant weight init:Noise is about ±4% and the sign flips between runs. No measurable difference.
Testing
gfx1250, change loaded into the aiter in the ATOM image below:
ldsandregvstdm, 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.pytest op_tests/flydsl_tests/test_flydsl_grouped_gemm.py -k epilogueon a full aiter build. Doesn't run in the ATOM image (aiter.fused_topkfails to JIT-build there, missingck_tile/core.hpp), so the bitwise check above calls the same_run_grouped_via_fused_moewith torch top-k routing.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, #7550 and #7601 applied: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
The env var is only for A/B and debugging; nobody needs to set it.
Dependencies
Breaking Changes
None. Output is bitwise identical to the TDM-store path.
Follow-ups (not in this PR)
PR Self-Review
Reviewed revision
4dcd0aef8Behavior 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:
ldsandregmatchtdmbit for bit on all 80 outputs (8 shapes incl. 4096 tokens and DeepSeek-V4-Pro shapes, a4w4/a8w4, requant on/off), andtest_flydsl_grouped_gemm.py --scenario kerneltiming is within ±4% oftdmfrom 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-buildaiter.fused_topkin 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
ldsandregdon'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.pyaddstest_grouped_output_epilogue_matches_tdm_store, which runs one grouped MoE call under thelds,regandtdmepilogues 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.