Repository navigation
[FlyDSL] MegaMoEV2: MiniMax-M3.1 EP4 layout on the fused small-input route - #8921
Conversation
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
20258e6 to
a8ea315
Compare
a8ea315 to
5d10f29
Compare
5d10f29 to
9d0c51a
Compare
|
Rebased on current main (1f9a7fb) to resolve the conflict with #8878 (V4.1-Flash shared_in) in |
7a2c9b6 to
9dd0348
Compare
…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 gains the layout, _FUSED_SWIGLU_LIMITS its clamp, and the new _FUSED_ACTS its act, which fused_layout_supported checks instead of SiLU for every layout. 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 (FusedStage1Knobs.bf16_rows_always, 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]>
The default AOT build ships MiniMax-M3.1 EP4 (32 experts a rank, top-4, hidden 6144, inter 3072, SwiGLU-OAI at 7), a8w4 and a4w4, at ATOM's M3.1 capacities: max_num_batched_tokens a rank, 512 and 16384. Each job builds the staged and the fused small-input route, so preload_aot_bundles() compiles the small-input kernels of the layout too. Co-Authored-By: Claude <[email protected]>
9dd0348 to
18b3533
Compare
Picks up #9129 (ReLU2 dispatch hotfix), whose absence failed the Heavy CI's test_moev2_differential.py. Co-Authored-By: Claude <[email protected]>
Ready for review. No blocking issues. Middle of a stack of three (gh stack), on top of the SwiGLU-OAI PR; the diff shows only this layer. Replaces #8917 (same commit).
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_LAYOUTSgains M3.1 EP4, both quants;_FUSED_SWIGLU_LIMITSgets its clamp 7, and a new_FUSED_ACTStable its SwiGLU-OAI.fused_layout_supportedchecks the act from that table (SiLU unless listed).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 (FusedStage1Knobs.bf16_rows_always, from [HIP] [FlyDSL] DeepSeek-V4.1-Flash: MegaMoEV2 DSpark draft BF16 return and small-input route, EP8 / EP4 small-input bucket tables, H64 attention scalar loads #9076); bucket 128 caches the GEMM1 weights.--network m31, a CPU test of the M3.1 gate, andbench_mega_moe_m31.pyfor captured routing.Review focus
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.
ef6599c43(kernel code): routes suite m31 a8w4 and a4w4 64 PASS, 0 FAIL each; V4.1-Flash EP4 57 PASS.a8ea315f2: route-plan tests 217 passed, AOT driver tests 5 passed. ruff, black clean.Follow-ups
combine_wire, honoured by every route: [FlyDSL] MegaMoEV2: combine_wire option that every route honours #8922.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.
_use_direct_fixed_slot); the ring kernel needs no other change for it.bf16_rows_alwaysis on in M3.1's tune at every bucket, so M3.1 never sends FP8 combine rows, whatever the caller asks.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.bf16_rows_always, which does what this PR'sbf16_wiredid (every rank sends BF16 GEMM2 rows), so this PR uses it and has no knob of its own. The M3.1 small-input kernels' names now carry_b16rainstead of_bw.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'saiter/ops/flydsl,aiter/aot,aiter/utility,op_tests/multigpu_testsandtestsover 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), branchact="swigluoai", combine_wire="bf16".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.
PR Self-Review
Reviewed revision
960b9bacc296Behavior and intent
The fused small-input route now serves MiniMax-M3.1 EP4 (4 ranks, 128 experts, top-4, hidden 6144, inter 3072) with SwiGLU-OAI at 7, for both a8w4 and a4w4.
FUSED_LAYOUTSgains M3.1, with its clamp in_FUSED_SWIGLU_LIMITSand its act in the new_FUSED_ACTS;fused_layout_supportedchecks the act. Other layouts keep SiLU and their clamps.SMALL_M_ONLY_LAYOUTSkeeps M3.1 off the large-input route, which is SiLU only and sends FP8 combine rows only. A call above 512 rows a rank goes staged._tune_m31_ep4_smallsetsFusedStage1Knobs.bf16_rows_always(BF16 combine rows always) and a bucket 128 tune.Before this PR, every M3.1 call took the staged route: 269 us (a8w4) and 297 us (a4w4) at 128 DP-group rows.
Validation and unverified scope
Hardware and config: 4 x MI355X (gfx950, pit2-p03-g07 GPUs 4-7), image
mengqing-108/agx:c2f06e01-mega-a40489a9e(FlyDSL 0.5.3), the tree'saiter/ops/flydsl,aiter/aot,aiter/utility,op_tests/multigpu_testsandtestscopied over the image's aiter. Commands run fromop_tests/multigpu_tests.GPU runs on
ef6599c43, which contains this layer's kernel commit unchanged. The kernel code is the same as atef6599c43, where the GPU tests ran; the AOT commits change onlyaiter/aot/flydsl/mega_moe.pyandtests/test_aot_drivers.py.Routes suite
--network m31 --quant {a8w4,a4w4} --mtpr 1024 --combine-wire bf16 --check-time-acc --time-bs 104,144,152: 64 PASS, 0 FAIL each, graph replay included. The call at 513 rows takes the staged route (relL2 0.0535 a8w4).Routes suite
--network v41_flash --quant a8w4 --time-bs 104(DeepSeek layout under the new gate): 57 PASS.python -m pytest tests/test_mega_moe_gfx950_route_plan.py: 216 passed on main, 217 ata8ea315f2.tests/test_aot_drivers.py::MegaMoEProductionJobsTestata8ea315f2: 5 passed, includingtest_m31_ep4_profile(PA-Gluon import stubbed on the CPU node).torchrun --nproc-per-node 4 bench_rows.py: one M3.1 layer, MTPR 512, routed, random top-4 routing, DP-group rows 8-512. Fused is 1.55-2.07x (a8w4) and 1.70-2.10x (a4w4) faster than main's staged route. The table is in Evidence above.black 26.10.1 and ruff 0.16.0 clean.
Rebased on main at
1f9a7fb50, which merged [FlyDSL] MegaMoEV2 DeepSeek-V4.1-Flash: FP8 shared expert computed inside the MegaMoE kernels (shared_in), standalone on main #8878 (V4.1-Flash shared_in) into the same small-input kernel builder and routes suite:compile_mega_moe_stage1takesbf16_wireandv41_shared(keyword-only), the kernel name carries both suffixes, and the routes suite takes--network m31beside--shared-in-only. At this head, over the image's aiter on CPU:tests/test_mega_moe_gfx950_route_plan.py+tests/test_mega_moe_gfx950_shared_in.py264 passed; black and ruff clean. The GPU runs above predate the rebase.Rebased on main at
926205e73, which merged [HIP] [FlyDSL] DeepSeek-V4.1-Flash: MegaMoEV2 DSpark draft BF16 return and small-input route, EP8 / EP4 small-input bucket tables, H64 attention scalar loads #9076 (V4.1-Flash DSpark draft layout) and the Kimi-K2.6 EP8 small_m / large_m change into the same config, kernel builder, routes suite and AOT driver. M3.1 now uses main'sbf16_rows_alwaysinstead of its ownbf16_wire(same kernel branch). It follows main's per-layout tables:FUSED_LAYOUTSstays a set, the clamp goes in_FUSED_SWIGLU_LIMITSand the act in a new_FUSED_ACTS.SMALL_M_ONLY_LAYOUTStakes main's (world_size, experts_per_rank, model_dim, inter_dim) keys and holds the draft layout and M3.1. The routes suite acceptskimi_k26andm31. The AOT job count adds M3.1's 4 jobs; main's EP4 filter (topk == 6) already leaves M3.1 out, sotest_v41_flash_ep4_profileis no longer edited. At this head, over the image's aiter on CPU:tests/test_mega_moe_gfx950_route_plan.py+tests/test_mega_moe_v41_draft_layout.py+tests/test_mega_moe_v41_small_knobs.py306 passed,MegaMoEProductionJobsTest6 passed; black 26.10.1 and ruff clean. The GPU runs above predate this rebase.Merged aiter main (at
66da04555, which has [Hotfix] Align ReLU2 dispatch with legacy and refresh snapshots #9129, the ReLU2 dispatch hotfix) into the branch instead of rebasing, so the approvals stay. The Heavy CI'stests/test_moev2_differential.py::test_dispatch_plans_match_legacyfailure came from that missing hotfix. The PR diff is unchanged. At this head, over the image's aiter on CPU: the MegaMoE route-plan, V4.1-Flash draft-layout and small-knob tests andMegaMoEProductionJobsTestpass as before; black and ruff clean.Unverified:
ef6599c43ran.PR-specific question
test_mega_moe_v2.py --suite routes --network m31: before this PR, the suite rejectsm31, and M3.1 builds no small-input route ("small-input route not built")._routes_above_small_mfails if a call one row above the small-input capacity takes the wrong route or misses the reference. For M3.1 that route is staged, since it has no large-input route. No existing routes check covers it: every other routes network has a large-input route, or no capacity above 512.tests/test_mega_moe_gfx950_route_plan.py::test_m31_fused_layoutfails before: M3.1 is not a fused layout, andSMALL_M_ONLY_LAYOUTSdoes not exist. It also pins that the gate refuses M3.1 with SiLU or limit 10, and refuses V4.1-Flash with SwiGLU-OAI.tests/test_aot_drivers.py::test_m31_ep4_profilefails before: the production job set has no M3.1 job. It pins the shape, act, limit, MTPRs and quants, and that the layout is fused.bench_mega_moe_m31.pyis new, so there is no before. It fails only with--baseline, when the emulation error exceeds the baseline's.Changed op tests
op_tests/multigpu_tests/test_mega_moe_v2.py: the routes suite takes--network m31and checks the call above the small-input capacity. Not redundant: it is the only test of the M3.1 fused route and its staged fallback.op_tests/multigpu_tests/bench_mega_moe_m31.py(new): times M3.1 decode points on captured server routing, with an error check against the op's own-quantization emulation. Not redundant:bench_mega_moe_v2.pyuses synthetic routing and has no M3.1 decode points.tests/test_aot_drivers.py(outsideop_tests/):test_m31_ep4_profile, and the production job count gains M3.1's 4 jobs.tests/test_mega_moe_gfx950_route_plan.py(outsideop_tests/):test_m31_fused_layout(CPU).🤖 Generated with Claude Code