Repository navigation
[ASM] [HIP] feat(fmoe): add SwiGLU OAI MXFP4 FLAT kernels for Minimax M3 (gfx950) - #5794
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
PR title tags & labels: |
Performance (MI355X, Minimax M3: model_dim=6144, inter_dim=768, E=129, topk=5)
24-53% faster than FlyDSL 2-stage across all target decode batch sizes. |
6f82fe9 to
f3fd0f0
Compare
|
Please address the following before replacing the existing tuned rows:
|
|
Please address the following before replacing the existing tuned rows:
|
7bb40e9 to
f187b0a
Compare
|
@zufayu thanks for the review. All four points are addressed:
|
|
@aiter-bot review |
ROCm/aiter PR #5794 — [ASM] [HIP] feat(fmoe): add SwiGLU OAI MXFP4 FLAT kernels for Minimax M3 (gfx950)Adds gfx950 SwiGLU-OAI MXFP4 "FLAT" one-stage asm fused-MoE kernels (16x32 wave-specialized and 16x128, bf16 activations quantized to MXFP4 in-kernel) and routes Minimax M3 decode tokens 1-8 to them via tuned config rows, with host-side guards that discard those rows for calls the kernels cannot honour (per-expert bias, swiglu_limit≠7.0, non-separated gate/up layout, inter_dim%128≠0). Review (advisory): 🔴 HIGH RISK 🔴 [verified] aiter/fused_moe.py is a Tier-2 downstream contract whose default dispatch this PR changes — the four replaced rows in aiter/configs/model_configs/minimax_m3_a16w4_tuned_fmoe.csv switch Minimax M3 TP4 decode tokens 1-8 from the FlyDSL 2-stage path to the new asm kernels for every gfx950 a16w4 deployment — yet the file's de-facto owner (valarLip, top committer with 21 commits) has not appeared on the PR, whose only reviewer (zufayu) has 3 commits to it. Reviewer must @-mention valarLip in a PR comment requesting explicit sign-off on the fused_moe.py dispatch change before merge. 📝 [verified] The new discard guard's gate_mode and gate_up_interleave arms (aiter/fused_moe.py:3852-3855) — the two protecting the GGUU-separated weight layout the FLAT kernels hard-code — are never driven by the new test, whose check_guard exercises only the bias and swiglu_limit arms (op_tests/test_moe_swiglu_oai_flat.py:289-291), so a regression in either arm would let an interleaved-weight call take the asm row and silently compute garbage. Author must extend check_guard with gate_mode and gate_up_interleave overrides. |
|
@zufayu addressed the aiter-bot findings in |
8535820 to
b3b1905
Compare
|
The previous correctness, guard, dispatch, and timing findings are addressed, and the current CI is green. The dispatch change is narrowly scoped: only the Minimax M3 TP4 token 1/2/4/8 tuned rows move from the FlyDSL two-stage path to the two new ASM kernels; token 16 and larger buckets remain on FlyDSL. The same-run measurements show a clear improvement, and unsupported bias/limit/layout cases fall back to the existing path. My remaining request is test organization. Please do not add a standalone 333-line Once the test is organized according to the existing AITER test structure, I do not see another blocker to approval. |
|
@zufayu thanks. Test organization is addressed in
Moving onto |
|
No activity for 15 days, so this is now labelled |
|
After one final check, the previous correctness, fallback, performance-data, reference, and test-organization issues have been addressed. There is one remaining blocker before approval. |
Add SwiGLU OAI activation to the MXFP4 FLAT fused-MoE asm kernels for gfx950 (MI355X), targeting Minimax M3 decode workloads. Three tile variants with optimal selection per batch size: - t=1,2,4: 16x32 (24 TGs/token, wave-specialized) - t=8: 16x128 (6 TGs/token, single-pass) - t=16: 16x256 (3 TGs/token, two-pass GEMM0) - t>=32: FlyDSL 2-stage baseline Performance (MI355X, model_dim=6144, inter_dim=768, E=129, topk=5): t=1: 18.2us (1.53x vs FlyDSL 27.9us) t=4: 32.8us (1.33x vs FlyDSL 43.5us) t=8: 54.2us (1.24x vs FlyDSL 67.4us) t=16: 94.5us (1.24x vs FlyDSL 117.3us) All kernels support in-kernel bf16->MXFP4 dynamic quantization (xbf16). Kernel .co files verified instruction-identical to sp3 reference. SILOTIGER-1128
…950) Rebuilt from dev-platform fmoe-mxfp4-upstream-sync (8742fa0): synced with poc_kl c2c2588 (LDS O staging, static zeroing election, single-pass 16x256, 512-dim output tail, padded DQ stride) plus a 16x128 fix: the D-scale buffer range straddled num_records on odd TGs, and MI355X returns 0 for a straddling dword (wrong outputs, max |diff| 0.03-0.05 with the previous binary). MI355X, Minimax M3 shape (6144/768/129/top-5), bf16 X, us: 16x128: 27.5->18.5 (1 tok), 29.5->25.0 (4), 49.8->47.1 (8), 96.5->88.5 (16) 16x256: 49.3->29.6 (1 tok), 50.2->32.1 (4), 60.4->49.2 (8), 93.3->89.6 (16) 16x32 : unchanged within noise
… 512 (gfx950) The 16x256 kernel computed the per-TG D-scale offset with the 16x128 pair formula, so TGs >= 2 along inter_dim read the wrong scales. Minimax M3 (inter_dim 768, 16 tokens -> 16x256) got logits_diff ~4.7e-2 against a fully-quantized reference; now ~6e-4, matching 16x128. Built from dev-platform c5a6a67 (fmoe-mxfp4-upstream-sync). 16x32 and 16x128 are unchanged.
…fx950) aiter launches ceil(inter_dim/256) FLAT 16x256 TGs. At inter_dim=384 (Minimax M3 TP8) the second TG's upper 128 rows lie past inter_dim: its gate rows read the up weights, its up rows read the next expert, and gemm2 added those activations to every output column (NRMS ~6 vs 5e-3). For the last expert the loads also ran up to ~384 KB past the weight allocation. The kernel now detects a half-out-of-range tile, points the second half's G/U/GQ/UQ loads at the first half, zeroes that half's activation, and bounds the D buffer at the expert end. Full tiles (inter_dim % 256 == 0, e.g. TP2/TP4) compute the same results; 16x32 and 16x128 are unchanged. fmoe_g1u1 now rejects inter_dim % 128 != 0 for the SwiGLU OAI FLAT config instead of launching a kernel that reads past the weights. Validated in llvmFSim against the CPU reference at model_dim=6144, topk=5, inter_dim 384/768/1536 (tokens 1/4/8, scale/topk sweeps, even routing): all pass, no out-of-bounds accesses.
E2E runs (ISL 8k/OSL 1k) show the 16x256 asm kernel 2.5-4% slower than FlyDSL at concurrency 16, beyond run-to-run noise. Keep the asm FLAT kernels for tokens 1/2/4/8 (about -10% TPOT at concurrency 4/8) and restore the FlyDSL row for token 16.
The 16x256 kernel was only selected for token=16, which now routes to FlyDSL (2.5-4% faster E2E at concurrency 16). FLAT kernels are never picked by the inter_dim heuristic, only by name from a tuned row, so nothing can reach it. Remove the code object and its manifest row. The inter_dim % 128 == 0 check now matches the remaining 16x32/16x128 kernels exactly.
…T rows get_torch_act mapped ActivationType.Swiglu to F.silu, so torch_moe in fused_moe_dp_shared_expert.py computed silu(gate) * up instead of OAI SwiGLU. Remove the alias; both torch_moe_act helpers now compute OAI SwiGLU (alpha 1.702, limit 7.0) explicitly and reject non-g1u1 input. The SwiGLU OAI FLAT asm kernels hard-code alpha/limit, read GGUU weights and have no bias input, and the 1-stage launch does not forward bias or swiglu_limit. get_2stage_cfgs now discards a Swiglu run_1stage row for calls with per-expert bias, swiglu_limit != 7.0, a non-SEPARATED gate mode or gate/up-interleaved weights, falling back to the default path instead of silently computing a different function.
op_tests/test_moe_swiglu_oai_flat.py runs the Minimax M3 shape (6144/768/129/top-5, a16w4) at tokens 1/2/4/8/16 on gfx950 with 256 CUs and skips elsewhere: - dispatch: tokens 1/2/4 -> 16x32, 8 -> 16x128 (FLAT), 16 -> FlyDSL 2-stage, plus the asm row being discarded for bias / swiglu_limit. - accuracy: the asm kernels quantize X and the SwiGLU output to MXFP4 in-kernel, so they are checked against a reference that does the same (e8m0 RoundUp, as in the kernel); the FlyDSL row against the bf16 one. Gate is logits_diff < 2e-3; MI355X measures ~9e-5 (16x32), ~3e-5 (16x128), 7e-6 (FlyDSL). Revert the swiglu choice in test_moe.py: that script has no MXFP4 path, so it never exercised these kernels.
Replace the us=0 placeholders for tokens 1/2/4/8 with measured kernel times. A zero us would win every config merge against competing tunes. Same-run on MI355X (FlyDSL rows from main vs asm 16x32 / 16x128, separate processes, 3 interleaved rounds, median, routing cycled so weights are not cache-resident), fused_moe GPU time: tokens FlyDSL best asm speedup 1 27.6 us 16.7 us (16x32) 1.65x 2 30.8 us 19.4 us (16x32) 1.59x 4 41.2 us 30.5 us (16x32) 1.35x 8 58.6 us 47.9 us (16x128) 1.22x 16 86.5 us 91.7 us (16x128) FlyDSL row kept
- test_torch_moe_act_swiglu (no GPU): torch_moe_act in fused_moe.py and fused_moe_dp_shared_expert.py computes OAI SwiGLU (matching swiglu() used by torch_moe_stage1) and rejects non-g1u1 input. - check_guard now also drives the gate_mode=INTERLEAVE and gate_up_interleave=True arms of the get_2stage_cfgs guard, binding the captured call by name so positional arguments can be overridden.
Per review, drop the standalone op_tests/test_moe_swiglu_oai_flat.py and cover the Minimax M3 rows in the existing a16w4 harness: - _iter_csv_cases now also runs the SwiGLU OAI asm FLAT rows from the tuned model CSVs (bias-free, as the kernels take no bias) and requires the row's kernel to be the one dispatched. - test_fmoe: when an a16w4 Swiglu call resolves to an asm FLAT 1-stage kernel, the reference MXFP4-quantizes X and the fp32 SwiGLU output, as the kernel does, and accuracy is gated on logits_diff < 2e-3 (elementwise mismatches near fp4 rounding boundaries are reported, not failed). - test_swiglu_oai_flat_dispatch: tokens 1/2/4 -> 16x32, 8 -> 16x128, 16 -> FlyDSL for 6144/768/129/top-5, the bias / swiglu_limit / gate-mode / GUGU fallbacks, and torch_moe_act computing OAI SwiGLU in fused_moe.py and fused_moe_dp_shared_expert.py.
… kernels (gfx950)
OAI SwiGLU is g = min(gate, 7); z = g * sigmoid(1.702 * g) * (clamp(up, 7) + 1).
The 16x32 / 16x128 kernels took the sigmoid of the unclamped gate and applied
min(gate, 7) afterwards. For gate > 7 that is 7 * 1.0 instead of
7 * sigmoid(11.914); when up is clamped too, z is exactly 56.0 instead of
55.9996, and MXFP4 quantization of z (block scale 16) rounds 3.5 to 4 instead
of 3.49998 to 3, a 33% error on those activations. With the clamps saturated
(test_moe_2stage's unscaled weights) logits_diff vs the OAI reference was 2.2e-2.
Rebuilt from dev-platform kernels/pyisa/gfx950/fused_moe/
fmoe_bf16_mxfp4_g1u1_flat_vs_silu_{16x32,16x128} (--activation swiglu_oai
--x-bf16 1) with the v_min moved ahead of the sigmoid: same instruction count,
only the clamp is reordered.
Every row in the SwiGLU OAI MXFP4 map is flat=1 and reads raw top-k routing. A caller without a kernel name passes host-sorted ids, so fmoe_g1u1's heuristic must not pick one of these kernels for it. - fmoe_g1u1 now rejects an empty kernel name for the SwiGLU OAI map before kernel lookup, in both the fp4 and bf16-X branches. - get_2stage_cfgs discards a SwiGLU 1-stage tuned row with an empty or NaN kernelName1, or with flat != 1, and uses the default path. - test_swiglu_oai_flat_dispatch covers both: the tuned-row fallback (empty name, NaN name, flat=0) and the fmoe_g1u1 rejection.
|
@zufayu thanks. Fixed in Unnamed lookup. Every row in the SwiGLU OAI map is
Regression test.
Rebase. It keeps MI355X results for tokens 1/2/4/8/16 are in the next comment. |
a3573d1 to
c14334b
Compare
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 |
|
Pushed The run exits 0. Minimax M3
The |
Summary
gate * sigmoid(1.702*gate) * (clamp(up,±7)+1)) to the MXFP4 FLAT fused-MoE asm kernels for gfx950 (MI355X)Routing (minimax_m3_a16w4_tuned_fmoe.csv, TP4)
flat_vs_swiglu_oai_16x32flat_novs_swiglu_oai_16x128Token 16 stays on FlyDSL: in E2E runs (ISL 8k / OSL 1k) a 16x256 asm kernel was 2.5-4% slower than FlyDSL at concurrency 16, beyond run-to-run noise (~1.5%), so it was dropped from this PR.
E2E TPOT with the asm rows for tokens 1-8 (baseline → PR):
TTFT unchanged (prefill stays on FlyDSL). GSM8K 5-shot strict-match unchanged.
inter_dim support (TP2 / TP4 / TP8)
fmoe_g1u1rejects inter_dim % 128 != 0 for the SwiGLU OAI FLAT config (the FLAT grid has no partial-tile handling).Known limitations
The xbf16 path quantizes X to MXFP4 in-kernel (fp4×fp4 MFMA), introducing quantization noise not present in the bf16 torch reference. logits_diff ~0.07 against the unquantized reference is expected — FlyDSL avoids this by doing bf16×fp4 GEMM directly. With a quantization-aware reference the accuracy matches at nrms ~1.2e-3.