Skip to content

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

Open
MengqingCao wants to merge 3 commits into
mengqing/megamoe-m31-ep4from
mengqing/megamoe-combine-wire
Open

MengqingCao wants to merge 3 commits into
mengqing/megamoe-m31-ep4from
mengqing/megamoe-combine-wire

Conversation

@MengqingCao

@MengqingCao MengqingCao commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Ready for review. No blocking issues. Top of a stack of three (gh stack), on top of the M3.1 EP4 layout PR; the diff shows only this layer. Replaces #8918 (same commit).

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.

Why MiniMax-M3.1 asks for BF16: it is a numerics-parity choice, not a measured FP8 failure.

  • M3.1's TP4 decode, the baseline this MegaMoE path replaces, reduces expert outputs in BF16 (all-reduce); there is no FP8 step between the experts and the residual add. A BF16 combine wire keeps the DEP path's output equal in precision to that baseline, so the switch to MegaMoE changes the kernel and the parallelism, not the combine numerics.
  • The NVIDIA reference for M3.1 P/D (vLLM with DeepGEMM nvfp4_mega_moe) also combines in BF16 with FP32 accumulation.
  • The combine rows are each expert's top-k-weighted output before the sum, so FP8 rounding there lands directly on the hidden state of every decode step. We have not measured an FP8-combine A/B for M3.1, so we keep BF16 until one shows FP8 holds accuracy (GSM8K and DSpark acceptance).
  • The cost: under "bf16" the large-input route is not built, so calls above the small-input capacity take the staged route. M3.1's decode steps fit the small-input capacity, so its decode does not hit this.

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_rows_always (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.
  • AOT: a job takes combine_wire (--combine-wire), and the M3.1 profile builds with "bf16", as ATOM requests. At 16384 that is a different staged Stage2.
  • 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 (kernel code): 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. 5866b970b: M3.1 AOT replay 4 ok, --check 4 ok, an M3.1 runtime ran every bucket from the cache with compiles forbidden. Route-plan 218 and AOT driver 5 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.

PR Self-Review

Reviewed revision

133408e927b9

Behavior and intent

MegaMoEV2(combine_wire="auto" | "bf16") is new. Under "bf16":

  • The staged route is built with stage2_p2p_quant="none"; an FP8 stage2_p2p_quant raises.
  • Every small-input bucket sends BF16 rows (SmallMRuntime(bf16_wire=True)).
  • The FP8-only large-input route is not built (large_m_dropped, rank-0 warning), and its calls go staged.
  • select_mega_moe_config(p2p_quant="none") now drops the FP8-only aligned-pair Stage2 instead of raising.

"auto" changes nothing. Before this PR, a caller could not get a BF16 combine wire: the staged route sends FP8 at capacity 1024 and up, and the small-input kernel switches to FP8 past a row threshold. ATOM (ROCm/ATOM#3930) needs to choose the wire per model.

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's aiter/ops/flydsl, aiter/aot, aiter/utility, op_tests/multigpu_tests and tests copied over the image's aiter. Commands run from op_tests/multigpu_tests.
GPU route tests at ef6599c43. The kernel code is the same as at ef6599c43, where the GPU tests ran; the AOT commits change only aiter/aot/flydsl/mega_moe.py and tests/test_aot_drivers.py.

  • Routes suite --network v41_flash --quant a8w4 --combine-wire bf16 --time-bs 104: 58 PASS. [WIRE] non-bf16 routes=[] PASS; the large-input route is not built, and the call at 513 rows runs staged (relL2 0.0520).

  • Routes suite --network m31 --quant {a8w4,a4w4} --mtpr 1024 --combine-wire bf16 --check-time-acc --time-bs 104,144,152: 64 PASS each, [WIRE] PASS, fp8_peers=0 on every edge case.

  • Routes suite --network v41_flash --quant a8w4 --time-bs 104 ("auto"): 57 PASS.

  • python -m pytest tests/test_mega_moe_gfx950_route_plan.py: 218 passed; tests/test_aot_drivers.py::MegaMoEProductionJobsTest: 5 passed (PA-Gluon import stubbed on the CPU node).

  • AOT runs: pit2-p03-g08 (functional node), same image, GPU_ARCHS=gfx950, the AOT cache (AITER_FLYDSL_AOT_CACHE_DIR) and FlyDSL runtime cache (FLYDSL_RUNTIME_CACHE_DIR) on shared storage.

  • python -m aiter.aot.flydsl.mega_moe --experts-per-rank 32 --world-size 4 --topk 4 --model-dim 6144 --inter-dim 3072 --swiglu-limit 7 --act swigluoai --combine-wire bf16 --mtpr 512 16384: replay 4 ok, 0 failed. The same with --check from a fresh container: 4 ok.

  • The same --check with --combine-wire auto: 2 ok (512), 2 failed (16384, the FP8 staged Stage2). So the BF16 build is the one ATOM needs.

  • GPU first use (g08 GPUs 0-3, FLYDSL_RUNTIME_RUN_ONLY=1, both caches): MegaMoEV2 for M3.1, routed, combine_wire="bf16", a8w4 and a4w4 at MTPR 512 and 16384. One forward at each of max_tokens 1-512 (small-input) and 513-16384 (staged): all ran, no AOT miss.

  • 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_stage1 takes bf16_wire and v41_shared (keyword-only), the kernel name carries both suffixes, and the routes suite takes --network m31 beside --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.py 264 passed; black and ruff clean. The GPU runs above predate the rebase.

  • Rebased on main at 926205e73 ([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; Kimi-K2.6 EP8 small_m / large_m), with [FlyDSL] MegaMoEV2: MiniMax-M3.1 EP4 layout on the fused small-input route #8921 under it. SmallMRuntime(bf16_wire=True) now sets main's FusedStage1Knobs.bf16_rows_always on every bucket ([FlyDSL] MegaMoEV2: MiniMax-M3.1 EP4 layout on the fused small-input route #8921 dropped its own knob for it), and the [WIRE] check reads that knob. [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's own aligned-pair fallback for its BF16-return layouts sits beside this PR's p2p_quant="none" one; both stay. 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.py 307 passed, MegaMoEProductionJobsTest 6 passed; black 26.10.1 and ruff clean. The GPU and AOT runs above predate this rebase; the M3.1 small-input kernels are renamed (_b16ra for _bw), so an AOT cache built before it misses them.

  • 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's tests/test_moev2_differential.py::test_dispatch_plans_match_legacy failure 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 and MegaMoEProductionJobsTest pass as before; black and ruff clean.

Unverified:

PR-specific question

  • test_mega_moe_v2.py --suite routes --combine-wire bf16: before this PR, MegaMoEV2(combine_wire=...) raises TypeError. [WIRE] fails if any built route can launch a config that sends non-BF16 rows. The edge cases fail if a peer's published flag says it sent FP8 rows. No existing test checks each route's combine-row dtype.
  • tests/test_mega_moe_gfx950_route_plan.py::test_bf16_wire_drops_aligned_pair_stage2 fails before: select_mega_moe_config(p2p_quant="none") raised on the aligned-pair buckets.
  • bench_mega_moe_m31.py: --combine-wire passes the option through; no pass/fail change.
  • tests/test_aot_drivers.py::test_m31_ep4_profile now also pins combine_wire="bf16"; it fails before this commit, which adds the job field.

Changed op tests

  • op_tests/multigpu_tests/test_mega_moe_v2.py: --combine-wire, _non_bf16_wire_routes ([WIRE]), and _fp8_peers in the edge cases. Not redundant: they are the only checks that every route sends BF16 under "bf16".
  • op_tests/multigpu_tests/bench_mega_moe_m31.py: --combine-wire, so the bench times the instance as ATOM builds it for M3.1. Not redundant: no other bench takes the option.
  • tests/test_mega_moe_gfx950_route_plan.py (outside op_tests/): test_bf16_wire_drops_aligned_pair_stage2 (CPU).
  • tests/test_aot_drivers.py (outside op_tests/): the M3.1 profile's combine_wire check.

🤖 Generated with Claude Code

@aiter-bot

aiter-bot commented Nov 30, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision 133408e927b9 · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

`MegaMoEV2(combine_wire="auto" | "bf16")` is new. Under `"bf16"`:
- The staged route is built with `stage2_p2p_quant="none"`; an FP8 `stage2_p2p_quant` raises.
- Every small-input bucket sends BF16 rows (`SmallMRuntime(bf16_wire=True)`).
- The FP8-only large-input route is not built (`large_m_dropped`, rank-0 warning), and its calls go staged.
- `select_mega_moe_config(p2p_quant="none")` now drops the FP8-only aligned-pair Stage2 instead of raising.

`"auto"` changes nothing. Before this PR, a caller could not get a BF16 combine wire: the staged route sends FP8 at capacity 1024 and up, and the small-input kernel switches to FP8 past a row threshold. ATOM (ROCm/ATOM#3930) needs to choose the wire per model.

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's `aiter/ops/flydsl`, `aiter/aot`, `aiter/utility`, `op_tests/multigpu_tests` and `tests` copied over the image's aiter. Commands run from `op_tests/multigpu_tests`.
GPU route tests at `ef6599c43`. The kernel code is the same as at `ef6599c43`, where the GPU tests ran; the AOT commits change only `aiter/aot/flydsl/mega_moe.py` and `tests/test_aot_drivers.py`.
- Routes suite `--network v41_flash --quant a8w4 --combine-wire bf16 --time-bs 104`: 58 PASS. `[WIRE] non-bf16 routes=[] PASS`; the large-input route is not built, and the call at 513 rows runs staged (relL2 0.0520).
- Routes suite `--network m31 --quant {a8w4,a4w4} --mtpr 1024 --combine-wire bf16 --check-time-acc --time-bs 104,144,152`: 64 PASS each, `[WIRE]` PASS, `fp8_peers=0` on every edge case.
- Routes suite `--network v41_flash --quant a8w4 --time-bs 104` (`"auto"`): 57 PASS.
- `python -m pytest tests/test_mega_moe_gfx950_route_plan.py`: 218 passed; `tests/test_aot_drivers.py::MegaMoEProductionJobsTest`: 5 passed (PA-Gluon import stubbed on the CPU node).
- AOT runs: pit2-p03-g08 (functional node), same image, `GPU_ARCHS=gfx950`, the AOT cache (`AITER_FLYDSL_AOT_CACHE_DIR`) and FlyDSL runtime cache (`FLYDSL_RUNTIME_CACHE_DIR`) on shared storage.
- `python -m aiter.aot.flydsl.mega_moe --experts-per-rank 32 --world-size 4 --topk 4 --model-dim 6144 --inter-dim 3072 --swiglu-limit 7 --act swigluoai --combine-wire bf16 --mtpr 512 16384`: replay 4 ok, 0 failed. The same with `--check` from a fresh container: 4 ok.
- The same `--check` with `--combine-wire auto`: 2 ok (512), 2 failed (16384, the FP8 staged Stage2). So the BF16 build is the one ATOM needs.
- GPU first use (g08 GPUs 0-3, `FLYDSL_RUNTIME_RUN_ONLY=1`, both caches): `MegaMoEV2` for M3.1, routed, `combine_wire="bf16"`, a8w4 and a4w4 at MTPR 512 and 16384. One forward at each of max_tokens 1-512 (small-input) and 513-16384 (staged): all ran, no AOT miss.
- black 26.10.1 and ruff 0.16.0 clean.

- Rebased on main at `1f9a7fb50`, which merged #8878 (V4.1-Flash shared_in) into the same small-input kernel builder and routes suite: `compile_mega_moe_stage1` takes `bf16_wire` and `v41_shared` (keyword-only), the kernel name carries both suffixes, and the routes suite takes `--network m31` beside `--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.py` 264 passed; black and ruff clean. The GPU runs above predate the rebase.

- Rebased on main at `926205e73` (#9076, V4.1-Flash DSpark draft layout; Kimi-K2.6 EP8 small_m / large_m), with #8921 under it. `SmallMRuntime(bf16_wire=True)` now sets main's `FusedStage1Knobs.bf16_rows_always` on every bucket (#8921 dropped its own knob for it), and the `[WIRE]` check reads that knob. #9076's own aligned-pair fallback for its BF16-return layouts sits beside this PR's `p2p_quant="none"` one; both stay. 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.py` 307 passed, `MegaMoEProductionJobsTest` 6 passed; black 26.10.1 and ruff clean. The GPU and AOT runs above predate this rebase; the M3.1 small-input kernels are renamed (`_b16ra` for `_bw`), so an AOT cache built before it misses them.

- Merged aiter main (at `66da04555`, which has ROCm/aiter#9129, the ReLU2 dispatch hotfix) into the branch instead of rebasing, so the approvals stay. The Heavy CI's `tests/test_moev2_differential.py::test_dispatch_plans_match_legacy` failure 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 and `MegaMoEProductionJobsTest` pass as before; black and ruff clean.

Unverified:
- `"auto"` timing against main was not re-measured at this

[truncated in readiness report; see the PR description for the full answer]

PR-specific question

- `test_mega_moe_v2.py --suite routes --combine-wire bf16`: before this PR, `MegaMoEV2(combine_wire=...)` raises `TypeError`. `[WIRE]` fails if any built route can launch a config that sends non-BF16 rows. The edge cases fail if a peer's published flag says it sent FP8 rows. No existing test checks each route's combine-row dtype.
- `tests/test_mega_moe_gfx950_route_plan.py::test_bf16_wire_drops_aligned_pair_stage2` fails before: `select_mega_moe_config(p2p_quant="none")` raised on the aligned-pair buckets.
- `bench_mega_moe_m31.py`: `--combine-wire` passes the option through; no pass/fail change.
- `tests/test_aot_drivers.py::test_m31_ep4_profile` now also pins `combine_wire="bf16"`; it fails before this commit, which adds the job field.

Changed op tests

- `op_tests/multigpu_tests/test_mega_moe_v2.py`: `--combine-wire`, `_non_bf16_wire_routes` (`[WIRE]`), and `_fp8_peers` in the edge cases. Not redundant: they are the only checks that every route sends BF16 under `"bf16"`.
- `op_tests/multigpu_tests/bench_mega_moe_m31.py`: `--combine-wire`, so the bench times the instance as ATOM builds it for M3.1. Not redundant: no other bench takes the option.
- `tests/test_mega_moe_gfx950_route_plan.py` (outside `op_tests/`): `test_bf16_wire_drops_aligned_pair_stage2` (CPU).
- `tests/test_aot_drivers.py` (outside `op_tests/`): the M3.1 profile's `combine_wire` check.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • FAIL — Aiter Test Gate: failed
  • Required CI failed; fix it before requesting human review.

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

GwilliamHu
GwilliamHu previously approved these changes Dec 2, 2026
zufayu
zufayu previously approved these changes Dec 2, 2026
@zufayu
zufayu force-pushed the mengqing/megamoe-combine-wire branch from 5866b97 to 7bd83fa Compare December 2, 2026 07:23
@MengqingCao
MengqingCao dismissed stale reviews from zufayu and GwilliamHu via cf389bf December 2, 2026 17:42
@MengqingCao
MengqingCao force-pushed the mengqing/megamoe-combine-wire branch from 7bd83fa to cf389bf Compare December 2, 2026 17:42
@MengqingCao

Copy link
Copy Markdown
Contributor Author

Restacked on the rebased #8921 (9d0c51a). One conflict in test_mega_moe_v2.py: the docstring keeps main's V4.1-Flash --shared-in-only line, and the [WIRE] check runs before the shared_in block. No other change. The push dismissed the approvals; a re-approval is needed.

zufayu
zufayu previously approved these changes Dec 3, 2026
GwilliamHu
GwilliamHu previously approved these changes Dec 3, 2026
@MengqingCao
MengqingCao dismissed stale reviews from GwilliamHu and zufayu via 4df445b December 3, 2026 08:40
@MengqingCao
MengqingCao force-pushed the mengqing/megamoe-combine-wire branch from cf389bf to 4df445b Compare December 3, 2026 08:40
@MengqingCao
MengqingCao force-pushed the mengqing/megamoe-combine-wire branch from 4df445b to 593c410 Compare December 3, 2026 08:42
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_rows_always. 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]>
A job takes combine_wire (CLI --combine-wire), passed to MegaMoEV2 and
named in the job. The M3.1 profile builds with combine_wire="bf16", as
ATOM requests it: at capacity 16384 the staged route then runs the BF16
Stage2 instead of the default FP8 one, so the cache holds the kernels
ATOM launches.

Co-Authored-By: Claude <[email protected]>
@MengqingCao
MengqingCao force-pushed the mengqing/megamoe-combine-wire branch from 593c410 to eb2da6d Compare December 3, 2026 08:49
…-wire

Brings in aiter main (#9129) through the base branch.

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

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants