Repository navigation
[FlyDSL] [Perf] gfx1250 MoE: fold a shared MXFP8 expert into the routed MXFP4 GEMMs - #8430
XiaobingSuper wants to merge 4 commits into
Conversation
…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 <noreply@anthropic.com>
…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 <noreply@anthropic.com>
…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 <noreply@anthropic.com>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
…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 <noreply@anthropic.com>
|
Update: pushed 2d81a36, the fix for the nondeterministic shared-fold GEMM2 launch described in the body.
|
|
Compile check for 2d81a36 (the GEMM2 C-store fix). FlyDSL compile-only for gfx1250 in a GPU-less container. These
The 4-wave T=32 routed tile (16x256x128 w1x4) is rejected by the fold's own thread-count check, as before. |
…-rows branch The bugfix branch (C tile leaves LDS by a ds_load read-back + buffer stores) sits on ROCm#8430; this branch sits on ROCm#8430 + ROCm#8431 + ROCm#7543. Conflicts were context only, both sides kept: build_gemm_a8w4_tdm_task takes both the tp_gather parameters and cq_lds_store, and the kernel name carries both the `_cldsst` / `_cqldsst` and `_tpg` suffixes; grouped_gemm_mxfp4 keeps both the tp_gather helpers and `_c_lds_store`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What
moe_shared_expert_fold(weights, scale)runs a dense MXFP8 shared expert inside the next gfx1250 grouped MoE call (_grouped_a8w4_tdm_moe). The shared expert is treated as one more expert that every token routes to, with weight 1.launch_gemm_a8w4_tdm_shared_foldputs the shared gate/up tiles in the routed GEMM1 launch. They run as the leading workgroups: FP8 x FP8 on the MXFP8 copy of the input that the A1 quant writes ([FlyDSL] gfx1250 MoE A1 quant: emit the shared expert's MXFP8 input in the same pass #8364), with SwiGLU and the MXFP8 quant in the same epilogue. The routed tiles follow, unchanged.moe_output_epiloguefrom [FlyDSL] [Perf] gfx1250 MoE gather-reduce: routed scale + shared-expert add epilogue #8429).The two workgroup classes share one LDS arena and never wait on each other.
To support the dense tiles,
build_gemm_a8w4_tdm_taskgains four knobs:b_fp8: row-major FP8 B, staged and read like the FP8 activation.inline_task: one tile per call, as an inlinable helper.dense_rows: a single expert over rows0 .. rows, with no tile map.c_stage_apart: stage C over input stage 1 instead of stage 0.All of them default to 0, so the routed tiles compile exactly as before.
prepare_shared_fold_weights()lays the weights out once at load: gate/up interleaved, scales in n32k4 order, a byte permutation only. The result lives in storage the fold owns, so a caller may still shuffle its own parameters in place afterwards. This was a real bug in our first integration:.contiguous()aliased a parameter that ATOM later shuffled.The fold is only taken for unclustered decode tiles without EP, compact or prequantized A1, or bias. Otherwise
consumedstays False and the caller runs the shared expert itself.Why
MiniMax-M3.1 runs its shared expert as two more GEMMs plus quant launches beside the routed MoE: on a second stream, or serially. At decode sizes these launches are latency-bound. Folding them into the routed launches removes four launches and the stream join.
Performance
MiniMax-M3.1 TP4 MoE layer (E128 top-4 MXFP4 routed + MXFP8 shared, hidden 6144), 4x MI455X, CUDA graph, us per layer:
Correctness
Known issue: nondeterministic fold GEMM2 launch (T <= 64, also seen at T = 80)
At decode T <= 64 the shared-fold GEMM2 launch is nondeterministic. That launch is the routed 16x128x128 tile with 4 buffers, plus the 64x64 shared tiles.
ds_store_b128writes are visible, despites_wait_dscnt 0ands_barrier, so it picks up stale LDS left by the previous kernel (GEMM1). A fix that stores C directly from registers is in progress.Status: do not enable by default until fixed. ROCm/ATOM#3681 no longer enters the fold for batches of 64 tokens or fewer, which removes the most frequent case but does not make the fold safe (see T = 80 above). Until the register-store fix lands, run with
ATOM_MINIMAX_M3_SHARED_FOLD=0.End-to-end (combined stack, not this PR alone)
MiniMax-M3.1 on 4x MI455X, TP4: agentic multi-turn trace replay (AgentX) at concurrency 64, 900 s per run, same node, same afternoon.
The stack is our 1120 integration image plus all the changes in this series, with every flag on. That covers ROCm/aiter PRs 8273, 8310 and 8427-8432 and ROCm/ATOM PRs 3680-3683. It also includes pieces not yet in a PR: the ATOM wiring for the fused QKV chain, the fast o_proj and the FlyDSL indexer CP scorer, and the paged-attention split-KV fused reduce. Speculative acceptance length was forced to 4.04 for this A/B; the same configuration passed our serving gate with real acceptance.
Baseline P90 interactivity varied from 164.6 to 181.8 across three baseline runs that day (mean 173.4; mean median 253.7). Our best estimate is therefore about +11% P90 and +14% median interactivity against the mean baseline. That is for the whole stack; this PR's own share is not separated out.
Dependencies
Depends on #8364 (MXFP8 copy of the input from the A1 quant) and #8429 (gather-reduce epilogue); please review only the top commit. The two commits below it are those PRs, unmodified apart from being rebased onto main.
Needs re-validation (rebase changed code)
This was validated on our gfx1250 integration stack. Since then main refactored
mxfp4_preshuffle_gfx1250_tdm.py: per-kernel explicit-VGPR attributes,load_b_half,place_vgpr, andDS_B = 4for FP4. The port:load_bbranch into main'sload_b;DS_B = 4 if a_is_fp4 or b_fp8 else 2;B_NDWinside main'sUSE_EXPLICIT_VGPR_PARTITIONblock;waves_per_eu/maxnreghints and passes both tasks'kernel_attrsto the fold launch instead (empty for decode tiles);env_once()helper withos.environ.get.Port compiles; GPU re-validation on main pending. It compiles offline for gfx1250 (COMPILE_ONLY) at the production GEMM1/GEMM2 decode configs.
Validation status: validated on the 1120 integration stack (aiter 576d3f0 / ATOM 6c20f00); not yet re-validated on main after rebase.
🤖 Generated with Claude Code