Skip to content

[FlyDSL] [CI] [MoE] MegaMoEV2: fully fused A4W4 routes, A8W4 performance optimizations, capacity 32768, rank-shared AOT - #8623

Merged
coderfeli merged 50 commits into
mainfrom
ghu/mega_a4w4_20261124
Nov 29, 2026
Merged

coderfeli merged 50 commits into
mainfrom
ghu/mega_a4w4_20261124

Conversation

@GwilliamHu

@GwilliamHu GwilliamHu commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

PR Self-Review

Reviewed revision

ec210fa

Behavior and intent

MegaMoEV2 served A4W4 (MXFP4 activations x MXFP4 weights) only through the staged path. This PR gives A4W4 the same fully fused routes as A8W4 (#7788): the persistent small-input kernel up to 512 rows a rank and the large-input kernel above that, with per-layout A4W4 tunes (V4-Pro EP8, V4.1-Flash EP8 / EP4 / EP2) and per-bucket large-input configs. FUSED_QUANTS gates both routes.

It also speeds up the fused routes for both quants:

Routing: forward(max_tokens=...) is the only route switch on a routed=True instance. With it, every call on a fused layout takes a fused route (V4.1-Flash EP4 / EP2 now build the large-input route at every capacity 1024..16384); without it, the staged route. set_large_m_enabled() / large_m_enabled are removed (their only external user was the unmerged sgl-project/sglang#47065).

Capacity 32768 (folded in from #8806): LARGE_M_MTPRS gains 32768, so every fused layout and both quants build the large-input route there and every call with max_tokens up to 32768 rows takes a fused route. At 32768 every large-input config uses dedup_rows; V4-Pro A8W4 takes the V4-Pro A4W4 large-input tune (_tune_v4_pro_large) since its route-major payload would need a 15.29 GiB/GPU heap. Configs at 1024..16384 are unchanged; 65536 stays out of reach (16-bit tagged counts).

Rank as a kernel argument (from #8806): the rank was a compile-time constant in every MegaMoE kernel, so the AOT build compiled each kernel once per rank. GEMM1 / GEMM2 now index W1 / W2 with global expert id % experts_per_rank; the staged kernels, prepare, the small- and large-input kernels and combine take i32_rank at launch (make_combine_kernel is shared with the generic EP combine, which passes it too); the AOT driver builds one job per (MTPR, experts per rank, quant) and one cache serves every rank. Callers are unchanged: MegaMoEV2 already knows its rank and passes it at launch.

Rebased onto main 55abe98 (includes #8600 and #8790): the MegaMoE launchers go through the AOT cache, whose source lists include the files this PR adds.

Validation and unverified scope

  • Static: ruff 0.16.0 on every changed file at every commit, black at the head; tests/test_mega_moe_gfx950_route_plan.py, tests/test_aot_drivers.py, tests/test_flydsl_aot_launch.py pass (246 passed, 1 skipped); python -m aiter.aot.flydsl.mega_moe builds and --checks the V4.1-Flash EP8 bundles. No small-input kernel uses scratch; the co-residency check covers the whole LDS.
  • Bitwise (asmval, 142 points: small / staged / large routes, uniform / zipf / hot / invalid slots, uneven and idle ranks): every perf and cleanup commit keeps outputs bitwise identical. This revision vs b8070c4 and the ring cores vs 93eaf48: 142 / 142 on V4.1-Flash EP8 / EP4 / EP2 and V4-Pro EP8, both quants. A8W4 vs main (with [FlyDSL] MegaMoE: fix the large-input launch cache on weight rebinding and the MegaMoEV2 op test import #8547): 142 / 142.
  • Multi-GPU op tests on this revision, four layouts x both quants: --suite routes pass; --suite size --expect-large-m --compare-main pass (relL2 vs fp32: A8W4 0.053-0.059, A4W4 0.181-0.184); layer-slot stress (61 slots, 9 cycles, 8 skewed route switches on EP8) pass, 0 mismatched rows.
  • Capacity 32768 (8x MI350X, MORI_SHMEM_HEAP_SIZE=16G): --suite size --expect-large-m --compare-main at 513..32768 rows (padded tails, uneven ranks, zipf, all rows to rank 0), layer-slot stress and --suite routes pass on four layouts x both quants; relL2 vs fp32 A8W4 0.0525-0.0535, A4W4 0.181-0.184. Symmetric heap at most 8.20 GiB/GPU (61 layer slots). Fused vs staged at 32768 rows: 0.89-1.88x (below 1x on zipf for V4-Pro and Flash EP4 A8W4 and on uniform for V4-Pro A8W4; fused is kept there, the large-input kernel is a follow-up).
  • Rank as a kernel argument: outputs bitwise identical to the previous revision (asmval 142 points on four layouts x both quants, and on the 32768 instance); timing within +-0.5% except 1 row a rank on the small-input route (+0.1-0.2 us). AOT production set 276 jobs / 8898 entries / 13622 GPU kernels -> 42 / 1333 / 2041, CPU time about 7.5x lower; --suite routes from the AOT cache (verify and normal): 0 misses, every rank hits the same entries.
  • Re-measured on ec210fa (8x MI355X, kernels from the AOT cache, 0 MegaMoE misses): fused-vs-staged unit table within +-2.5% of the table below on every point, fused outputs bitwise identical to 19902fb; real-routing replay within +-0.11% of 19902fb, A8W4 bitwise identical to main fused; ATOM DeepSeek-V4.1-Flash DEP8 A4W4 c256 throughput -0.3% (within run-to-run spread), gsm8k unchanged.
  • About 1/7 of the fast prepare variants compile to .o files differing by a few instructions between builds of the same IR (LLVM backend).
  • Performance: all numbers below are speedups (baseline time / this PR's time, >1 = this PR faster); 8x MI355X, V4.1-Flash, one CUDA graph per input, ABBA-interleaved runs.
  • Not covered: V4-Pro timing on this revision. Known small regressions of the ring cores on V4.1-Flash EP8 synthetic routing vs the previous GEMM bodies: 16-32 rows uniform and 4-16 rows hot down to 0.95x (32 rows hot 1.23x; real serving routing unchanged).

Real serving routing (8-GPU layer-10 replay of serving-captured routing, rocm/fw-bringup-mlperf:mi355x-megamoe-replay-8633-20261126, EP8, 8 routing steps per bucket, 4 runs x 10 rounds; A8W4 outputs bitwise identical to main fused):

Quant Bucket (rows/rank) vs main staged vs main fused vs #8633
A8W4 64 (72) 1.69x 1.07x 1.04x
A8W4 128 (186) 1.70x 1.15x 1.07x
A8W4 256 (192) 1.71x 1.19x 1.13x
A4W4 64 (72) 1.89x n/a n/a
A4W4 128 (186) 1.86x n/a n/a
A4W4 256 (192) 1.73x n/a n/a

Synthetic routings on the same buckets: A8W4 vs main fused 1.01-1.47x, vs main staged 1.73-2.53x; A4W4 vs main staged 1.87-2.24x. Main fused and #8633 have no fused A4W4. relL2 vs fp32: A4W4 this PR 0.135-0.146, main staged 0.194-0.200.

Against #8186 (A4W4 EP8, its author's best settings: MXFP4 combine, fixed-slot MTPR 512, compact MTPR 4096; this PR at MTPR 512 small-input and 4096 large-input):

Rows per rank Uniform Zipf Hot
1 1.61x 1.62x 1.30x
16 1.19x 1.35x 1.19x
64 1.17x 1.31x 1.58x
128 1.19x 1.21x 1.24x
256 1.12x 1.27x 1.28x
512 1.48x 1.69x 1.72x
1024 1.43x 1.17x 1.45x
2048 1.33x 1.45x 1.04x
4096 1.21x 1.33x 1.16x

relL2 vs fp32: this PR 0.180-0.183, #8186 0.239-0.241.

Against amd-kernels PR #12 (A8W4 EP8, its benchmark_experts.py protocol):

Rows per rank 1 4 8 16 32 64 96 128 160 192 256 384 512
Uniform 1.01x 0.95x 0.97x 0.96x 0.95x 1.01x 1.02x 1.01x 1.01x 0.99x 0.97x 0.98x 0.98x
Zipf 0.97x 0.93x 0.99x 0.99x 0.98x 0.99x 1.04x 1.01x 1.02x 1.04x 1.03x 1.08x 1.18x
Hot 0.97x 0.95x 0.96x 0.97x 1.18x 0.96x 1.12x 1.12x 1.15x 1.16x 1.16x 1.15x 1.08x

Fused vs staged (unit benchmark, same tree: fused = routed=True + max_tokens, staged = routed=False, whose outputs are bitwise identical to main; decode MTPR 512, prefill MTPR 16384; EP8):

Rows per rank A8W4 uniform A8W4 zipf A8W4 hot A4W4 uniform A4W4 zipf A4W4 hot
1 2.23x 2.25x 1.60x 2.48x 2.51x 1.76x
4 1.58x 1.81x 1.56x 1.70x 1.91x 1.72x
16 1.54x 1.62x 1.77x 1.80x 1.84x 2.01x
64 1.73x 1.71x 1.74x 1.97x 1.78x 1.55x
128 1.80x 1.67x 1.86x 2.06x 1.83x 1.54x
256 1.76x 1.80x 1.44x 1.80x 1.78x 1.47x
512 1.33x 1.83x 1.54x 1.49x 1.97x 1.46x
1024 1.52x 1.37x 1.48x 1.55x 1.33x 1.57x
2048 1.55x 1.42x 1.54x 1.66x 1.44x 1.62x
4096 1.22x 1.18x 1.18x 1.32x 1.30x 1.31x
8192 1.17x 1.05x 1.24x 1.35x 1.14x 1.40x
16384 1.07x 1.07x 1.56x 1.23x 1.16x 1.67x

EP4: decode 1.45-3.29x, prefill 1.06-2.04x; EP2: decode 1.35-3.12x, prefill 1.46-2.17x (both quants). relL2 vs fp32: A4W4 fused 0.181-0.183 vs staged 0.211-0.212; A8W4 fused 0.052-0.058 vs staged 0.058.

PR-specific question

Do the perf commits change A8W4 results? No: every perf, cleanup and rank-argument commit is bitwise identical on all four layouts and both quants, and A8W4 stays bitwise identical to main.

Changed op tests

  • op_tests/multigpu_tests/test_mega_moe_v2.py: the routes suite gains --quant a4w4 and A4W4 large-input coverage; the fused-vs-staged gates also fail on any row off by more than half its norm; the epoch-wrap case presets the launch-epoch word; --compare-main and the layer-slot stress take the staged reference from a call without max_tokens.

Motivation

A4W4 MegaMoE ran staged; the fused routes are 1.7-1.9x faster on real serving routing. The A8W4 fused route gets 1.07-1.19x over main on the same replay, and the small-input kernel matches or beats amd-kernels PR #12 from 64 rows on skewed routing.

Changes

Test Plan

See "Validation and unverified scope". ATOM passes max_tokens via ROCm/ATOM#3187 (merged).

🤖 Generated with Claude Code

@GwilliamHu
GwilliamHu requested a review from a team November 25, 2026 01:44
@GwilliamHu GwilliamHu added FlyDSL ci:multi-gpu Trigger multi-GPU op tests on PR labels Nov 25, 2026
@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 8623 --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.

@GwilliamHu
GwilliamHu force-pushed the ghu/mega_a4w4_20261124 branch 2 times, most recently from 8a3b30c to 155a18e Compare November 25, 2026 06:28
@aiter-bot

aiter-bot commented Nov 25, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision ecc8eef15407 · 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. What permissions and untrusted-input boundary does this CI change have, and can fork PR code or text reach a privileged execution path?
  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
  • FAIL — changed op test not explained in Changed op tests: op_tests/multigpu_tests/bench_mega_moe_v2.py

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 force-pushed the ghu/mega_a4w4_20261124 branch from 155a18e to 2e26528 Compare November 25, 2026 07:29
@GwilliamHu
GwilliamHu force-pushed the ghu/mega_a4w4_20261124 branch from 93eaf48 to b8070c4 Compare November 26, 2026 16:23
@GwilliamHu GwilliamHu changed the title [FlyDSL] [MoE] MegaMoEV2: fully fused A4W4 small- and large-input routes, tuned per layout [FlyDSL] [MoE] MegaMoEV2: fully fused A4W4 routes and A8W4 performance optimizations Nov 27, 2026
@github-actions github-actions Bot changed the title [FlyDSL] [MoE] MegaMoEV2: fully fused A4W4 routes and A8W4 performance optimizations [FlyDSL] [CI] [MoE] MegaMoEV2: fully fused A4W4 routes and A8W4 performance optimizations Nov 27, 2026
@github-actions github-actions Bot added the CI label Nov 27, 2026
GwilliamHu and others added 9 commits November 27, 2026 06:13
…lash at 16 and 32 tokens

Half the GEMM1 tiles and GEMM2 blocks, each streaming a longer weight slab.
Measured on 8x MI355X (EP8 V4.1-Flash a8w4, MTPR 1024, one CUDA graph per
distinct input, max over ranks): -2..-8% per call at 16-32 rows a rank
under uniform, zipf and hot routing. Bitwise identical outputs (asmval, 142
points). The EP8 fused-config digest follows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A deduplicated token row goes to its destination's token-row region, whose
place does not depend on the expert offset the counter atomic returns, so the
row push is issued first and overlaps the atomic's remote round trip.
Bitwise identical outputs (asmval, 142 points: decode MTPR 128 and prefill
MTPR 16384, uniform / zipf / hot / invalid-slot routing, uneven and idle
ranks). Measured with the next three commits: 1-8% per call at 16-512 rows a
rank (EP8 V4.1-Flash a8w4, MTPR 1024; e.g. 512 rows 355.9 -> 344.4 us
uniform, 618.0 -> 587.9 zipf, 1487.4 -> 1417.6 hot).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With dedup_rows a producer wave takes a token instead of a route: it loads
and quantizes the row once and pushes it to each distinct destination rank
of its top-k (one lane a route; v_readlane keeps the remote pointers
scalar), and the top-k counter atomics go out from one instruction. Before,
each route's wave quantized the row again. Bitwise identical outputs
(asmval, 142 points); part of the 1-8% measured with the neighbouring
dispatch and entry changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…iles

m-tile t of an expert with nt m-tiles takes its slots t, t + nt, ..., so the
rows of a GEMM2 tile come from many source ranks and its returns spread over
their links instead of one. A row's GEMM math and the combine's fixed top-k
order are unchanged, and the slot order within an expert was already decided
by racing atomics: bitwise identical outputs (asmval, 142 points); part of
the 1-8% measured with the neighbouring dispatch and entry changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… gate

Protocol change: a launch no longer takes an entry ticket (one atomic per
CTA) or waits at an epoch gate. Roles go by block id (owner, producers,
consumers), and every CTA reads the entry state past L2: the previous
launch's epoch (DispatchSlot.LAUNCH_EPOCH), parity and expected source
value, and advances them itself. The last WG of a launch (the combine's last
ticket, when every CTA is past its reads) zeroes the work and producer
counters and stores this launch's epoch, parity and expected value for the
next one; stream order puts those stores before the next launch's loads.
Cross-rank buffers written before the plan stay parity double-buffered, so
no handshake is needed. The names follow (launch_epoch, cta).

The op test's epoch-wrap case now presets the runtime's launch-epoch word
(the entry ticket counter it preset is gone); the next launches still cross
the 32-bit wrap. Bitwise identical outputs (asmval, 142 points); part of the
1-8% measured with the dispatch changes before it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s into 64-row units

On a rank that reads W1 through the cache (a hot expert or many routed rows), each GEMM1 unit of an expert
with more than one m-tile runs a pair of its interleaved m-tiles (2j, 2j + 1) as one 64-row tile, so its W1
slab is read once per 64 rows instead of once per 32. The local plan keeps a per-expert unit-group table
next to its m-tile table; a unit's plan comes from one ballot lookup over it (shared with the m-tile lookup).
The XCD slices of the GEMM1 unit space stay equal in m-tile units (a pair's units weigh two m-tiles'), so an
XCD holding a paired hot expert does not take more rows than the others; a rank that does not pair skips
those lookups. GEMM2 keeps its m-tile units and slices.

V4.1-Flash EP8 configs: pair_tiles at 64 and 128 tokens. Measured on 8x MI355X (a8w4, MTPR 1024, 3 ABBA
rounds against the parent): hot -11.7% at 64 rows a rank and -17.3% at 128, zipf -1.0% / -4.2%, uniform and
the other sizes within +-0.2%. Bitwise identical outputs (asmval, 142 points; MFMA order per accumulator
unchanged).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
V41_FLASH_EP8_LARGE_M_MTPRS lists every large-input capacity (1024..16384).
The fault that kept capacities 1024-4096 on the staged route came from
another process's kernels sharing the GPUs, not from the kernel: on exclusive
GPUs the large-input route at 1024, 2048 and 4096 passes the asmval large
points three times each without a fault. An EP8 instance below 8192 now
serves prefill through the fused route (768 rows a rank at capacity 1024:
354 us vs 518 us staged, uniform). The config docstring and the AOT README
follow.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… route

An A4W4 MegaMoEV2(routed=True) on a FUSED_LAYOUTS layout (EP8 DeepSeek-V4-Pro,
EP8 / EP4 / EP2 DeepSeek-V4.1-Flash) now builds the small-input runtimes and
sends calls of up to 512 rows a rank through the fused dispatch + GEMM1 +
GEMM2 + combine kernel; above that A4W4 takes the staged route. The
large-input route stays A8W4 (LARGE_M_QUANTS).

- The producers quantize each bf16 row to MXFP4 (E2M1 + E8M0 per 32 values),
  bit-identical to per_1x32_mx_quant(quant_mode="fp4") of the staged route,
  with the MXFP8 lane mapping (16 values a lane, a scale group per lane pair):
  a lane stores 8 payload bytes per 1024-value chunk, so rows of 5120 / 7168
  values tile exactly. The dedup_rows producers (one quantization a token)
  take the same path.
- GEMM1 reads FP4 A (128-byte K-steps), also through the dedup_rows srcmap.
- The GEMM1 output stays FP8, so GEMM2 and the combine are unchanged; the
  shared GEMM1-output arena is sized per route dtype.
- Kernel names gain _afp4 for A4W4 only; the A8W4 kernels are unchanged.
- The V4.1-Flash AOT profiles ship A4W4 as well.

The A4W4 small-input kernels use the A8W4 small-input tunes unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The routes suite builds the instance with --quant (A4W4: small-input and
staged routes, gated at relL2 0.25 against the fp32 reference and the staged
route).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
MengqingCao added a commit to MengqingCao/aiter that referenced this pull request Nov 27, 2026
…sed layout, combine_wire) (#5)

* MegaMoEV2: MiniMax-M3.1 EP4 on the ring cores (SwiGLU-OAI, fused layout, combine_wire)

- act="swigluoai" (gate clamped at swiglu_limit, sigmoid slope 1.702, up + 1)
  in the ring GEMM1 epilogue and the shared GEMM1 epilogue (staged and
  large-input routes), both quants, through gated_act_f32.
- The EP4 M3.1 layout (4, 6144, 3072, 128, 4) in FUSED_LAYOUTS, which now maps
  each layout to its (act, swiglu_limit); small-input route only
  (SMALL_M_ONLY_LAYOUTS), so a call above its capacity goes staged. Bucket 128
  tune: cached W1 and early GEMM2 CTAs.
- MegaMoEV2(combine_wire="auto"|"bf16"): under "bf16" the staged route is built
  with stage2_p2p_quant="none", the small-input runtimes send BF16 rows
  (FusedStage1Knobs.bf16_wire), and the large-input route, FP8 only, is not
  built; its calls go staged.
- Routes suite: --network m31, --combine-wire, the [WIRE] check, FP8-peer check
  on skewed edges, a call above the small-input capacity. New
  bench_mega_moe_m31.py: EP4 on captured M3.1 routing, error against the op's
  own-quant emulation.

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

* MegaMoEV2 tests: M3.1 fused-layout config test; bf16_wire as a late knob in the config digests

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

* Restore .claude/skills, deleted by mistake in the previous commit

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

* MegaMoEV2: log the large-input route left out under combine_wire='bf16' as a warning

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

---------

Co-authored-by: Claude <[email protected]>
GwilliamHu and others added 6 commits November 27, 2026 15:01
The GEMM1 tile scheduler and GEMM2 subtracted a compile-time rank * experts
offset from the global expert IDs the dispatch plan writes. A rank's IDs
modulo its expert count are the same indices, so the GEMMs no longer need
the rank: expert_offset becomes experts_per_rank. The aligned-pair Stage2
passes its pair's local experts directly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The staged Stage1 bundle, prepare, Stage2 and aligned-pair Stage2 kernels
took the rank as a compile-time constant, so the AOT cache built every
kernel once per rank. They now take it as an i32 kernel argument: the
compile functions and their AOT keys drop rank, and the run/preload
helpers pass it at launch. Rank-dependent index math becomes a few scalar
ops; the source < rank prefix sums become select chains over the running
sums. Outputs are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
make_combine_kernel baked the rank into its P2P slot offsets, its
cross-device barrier word and the invalid-slot peer, so MegaMoE's fused
combine (mega_moe_combine) was compiled once per rank. The kernel now
takes an i32 rank argument, which the op passes on every launch; the
generic dispatch/combine path shares the same kernel.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The small-input persistent kernel takes the rank as an i32 kernel
argument instead of a compile-time constant, so one AOT entry serves
every rank. The fused combine publishes its flag at a byte offset
(rank * 8) read from the runtime's dispatch table where it is used,
rather than keeping the rank live across the GEMMs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The large-input persistent kernel takes the rank as an i32 kernel
argument. large_m_kernel_specs drops ("rank", rank) from the fused Stage2
spec, so the kernel name hash (S2_KEY) and the AOT key no longer depend on
the rank; the skew boost of the payload geometry tests the destination
against the rank at run time, and the plan writes its counts through the
base of its own row in each destination's count matrix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every MegaMoE kernel now takes the rank at launch and no AOT key holds
it, so rank 0's replay builds the kernels of every rank. default_jobs
yields one job per (MTPR, experts per rank, quant): the default build
drops from 276 jobs and 8898 AOT entries to 42 jobs and 1333 entries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@GwilliamHu GwilliamHu changed the title [FlyDSL] [CI] [MoE] MegaMoEV2: fully fused A4W4 routes and A8W4 performance optimizations [FlyDSL] [CI] [MoE] MegaMoEV2: fully fused A4W4 routes, A8W4 performance optimizations, capacity 32768, rank-shared AOT Nov 27, 2026
@coderfeli
coderfeli merged commit 333b78d into main Nov 29, 2026
96 of 100 checks passed
@coderfeli
coderfeli deleted the ghu/mega_a4w4_20261124 branch November 29, 2026 00:10
Yaowu-Xiong added a commit that referenced this pull request Dec 3, 2026
main's small-input kernel runs only the ring GEMM cores (#8623), so the old-path small_m options of this branch
go (g1_k_unroll, g1_a_early, the 8-wave kernel, hot_block_n, the call_pipe_am a_early order) together with the
Kimi-K2.6 / DeepSeek-V4-Pro small_m extras built on them. Kept on main's code:

- Kimi-K2.6 EP8 A8W4 in FUSED_LAYOUTS (no SwiGLU clamp, A8W4 only), its network profile, AOT jobs and op test;
  the shape-keyed large_m GEMM2 claim chunk and small_m FP8 GEMM2 row count.
- The EP8 hidden-7168 large_m tune: Kimi-K2.6 at every LARGE_M_MTPRS capacity, DeepSeek-V4-Pro A8W4 below
  MAX_MTPR_CLASS (main's _tune_v4_pro_large at 32768), as main's capacities share one tune.
- The EP8 V4.1-Flash small_m tune for Kimi-K2.6 / DeepSeek-V4-Pro A8W4; A4W4 keeps main's tunes.
- The Kimi-K2.6 main-path tune at 16K / 32K.
- tests: the V4-Pro fused-config digest and knob checks follow the tunes; payload sharing, batch_rows, the
  Kimi-K2.6 layout gate and the AOT job count.

Co-authored-by: Cursor <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:multi-gpu Trigger multi-GPU op tests on PR CI FlyDSL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants