Skip to content

[ASM] [HIP] feat(fmoe): add SwiGLU OAI MXFP4 FLAT kernels for Minimax M3 (gfx950) - #5794

Merged
zufayu merged 13 commits into
mainfrom
feature/fmoe-swiglu-oai
Nov 10, 2026
Merged

zufayu merged 13 commits into
mainfrom
feature/fmoe-swiglu-oai

Conversation

@alexioslyrakis-amd

@alexioslyrakis-amd alexioslyrakis-amd commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add SwiGLU OAI activation (gate * sigmoid(1.702*gate) * (clamp(up,±7)+1)) to the MXFP4 FLAT fused-MoE asm kernels for gfx950 (MI355X)
  • Two tile variants: 16x32 (wave-specialized), 16x128
  • All kernels support in-kernel bf16→MXFP4 dynamic quantization (X_BF16=1)
  • Integrated into aiter dispatch for Minimax M3 (model_dim=6144, inter_dim=768, experts=129, topk=5)

Routing (minimax_m3_a16w4_tuned_fmoe.csv, TP4)

tokens kernel
1, 2, 4 asm flat_vs_swiglu_oai_16x32
8 asm flat_novs_swiglu_oai_16x128
16 and up, prefill FlyDSL 2-stage (unchanged)

Token 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):

  • ISL 8k / OSL 1k, conc 4: 6.95 → 6.17 ms (-11.2%)
  • ISL 8k / OSL 1k, conc 8: 8.35 → 7.50 ms (-10.2%)
  • ISL 60k / OSL 600, conc 4: 9.61 → 8.91 ms (-7.3%)

TTFT unchanged (prefill stays on FlyDSL). GSM8K 5-shot strict-match unchanged.

inter_dim support (TP2 / TP4 / TP8)

  • Both kernels are correct for inter_dim = 1536 (TP2), 768 (TP4) and 384 (TP8), validated in llvmFSim against the CPU reference at model_dim=6144, topk=5 (tokens 1/4/8, scale/topk sweeps, even routing), with no out-of-bounds accesses.
  • fmoe_g1u1 rejects inter_dim % 128 != 0 for the SwiGLU OAI FLAT config (the FLAT grid has no partial-tile handling).
  • Only TP4 rows are tuned in this PR; TP2/TP8 rows need a gfx950 tuning run.

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.

@alexioslyrakis-amd
alexioslyrakis-amd requested a review from a team September 23, 2026 16:52
@github-actions

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; main branch always runs both MI35X and MI300X
multigpu 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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 5794 --add-label <label>

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 opt this PR out.

@github-actions github-actions Bot changed the title feat(fmoe): add SwiGLU OAI MXFP4 FLAT kernels for Minimax M3 (gfx950) [ASM] [HIP] feat(fmoe): add SwiGLU OAI MXFP4 FLAT kernels for Minimax M3 (gfx950) Sep 23, 2026
@zufayu
zufayu self-requested a review September 24, 2026 01:45
@zufayu zufayu self-assigned this Sep 24, 2026
@alexioslyrakis-amd

alexioslyrakis-amd commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Performance (MI355X, Minimax M3: model_dim=6144, inter_dim=768, E=129, topk=5)

Batch (tokens) Kernel ASM FLAT (us) FlyDSL baseline (us) Speedup
t=1 16x32 18.2 27.9 1.53x
t=2 16x32 21.5 32.4 1.51x
Conc1 (t=4) 16x32 32.8 43.5 1.33x
Conc2 (t=8) 16x128 54.2 67.4 1.24x
Conc4 (t=16) 16x256 94.5 117.3 1.24x

24-53% faster than FlyDSL 2-stage across all target decode batch sizes.

@zufayu

zufayu commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Please address the following before replacing the existing tuned rows:

  • Rebase onto current main; the PR currently conflicts in aiter/fused_moe.py and csrc/py_itfs_cu/asm_fmoe.cu.
  • Add an exact gfx950 regression for the Minimax shape (6144/768/129/top-5, tokens 1/2/4/8/16) covering all three kernels, dispatch selection, and a quantization-aware OAI SwiGLU reference. Adding swiglu as a CLI choice does not exercise this path in the default CI run.
  • Populate the CSV with real correctness and latency results. us=0 is not neutral: config merging treats the lowest us as the winner, so these rows will override competing tunes. Also, the latest t=16 result reported in the commit is 89.6 us, while the deleted row records 82.5813 us. Please provide same-run base-vs-head results for every replaced bucket and retain the old row wherever the new kernel does not win.
  • Please do not map ActivationType.Swiglu globally to F.silu; fused_moe_dp_shared_expert.py would then compute plain silu(gate) * up instead of the OAI SwiGLU formula. Remove the alias or update all callers and tests.

@zufayu

zufayu commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Please address the following before replacing the existing tuned rows:

  • Rebase onto current main; the PR currently conflicts in aiter/fused_moe.py and csrc/py_itfs_cu/asm_fmoe.cu.
  • Add an exact gfx950 regression for the Minimax shape (6144/768/129/top-5, tokens 1/2/4/8/16) covering all three kernels, dispatch selection, and a quantization-aware OAI SwiGLU reference. Adding swiglu as a CLI choice does not exercise this path in the default CI run.
  • Populate the CSV with real correctness and latency results. us=0 is not neutral: config merging treats the lowest us as the winner, so these rows will override competing tunes. Also, the latest t=16 result reported in the commit is 89.6 us, while the deleted row records 82.5813 us. Please provide same-run base-vs-head results for every replaced bucket and retain the old row wherever the new kernel does not win.
  • Please do not map ActivationType.Swiglu globally to F.silu; fused_moe_dp_shared_expert.py would then compute plain silu(gate) * up instead of the OAI SwiGLU formula. Remove the alias or update all callers and tests.

@alexioslyrakis-amd

alexioslyrakis-amd commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

@zufayu thanks for the review. All four points are addressed:

  • Rebase: the branch is rebuilt on main and merges cleanly.
  • Regression test: added op_tests/test_moe_swiglu_oai_flat.py (gfx950). It checks kernel dispatch for 6144/768/129/top-5 at tokens 1/2/4/8/16, and accuracy against a quantization-aware OAI SwiGLU reference. It also checks a new guard that skips the asm row for calls with bias or a non-default swiglu_limit, which the 1-stage launch doesn't forward.
  • CSV: the us=0 rows now have measured times. Token 16 keeps the original FlyDSL row. Same-run fused_moe GPU time on MI355X:
tokens FlyDSL (main) 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
  • Swiglu → F.silu alias: removed. Both torch_moe_act helpers now compute OAI SwiGLU explicitly.

@zufayu

zufayu commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

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
Validation (deterministic): NOT RUN — REVIEW_AUTO_VALIDATE=0 and no GPU access on this review box; the target op_tests/test_moe_swiglu_oai_flat.py exists but was not executed here (environment gap, not a PR defect)
Perf (advisory): NOT RUN — no GPU on this review box and the target ships no benchmark entry point; the PR's own same-run base-vs-head table (27.6→16.7/30.8→19.4/41.2→30.5/58.6→47.9 us on MI355X, tokens 1/2/4/8) is author-reported and is the only timing evidence

🔴 [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 SwiGLU branch in torch_moe_act (aiter/fused_moe.py:5074, aiter/fused_moe_dp_shared_expert.py:766) is executed by no default-run test — the new test's reference goes through torch_moe_stage1/torch_moe_stage2, and none of the four tests calling torch_moe passes ActivationType.Swiglu except test_moe.py's non-default --activation swiglu — so a wrong gate/up split or formula in the torch fallback would silently compute a different activation for SwiGLU callers and poison test_moe.py --activation swiglu as a reference. Author must add a SwiGLU case to a default-run torch_moe reference test (or run test_moe.py --activation swiglu) and confirm it matches torch_moe_stage1's swiglu() output.

📝 [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.

@alexioslyrakis-amd

Copy link
Copy Markdown
Contributor Author

@zufayu addressed the aiter-bot findings in 8535820ac: test_torch_moe_act_swiglu now covers the torch_moe_act SwiGLU branch in both fused_moe.py and fused_moe_dp_shared_expert.py, and check_guard now also covers interleaved gate mode and GUGU weights. Verified on MI355X.

@zufayu

zufayu commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

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 op_tests/test_moe_swiglu_oai_flat.py with its own weight construction, reference, dispatch-capture framework, and test runner. Integrate the Minimax 6144/768/129/top-5 cases into the existing FMoE/A16W4 test entry using the established parameterized test structure. Keep the required coverage there: tokens 1/2/4/8/16, expected dispatch, the quantization-aware OAI SwiGLU reference, and the bias/limit/gate-layout fallback guards.

Once the test is organized according to the existing AITER test structure, I do not see another blocker to approval.

@alexioslyrakis-amd

Copy link
Copy Markdown
Contributor Author

@zufayu thanks. Test organization is addressed in d919e51e9: the standalone test_moe_swiglu_oai_flat.py is removed, and the Minimax 6144/768/129/top-5 coverage now runs in op_tests/test_moe_2stage.py:

  • the tuned-CSV cases include the SwiGLU OAI asm rows (bias-free) and check that the row's kernel is the one dispatched;
  • for those rows test_fmoe uses a reference that quantizes activations to MXFP4 like the kernel;
  • test_swiglu_oai_flat_dispatch checks the kernel for tokens 1/2/4/8/16 and the bias / swiglu_limit / gate-layout fallbacks.

Moving onto test_fmoe's data also found a kernel bug, fixed in a3573d168. The kernels took the sigmoid of the unclamped gate, while OAI SwiGLU clamps the gate first. When gate and up both saturate, the activation is exactly 56.0 instead of 55.9996, and MXFP4 quantization rounds it to the wrong neighbour (logits_diff 2.2e-2 vs the OAI reference). Both kernels are rebuilt with the clamp moved ahead of the sigmoid (same instruction count). On MI355X they now give logits_diff ≤ 1.1e-4 with timing unchanged (within 0.5% of the CSV values).

@github-actions

github-actions Bot commented Nov 7, 2026

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 7, 2026
@zufayu

zufayu commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

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.
After rebasing onto current main, unnamed heuristic lookup can select these new flat=1 SwiGLU kernels when kernelName is empty. Those callers provide host-sorted routing tensors, while the FLAT kernels expect the raw top-k input contract. This may produce incorrect routing or a GPU fault.
Please require an explicit non-empty kernel name in both new SwiGLU config branches, or otherwise exclude these FLAT rows from unnamed heuristic selection, and add an empty-name rejection/fallback regression test.
Once this is fixed, the branch is rebased cleanly while preserving the latest AsmMoeMode and test_moe_2stage.py changes, and the final head passes the Minimax tokens 1/2/4/8/16 tests on MI355X plus required CI, I have no other blocker to approval and merge.

@github-actions github-actions Bot removed the stale The PR hasn't been updated in 2 weeks label Nov 8, 2026
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.
@alexioslyrakis-amd

alexioslyrakis-amd commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor Author

@zufayu thanks. Fixed in c14334b02, and the branch is rebased onto current main.

Unnamed lookup. Every row in the SwiGLU OAI map is flat=1, so these kernels must never be picked without an explicit name:

  • fmoe_g1u1 (asm_fmoe.cu): both SwiGLU OAI branches (fp4 X and bf16 X) now reject an empty kernel name before kernel lookup. get_heuristic_kernel is never reached for this map.
  • get_2stage_cfgs: a SwiGLU 1-stage tuned row whose kernelName1 is empty or blank (NaN in the CSV) is discarded, and the call falls back to the default 2-stage path. A row with flat != 1 is discarded too, since it would pass host-sorted ids to a named FLAT kernel.

Regression test. test_swiglu_oai_flat_dispatch in test_moe_2stage.py now also:

  • replaces the token-1 tuned row with kernelName1="", kernelName1=NaN and flat=0, and checks that each falls back to 2-stage;
  • calls aiter.fmoe_g1u1 directly with an empty name and ActivationType.Swiglu, and checks that it raises.

Rebase. It keeps main's AsmMoeMode, kernel_fits/ps_grid_fits and test_moe_2stage.py changes. main's _iter_csv_cases already includes per_1x32 asm rows. On top of that, the SwiGLU OAI rows keep their bias-free run, expected_kernel1 check and MXFP4-quantized reference.

MI355X results for tokens 1/2/4/8/16 are in the next comment.

@aiter-bot

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision c14334b0238f · 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. Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?
  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 — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_moe_2stage.py
  • FAIL — Changed op tests must explain why each changed op test is necessary and non-redundant

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

@alexioslyrakis-amd

Copy link
Copy Markdown
Contributor Author

Pushed c14334b02 (rebased onto current main, merges cleanly). It passes on MI355X:

python3 op_tests/test_moe_2stage.py --no-legacy --csv-filter swiglu_oai flydsl_moe2_abf16_wfp4_bf16_t16x256x256_atomic_bnt2_persist

The run exits 0. test_swiglu_oai_flat_dispatch passes, including the new cases: the empty / NaN kernelName1 and flat=0 rows fall back to 2-stage, and a direct unnamed fmoe_g1u1 SwiGLU call is rejected. The presorted-MoE contract tests also pass.

Minimax M3 6144/768/129/top-5 tuned-CSV cases (test_fmoe, strict accuracy, MXFP4-quantized OAI SwiGLU reference for the asm rows, expected_kernel1 checked):

tokens dispatched kernel logits_diff us (test harness)
1 asm flat_vs_swiglu_oai_16x32 9.0e-5 19.0
2 asm flat_vs_swiglu_oai_16x32 8.7e-5 22.8
4 asm flat_vs_swiglu_oai_16x32 8.9e-5 33.2
8 asm flat_novs_swiglu_oai_16x128 2.5e-5 51.8
16 FlyDSL 2-stage (unchanged row) 7.9e-4 103.6

The us column is test_fmoe's end-to-end timing, so it is not directly comparable to the per-kernel us in the tuned CSV.

@zufayu
zufayu merged commit 6916e20 into main Nov 10, 2026
@zufayu
zufayu deleted the feature/fmoe-swiglu-oai branch November 10, 2026 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants