Skip to content

[FlyDSL] MegaMoEV2: combine_wire option that every route honours - #8918

Closed
MengqingCao wants to merge 3 commits into
ROCm:mainfrom
MengqingCao:mengqing/main-megamoe-combine-wire
Closed

MengqingCao wants to merge 3 commits into
ROCm:mainfrom
MengqingCao:mengqing/main-megamoe-combine-wire

Conversation

@MengqingCao

Copy link
Copy Markdown
Contributor

Ready for review. No blocking issues. Stacked on #8917 and #8916; review only the last commit (ef6599c43). A cross-repo PR cannot target a fork branch, so this branch carries their commits too.

Why

A caller whose model needs a BF16 combine wire cannot ask MegaMoEV2 for one. At capacity 1024 and up the staged route sends FP8 rows, the small-input kernel switches to FP8 rows past a row threshold, and the large-input kernel is FP8 only. ATOM (ROCm/ATOM#3930) wants to pick the wire per model.

What changed

  • MegaMoEV2(combine_wire="auto" | "bf16"). "auto" changes nothing.
  • Under "bf16" the staged route is built with stage2_p2p_quant="none"; an FP8 stage2_p2p_quant raises. Every small-input bucket gets bf16_wire (SmallMRuntime(bf16_wire=True)).
  • The large-input route is not built under "bf16" (large_m_dropped, a rank-0 warning); its calls take the staged route.
  • select_mega_moe_config(p2p_quant="none") drops the FP8-only aligned-pair Stage2 instead of raising.
  • Routes suite --combine-wire: under "bf16", [WIRE] fails if any built route can launch a non-BF16 config, and the edge cases fail if a peer sent FP8 rows.

Review focus

  • Under "bf16", calls above the small-input capacity go staged rather than to the large-input route (Dev record, Decided).

Testing

Under "bf16" no built route can send a non-BF16 row, and every route still matches the reference.
ef6599c43: routes suite --combine-wire bf16 m31 a8w4 and a4w4 64 PASS each, V4.1-Flash EP4 58 PASS. "auto" V4.1-Flash EP4 57 PASS. CPU route-plan tests 218 passed. ruff, black clean.

Follow-ups

  • none
Dev record

Found. none

Decided.

  • Under "bf16" the large-input route is dropped and its calls run staged with a BF16 wire. A BF16 large-input kernel is new kernel work; refusing would break every caller above 512 rows a rank. The cost is staged time on those calls only (V4.1-Flash EP4 at 8192: large-input route not built).
  • "bf16" with an FP8 stage2_p2p_quant raises instead of silently overriding it.

Surprised. none

Left undone. Not run: EP8 and EP2 layouts, MI300X, MI250X. "auto" timing against main was not re-measured on this head. The pre-merge measurement on #8623's head (MengqingCao#4) found -1.4% to +1.0%.

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), this tree's aiter/ops/flydsl, aiter/aot, aiter/utility, op_tests/multigpu_tests and tests over the image's aiter. From op_tests/multigpu_tests:

torchrun --nproc-per-node 4 test_mega_moe_v2.py --suite routes --network v41_flash --quant a8w4 --combine-wire bf16 --time-bs 104
[SETUP] network=v41_flash quant=a8w4 mtpr=8192 small_m_mtpr=512 large_m=False world=4 combine_wire=bf16 (large-input route not built)
[WIRE] non-bf16 routes=[] PASS
[ABOVE] max_tokens=513 route=staged relL2_vs_ref=0.051972 PASS
[RESULT] ALL PASS
torchrun --nproc-per-node 4 test_mega_moe_v2.py --suite routes --network m31 --quant a4w4 --mtpr 1024 --combine-wire bf16 --check-time-acc --time-bs 104,144,152
[WIRE] non-bf16 routes=[] PASS
[RESULT] ALL PASS

CPU: test_bf16_wire_drops_aligned_pair_stage2 (new) checks that p2p_quant="none" never returns the aligned-pair Stage2, on layouts where "auto" tunes it. Pre-merge revert-red on the same code: without bf16_wire=combine_wire == "bf16", [WIRE] lists the small-input buckets and the suite fails.

🤖 Generated with Claude Code

MengqingCao and others added 3 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]>
Adds MegaMoEV2(combine_wire="auto" | "bf16"). "bf16" makes every route
the instance builds send BF16 combine rows: the staged route is built
with stage2_p2p_quant="none" (an FP8 stage2_p2p_quant raises), and every
small-input token bucket gets bf16_wire. The large-input kernel combines
over FP8 only, so under "bf16" it is not built (large_m_dropped, a rank-0
warning) and its calls take the staged route. "auto" changes nothing.

select_mega_moe_config(p2p_quant="none") now drops the FP8-only
aligned-pair Stage2 instead of raising; "auto" is unchanged.

The routes suite takes --combine-wire; under "bf16" a [WIRE] check fails
if any built route can launch a config that sends non-BF16 rows, and the
edge cases check that no peer sent FP8 rows. A CPU test covers the
aligned-pair fallback. bench_mega_moe_m31.py takes --combine-wire.

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 8918 --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 #8922: 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