Skip to content

[FlyDSL] [Perf] MegaMoE: shorten EP8 prepare chain, coalesce MXFP8 quant (gfx950) - #6900

Merged
coderfeli merged 12 commits into
ROCm:mainfrom
chushic:pr/megamoe_prepare
Nov 17, 2026
Merged

coderfeli merged 12 commits into
ROCm:mainfrom
chushic:pr/megamoe_prepare

Conversation

@chushic

@chushic chushic commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR rewrites the fast path of the MegaMoE compact-dispatch prepare kernel (mega_moe_prepare.py) for EP8 layouts on gfx95x (validated on gfx950 only).

  • Kernel (aiter main a29547a, FlyDSL 0.4.0, DeepSeek-V4-Pro a8w4, EP8, cold L2): prepare is 5.5-6.1x faster at decode (≈72-82 → 12-14 µs, CUDA graph) and 6.1x → 2.2x faster from 452 to 8192 tokens/rank (8192: 126.6 → 58.6 µs). Weighted by the calls of a live DeepSeek-V4-Pro server: 109.9 → 43.5 µs per call (2.53x; shape mix captured with the CI flag set). No measured shape is slower.
  • E2E, CI flags (DeepSeek-V4-Pro TP8/DP8/EP8, c128 agentic, n=2 vs 2, same node): output tok/s +3.5 % after warm-up (3173.6 → 3283.6, runs do not overlap) and +3.0 % over the full 35 min; interactivity p50 +6.3 %, p90 +4.0 %; TTFT p50 −5.5 %; per-rank decode step −3.6…−6.1 % at 4-23 running requests (−2.4 % at 1-3), prefill step −4…−5 %. An independent replicate on another node: +4.3 % / +4.2 %.
  • E2E, current cookbook recipe (separate fixed-slot decode instance): within noise (+0.3 % / +0.6 %). Pure-decode steps do not run this kernel there, so only prefill and mixed steps can gain.
  • Output is bit-identical to stock at every measured point, and accept length is unchanged.

Everything outside the guard (EP ≠ 8, more than 64 experts per rank, top-k > 8) compiles main's kernel unchanged (see "Stock path" below).

Updates after review (86e5ba0, 371eb60, 500523c, 8995b51, c2ad464, 216870d, f362cd8, b760aca, 5e30506, 2d66a0c, e6e42c7):

  • Fixed a BLOCK_HIST read/write race. It only affects EP8 layouts with epr 56-63 (more than 7 prefix rounds); DSV4-Pro (epr 48) is not affected.
  • Fixed the work-steal counter aliasing an epoch-gate slot when a launch uses Q == quant_cu_capacity. The counter now has a dedicated slot.
  • Fixed the tile_m/tag overlap in the count exchange. At mtpr × top-k < 64 (non-fixed-slot layouts only) the tile_m word could spill into the launch tag and hang prepare. The tag now starts at bit 8 at least; served configs are unchanged.
  • Merged latest main (a0c4b69, flydsl 0.4.2). DSv4.1 (EP8, epr 48, top-k 6) runs this fast path instead of [FlyDSL] Tune DSv4.1 EP8 A8W4 MegaMoE #7127's stock-path change; prepare is 2.4-4.7x faster than main with [FlyDSL] Tune DSv4.1 EP8 A8W4 MegaMoE #7127, and outputs are bit-identical.
  • No inline asm or private helpers left: llvm.fake.use keep-alive, a tid-indexed steal address, fx.inttoptr, update_dpp_i32. ISA of 667 prepare kernels is unchanged, except one fewer prologue instruction in the work-steal kernels.
  • FlyDSL kernel-code-cleanup pass, and main merged again (075695e, flydsl 0.5.0).
    • Removed the always-true const_expr(True), replaced arith.unwrap with .ir_value(), and removed dead params, flags and comments.
    • Removed misplaced # fmt markers and black-formatted the fast path. The formatting is its own commit, b760aca, with the AST unchanged.
    • ISA is byte-identical for all 667 kernels, outputs are bit-exact vs main, and AOT is 192/192 under flydsl 0.5.0.
    • Removed the scalar-cache warm-up (5e30506, 2d66a0c). Its loads had no consumer, so keeping them alive needed a raw llvm.intr.fake.use, and FlyDSL has no fx wrapper for it. No raw MLIR dialect use is left in the file. A paired A/B gave the cost: none for the peer-table part, and ~3% (~0.5 us) of decode prepare at bs 1/42 for the dispatch-table part. Prefill is unaffected and outputs are bit-exact.
  • Deduplicated fast-path helpers (e6e42c7, -300 lines). Merged near-duplicate functions and removed dead arms. gfx950 ISA is unchanged: 3273/3328 kernel instances are byte-identical, and the rest have identical LLVM IR, differing only by backend operand-order nondeterminism. Outputs are bit-exact vs main and AOT is 192/192. The diff is now +3855/-3.
  • Trimmed the diff from +5515/−14 to +3837/−4. Code that no fast-path compile reaches is gone, and main's compile_mega_moe_prepare stays in place.
  • Validation: both bugs were reproduced on GPU and pass after the fix. Outputs are bit-identical to the previous revision. Final ISA of all 4144 production prepare kernels matches up to compiler run-to-run noise (plus the intended changes for the two fixes). The paired prepare microbench is unchanged (epr 56 up to 1.085x faster).

Review layout. This is one file (+3.9k lines; main's code is unchanged apart from a guard and one kwarg). If you prefer, I can restructure before review, either way with a GPU re-validation:

  • Module split: the fast path in a new mega_moe_prepare_ep8.py, with main's mega_moe_prepare.py untouched except a ~10-line guard. The diff becomes a pure addition.
  • Stacked split: PR1 protocol chain → PR2 fused small-P owner and PR3 coalesced quant (both on PR1). Without PR1, PR3 gives no gain.

Motivation

On an earlier build (an older aiter with FlyDSL 0.3.4.1, before this change was rebased on main) I timed the prepare kernel's phases with in-kernel timestamps. The critical path was the cross-rank protocol chain, not the activation quant, even for 8192-token prefill. The chain: count routes, exchange per-rank histograms with the 7 peers over XGMI, plan the tile layout, fill the pair order. On that build the chain took about 65 µs at decode and 100-119 µs with 32 prepare CTAs (P=32). I did not repeat the timestamp breakdown on main; the main kernel times are under Performance.

The kernel runs once per MoE layer per step, so this latency shows up in every decode and prefill step.

Changes

All changes are in aiter/ops/flydsl/kernels/mega_moe/mega_moe_prepare.py. Call sites, the API, the workspace layout and the plan contract with Stage1/Stage2 are unchanged.

Shorter protocol chain

  • No L2 writeback per flag. On gfx950 every agent- or system-scope release lowers to buffer_wbl2, which writes back the whole dirty L2 of the XCD (during prefill mostly the concurrent quant output). Plan data and counts are now written with relaxed system/agent-scope or write-through (sc0|sc1) stores, drained with s_waitcnt vmcnt(0) plus a barrier. Only the flag the consumer acquires is published after that.
  • Each prepare CTA reduces its own histogram rows and derives its bases with an LDS prefix, instead of a serial read-modify-write in the owner. The owner pushes each reduced segment to the peers as soon as it is ready. Pushed count words carry the launch tag, so consumers poll exactly the words they need and the separate "done" round trip goes away.
  • Small batches (P ≤ 16 prepare CTAs) take a single-CTA path. The owner counts, plans and fills alone, and the group CTAs retire at once. At decode the CTA role is the block index, which removes the ticket atomic. This is safe because no CTA waits on another on this path and the grid is co-resident.
  • Host-constant dispatch and peer tables are read with scalar loads, so buffer descriptors stay in SGPRs.
  • Idle warps take the dependent work: offset derivation, next-launch fanout pairs and metadata stores.

Faster MXFP8 quant (FP8 only; buckets with tile_m ≥ 128, and the m64 P32 bucket from 2048 tokens)

  • 16 B per lane, the 1x32 amax across a lane quad with DPP, packed cvt_pk_fp8.
  • A software-pipelined load stream with work stealing over the last two rounds, plus a larger quant CTA count per compile key (see Known gaps on prepare_quant_cu).
  • Output is bit-identical to quant.emit_per_1x32_mx_fp8_group. FP4 keeps the existing per-group quant.

Why private plan/group emitters instead of extending dispatch.py. The fast path does not call dispatch.emit_dispatch_plan / emit_dispatch_group; it has its own _emit_plan / _emit_group (it reuses dispatch._classify_fanout_wave_route, _wave_inclusive_scan_i32 and the slot table as is). Relative to dispatch.py they change:

  • publish order: data with relaxed/write-through stores, then one vmcnt drain + barrier, then the flag (dispatch.py: one release per flag);
  • write-through stores on the owner and group CTAs (an explicit compile-time argument per variant);
  • tagged per-segment count words pushed early, instead of a reduced block and a done flag;
  • group self-reduce with LDS prefix, idle-warp offset/pair derivation, and the fused small-P owner, which change the phase structure and not just store flavours.

Only main's prepare kernel calls the shared emitters. Turning these differences into parameters of dispatch.py would mean editing the code main runs for every other layout and for the stock fallback here, which this PR keeps byte-identical on purpose. Drift risk: a fix to the shared emitters (e.g. from the #6127 Stage1 work) has to be checked against both copies until they are merged. I offer as a follow-up moving the private emitters into their own module; it needs a GPU re-validation.

Stock path. Main's compile_mega_moe_prepare stays where it is and is unchanged except for two additions:

  • the new optional m64_qdpp kwarg;
  • an early if _fast_prepare_supported(...): return _compile_fast_mega_moe_prepare(...).

Every other line of that function shows as unchanged context in the diff:

git diff origin/main...HEAD -- aiter/ops/flydsl/kernels/mega_moe/mega_moe_prepare.py | grep -c '^-[^-]'   # 4: import lines only

Guard and rollback.

  • _fast_prepare_supported(npes, epr, topk) sits next to the dispatch in compile_mega_moe_prepare: EP8, epr ≤ 64, top-k ≤ 8. That covers DeepSeek-V4-Pro (epr 48), R1 and GLM-5.2 (epr 32), and also layouts with redundant experts such as V4-Pro with 32 or 64 extra experts (epr 52/56; the open MoonEP PR [FlyDSL] [CI] [MoonEP] Balance MegaMoE v2 prefill with MoonEP placed inside the compact prepare #6268 with 8 extra experts per rank gives epr 56). Correctness was checked with the repo test across the guard: epr 16/32/48/52/56/64 and top-k 2/4/6/8, including the epr 64 boundary (see Testing). Perf data exists only for V4-Pro, R1 and GLM-5.2.
  • Everything else compiles main's kernel, under the same kernel name (_v13). Fast-path kernel names contain _v14, so traces show which path ran. The gfx95x arch check is unchanged.
  • No new environment variable. Rollback is a revert of this one file. If you prefer a narrower activation, I can restrict the guard to the layouts with perf data (epr 32/48, top-k 6/8); that is a one-line change but needs a GPU re-run.

Performance

Setup. 8x MI355X (gfx950), ROCm 7.2.0. Docker image built from aiter main a29547a and sglang main d0a7565436 (plus a one-line import fix needed for sglang main to serve DeepSeek-V4 on gfx950, unrelated to MoE), FlyDSL 0.4.0. Stock and PR arms use the same image and differ only in mega_moe_prepare.py and its regenerated AOT cache. These numbers predate the merge of main a0c4b69 (FlyDSL 0.4.2, #7127). On that merged head I re-measured prepare against main (see Testing, "Merge with main"): V4-Pro 5.2-6.2x at decode and 2.1x at 8192, consistent with the table below.

Microbench: prepare kernel time (µs), DeepSeek-V4-Pro a8w4, EP8, MTPR 8192

Method. My own 8-rank harness, not in the repo: a real MegaMoEV2 forward per measurement, prepare kernel time from the torch profiler, slowest rank's median over 50 iterations, 1 GiB L2 flush before every forward. Decode is timed under CUDA graph (as served), prefill eager. Each sweep runs in a fresh 8-rank process; stock (3 processes) and PR (4 processes) are interleaved (a4w4 rows: 30 iterations, 4 vs 4 processes; MTPR 16384 eager rows: 4 vs 4; GLM-5.2 / R1 / Kimi checks below: 20 iterations, 1 process per arm). Medians over processes, range in brackets; "worst" = slowest PR process vs fastest stock process. I did not use bench_mega_moe_v2.py --mega-only for these numbers (it replays warm, without an L2 flush); I can add the harness as a test-only change if that helps.

tokens/rank (bucket) stock + PR speedup median / worst
1 (decode, graph) 71.6 (71.5-72.1) 13.0 (12.3-13.7) 5.52x / 5.22x
42 (decode, graph) 73.9 (73.7-75.0) 12.2 (12.2-13.3) 6.04x / 5.53x
128 (decode, graph) 76.0 (74.8-77.0) 12.4 (12.2-13.0) 6.14x / 5.75x
224 (decode, graph) 82.1 (81.8-82.2) 14.0 (13.2-15.4) 5.85x / 5.30x
452 (m64) 85.5 (85.5-86.0) 14.1 (14.0-14.2) 6.07x / 6.03x
868 (m64) 89.1 (89.1-89.9) 18.2 (18.1-18.7) 4.90x / 4.77x
1548 (m64) 96.4 (95.9-97.4) 23.6 (23.4-23.7) 4.09x / 4.04x
2394 (m64 P32 qdpp) 102.6 (102.5-103.3) 28.0 (27.9-28.0) 3.67x / 3.66x
4917 (m128) 117.9 (115.8-118.3) 38.0 (37.5-38.0) 3.10x / 3.05x
8192 (m128) 126.6 (125.5-126.9) 58.6 (58.4-58.8) 2.16x / 2.13x
MTPR 16384: 1 / 42 / 224 (graph) 76.0 / 75.4 / 83.2 15.9 / 13.8 / 16.2 4.77x / 5.45x / 5.12x (worst 4.23-4.92x)
MTPR 16384: 8192 / 12288 / 16384 129.2 / 141.2 / 152.1 59.2 / 84.5 / 100.8 2.18x / 1.67x / 1.51x
mixed per-rank 1/12/452/868/1548/2394/4917/8192 209.1 (208.9-210.6) 141.4 (140.5-142.7) 1.48x / 1.46x
a4w4 (eager): 1 / 42 / 2394 / 8192 74.0 / 73.6 / 99.3 / 122.2 14.4 / 12.0 / 24.9 / 71.5 5.13x / 6.15x / 4.00x / 1.71x
  • Call-weighted over the 51 prepare shapes recorded from a live DeepSeek-V4-Pro server running the CI flag set (nearest measured point): 109.9 → 43.5 µs per call, 2.53x (worst case 2.49x). Decode shapes alone 5.96x; 8192-token prefill carries 67 % of the weight (2.16x).
  • Where the gain stops. At large token counts the fused MXFP8 quant stream is the floor: 2.2x at 8192, 1.5x at 16384. No measured shape is below 1.0x.
  • Other layouts inside the guard (1 run each, 1 / 42 / 452 / 2394 / 8192 tokens): GLM-5.2 5.04x / 5.62x / 6.01x / 3.91x / 2.56x; R1 5.19x / 5.90x / 6.15x / 3.60x / 2.11x.
  • Outside the guard (kimi_k3_route, epr 112, top-k 16): the same _v13 stock kernel runs, 0.99-1.00x.
  • Op level. The sum of all kernels in one MegaMoE forward (prepare + Stage1 + Stage2 + combine, same runs) drops by 45-100 µs at the V4-Pro, R1 and GLM-5.2 points (more under Zipf routing), e.g. 42 tokens 509 → 446 µs (graph), 8192 tokens 4604 → 4528 µs (eager). These are single-median deltas without a spread.

End to end: DeepSeek-V4-Pro, TP8 / DP-attention 8 / EP8, MegaMoE a8w4, DSPARK MTP, c128

Setup. Agentic trace replay with aiperf (InferenceX dsv4/sglang/mi355x-fp4-mtp/agentic.yaml, variant override_tp8_c128_dp_ep8_megamoe_hicache, seed 42, simulated accept length 3.77). One node, fresh container and caches per arm; the PR arm ships only the new file plus the cache written by python -m aiter.aot.flydsl.mega_moe --quant a8w4. 1422 warm-up requests are dropped, then a 35-min profile. "[10,35]" scores requests that start after minute 10 and end by minute 35; "full" is the whole profile. Interactivity = 1/ITL (tok/s/user). Flag sets:

  • CI: the flags of the InferenceX CI job (SGLANG_AMD_FLYDSL_MEGA_MOE_MTPR=8192, chunked prefill 65536, prefill-decode interval 20). Every step runs the compact path, so prepare runs in every decode and prefill step.
  • cookbook: the current recipe (InferenceX [Fix][FlyDSL] Handle remainder workgroups in MoE XCD swizzle #4315): MTPR 16384, SGLANG_AMD_FLYDSL_MEGA_MOE_DECODE_MTPR=512, AITER_MEGA_FIXED_SLOT_MAX_MTPR=1023, chunked prefill 131072, interval 40. Pure-decode steps use the fixed-slot decode instance, which does not call this kernel.
flags arm (n) output tok/s [10,35] (range) Δ full window Δ interactivity p50 / p90 TTFT p50 (s) accept len
CI stock (2) 3173.6 (3154.8-3192.5) - - 36.74 / 33.10 2.960 3.770-3.774
CI + PR (2) 3283.6 (3268.0-3299.2) +3.47 % +3.05 % 39.05 / 34.41 (+6.3 % / +4.0 %) 2.797 (−5.5 %) 3.767
cookbook stock (1) 3318.1 - - 41.82 / 37.16 4.911 3.773
cookbook + PR (2) 3327.3 (3295.8-3358.7) +0.28 % +0.58 % 42.02 / 37.27 (+0.5 % / +0.3 %) 4.806 (−2.1 %) 3.767-3.772
  • CI flags. Both PR runs are above both stock runs; stock run-to-run spread is 1.2 %. Per pair: +2.4 % and +4.6 % on [10,35]. Per-rank step time at equal batch size ([10,35], median): decode −3.6…−6.1 % at 4-23 running requests and −2.4 % at 1-3 (the 24-31 bucket has only 9 PR log lines and is left out), prefill −3.9…−5.4 % from 512 new tokens up. A replicate on a second node (n=2 vs 2) gave +4.25 % [10,35] / +4.20 % full, decode steps −5…−8 %.
  • cookbook flags. The change is within noise: the two PR runs bracket the single stock run. The second stock run was not completed. Prefill step times are within ±2 %. A replicate on a third node (n=2 vs 2) gave +0.1 % / +1.0 %. I do not claim an e2e gain for this recipe.
  • Clean runs. 0 request errors and no EPLB warm-up hang in any arm. With the regenerated AOT cache, no prepare kernel JIT-compiled at startup, warm-up or during the profile in any PR arm.

Accuracy

  • Quant: bit-identical to the existing MXFP8 group quant; FP4 keeps the existing quant.
  • Prepare: only changes how routes are counted and published. The plan and pair order it writes are the same.
  • Bit-exact vs stock: per-rank sha256 of the bf16 MoE output is identical between stock and PR at all 78 harness points (v4_pro a8w4/a4w4, MTPR 1024/8192/16384, R1, GLM-5.2, kimi_k3_route, Zipf routing, mixed and zero-token ranks).
  • test_mega_moe_v2.py vs the fp32 reference: all configurations listed under Testing pass, with per-bs rel-L2 identical to stock (a8w4 0.0591-0.0592, a4w4 0.2110-0.2121).
  • Guard path: kimi_k3_route runs the stock _v13 kernel and is bit-exact vs stock.
  • Accept length (e2e): 3.764-3.774 in every arm (both nodes and flag sets; simulated golden 3.77).

FlyDSL AOT cache

The prepare cache keys change, so the shipped FlyDSL AOT cache has to be regenerated.

  • An image built with PREBUILD_KERNELS=1 does that automatically. preload_mega_moe_prepare also compiles the second (qdpp) variant of the m64 P32 bucket.
  • Manually: python -m aiter.aot.flydsl.mega_moe --quant a8w4 and --quant a4w4. Each prints Compiled: 192 ok, 0 failed on main.
  • Each compiled variant's write-through policy is an explicit compile-time argument (no module state), so the cache keys do not depend on compile order. After --quant a8w4 alone, test_mega_moe_v2.py (MTPR 8192 and 16384, mixed and zero-token ranks) had 0 runtime cache misses, also with FLYDSL_RUNTIME_RUN_ONLY=1, and the e2e PR arms compiled no prepare kernel at runtime.
  • If only the source file is swapped into an existing image, every prepare specialization JIT-compiles at first use, with all EP8 ranks waiting. On main with FlyDSL 0.4.0 these compiles were short: an e2e arm that missed the cache for some prepare kernels had no engine-wide stall above 5 s. On an older FlyDSL (0.3.4.1) each one took about 30 s.

How to reproduce

run() { MORI_SHMEM_HEAP_SIZE=40G torchrun --standalone --nproc_per_node=8 "$@"; }
T="op_tests/multigpu_tests/test_mega_moe_v2.py --accuracy-max-bs 8192"
python -m aiter.aot.flydsl.mega_moe --quant a8w4 && python -m aiter.aot.flydsl.mega_moe --quant a4w4
# served buckets, MTPR classes, both quant modes
run $T --network v4_pro --quant a8w4 --max-tok-per-rank 8192 --bs-list 1,7,12,21,42,84,128,168,224,452,868,1548,2394,3190,4917,7404,8192
run $T --network v4_pro --quant a8w4 --max-tok-per-rank 16384 --bs-list 1,42,224,2394,8192,16384 --accuracy-max-bs 16384
run $T --network v4_pro --quant a4w4 --max-tok-per-rank 8192 --bs-list 1,42,224,452,2394,8192
for M in 512 1024; do run $T --network v4_pro --max-tok-per-rank $M --bs-list 1,12,42,128,224,$M --accuracy-max-bs $M; done
# per-rank token skew, including zero-token ranks
for R in 1,12,452,868,1548,2394,4917,8192 0,1,1,1,1,1,1,1 0,42,42,42,42,42,42,42 0,8192,8192,8192,8192,8192,8192,8192 \
         0,1,42,224,2048,2394,3190,7404 0,0,0,0,0,0,0,0; do
  run $T --network v4_pro --max-tok-per-rank 8192 --rank-tokens $R --bs-list 8192; done
run $T --network v4_pro --quant a4w4 --max-tok-per-rank 8192 --rank-tokens 0,1,42,224,2048,2394,3190,7404 --bs-list 8192
# other layouts inside the guard, and the stock path
for N in r1_v3 glm52 kimi_k3_route; do run $T --network $N --max-tok-per-rank 8192 --bs-list 1,42,452,2394,8192; done
for F in --force-fanout-boundary --inject-invalid-route; do run $T --network kimi_k3_route --max-tok-per-rank 8192 --bs-list 42,2394 $F; done
run $T --network kimi_k3_route --max-tok-per-rank 8192 --bs-list 1 --force-padding-boundary
# routing stress on the fast path
run $T --network v4_pro --max-tok-per-rank 8192 --bs-list 1,42,2394,8192 --pad-tail-rows 3
run $T --network v4_pro --max-tok-per-rank 8192 --bs-list 42,1024 --concentrate-experts 4
run $T --network v4_pro --max-tok-per-rank 8192 --bs-list 42,2394,8192 --zipf 1.2
run $T --network v4_pro --max-tok-per-rank 8192 --bs-list 1,42,2394,8192 --burst-depth 16

E2E. sglang d0a7565436, server and router flags exactly as in the InferenceX recipe above (CI flag set = the 2026-10-07 CI job of that recipe; cookbook = the recipe after #4315), aiperf agentic replay at concurrency 128, 35-min profile after warm-up. Both arms use the same container image; the PR arm bind-mounts the new mega_moe_prepare.py and the AOT cache from the command above.

Known gaps

  • Quant CTA count overrides the config. For the quant_dpp buckets the kernel raises num_quant_cu (from MegaMoEConfig.prepare_quant_cu, 64-192) to 216 (m128) / 80 (m64 P32), clamped to quant_cu_capacity − 1 − P. 216 assumes a 256-CU part for co-residency (grid 1+P+Q ≤ 249). Follow-up offered: move the values into prepare_quant_cu per bucket or derive them from the CU count.
  • R1, GLM-5.2 and other in-guard layouts run the fast path without model-specific tuning. R1 and GLM-5.2 pass the repo test, are bit-exact vs stock and 2.1-6.2x faster at the kernel level (1 run each). The synthetic layouts (epr 16/52/56/64, top-k 2/4) were checked for correctness only (rel-L2 identical to stock, not sha256-compared); no perf numbers and no e2e on any model except V4-Pro. See "Guard and rollback" for narrowing.
  • Cookbook recipe: no e2e gain above noise (see above), because its pure-decode steps do not run this kernel.
  • The repo test unifies the config across ranks. As served, ranks can pick different prepare variants in one step; --rank-tokens covers mixed tokens, but the fields are still unified.
  • The m64 P32 variant is picked on the host from the live token count; decode CUDA graphs stay below that bucket.
  • MTPR 512/1024 decode-instance classes are not in the default AOT set (same as stock).
  • No gfx942 path: gfx95x-only, as before.

Testing

test_mega_moe_v2.py and bench_mega_moe_v2.py are in skip_tests of .github/scripts/aiter_test.sh, which also applies with ci:multi-gpu. aiter CI therefore does not run any test of this kernel; all correctness and perf runs were manual on 8x MI355X with main a29547a.

  • test_mega_moe_v2.py: every command under "How to reproduce" passes (rc 0, graph replay PASS) with rel-L2 identical to stock: 22 configurations, including MTPR 512/1024/8192/16384, a8w4 and a4w4, mixed and zero-token per-rank tokens, the all-zero step, R1, GLM-5.2, kimi_k3_route with fanout/invalid-route/padding boundaries, pad-tail, concentrated experts, Zipf 1.2 and burst 16.
  • These runs, the microbench and the bit-exactness checks used the revision just before the last refactor, which only moved the write-through policy from module state into an explicit compile-time argument. With the final file I re-ran the AOT tool for a8w4 and a4w4 (192 ok, 0 failed each), the a8w4 repo tests (MTPR 8192 and 16384, mixed and zero-token ranks) and the a4w4 repo tests (bs 1-8192, zero-token mixed and 0,1,1,1,1,1,1,1 ranks), all with 0 runtime cache misses and also passing with FLYDSL_RUNTIME_RUN_ONLY=1, rel-L2 identical to stock and to that revision; plus 29 a8w4 harness points: outputs bit-identical to that revision, prepare time ratio 1.002 (0.974-1.057). The e2e runs used the final file.
  • Guard width, final file: the repo test with extra NETWORKS entries (test-side only, not in this PR; I can add them) at epr 52/56/64 with top-k 6, epr 64 with top-k 8, epr 16 with top-k 4 and epr 32 with top-k 2, bs 1/42/452/2394/8192 at MTPR 8192, plus the zero-token mixed ranks at epr 56 and 64. All take the fast path, pass, and give rel-L2 identical to stock main (6 digits) at every bs.
  • Review fixes (86e5ba0, 371eb60).
    • BLOCK_HIST race (epr 56). The race window is not hit naturally (20x repeats were bit-stable). I widened it with a test-only s_sleep in each group CTA between the GROUP_DONE spin and the BLOCK_HIST read. Before the fix this faults on all 8 GPUs; after the fix it passes and is bit-stable.
    • Steal-counter alias. I ran one launch with Q == capacity, then a normal launch at the same P. Before the fix the normal launch gives relL2 0.72; after the fix it gives 0.0592.
    • Generated code. Final gfx950 ISA was compared over all 4144 production prepare kernels plus 3253 kernels of a coverage sweep (EP8 epr 16-64, top-k 2-8, MTPR 512-32768, fp8/fp4, P sweep). The only differences are:
      • the counter-offset immediate in the work-steal kernels;
      • about 950 fewer instructions in the epr 56 non-fused kernels;
      • compiler run-to-run operand reordering, of the same kind and amount as compiling the previous revision twice.
    • Outputs and AOT. Outputs are bit-identical to the previous revision (test_mega_moe_v2 a8w4/a4w4/epr56, 112 rank-points). AOT compiles 192/192 per quant, and FLYDSL_RUNTIME_RUN_ONLY=1 passes.
    • Paired prepare microbench (3 processes per arm, cold L2): within noise for V4-Pro a8w4/a4w4 decode and prefill; epr 56 prefill 0.98-1.085x (faster at 1548/4917).
  • tile_m/tag fix (500523c). At mtpr × top-k < 64 on non-fixed-slot layouts, the tile_m word spilled into the launch tag.
    • Before the fix these configs hang: GLM-5.2 mtpr 2 (a8w4 and a4w4), EPLB epr 52 a8w4 mtpr 4, and epr 52 a4w4 mtpr 8 (bs 8 with tile_m 64).
    • After the fix all of them pass.
    • V4-Pro MTPR 8192 outputs are bit-identical to the previous revision. AOT is 192/192, and RUN_ONLY passes.
  • Merge with main a0c4b69 + API cleanup (8995b51, c2ad464). Validated on latest main with FlyDSL 0.4.2.
    • Generated code: gfx950 ISA was compared over 667 prepare kernels (V4-Pro MTPR 8192/16384, DSv4.1, epr 56, GLM-5.2). 626 are identical. The 41 work-steal kernels differ only by one fewer prologue instruction, and their waitcnt/barrier/atomic sequence is the same.
    • Outputs: bit-identical to main for V4-Pro a8w4 and a4w4 and for DSv4.1 a8w4 (bs 1-8192, MTPR 8192). This includes the buckets [FlyDSL] Tune DSv4.1 EP8 A8W4 MegaMoE #7127 retuned: MTPR 8192 bs 100, MTPR 512, and MTPR 32768 bs 1/128/512.
    • Prepare vs main (paired, cold L2):
      • DSv4.1 is 3.6-4.4x faster at decode and 4.7x → 2.4x faster from 452 to 8192 tokens. Main here runs [FlyDSL] Tune DSv4.1 EP8 A8W4 MegaMoE #7127's _pf1_pg1_qfo1 kernel.
      • V4-Pro is 5.2-6.2x faster at decode and 2.1x faster at 8192.
      • The API cleanup itself is within noise on the work-steal buckets.
    • AOT: the repo tool builds 192/192 kernels for a8w4 and a4w4, and --check (RUN_ONLY) finds all 192. One test-only workaround was needed: in this image, torch 2.9.1 cannot run the hidden-GPU replay's build_p2p_table, so the harness returned a zero table. The same failure happens with main's unmodified file.
  • Validating on main found two issues in an earlier revision of this change, both fixed here and covered by the tests above: a rank with zero tokens (empty topk_ids) faulted on the speculative top-k index load, so all top-k index buffers are now bounded to tokens × top-k; and the FP8 DPP quant stream was not restricted to its buckets, so a4w4 output was wrong and the m32/m64 FP8 buckets quantized twice. The zero-token --rank-tokens cases and the a4w4 runs fail on that revision and pass now.
  • Unit tests run: op_tests/multigpu_tests/test_mega_moe_v2.py (8 GPU, manual, see above)
  • Performance benchmarks run (kernel microbench and e2e, see Performance)
  • Tested on MI250X: not applicable (gfx95x-only kernel)
  • Tested on MI300X: not applicable (gfx95x-only kernel)
  • Tested on MI355X (gfx950)

Documentation

  • Docstrings updated
  • User guide updated: not needed
  • Performance guide updated: not needed

Dependencies

  • No new third-party dependencies added

Breaking Changes

None. The API and workspace layout are unchanged; compile_mega_moe_prepare gains one new internal optional kwarg (m64_qdpp, default False), set by the host-side bucket gate. Layouts outside the guard run the previous kernel.

PR Self-Review

Reviewed revision

e6e42c7

Behavior and intent

  • What changes. The MegaMoE compact-dispatch prepare kernel gets a new fast path for EP8 layouts with epr ≤ 64 and top-k ≤ 8 on gfx95x:
    • a shorter cross-rank count → plan → fill chain (tagged histogram push, group self-prefix, idle-warp offset derivation);
    • a fused single-CTA owner for small P;
    • a coalesced, work-stealing MXFP8 quant.
  • Why. On main, prepare's critical path is this protocol chain, not the activation quant. The fast path makes prepare 5.5-6.1x faster at decode and 2.2x at 8192 tokens/rank, and gives +3.5 % e2e output tok/s on DeepSeek-V4-Pro with the CI flag set.
  • Other layouts. Every other layout still compiles main's compile_mega_moe_prepare unchanged.

Validation and unverified scope

  • Validated. All runs on 8x MI355X (gfx950), ROCm 7.2, aiter main a29547a, FlyDSL 0.4.0:
    • op_tests/multigpu_tests/test_mega_moe_v2.py, 22 configurations: a8w4/a4w4, MTPR 512-16384, mixed and zero-token ranks, R1, GLM-5.2, kimi_k3_route. Rel-L2 is identical to stock.
    • Guard-width runs: epr 16-64, top-k 2-8.
    • Output sha256 is bit-identical to stock at 78 harness points.
    • AOT python -m aiter.aot.flydsl.mega_moe --quant a8w4|a4w4: 192/192 compiled, and runs with FLYDSL_RUNTIME_RUN_ONLY=1 hit the cache with 0 misses.
    • Prepare microbench, paired, cold L2.
    • E2E: aiperf agentic c128 on DeepSeek-V4-Pro, n=2 vs 2.
    • Revision 371eb60: final ISA of all 4144 production prepare kernels matches the previous revision up to compiler run-to-run noise, and outputs are bit-identical to it.
    • Revision b760aca (main 075695e, FlyDSL 0.5.0): ISA byte-identical to c2ad464 for all 667 kernels. Outputs bit-exact vs main for V4-Pro a8w4/a4w4 and DSv4.1 a8w4. Prepare is 2.2-5.9x (V4-Pro) and 2.4-4.4x (DSv4.1) faster than main. AOT 192/192, and --check passes.
    • Revision c2ad464, merged on main a0c4b69 with FlyDSL 0.4.2:
      • ISA of 667 prepare kernels is unchanged, except one fewer work-steal prologue instruction.
      • Outputs are bit-identical to main for V4-Pro and DSv4.1, including the buckets [FlyDSL] Tune DSv4.1 EP8 A8W4 MegaMoE #7127 retuned.
      • Prepare is 2.1-6.2x faster than main.
      • AOT is 192/192 and --check passes.
  • Unverified.
    • No perf data for synthetic in-guard layouts (epr 16/52/56/64, top-k 2/4); they were checked for correctness only.
    • No e2e on any model other than V4-Pro.
    • The cookbook recipe shows no e2e gain above noise.
    • No gfx942 (the kernel is gfx95x-only, as before).
    • aiter CI skips test_mega_moe_v2.py, so all of the above was run manually.

PR-specific question

  • Most important boundary. The cross-rank / cross-CTA ordering of the new protocol: tagged count words, the group self-prefix after GROUP_DONE, and the epoch-gate and work-steal slots.
  • Bugs found here and fixed (revisions 86e5ba0, 500523c):
    • A BLOCK_HIST read/write race at epr 56-63. Reproduced with an injected group delay: all 8 GPUs faulted before the fix; after the fix the run passes and is bit-stable.
    • The steal counter aliasing an epoch gate at Q == capacity. Reproduced: relL2 0.72 before the fix, 0.0592 after.
    • The tile_m word spilling into the count-exchange tag at mtpr × top-k < 64. Reproduced: prepare hangs before the fix (GLM-5.2 mtpr 2, epr 52 mtpr 4/8) and passes after it.
  • Other coverage:
    • zero-token ranks and mixed per-rank tokens;
    • burst 16;
    • graph replay;
    • the epr 64 guard boundary.
  • Rollback. The guard _fast_prepare_supported limits the blast radius, and rollback is a revert of one file.

Changed op tests

None.

…ant (gfx950)

The compact prepare kernel's critical path is the cross-rank protocol
chain (count, histogram exchange over XGMI, plan, pair-order fill), not
the activation quant. This change shortens that chain for EP8 layouts
with at most 64 experts per rank and top-k <= 8 (DeepSeek-V4-Pro, R1,
GLM-5.2) and keeps main's kernel for every other layout.

Protocol:
- Publish plan data and flags with relaxed system/agent-scope or
  write-through (sc0|sc1) stores drained by s_waitcnt vmcnt(0) plus a
  barrier, instead of a release fence per flag. On gfx950 each agent or
  system release lowers to buffer_wbl2, which writes back the whole
  dirty L2 of the XCD, including the concurrent quant output.
- Prepare CTAs reduce their own histogram rows and derive their bases
  with an LDS prefix; the owner pushes each reduced segment to the peers
  as soon as it is ready. Pushed counts carry the launch tag, so
  consumers poll exactly the words they need.
- For P <= 16 (decode and small prefill) the owner CTA counts, plans and
  fills alone; group CTAs retire at once and, at decode, the role is the
  block index (no ticket atomic). All roles on this path are
  self-contained and the grid is co-resident.
- Host-constant dispatch and peer tables are read with scalar loads so
  descriptors stay in SGPRs.
- The top-k index buffer views are bounded to the live rows
  (tokens * top-k * 4 B), so the clamped and speculative index loads of
  a rank with zero tokens are out-of-bounds zero-fills, not faults.

Quant (FP8, tile_m >= 128, and the m64 P32 bucket from 2048 tokens):
16 B per lane, 1x32 amax across a lane quad with DPP, packed
cvt_pk_fp8, a software-pipelined stream with work stealing on the last
two rounds, and a larger per-compile-key quant CTA count. Output is
bit-identical to quant.emit_per_1x32_mx_fp8_group. FP4 keeps the
existing per-group quant.

Layouts outside the guard (Kimi-K3, EP2/EP4, epr > 64) compile the
previous kernel unchanged. No new environment variable. Fast-path
kernel names contain _v14. The FlyDSL AOT cache must be
regenerated, since the prepare cache keys change.

Signed-off-by: Chushi Chen <[email protected]>
@chushic
chushic requested a review from a team October 24, 2026 06:23
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
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 gfx1201 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 6900 --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.

- Owner fallback prefix (more than 7 rounds of 64 segments, e.g. EP8 epr 56-63)
  no longer overwrites the raw BLOCK_HIST counts when the group CTAs
  self-prefix: a group that is still reading them after GROUP_DONE could
  otherwise take offsets for counts.
- The quant work-steal counter moves to PREP_EPOCH_GATE row 0 (slot P),
  which is never an epoch gate (P >= 1), so a launch with
  Q == quant_cu_capacity can no longer leave its epoch value in the counter.

Signed-off-by: Chushi Chen <[email protected]>
…ile in place

The fast path is only compiled for EP8 with epr <= 64 and top-k <= 8
(_fast_prepare_supported). Remove code no compile on that path reaches:
- 16 helpers that are never executed (alternate count/fill/offset
  variants and copies of dispatch.py helpers);
- branches the guard makes impossible (not ll / not split_meta /
  epr > 64 ...) and the always-true ll, split_meta, own_ll, fused_pairs
  and fused_regs flags;
- the non-merged section-ready init: Stage1 already requires
  payload_chunk_rows % sort_block_m == 0 for compact dispatch.

Keep main's compile_mega_moe_prepare where it was instead of moving it;
it now hands supported layouts to _compile_fast_mega_moe_prepare.

Generated code is unchanged: final ISA of all production prepare kernels
matches the previous revision up to compiler run-to-run noise, and
test_mega_moe_v2 outputs are bit-identical.

Signed-off-by: Chushi Chen <[email protected]>
@aiter-bot

aiter-bot commented Oct 30, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision e6e42c74a59d · 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

- **What changes.** The MegaMoE compact-dispatch prepare kernel gets a new fast path for EP8 layouts with epr ≤ 64 and top-k ≤ 8 on gfx95x:
  - a shorter cross-rank count → plan → fill chain (tagged histogram push, group self-prefix, idle-warp offset derivation);
  - a fused single-CTA owner for small P;
  - a coalesced, work-stealing MXFP8 quant.
- **Why.** On main, prepare's critical path is this protocol chain, not the activation quant. The fast path makes prepare 5.5-6.1x faster at decode and 2.2x at 8192 tokens/rank, and gives +3.5 % e2e output tok/s on DeepSeek-V4-Pro with the CI flag set.
- **Other layouts.** Every other layout still compiles main's `compile_mega_moe_prepare` unchanged.

Validation and unverified scope

- **Validated.** All runs on 8x MI355X (gfx950), ROCm 7.2, aiter main a29547a2f, FlyDSL 0.4.0:
  - `op_tests/multigpu_tests/test_mega_moe_v2.py`, 22 configurations: a8w4/a4w4, MTPR 512-16384, mixed and zero-token ranks, R1, GLM-5.2, kimi_k3_route. Rel-L2 is identical to stock.
  - Guard-width runs: epr 16-64, top-k 2-8.
  - Output sha256 is bit-identical to stock at 78 harness points.
  - AOT `python -m aiter.aot.flydsl.mega_moe --quant a8w4|a4w4`: 192/192 compiled, and runs with `FLYDSL_RUNTIME_RUN_ONLY=1` hit the cache with 0 misses.
  - Prepare microbench, paired, cold L2.
  - E2E: aiperf agentic c128 on DeepSeek-V4-Pro, n=2 vs 2.
  - Revision 371eb607f: final ISA of all 4144 production prepare kernels matches the previous revision up to compiler run-to-run noise, and outputs are bit-identical to it.
  - Revision b760acac8 (main 075695e89, FlyDSL 0.5.0): ISA byte-identical to c2ad46460 for all 667 kernels. Outputs bit-exact vs main for V4-Pro a8w4/a4w4 and DSv4.1 a8w4. Prepare is 2.2-5.9x (V4-Pro) and 2.4-4.4x (DSv4.1) faster than main. AOT 192/192, and `--check` passes.
  - Revision c2ad46460, merged on main a0c4b69c1 with FlyDSL 0.4.2:
    - ISA of 667 prepare kernels is unchanged, except one fewer work-steal prologue instruction.
    - Outputs are bit-identical to main for V4-Pro and DSv4.1, including the buckets #7127 retuned.
    - Prepare is 2.1-6.2x faster than main.
    - AOT is 192/192 and `--check` passes.
- **Unverified.**
  - No perf data for synthetic in-guard layouts (epr 16/52/56/64, top-k 2/4); they were checked for correctness only.
  - No e2e on any model other than V4-Pro.
  - The cookbook recipe shows no e2e gain above noise.
  - No gfx942 (the kernel is gfx95x-only, as before).
  - aiter CI skips `test_mega_moe_v2.py`, so all of the above was run manually.

PR-specific question

- **Most important boundary.** The cross-rank / cross-CTA ordering of the new protocol: tagged count words, the group self-prefix after GROUP_DONE, and the epoch-gate and work-steal slots.
- **Bugs found here and fixed (revisions 86e5ba081, 500523c57):**
  - A BLOCK_HIST read/write race at epr 56-63. Reproduced with an injected group delay: all 8 GPUs faulted before the fix; after the fix the run passes and is bit-stable.
  - The steal counter aliasing an epoch gate at Q == capacity. Reproduced: relL2 0.72 before the fix, 0.0592 after.
  - The tile_m word spilling into the count-exchange tag at mtpr × top-k < 64. Reproduced: prepare hangs before the fix (GLM-5.2 mtpr 2, epr 52 mtpr 4/8) and passes after it.
- **Other coverage:**
  - zero-token ranks and mixed per-rank tokens;
  - burst 16;
  - graph replay;
  - the epr 64 guard boundary.
- **Rollback.** The guard `_fast_prepare_supported` limits the blast radius, and rollback is a revert of one file.

Changed op tests

None.

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
  • PASS — Aiter Test Gate: passed

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

The tile_m word pushed to every peer is fz_tile_m | (launch tag << tag_shift)
with tag_shift = bit_length(mtpr * topk).  When a plan's tile_m (32, or 64
for fp4 small buckets) is >= 2^tag_shift, i.e. mtpr * topk < 64 on a
non-fixed-slot EP8 layout (e.g. R1/GLM at mtpr 1-2, V4 EPLB epr 52/56 at
mtpr <= 8), tile_m bits land in the tag: the peer either never sees the
expected tag (hang) or decodes tile_m as 0.

Start the tag at bit 8 at least (tile_m <= 128).  The shift still depends
only on mtpr and topk, so it stays identical on all ranks even when they
pick different tile_m.  For mtpr * topk >= 128 (every served and AOT
config) tag_shift and the generated code are unchanged.

Signed-off-by: Chushi Chen <[email protected]>
… APIs

- Scalar-cache warm-up: keep the s_buffer_load results alive with
  llvm.fake.use (same idiom as mla_gfx1250 keep_alive) plus an explicit
  s_waitcnt lgkmcnt(0), instead of an empty side-effecting inline asm.
- Quant work steal: index the in-loop grab address by tid (only tid 0
  issues it, so the address is unchanged) instead of an opaque-zero
  v_mov_b32 asm; the divergent address still keeps the AMDGPU atomic
  optimizer off the grab.
- Use fx.inttoptr instead of the private comm_ops._to_ptr_global, and
  dpp_utils.update_dpp_i32 instead of raw rocdl.update_dpp + ir_value().

gfx950 ISA of all 667 compiled prepare kernels is unchanged except the
work-steal kernels' prologue (v_mov_b32 + v_ashrrev_i32 -> v_lshlrev_b32,
same waitcnt/atomic sequence); outputs bit-identical to main.

Signed-off-by: Chushi Chen <[email protected]>
- Drop the always-true `if const_expr(True):` in _emit_plan.
- arith.unwrap -> .ir_value(); drop the raw `arith` import; use
  fx.rocdl / fx.math instead of the module aliases.
- Keep-alive of the scalar-cache warm-up loads uses the typed LLVM-dialect
  op llvm.intr_fake_use instead of call_intrinsic by name (FlyDSL has no
  fx wrapper for an operand-only keep-alive).
- Remove unused parameters, always-true/alias flags, dead stores, a
  duplicate tid, and stale comments; remove misplaced `# fmt: off/on`
  markers (the `# fmt: on` sat inside a function body, so black skipped
  the rest of the file). The black reformat follows in the next commit.

gfx950 ISA is byte-identical for all 667 compiled prepare kernels
(flydsl 0.5.0).

Signed-off-by: Chushi Chen <[email protected]>
Formatting only (black 26.10.1); the AST is unchanged.

Signed-off-by: Chushi Chen <[email protected]>
A/B on main 075695e (flydsl 0.5.0, 8x MI355X, 8 paired rounds) shows
no measurable gain from warming the peer tables (decode prepare ratio
0.998, 95% CI 0.983-1.014), so remove it: 9 fewer scalar loads, a
branch and 2 waits per decode kernel; outputs bit-exact. The
dispatch-table warm-up stays (removing it costs ~3% of decode prepare
at bs 1/42).

Signed-off-by: Chushi Chen <[email protected]>
The warm-up loads have no consumer, so keeping them alive needed a raw
llvm.intr.fake.use (FlyDSL has no fx wrapper for it). Remove the warm-up
and with it the last raw MLIR dialect use in the file. Cost: about 3%
(~0.5 us) of decode prepare at bs 1/42; prefill kernels are unaffected.
Outputs bit-exact.

Signed-off-by: Chushi Chen <[email protected]>
GwilliamHu
GwilliamHu previously approved these changes Nov 11, 2026
Merge duplicated code in the MegaMoE prepare fast path (-300 lines):

- fold _group_count_held into _group_count_regs (route_segment=None)
- fold _next_pair_packed_top2 into _next_pair_packed(top2=)
- _emit_mx_fp8_quad_chunk reuses _mx_fp8_quad_convert
- new helpers: _pack/_unpack_route_segment, _pair_mask/_pair_member,
  _tok_idx_buffers, _lds_round_carry, a local _offsets_pairs closure and
  quant-loop _load/_convert closures
- _emit_plan: drop defer_plan_ready and dead fused/non-fused arms
- drop unreachable guards and the split>1 select chain (the fast path is
  always npes==8, topk<=8), the unused prefetch fallback in
  _emit_fused_count_tok, and a dead non-fused fence

The stock compile_mega_moe_prepare path is unchanged. gfx950 ISA is
unchanged (3273/3328 kernel instances byte-identical; the other 55 have
identical LLVM IR and differ only by backend operand-order
nondeterminism, also seen when rebuilding the same file). EP8 outputs
are bit-exact against main and the previous revision; AOT 192/192.

Signed-off-by: Chushi Chen <[email protected]>
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.

6 participants