Repository navigation
[FlyDSL] [CI] [MoE] MegaMoEV2: fully fused A4W4 routes, A8W4 performance optimizations, capacity 32768, rank-shared AOT - #8623
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
8a3b30c to
155a18e
Compare
WAITING ON AUTHORPR Self-ReviewRevision 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
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
155a18e to
2e26528
Compare
93eaf48 to
b8070c4
Compare
…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]>
…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]>
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]>
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]>
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_QUANTSgates both routes.It also speeds up the fused routes for both quants:
Routing:
forward(max_tokens=...)is the only route switch on arouted=Trueinstance. 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_enabledare removed (their only external user was the unmerged sgl-project/sglang#47065).Capacity 32768 (folded in from #8806):
LARGE_M_MTPRSgains 32768, so every fused layout and both quants build the large-input route there and every call withmax_tokensup to 32768 rows takes a fused route. At 32768 every large-input config usesdedup_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 takei32_rankat launch (make_combine_kernelis 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:MegaMoEV2already 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
tests/test_mega_moe_gfx950_route_plan.py,tests/test_aot_drivers.py,tests/test_flydsl_aot_launch.pypass (246 passed, 1 skipped);python -m aiter.aot.flydsl.mega_moebuilds and--checks the V4.1-Flash EP8 bundles. No small-input kernel uses scratch; the co-residency check covers the whole LDS.--suite routespass;--suite size --expect-large-m --compare-mainpass (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.MORI_SHMEM_HEAP_SIZE=16G):--suite size --expect-large-m --compare-mainat 513..32768 rows (padded tails, uneven ranks, zipf, all rows to rank 0), layer-slot stress and--suite routespass 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).--suite routesfrom the AOT cache (verifyand normal): 0 misses, every rank hits the same entries..ofiles differing by a few instructions between builds of the same IR (LLVM backend).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):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):
relL2 vs fp32: this PR 0.180-0.183, #8186 0.239-0.241.
Against amd-kernels PR #12 (A8W4 EP8, its
benchmark_experts.pyprotocol):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):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 a4w4and 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-mainand the layer-slot stress take the staged reference from a call withoutmax_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
gemm_ring.py) for every small-input layout and bucket, 32-row m-tiles for EP groups of at most 128 tokens; previous small-input GEMM bodies, knobs and unread dispatch slots removed.max_tokensis the route switch (set_large_m_enabled/large_m_enabledremoved); co-residency check over the whole LDS.skip_testssince megamoe #4439).Test Plan
See "Validation and unverified scope". ATOM passes
max_tokensvia ROCm/ATOM#3187 (merged).🤖 Generated with Claude Code