Skip to content

[FlyDSL] MegaMoE EP: expert-parallel MoE as one persistent kernel - #7859

Open
Yaowu-Xiong wants to merge 7 commits into
mainfrom
xyw/megamoe_ep
Open

Yaowu-Xiong wants to merge 7 commits into
mainfrom
xyw/megamoe_ep

Conversation

@Yaowu-Xiong

@Yaowu-Xiong Yaowu-Xiong commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds aiter.ops.flydsl.mega_moe_ep.MegaMoeEP, an expert-parallel MoE layer that runs a whole forward as one persistent kernel launch per rank. The launch does all of these:

  • the all-to-all dispatch;
  • an in-kernel planner;
  • the local experts' GEMM1 + activation + GEMM2;
  • the all-to-all combine.

It takes the same inputs as MegaMoEV2 (bf16 tokens, top-k ids / weights, MXFP4 weights; a8w4 or a4w4).

The baseline is main's MegaMoEV2, which has three paths:

  • V2 2-stage (the main path, any shape): Stage1 fuses dispatch + GEMM1 and Stage2 fuses GEMM2 + combine, as two launches.
  • V2 small_m (AITER_MEGA_SMALL_M=1): quant, dispatch, GEMM1, GEMM2 and combine in one kernel, up to 512 tokens per rank.
  • V2 large_m (AITER_MEGA_LARGE_M=1): a quant kernel, then dispatch, GEMM1, GEMM2 and combine in one persistent kernel, at mtpr 8192.

small_m and large_m only accept DeepSeek-V4-Pro a8w4 on 8 ranks; every other shape (including V4-Pro a4w4 and Kimi-K2.6) runs the 2-stage path. This PR runs every shape.

Results of this PR:

  • DeepSeek-V4-Pro single op:
    • a8w4 vs large_m (mtpr 8192, bs 1024 … 8192): 5–34% faster.
    • a8w4 vs small_m (mtpr 512, bs 1 … 512): up to 23% faster. The one clearly slower point is zipf:1 bs 4 (+17%); uniform / spike bs 1 / 4 are within 4%.
    • vs 2-stage: a8w4 10–34% faster at mtpr 8192 and 27–64% at mtpr 512; a4w4 23–36% and 25–67%; a8w4 at mtpr 32768 (beyond large_m's mtpr) 5–29%.
  • DeepSeek-V4-Pro full network (ATOM, EP8 with EPLB): output throughput +4.7% at c512 and +4.9% at c4096 vs small_m + large_m. GSM8K 0.947. 2-stage was not measured on this model.
  • Kimi-K2.6 single op vs 2-stage: 14–30% faster at mtpr 8192 and 33–64% at mtpr 512.
  • vs the unfused mori + fused_moe EP MoE (what ATOM runs online; a8w4, V4-Pro and K2.6, mtpr 512 / 8192, uniform / zipf:1 / spike): 14–62% faster.
  • Kimi-K2.6 full network (sglang, DP8 attention + EP8): c512 output throughput +28.7% vs 2-stage (sglang's default) and +6.2% vs small_m + large_m on a branch that lets them take the K2.6 shape. GSM8K 0.929 / 0.944 (2 runs).

Accuracy is also tested on the DeepSeek-V4.1-Flash, Kimi-K3 and Mixtral-8x7B shapes (see Testing).

The layer is opt-in: nothing in aiter calls it at run time, and frameworks choose it explicitly. The AOT build (setup.py → run_aot) precompiles its kernels for the V4-Pro and K2.6 deployment profiles, so serving does not JIT them at startup.

Motivation

  • V2 2-stage, the only path for most shapes, runs a forward as two launches (Stage1, then Stage2) with a host-visible boundary between them.
    • At decode sizes the launches and the cross-rank handshakes are a large part of the time.
    • At prefill sizes GEMM2 and the combine wait for all of Stage1.
  • V2 small_m / large_m are fused, but only for DeepSeek-V4-Pro a8w4 on 8 ranks (large_m also needs mtpr 8192).
  • Routing skew leaves CUs idle on the ranks or experts with little work.

This PR is one persistent kernel for every supported shape. Dispatch, planning, GEMMs and combine overlap inside the launch, and the planner places work by the routing it actually received.

Changes

New files:

  • aiter/ops/flydsl/mega_moe_ep.py: the public wrapper.
    • MegaMoeEPConfig and MegaMoeEP provide forward, prepare, set_weights, poll_errors, reset and reference_forward.
    • Also exports mega_moe_ep_supported (gfx950) and the pure-torch oracle ep_reference.
  • aiter/ops/flydsl/kernels/mega_moe_ep/: the kernel (FlyDSL). One CTA per CU, 8 waves, all of them compute.
    • mega_moe_ep_kernel.py: the entry and launcher.
    • communication.py: hipIpc symmetric arena, epoch flags, dispatch sends, the combine finish and the cross-rank waits.
    • schedule.py: the in-kernel planner and the XCD-local tile queue.
    • gemm.py: inline-A GEMM1 + activation + GEMM2 with the combine fused into the GEMM2 epilogue.
    • mega_moe_ep_config.py: compile-time layout.
    • mega_moe_ep.py: the host engine, launch configs and oracle.
  • Two kernel variants, chosen from max_tok_per_rank, so every rank runs the same one:
    • Small-batch (mtpr ≤ 512):
      • each sender writes an epoch-tagged header, its routing and payload rows;
      • each owner buckets its rows with XCD-private counters, so there is no grid barrier and no host-side fill;
      • for tiny batches, and for batches whose expert-aligned XCD split is imbalanced (hot experts), every CTA ranks its XCD's routes itself on an even split, so a hot expert's tiles spread over all XCDs;
      • weights are streamed non-temporally.
    • Large-batch:
      • the routing goes first, so owners plan while the payload is still in flight;
      • the payload goes in 4 token buckets, so a GEMM1 tile starts once its rows have landed;
      • hot experts are split over the XCDs;
      • a8w4 uses a 64-row tile and a4w4 a 64- or 128-row tile.
  • Combine: partials are sent back to the source rank as per-8 FP8 + E8M0 (half the bytes of bf16). The source does the top-k weighted sum.
  • Cross-rank waits spin until their flag arrives, so a late rank (a JIT compile or a host stall) only delays its peers.
    • AITER_MEGAMOE_EP_WATCHDOG=1 (debug, default off) bounds each wait by 2 s. On expiry it sets the sticky error word and traps (s_trap 2).
    • The kernel name gets _wd, so the debug build has its own cache entry.
  • Ops: prepare() compiles every variant the engine can launch and ends in a barrier. No rank then JIT-compiles inside a launch while its peers wait.
  • AOT: aiter/aot/flydsl/mega_moe_ep.py (new), run by run_aot after the MegaMoEV2 replay (aiter/aot/flydsl/common.py, 3 lines), documented in aiter/aot/flydsl/README.md.
    • Like mega_moe.py, it builds the runtime's own MegaMoeEP inside dry_run, with FakeTensor weights and a fake hipIpc SymmetricArena, and replays prepare() plus one forward() (for the activation quant). No GPU or process group is needed.
    • Rank, world size, token count and peer addresses are launch arguments of the kernel, so one job per profile serves all 8 ranks.
    • Profiles: DeepSeek-V4-Pro epr 48 / 52 / 56 (r0 / r32 / r64) × a8w4 / a4w4, and Kimi-K2.6 epr 48 a8w4, each at mtpr 512 and 8192 (the two capacities ATOM and sglang build). 14 jobs, 34 artifacts, about 22 s with 14 workers.
    • --check (FLYDSL_RUNTIME_RUN_ONLY=1) verifies a cache without compiling.
  • Tests: op_tests/multigpu_tests/test_mega_moe_ep.py (accuracy vs ep_reference) and op_tests/multigpu_tests/bench_mega_moe_ep.py (perf vs MegaMoEV2 and the mori dispatch → fused_moe → mori combine baseline, --engine mori).
  • Shared code: aiter/ops/flydsl/kernels/mega_moe/gemm_util.py, 3 lines.
    • With fewer A chunks than threads (this PR's small-batch mt2 tile), ATileLoader's surplus threads now repeat a chunk instead of reading past the tile.
    • The branch is a trace-time const_expr. In V2 it is taken only by the fp4 Stage1 with SBM32 and 8 waves (256 chunks, 512 threads): V4-Pro mtpr 8192 bucket 8, R1 buckets 8 / 16 / 32, V4.1-Flash EP2 bucket 512 (enumerated with select_mega_moe_config). All of these use the async A copy, whose surplus waves are already masked by copy_active. The modulo only changes addresses they never use, so V2 outputs are unchanged (see Testing).

Performance (if applicable)

Columns. "V2 2-stage" and "V2 small_m / large_m" are main's MegaMoEV2 paths (see Summary); "mori + fused_moe" is the unfused EP MoE that ATOM runs online (--engine mori); "This PR" is MegaMoeEP at this PR's head. "–" means the path does not accept the shape, or (full network) was not measured. Change is this PR relative to each baseline column, in that order.

Single-op setup:

  • op_tests/multigpu_tests/bench_mega_moe_ep.py on 8x MI355X, EP8, FlyDSL 0.5.0. V2 on main 9c119bb65: 2-stage with AITER_MEGA_SMALL_M=0 AITER_MEGA_LARGE_M=0, small_m / large_m with both set to 1.
  • mori + fused_moe (bench_mega_moe_ep.py --engine mori, a8w4 only): bf16 mori dispatch, fused_moe (per-1x32 MXFP4 weights with gate|up interleaved, MXFP8 activations, num_local_tokens from the dispatch), mori combine. ATOM's launch geometry: decode (mtpr ≤ 512) 64 blocks × 4 warps with the receive buffer cut to bs × 8 rows, prefill 128 × 16. Measured 11-12 in its own session, alternating with this PR's head, whose times there were within 4% of the This PR column.
  • ms per forward: CUDA-graph replays, worst rank, mean of 2 alternating rounds. The V4-Pro a8w4 rows ran all three engines in the same session.
  • bs is tokens per rank; mtpr is the instance's max tokens per rank.
  • Routings (bench_mega_moe_ep.py -r):
    • uniform: top-k of softmax(randn) logits; every rank and expert evenly loaded.
    • zipf:S: the expert of popularity rank r (a fixed random permutation) gets a logit bias of -S * log(1 + r). The hot experts land on different ranks, so the load is uneven between ranks: for V4-Pro, mean / max rows per rank is 0.54 / 0.37 / 0.31 for S = 0.5 / 1 / 2.
    • spike (spike:0.8,0.5,0.35,0.26,0.2,0.17): the shape the full model shows after EPLB. Hot expert j lives on rank j and is picked by 80 / 50 / 35 / 26 / 20 / 17 % of the tokens; ranks stay fairly balanced (mean / max 0.83), but a hot rank's rows mostly belong to one expert, so the imbalance is within a rank.

Full-network setup: random dataset, input 8192 / output 1024; c512 with 2048 prompts, c4096 with 8192 prompts.

  • V4-Pro: V4-Pro A8W4 on ATOM, DP attention + EP8 with EPLB, 2 rounds each.
    • small_m / large_m: decode on small_m (mtpr 512), prefill on large_m (mtpr 8192). Main a0c4b69c1, FlyDSL 0.4.2, on an ATOM tree from 11-01 with PR 6881's MQA-logits module overlaid (that tree needs the old interface). Measured 11-09.
    • This PR: decode on the small-batch kernel (mtpr 512), prefill on the large-batch kernel (mtpr 8192). FlyDSL 0.5.0, ATOM main. Measured 11-12.
  • K2.6: Kimi-K2.6-MXFP4 on sglang v0.5.23, DP8 attention + EP8, no EPLB.
    • 2-stage: sglang's default, one mtpr 8192 instance. 2 rounds, 11-06.
    • small_m / large_m: decode on small_m (mtpr 512), prefill on large_m (mtpr 8192), with AITER_LM_DEDUP=1 AITER_LM_HELPER_CU=8. 3 rounds, 11-07.
    • Both V2 columns ran the K2.6 tuning branch's tree (main a0c4b69c1 base, whose small_m / large_m accept the K2.6 shape) with FlyDSL 0.4.2.
    • This PR: decode on the small-batch kernel (mtpr 512), prefill on the large-batch kernel (mtpr 8192). FlyDSL 0.5.0. 2 rounds, 11-12.
Hardware Workload/configuration V2 2-stage V2 small_m / large_m mori + fused_moe This PR Change
8x MI355X V4-Pro a8w4 single op, mtpr 8192, bs 2048, uniform / spike 1.552 / 2.200 ms 1.389 / 2.184 ms (large_m) 2.128 / 2.675 ms 1.118 / 1.448 ms -28% / -34% vs 2-stage; -20% / -34% vs large_m; -47% / -46% vs mori
8x MI355X V4-Pro a8w4 single op, mtpr 8192, bs 8192, uniform / spike 4.511 / 5.424 ms 4.178 / 5.153 ms (large_m) 6.991 / 8.871 ms 3.853 / 4.905 ms -15% / -10% vs 2-stage; -8% / -5% vs large_m; -45% / -45% vs mori
8x MI355X V4-Pro a8w4 single op, mtpr 512, bs 64 / 256, uniform 0.469 / 0.558 ms 0.307 / 0.401 ms (small_m) 0.407 / 0.567 ms 0.288 / 0.345 ms -39% / -38% vs 2-stage; -6% / -14% vs small_m; -29% / -39% vs mori
8x MI355X V4-Pro a8w4 single op, mtpr 512, bs 512, zipf:1 / spike 1.281 / 1.071 ms 1.004 / 0.726 ms (small_m) 1.229 / 1.150 ms 0.788 / 0.629 ms -39% / -41% vs 2-stage; -22% / -13% vs small_m; -36% / -45% vs mori
8x MI355X V4-Pro a8w4 single op, mtpr 32768, bs 8192 / 32768, uniform 4.549 / 16.776 ms – – 3.963 / 16.006 ms -13% / -5% vs 2-stage
8x MI355X V4-Pro a4w4 single op, mtpr 8192, bs 2048 / 8192, uniform 1.286 / 3.725 ms – – 0.909 / 2.691 ms -29% / -28% vs 2-stage
8x MI355X V4-Pro a4w4 single op, mtpr 512, bs 64 / 512, uniform 0.560 / 0.635 ms – – 0.290 / 0.476 ms -48% / -25% vs 2-stage
8x MI355X K2.6 a8w4 single op, mtpr 8192, bs 8192, uniform 4.620 ms – 8.170 ms 3.867 ms -16% vs 2-stage; -53% vs mori
8x MI355X K2.6 a8w4 single op, mtpr 512, bs 64, uniform 0.409 ms – 0.350 ms 0.217 ms -47% vs 2-stage; -38% vs mori
8x MI355X V4-Pro full network (ATOM), c512 – 6163 tok/s, TPOT 58.00 ms – 6452 tok/s, TPOT 55.08 ms +4.7% vs small_m / large_m
8x MI355X V4-Pro full network (ATOM), c4096 – 8804 tok/s, TPOT 274.5 ms – 9237 tok/s, TPOT 259.1 ms +4.9% vs small_m / large_m
8x MI355X K2.6 full network (sglang), c512 6079 tok/s, TPOT 65.6 ms 7371 tok/s, TPOT 49.8 ms – 7827 tok/s, TPOT 47.0 ms +28.7% / +6.2%
8x MI355X K2.6 full network (sglang), c4096, per-step decode / prefill tok/s per rank 4239 / 12385 4722 / 13331 – 5203 / 14590 +22.7% / +17.8% vs 2-stage; +10.2% / +9.4% vs small_m / large_m

Notes:

  • The full-network V2 and This PR columns were measured on different days and software stacks (FlyDSL 0.4.2 vs 0.5.0; for V4-Pro also a different ATOM tree). This PR's single op is unchanged between the two FlyDSL versions (V4-Pro, 36 points, geomean time -0.5%, within ±1.3% on the large-batch kernel); the V2 full networks were not re-measured on FlyDSL 0.5.0.
  • K2.6 c4096: end-to-end throughput depends on which of a few scheduling trajectories a run falls into (up to 13% apart for the same server), so the row gives per-step rates from the DP0 server log: mean decode generation throughput while ≥ 300 requests run, and median prefill input throughput over full 8192-token chunks, averaged over the runs.
  • This PR serializes shared experts with the routed MoE: the kernel needs every CU, so frameworks turn off the shared-expert / routed-MoE stream overlap that V2 uses in decode.

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Setup: accuracy runs on 8x MI355X with FlyDSL 0.5.0 on main 9c119bb65. Each case runs eager, then CUDA-graph replays on the current stream and two side streams, and the error word must stay 0. Then it runs 8 back-to-back launches (eager and replay) that alternate with a second input without a host sync, and each output must be bitwise equal to a standalone launch (b2b). All PASS:

  • test_mega_moe_ep.py, 5 networks (v4_pro, kimi_k26, v41_flash, kimi_k3 with the situv2 activation, mixtral_8x7b with I > H). Commands, per network N (Mixtral uses fewer token counts):
    torchrun --nproc_per_node=8 op_tests/multigpu_tests/test_mega_moe_ep.py --network N -q a8w4 a4w4 --mtpr 512 8192 \
        -t 0 1 8 64 256 512 1024 2048 3072 4096 6144 8192 -r uniform zipf:1 spike same invalid
    torchrun --nproc_per_node=8 op_tests/multigpu_tests/test_mega_moe_ep.py --network N -q a8w4 a4w4 --mtpr 256 512 \
        -t 0 1 8 64 128 192 256 320 384 448 512 -r uniform zipf:1 zipf:2 spike same invalid
    torchrun --nproc_per_node=8 op_tests/multigpu_tests/test_mega_moe_ep.py --network N -q a8w4 a4w4 --mtpr 512 8192 \
        -t 1 64 300 512 2048 8192 -r uniform zipf:1 spike invalid --uneven
    
    Results:
    • a8w4 / a4w4 × mtpr 512 / 8192 × bs 0 … 8192 × uniform / zipf:1 / spike / same / invalid routing: 180/180 per network (Mixtral 66/66);
    • the small-batch kernel at mtpr 256 / 512 × bs 0 … 512 (11 sizes), adding zipf:2: 216/216 per network;
    • --uneven (different token counts per rank): 80/80 per network.
  • AOT (python -m aiter.aot.flydsl.mega_moe_ep, FlyDSL 0.5.0):
    • From an empty cache: 14/14 jobs ok; --check: 14/14 ok.
    • The same tests JIT-compiled from an empty cache produce 16 artifacts (14 EP variants + 2 activation quants). All 16 are in the AOT cache with identical IR and binary; none is JIT-only.
    • Accuracy on the AOT cache with FLYDSL_RUNTIME_RUN_ONLY=1 (any cache miss fails): the three test commands above, V4-Pro a8w4 / a4w4 180/180, 132/132, 80/80; K2.6 a8w4 90/90, 66/66, 40/40. The cache gains no artifact.
    • Single-op perf, AOT cache vs in-memory JIT (bench_mega_moe_ep.py --engine ep, 2 alternating rounds): AOT / JIT geomean 0.998 (V4-Pro a8w4 mtpr 8192, 20 points), 1.001 (mtpr 512, 27 points), 1.002 (K2.6 mtpr 8192, 6 points); every point within ±2%.
  • Debug mode (AITER_MEGAMOE_EP_WATCHDOG=1): V4-Pro 60/60, Kimi-K3 60/60. With one rank 5 s late, every rank traps as designed.
  • Stress checks (extra scripts, not committed), all PASS:
    • a mix of small-batch / large-batch instances and token counts on the current stream and 6 side streams over 28 steps;
    • forward(stream=s) with the inputs written late on the current stream (the forward waits for them);
    • epoch wrap-around;
    • one rank entering the forward 5 s after its peers (4 networks, both kernels): the peers wait and the output and error word are correct;
    • large-batch payload rounds delayed by 30 µs and 300 µs each, to widen any window in which a consumer could read a stale cache line: all bitwise equal.
  • mori + fused_moe baseline (extra script, not committed): on the same weights and inputs (V4-Pro and K2.6 a8w4, mtpr 512 / 8192, bs 1 … 4096, uniform / zipf:1 / spike) its output is relL2 0.046 from ep_reference, this PR's 0.053, and 0.027–0.031 from this PR's. With MXFP4 activations (a4w4) and interleaved gate|up, fused_moe does not match the reference (relL2 1.41), so --engine mori rejects a4w4.
  • V2 unchanged by the gemm_util.py change: test_mega_moe_v2.py with and without the change. Paths covered: the V4-Pro main path, a8w4 / a4w4, mtpr 512 (bs 1 … 512) and mtpr 8192 (bs 1 … 8192, including bs 8, which takes the branch); the R1 (r1_v3) a4w4 main path at mtpr 128 / 512, bs 8 / 16 / 32; small_m (AITER_MEGA_SMALL_M=1); large_m (AITER_MEGA_LARGE_M=1 --expect-large-m --compare-main, bs 1 … 8192). All 51 relL2 values are identical with and without the change (the large_m run exits with HIP error: invalid argument after its last case on main too). V2 perf of the branch-taking bucket (V4-Pro a4w4 mtpr 8192 bs 8, 2 alternating rounds): 0.336 / 0.336 ms uniform, 0.225 / 0.225 ms zipf:1; other sizes within one timer tick (0.002 ms).
  • Full network (same setups as Performance):
    • V4-Pro on ATOM, this PR's head: GSM8K 0.947 (3-shot flexible = strict), no error word, no fatal log pattern, every benchmark run completed.
    • V4-Pro on ATOM from an empty FlyDSL cache, on an earlier revision with the cross-rank wait fix: GSM8K 0.951 / 0.952. No error word, no stall; the longest server log gap is 48 s, during serving-time JIT of other kernels. Before the fix, the same cold start stalled for 419 s and then hung.
    • K2.6 on sglang (5-shot, 1319 questions): this PR 0.929 / 0.944 (2 runs), V2 2-stage 0.934, V2 small_m / large_m 0.940.

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

The module docstrings describe the kernels, their assumptions and the debug watchdog. aiter/aot/flydsl/README.md describes the new AOT module. Performance results are in this description (Performance section).

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Uses the FlyDSL pinned by main (0.5.0) and the existing mega_moe / mega_moe_tp helpers. The symmetric memory uses hipIpc; in containers on the host network, ROCm 7.1 needs HSA_ENABLE_IPC_MODE_LEGACY=1 (wrapper docstring).

Breaking Changes

None. New module; the only shared-code change is the ATileLoader surplus-thread branch, which V2's tiles never take. The AOT build runs one more replay (14 jobs, gfx950 only; skipped when GPU_ARCHS omits gfx950), and a failure there fails the build like the other replays.

PR Self-Review

Reviewed revision

99c6e9948

Behavior and intent

New opt-in module; no existing behavior changes. MegaMoEV2's 2-stage path, the only one for most shapes, runs a forward as two launches with a host-visible boundary, which costs time at decode sizes (launches and handshakes) and at prefill sizes (Stage2 waits for all of Stage1); its fused small_m / large_m paths only accept DeepSeek-V4-Pro a8w4 on 8 ranks. MegaMoeEP does the whole forward in one persistent launch for every supported shape, and its planner places work by the received routing. The AOT build precompiles its kernels for the shipped profiles (new aiter/aot/flydsl/mega_moe_ep.py, run by run_aot). The only shared-code change (gemm_util.py) only changes addresses that V2's surplus threads never use.

Validation and unverified scope

  • Validated (commands and results under Testing; e.g. torchrun --nproc_per_node=8 op_tests/multigpu_tests/test_mega_moe_ep.py --network v4_pro -q a8w4 a4w4 --mtpr 512 8192 -r uniform zipf:1 spike same invalid: 180/180 PASS on 8x MI355X; bench_mega_moe_ep.py --engine ep|v2|mori for the Performance table): accuracy on 5 networks × a8w4 / a4w4 × both kernels × 0 … 8192 tokens × 6 routings, uneven token counts, back-to-back inputs, epoch wrap-around, multi-stream mixes, a late rank, the watchdog build; V2 unchanged; single-op perf vs main's V2 2-stage / small_m / large_m and vs mori + fused_moe; full networks on ATOM (V4-Pro) and sglang (K2.6); the AOT module from an empty cache, --check, artifacts identical to the runtime JIT's, and accuracy / perf on the AOT cache with FLYDSL_RUNTIME_RUN_ONLY=1.
  • Unverified:
    • The AOT module ran standalone (python -m aiter.aot.flydsl.mega_moe_ep), not inside a full setup.py wheel build.
    • Large-batch visibility of the payload scale rows: they are not 128 B aligned and are read with cached loads after a sys-scope count wait, without an L2 invalidate. Back-to-back alternating inputs and payload rounds delayed by up to 300 µs never read stale data, but no hardware document guarantees it.
    • The kernels assume every rank calls each forward (collective), distinct expert ids within a token, and that no other spinning kernel shares the GPU; none of these is checked at run time (module docstring).
    • The small-batch kernel's choice between its two planners uses an imbalance threshold tuned on the synthetic routings above.
    • Tested only on 8x MI355X (gfx950, 8 XCDs) with 8 ranks.

PR-specific question

Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?

This PR changes no tuning table, config file or kernel-selection rule of an existing op. MegaMoeEP is a new class, used only by callers that construct it, and its launch configs live in the new module. The AOT change only adds a replay to run_aot; the existing modules' job lists are untouched. The one shared-code change, ATileLoader in mega_moe/gemm_util.py, is a trace-time branch for tiles with fewer A chunks than threads. In MegaMoEV2 it is taken only by the fp4 Stage1 with SBM32 and 8 waves (V4-Pro mtpr 8192 bucket 8, R1 buckets 8 / 16 / 32, V4.1-Flash EP2 bucket 512, enumerated with select_mega_moe_config), whose surplus waves are already masked by copy_active. Evidence: test_mega_moe_v2.py gives identical relL2 on all 51 cases with and without the change (main path, small_m, large_m; including bs 8), and the branch-taking bucket's V2 time is unchanged (0.336 / 0.336 ms uniform, 0.225 / 0.225 ms zipf:1); see Testing.

Changed op tests

  • op_tests/multigpu_tests/test_mega_moe_ep.py (new): accuracy of MegaMoeEP against the pure-torch ep_reference on 8 ranks, per network / quant / mtpr / token count / routing, including invalid routes, uneven token counts per rank and back-to-back alternating inputs (bitwise). No other test covers this module.
  • op_tests/multigpu_tests/bench_mega_moe_ep.py (new): CUDA-graph perf of MegaMoeEP, MegaMoEV2 and the mori dispatch → fused_moe → mori combine baseline on the same shapes and routings; not a correctness test.

@Yaowu-Xiong
Yaowu-Xiong requested a review from a team November 12, 2026 07:10
@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 7859 --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.

@aiter-bot

aiter-bot commented Nov 12, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision ceba4c939c08 · 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 exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?
  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 — Reviewed revision must contain at least the first 7 characters of the current head SHA

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

…x950, MXFP4)

Add aiter.ops.flydsl.mega_moe_ep.MegaMoeEP: an expert-parallel MoE layer that
runs a whole forward (all-to-all dispatch, in-kernel planner, the local experts'
GEMM1 + activation + GEMM2, all-to-all combine) as one persistent kernel launch
per rank. Same inputs as MegaMoEV2 (bf16 tokens, top-k ids / weights, MXFP4
weights; a8w4 or a4w4). Opt-in: nothing in aiter calls it.

- aiter/ops/flydsl/mega_moe_ep.py: public wrapper (MegaMoeEPConfig, MegaMoeEP,
  mega_moe_ep_supported, the pure-torch oracle ep_reference).
- aiter/ops/flydsl/kernels/mega_moe_ep/: the kernel. One CTA per CU, 8 waves,
  all of them compute; hipIpc symmetric arena with epoch flags.
  - Small-batch kernel (mtpr <= 512): epoch-tagged sends, XCD-private
    bucketing without a grid barrier, even-split planning for hot experts.
  - Large-batch kernel: routing first so owners plan while the payload is in
    flight, payload in 4 token buckets, hot experts split over the XCDs.
  - Combine partials go back as per-8 FP8 + E8M0; the source does the top-k
    weighted sum.
  - Cross-rank waits are unbounded; AITER_MEGAMOE_EP_WATCHDOG=1 (debug)
    bounds them by 2 s and traps.
  - prepare() compiles every variant before graph capture.
- op_tests/multigpu_tests: test_mega_moe_ep.py (accuracy vs ep_reference,
  CUDA graph, uneven ranks, back-to-back inputs) and bench_mega_moe_ep.py
  (perf vs MegaMoEV2).
- mega_moe/gemm_util.py: ATileLoader threads beyond the chunk count repeat a
  chunk instead of reading past the tile (V2 outputs unchanged).

Co-authored-by: Cursor <[email protected]>
Yaowu-Xiong and others added 3 commits November 12, 2026 07:51
aiter/aot/flydsl/mega_moe_ep.py builds the runtime's own MegaMoeEP inside
dry_run (FakeTensor weights, a fake hipIpc SymmetricArena) and replays
prepare() plus one forward(), so every launch variant and the activation
quant land in the cache. Rank, world size, token count and peer addresses
are launch arguments, so one job per profile serves every rank.

Profiles: DeepSeek-V4-Pro epr 48/52/56 x a8w4/a4w4 and Kimi-K2.6 epr 48
a8w4, each at MTPR 512 and 8192 (14 jobs). run_aot runs it after the
MegaMoEV2 replay; --check verifies a cache without compiling.

Co-authored-by: Cursor <[email protected]>
Rename the kernel's terse constants, helpers and arena keys to descriptive
names (e.g. TMAX -> TOKEN_SLOTS, NPES -> N_RANKS, cbar -> cta_barrier,
recv_le -> recv_expert), keep comments to the EP op itself, and remove
unused layout entries, re-exports and redundant branches. Public API and
kernel names are unchanged; the compiled binaries are byte-identical.

Co-authored-by: Cursor <[email protected]>
bench_mega_moe_ep.py --engine mori times the unfused EP MoE as ATOM runs
it online: bf16 mori dispatch, fused_moe on the gate|up interleaved MXFP4
weights with MXFP8 activations, mori combine, with ATOM's launch geometry
per phase (--mori-phase; auto picks decode at mtpr <= 512). a8w4 and
SwiGLU networks only.

Co-authored-by: Cursor <[email protected]>
…, group-aware reference

- set_weights binds preshuffled weights by pointer and refuses natural ones: a
  shuffled copy made there was freed while a captured graph still read it. The
  copies shuffled at construction live as long as the instance.
- prepare() / forward() run on the engine's device and its current stream; an
  explicit stream on another device is refused.
- ep_reference / _all_gather_variable take the EP group, so the reference
  matches the engine under DP x EP.
- mega_moe_ep_supported() checks the live GPU (get_gfx_runtime), not the build
  target list.
- test_mega_moe_ep.py: a rebind row per layer (graph replay after set_weights is
  bit-identical, eager matches the reference on the new weights), --ep-groups N,
  default spike routing sized to the EP world.

Co-authored-by: Cursor <[email protected]>

@coderfeli coderfeli left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why another mega moe ep?

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.

5 participants