Skip to content

[FlyDSL] MegaMoEV2: MiniMax-M3.1 EP4 layout on the fused small-input route - #8917

Closed
MengqingCao wants to merge 2 commits into
ROCm:mainfrom
MengqingCao:mengqing/main-megamoe-m31-ep4
Closed

MengqingCao wants to merge 2 commits into
ROCm:mainfrom
MengqingCao:mengqing/main-megamoe-m31-ep4

Conversation

@MengqingCao

@MengqingCao MengqingCao commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Ready for review. No blocking issues. Stacked on #8916; review only the last commit (20258e647). A cross-repo PR cannot target a fork branch, so this branch carries #8916's commit too.

Why

On main, a MiniMax-M3.1 EP4 call (128 experts, top-4, hidden 6144, inter 3072) always takes the staged route. At 128 decode rows a rank, one MoE layer takes 269 us (a8w4) and 297 us (a4w4). The fused small-input kernel serves only DeepSeek layouts at SiLU 10.

What changed

  • FUSED_LAYOUTS maps each layout to the one (act, swiglu_limit) it is built for, and adds M3.1 EP4 at SwiGLU-OAI 7, both quants. fused_layout_supported checks that pair.
  • M3.1 is in SMALL_M_ONLY_LAYOUTS: the large-input kernel is SiLU and FP8-wire only, so a call above 512 rows a rank takes the staged route.
  • _tune_m31_ep4_small: the V4.1-Flash EP4 tune plus BF16 combine rows always (new FusedStage1Knobs.bf16_wire); bucket 128 caches the GEMM1 weights.
  • Tests: routes suite --network m31, a CPU test of the M3.1 gate, and bench_mega_moe_m31.py for captured routing.

Review focus

  • M3.1 has no large-input route; above 512 rows a rank it runs staged (Dev record, Decided).
  • a4w4 fused writes an MXFP8 GEMM1 output, staged writes MXFP4, so they agree only to the suite's a4w4 tolerance (Dev record, Found).

Testing

At DP-group rows 8-512 the fused route is 1.55-2.07x (a8w4) and 1.70-2.10x (a4w4) faster than main's staged route, with every routes-suite check passing.
mengqing/main-megamoe-combine-wire @ ef6599c43: routes suite m31 a8w4 and a4w4 64 PASS, 0 FAIL each; V4.1-Flash EP4 57 PASS. CPU route-plan tests 218 passed. ruff, black clean.

Follow-ups

Dev record

Found. The fused a4w4 GEMM1 output is MXFP8 (#8623's design), so a4w4 fused differs from staged by relL2 0.15 but is closer to fp32 (0.196 vs 0.23).

Decided.

  • The fixed-slot dispatch admits 4 ranks x 32 experts (_use_direct_fixed_slot); the ring kernel needs no other change for it.
  • No large-input route for M3.1: that kernel combines over FP8 only, and M3.1 needs a BF16 wire. A call above 512 rows a rank runs staged.
  • bf16_wire is on in M3.1's tune at every bucket, so M3.1 never sends FP8 combine rows, whatever the caller asks.
  • The bucket 128 tune (b_nt=0, early GEMM2 2/2) comes from a sweep on [FlyDSL] [CI] [MoE] MegaMoEV2: fully fused A4W4 routes, A8W4 performance optimizations, capacity 32768, rank-shared AOT #8623's pre-merge head; other buckets keep the V4.1-Flash EP4 tune, unmeasured on M3.1. The ring kernel is unchanged since then.
  • Edited existing test: _LATE_KNOBS in tests/test_mega_moe_gfx950_route_plan.py gains bf16_wire, so the pinned DeepSeek config digests stay as they were.

Surprised. none

Left undone. Not run: EP8 layouts, MI300X, MI250X. This commit alone was not run on GPU; the stack head was.

Evidence

4 x MI355X (gfx950), gpool lease on pit2-p03-g07 GPUs 4-7, image mengqing-108/agx:c2f06e01-mega-a40489a9e (FlyDSL 0.5.3), each tree's aiter/ops/flydsl, aiter/aot, aiter/utility, op_tests/multigpu_tests and tests over the image's aiter.

One M3.1 layer, MTPR 512, routed, random top-4 routing and MXFP4 weights, R/4 rows a rank, max_tokens = R/4. Time is the median of 15 replays of a 20-call graph, max over ranks. Main runs act="silu" (it rejects SwiGLU-OAI; same staged kernels and time), branch act="swigluoai", combine_wire="bf16".

DP rows a8w4 main staged us a8w4 branch fused us speedup a4w4 main staged us a4w4 branch fused us speedup
8 132.6 64.0 2.07x 133.3 63.5 2.10x
16 179.4 91.7 1.96x 191.1 91.3 2.09x
32 238.5 135.8 1.76x 265.2 135.6 1.96x
64 250.2 148.3 1.69x 277.4 148.2 1.87x
128 268.9 163.3 1.65x 296.5 161.5 1.84x
192 285.6 165.3 1.73x 313.8 163.6 1.92x
256 287.6 168.2 1.71x 314.0 166.2 1.89x
384 296.2 191.0 1.55x 319.1 187.1 1.71x
512 304.7 196.7 1.55x 325.0 191.3 1.70x

Branch relL2 vs fp32 SwiGLU-OAI reference: a8w4 0.053-0.054, a4w4 0.195-0.197. Captured-routing results (c140/c150 points, layers 3/20/40/59, error vs own-quant emulation no worse than staged) are in MengqingCao#5 on #8623's pre-merge head.

torchrun --nproc-per-node 4 test_mega_moe_v2.py --suite routes --network m31 --quant {a8w4,a4w4} --mtpr 1024 --combine-wire bf16 --check-time-acc --time-bs 104,144,152
[SETUP] network=m31 quant=a8w4 mtpr=1024 small_m_mtpr=512 large_m=False world=4 combine_wire=bf16
[ABOVE] max_tokens=513 route=staged relL2_vs_ref=0.053466 PASS
[GRAPH] layers=8 reps=6 bs/rank=168 route=small_m replay_vs_eager_mismatched_rows=0 PASS
[RESULT] ALL PASS
torchrun --nproc-per-node 4 test_mega_moe_v2.py --suite routes --network v41_flash --quant a8w4 --time-bs 104
[SETUP] network=v41_flash quant=a8w4 mtpr=8192 small_m_mtpr=512 large_m=True world=4 combine_wire=auto
[RESULT] ALL PASS
python -m pytest tests/test_mega_moe_gfx950_route_plan.py    # main 216 passed, stack head 218 passed

🤖 Generated with Claude Code

MengqingCao and others added 2 commits November 30, 2026 07:38
MiniMax-M3.1's experts use SwiGLU-OAI: the gate clamped above and the
up projection to +-swiglu_limit, then gate * sigmoid(1.702 * gate) *
(up + 1). MegaMoEV2 accepts act="swigluoai" (with a positive
swiglu_limit) and applies it in both GEMM1 epilogues through one helper,
gated_act_f32: the shared SiluQuantEpilogue (staged route) and the ring
GEMM1 of the fused small-input kernel, which takes act and keys its
kernel name on it.

The test reference gains the activation, an "m31" network and an MX
rounding emulation (_reference(quantize=(input, hidden))) for an error
check against the op's own quantization.

Co-Authored-By: Claude <[email protected]>
…route

Adds the MiniMax-M3.1 EP4 layout (4 ranks, 128 experts, top-4, hidden
6144, inter 3072) to the fused small-input kernel, both quants, with its
SwiGLU-OAI activation clamped at 7. FUSED_LAYOUTS now maps each layout
to the one (act, swiglu_limit) it is built for, and fused_layout_supported
checks that pair instead of SiLU at 10.

M3.1 is in SMALL_M_ONLY_LAYOUTS: the large-input kernel's epilogue is
SiLU only and it combines over FP8, so a call above the small-input
capacity takes the staged route. The fixed-slot dispatch admits 4 ranks
x 32 experts.

_tune_m31_ep4_small starts from the EP4 DeepSeek-V4.1-Flash tune, sends
BF16 combine rows at every row count (new FusedStage1Knobs.bf16_wire,
the M3.1 numerics) and, at bucket 128 (the decode points), caches W1 and
starts GEMM2 early.

Tests: the routes suite takes --network m31 and checks a call one row
above the small-input capacity; a CPU test pins the M3.1 layout gate and
its BF16 wire; bench_mega_moe_m31.py times M3.1 decode points on
captured routing.

Co-Authored-By: Claude <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter standard tests on MI35X
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
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 Radeon R9700 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 8917 --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.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@MengqingCao

Copy link
Copy Markdown
Contributor Author

Superseded by #8921: the same commit, reopened from a ROCm/aiter branch so the three PRs form a stack (stack #8923) and each shows only its own diff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant