Repository navigation
[FlyDSL] [MoE] MegaMoEV2: fused large-input route at capacity 32768, rank as a kernel argument (stacked on #8623) - #8806
Merged
Conversation
GwilliamHu
force-pushed
the
ghu/mega_a4w4_20261124
branch
from
November 27, 2026 06:14
7cadc30 to
19902fb
Compare
Add 32768 to LARGE_M_MTPRS, so a 32768-capacity instance (ATOM's prefill max_num_batched_tokens) builds the large-input route and every call that passes max_tokens takes a fused route (small-input up to 512 rows a rank, large-input above) instead of staging 513..32768 rows. At 32768 every layout's large-input config sends a token row to a destination once (dedup_rows, indexed payload). The V4.1-Flash tunes and the V4-Pro A4W4 tune already do; V4-Pro A8W4 (all fused knobs off, route-major payload: a 15.29 GiB/GPU symmetric heap) takes the V4-Pro A4W4 large-input tune at 32768 only, renamed _tune_v4_pro_large (8.04 GiB/GPU). Its 1024..16384 configs are unchanged. 65536 stays out of reach: the tagged count words hold 16-bit counts. The AOT default V4.1-Flash MTPRs gain 32768 (+28 jobs per quant set); V4-Pro's 32768 jobs build the large-input kernel through LARGE_M_MTPRS. Tests: the never-staged exhaustive check covers pow2 capacities up to 32768, the 32-bit offset test also bounds the GEMM1 out-scale view and the GEMM1 output (per-tile resources past 2^31), every 32768 config is checked to use dedup_rows, and the A4W4 digests stay pinned to the pre-existing capacities. Co-Authored-By: Claude Opus 5.5 <[email protected]>
GwilliamHu
force-pushed
the
ghu/mega_32k
branch
from
November 27, 2026 06:14
f91ae51 to
5dc1635
Compare
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]>
Member
Author
RolaoDenthu
added a commit
to RolaoDenthu/sglang
that referenced
this pull request
Nov 30, 2026
aiter dropped the large_m_enabled constructor argument: routed=True now builds the small- and large-input routes, and an unrouted instance holds the staged route only. Pass routed=True and turn the large-input route back on; with _AITER_LARGE_INPUT_ROUTE off, pin small_m_mtprs so the small-input route is still built. DEP4 DeepSeek-V4.1-Flash on gfx950 at MTPR 8192 and 16384 served prompts of 61 to 44,030 tokens through the small- and large-input routes without the stage1 illegal-address fault.
This was referenced Dec 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Self-Review
Reviewed revision
ec210fa
Behavior and intent
Stacked on #8623 (this PR's base branch is #8623's; it will be rebased onto main once #8623 merges). Two parts: the MTPR 32768 large-input route (one commit) and the rank as a kernel argument (six commits).
A MegaMoEV2 instance of capacity 32768 (e.g. ATOM with
max_num_batched_tokens32768) builds no large-input route today, so its calls of 513..32768 rows a rank take the staged route. This PR adds 32768 toLARGE_M_MTPRS: every fused layout (V4.1-Flash EP8 / EP4 / EP2, V4-Pro EP8) and both quants build the large-input route at 32768, and every call that passesmax_tokenstakes a fused route.At 32768 every large-input config sends a token row to a destination once (
dedup_rows, indexed payload). The V4.1-Flash tunes and the V4-Pro A4W4 tune already do; V4-Pro A8W4's route-major payload would need a 15.29 GiB/GPU symmetric heap, so at 32768 only it takes the V4-Pro A4W4 large-input tune (renamed_tune_v4_pro_large; 8.04 GiB/GPU). Configs at 1024..16384 are unchanged. 65536 stays out of reach (16-bit tagged counts). The AOT default V4.1-Flash MTPRs gain 32768.The rank was a compile-time constant in every MegaMoE kernel (
const_expr(source < rank),rank*eprandrank*mtprfolded into address math), so the AOT build compiled each kernel once per rank with nothing shared. The rank is now a kernel argument: GEMM1 / GEMM2 index W1 / W2 withglobal expert id % experts_per_rank(the GEMMs no longer see the rank); the staged kernels, prepare, the small- and large-input kernels and combine takei32_rankat launch; the threeconst_expr(source < rank)prefix sums become selects.make_combine_kernelis shared with the generic EP combine, which passes the rank too. The AOT driver builds one job per (MTPR, experts per rank, quant) and replays it on rank 0; one cache serves every rank.Validation and unverified scope
--suite routesfrom the AOT cache (V4.1-Flash EP8 and V4-Pro EP8, both quants, MTPR 32768,AITER_FLYDSL_AOT_CACHE=verifyand normal): all pass, 0 misses, every rank hits the same entries.tests/test_mega_moe_gfx950_route_plan.py(216 passed; the never-staged exhaustive check now covers pow2 capacities up to 32768, the 32-bit offset test also bounds the GEMM1 out-scale view and the GEMM1 output, every 32768 config usesdedup_rows),tests/test_aot_drivers.py.MORI_SHMEM_HEAP_SIZE=16G):--suite size --expect-large-m --compare-mainat 513..32768 rows with padded tails, uneven ranks, zipf, and all rows to rank 0 (GEMM1 output > 2^31 bytes); layer-slot stress (61 slots x 9 cycles, skewed route switches on EP8);--suite routes: all pass. relL2 vs fp32: A8W4 0.0525-0.0535, A4W4 0.181-0.184 (same as at 16384)..ofiles that differ by a few instructions between builds of the same IR (LLVM backend), so byte-exact AOT rebuild checks can differ there.PR-specific question
Does anything change below 32768? No: configs at 1024..16384 are unchanged and outputs bitwise identical; the kernels now take the rank at launch.
Changed op tests
None.
Motivation
Capacity 32768 is a common prefill setting; without this its prefill chunks ran staged. The AOT prebuild compiled every MegaMoE kernel once per rank.
Changes
LARGE_M_MTPRSup to 32768; V4-Pro A8W4 takes the shared V4-Pro large-input tune at 32768.dedup_rowsat 32768, digests pinned; AOT driver job counts.Test Plan
See "Validation and unverified scope".
🤖 Generated with Claude Code