Repository navigation
[FlyDSL] [MoE] MegaMoEV2: faster small-input route (bitwise identical), EP8 V4.1-Flash large-input route at every capacity - #8633
GwilliamHu wants to merge 13 commits into
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
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 |
…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]>
f0ba7b3 to
92ce2c7
Compare
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]>
9dd5047 to
6420f64
Compare
…lash (48 experts a rank, on #8633) (#8758) * tune(mega_moe): per-bucket small-input knobs for EP8 V4.1-Flash (48 experts a rank) The EP8 DeepSeek-V4.1-Flash small-input kernel ran _tune_v41_flash_ep8_small alone. Add a per-bucket knob table on top of it, _V41_FLASH_EP8_SMALL_KNOBS, the default for the 48-expert layout (no switch): - en_order (FusedStage1Knobs, default 0): the GEMM1 (bit 1) and GEMM2 (bit 2) units of the run of one expert's m-tiles that lies wholly inside an XCD's slice go in (expert, n)-major order, so the run's m-tiles read each weight tile at about the same time and share it in the L2; bit 4 reads such grouped units' weights through the cache. The remap is a bijection on the slice's units that keeps every unit in its own expert's m-tiles and leaves the m-tiles cut by the slice ends in place: only the order changes. Its GEMM1 order runs on m-tile units, so it is refused together with pair_tiles (at 64 and 128 tokens it takes their place); it reads the experts from the local plan, so it needs plan_local. - The table: en_order, 256-wide GEMM1 tiles and cached W1 at 256 / 512 tokens, the lean GEMM1 / GEMM2 epilogues, dispatch CUs and waves per EU. None of them changes what ranks and launches exchange or what a tile computes. Other layouts keep en_order 0: their kernels and configs are unchanged (the pinned config digests take en_order only when set; the V4.1-Flash EP8 digest is re-pinned). Tests: - tests/test_mega_moe_v41_ep8_small_knobs.py: each bucket is the tune plus exactly its table entry, one launch protocol across buckets (the same as without the table), every en_order buildable, the other fused layouts unchanged. - op_tests/multigpu_tests/test_mega_moe_v2.py --suite routes --network v41_flash --compare-untuned (8 GPUs): every small-input case again with the configs selected without the table, bit for bit. Co-Authored-By: Claude Opus 5.5 <[email protected]> * tune(mega_moe): EP8 V4.1-Flash small-input bucket 32 runs the bucket-64 knobs nearest_token_bucket sends 24..47 rows a rank to bucket 32. Its table entry (64 dispatch CUs, 2 waves per EU, b_nt 1, g2_epi_lean 1) was searched on c512 decode replays; in serving at c128 (4..7 requests a rank) it is slower than the bucket-64 entry, so 42 rows a rank ran slower than 48. Bucket 32 now takes the bucket-64 entry (128 dispatch CUs, one wave per EU, streamed W1 b_nt 3, full GEMM2 epilogue) and keeps its 256-wide GEMM2 blocks: its config is now equal to bucket 64's field for field. Only dispatch / occupancy / load-hint / epilogue knobs change, so the outputs are unchanged. No pinned digest case falls in bucket 32, so the digests stay. Tests (gfx950, 8 GPUs): - test_mega_moe_v2.py --suite routes --network v41_flash --compare-untuned: ALL PASS, 0 mismatched rows against the configs selected without the table. - The old and the new bucket-32 entry at 24/30/36/42 rows a rank (uniform and Zipf 0.4/0.8/1.2 routes): 0 mismatched rows. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
…ute, BF16 return DeepSeek-V4.1-Flash's DSpark draft layer with the shared expert computed apart runs a MegaMoE of 16 routed experts a rank and topk 3 on 8 ranks. No fused layout covered it, so every draft call took the staged route. Make it a small-input-only fused layout, V41_FLASH_EP8_DRAFT_LAYOUT (8, 16, 5120, 2304) with topk 3, the default (no switch): - FUSED_LAYOUTS takes it; SMALL_M_ONLY_LAYOUTS keeps it off the large-input kernel: large_m_mtprs_for() takes the experts a rank and gives such a layout no capacity, so calls above SMALL_M_MAX_MTPR rows a rank stay on the staged route (MegaMoEV2 and LargeMRuntime pass experts_per_rank). - The small-input kernel dispatches it into fixed slots, as the 48-expert layout (one receive row a source token and slot either way). - Its tune (_tune_v41_flash_ep8_draft_small) is the 48-expert EP8 small-input tune without its per-bucket table. Every route of the layout returns BF16 rows (BF16_RETURN_LAYOUTS), the precision of the default MoE backend, whose MoRI combine returns BF16: - small-input route: bf16_rows_always (FusedStage1Knobs, default off) makes every rank send BF16 GEMM2 rows instead of the rows-received choice of FP8 or BF16 rows (a hot expert or many received rows picked FP8). - staged route: p2p_quant "auto" resolves to "none" at every MTPR for the layout (it picked fp8_blockwise_1x32 from P2P_FP8_MIN_MTPR, i.e. at the 16384-token draft instance), and the FP8-only aligned-pair Stage2 gives way to the plain Stage2 of the same bucket. An explicit p2p_quant is kept. Every other layout, the 48-expert target layout included, keeps its configs (the pinned digests take bf16_rows_always only when set). Tests: - tests/test_mega_moe_v41_ep8_draft_layout.py: layout gate, no large-input capacity, the route for every max_tokens, each bucket's config (the EP8 tune with the BF16 return), one launch protocol, the staged route's BF16 return at every capacity, the other layouts' returns unchanged, fixed-slot dispatch. - op_tests/multigpu_tests/test_mega_moe_v2.py gains --network v41_flash_draft for the routes suite, --staged-rtol (the relL2 gate against the staged route) and, for a BF16_RETURN_LAYOUTS layout, the [BF16RET] checks: the instance's return configs, skewed routes (whose hot rank picked FP8 rows before) against the staged route, staged calls above the small-input capacity against the fp32 reference. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ry EP width BF16_RETURN_LAYOUTS held only the EP8 draft layout (8, 16, 5120, 2304). The draft MoE (128 routed experts, topk 3) on 4 ranks is (4, 32, 5120, 2304), on 2 ranks (2, 64, ...), on 1 rank (1, 128, ...): none of them is a fused layout, so every draft call takes the staged route, and at the draft instance's 16384-token capacity p2p_quant "auto" picked fp8_blockwise_1x32 (P2P_FP8_MIN_MTPR) -- a DEP4 draft MoE returned FP8 rows. - V41_FLASH_DRAFT_LAYOUTS: the draft MoE on 1, 2, 4 and 8 ranks; BF16_RETURN_LAYOUTS is that set. The staged route's "auto" resolves to "none" for each (the FP8-only aligned-pair Stage2 gives way to the plain Stage2), an explicit p2p_quant is kept. - _fused_config gives any BF16_RETURN_LAYOUTS layout bf16_rows_always, not only the EP8 one (the EP1/2/4 drafts have no fused route today). - Target-model layouts (V4-Pro, V4.1-Flash EP8/EP4/EP2, EPLB profiles, R1, Kimi-K3, GLM-5.2) keep every config field. Tests: tests/test_mega_moe_v41_ep8_draft_layout.py checks the EP1/EP2/EP4 draft staged returns at every capacity and the target layouts' returns; test_mega_moe_v2.py --suite routes --network v41_flash_draft on 4 or 2 ranks runs the staged-only BF16 check (configs, fp32 reference, FP8-return instance told apart by --staged-rtol). Co-Authored-By: Claude Opus 5.5 <[email protected]>
[FlyDSL] [MoE] MegaMoEV2: EP8 V4.1-Flash DSpark draft MoE on the small-input route, BF16 return on every draft route (on #8758)
…raft MoE changes Co-Authored-By: Claude Opus 5.5 <[email protected]>
PR Self-Review
Reviewed revision
6420f64
Behavior and intent
Speeds up MegaMoEV2's fused small-input route (<=512 rows a rank) without changing any output, and lets EP8 V4.1-Flash take the large-input route at every capacity. Six small-input changes, found by comparing ATT traces of this kernel with a competing single-launch EP8 MoE kernel: (1) EP8 V4.1-Flash takes 256-wide GEMM1/GEMM2 tiles at 16 and 32 tokens; (2) a deduplicated token row is pushed before its expert-counter atomic, so the push overlaps the remote round trip (its destination never depended on the counter); (3) the dispatch quantizes each token row once per token instead of once per route (one wave per token pushes to each distinct destination; the top-k counter atomics go out from one instruction); (4) the m-tiles of an expert take its slots interleaved (tile t: t, t+nt, ...), so a GEMM2 tile's returns spread over the source ranks' links; (5) the kernel entry drops the ticket atomic and epoch gate: roles come from the block id, and the last retiring CTA resets the counters and advances parity / expected / epoch for the next launch; (6) on EP8 the GEMM1 of a rank that reads W1 through the cache (hot experts) pairs an expert's 32-row m-tiles into one 64-row unit, so W1 streams once per 64 rows; the XCD slices are cut by m-tile weight so a pair counts twice. Separately,
V41_FLASH_EP8_LARGE_M_MTPRSnow lists every large-input capacity (1024-16384): the fault that kept 1024-4096 staged came from another process's kernels sharing the GPUs (the persistent kernels need the whole grid resident), not from the kernel. The protocol across ranks (each rank may pick a different bucket) is unchanged.Validation and unverified scope
Static:
ruff check(0.16.0) andblack --checkon the changed files;pytest tests/test_mega_moe_gfx950_route_plan.py tests/test_aot_drivers.py: 99 passed (the EP8 fused-config digest is updated for change 1). Offline AOT of the small-input kernels: no new VGPR spill, LDS unchanged, 2 CTAs a CU still resident.Bitwise: on 8x MI355X (gfx950), FlyDSL 0.5.3, the asmval harness (MegaMoEV2 V4.1-Flash EP8, a8w4, 142 points: decode instance MTPR 128 and prefill instance MTPR 16384, small/staged/large routes, uniform / zipf / hot / invalid-slot routing, uneven and idle ranks) gives outputs
torch.equalto main (with [FlyDSL] MegaMoE: fix the large-input launch cache on weight rebinding and the MegaMoEV2 op test import #8547) on every rank and point.Timing, V4.1-Flash EP8 a8w4, MTPR 1024, one CUDA graph per distinct input (30 inputs), us per call (max over ranks), serial ABBA; main includes [FlyDSL] MegaMoE: fix the large-input launch cache on weight rebinding and the MegaMoEV2 op test import #8547:
Change 6 alone (same protocol, 3 ABBA rounds, vs changes 1-5): hot -11.7% at 64 rows and -17.3% at 128 rows, zipf -1.0% / -4.2% at 64 / 128 rows; uniform and the other sizes within +-0.2%; bitwise identical on the 142 points.
Large-input route at capacity 1024 / 2048 / 4096 (EP8 V4.1-Flash, exclusive GPUs): the asmval large points within each capacity pass three times each, no fault (the points above the capacity are refused by
_routeas expected). Timing, same protocol, us per call: 768 rows uniform / zipf / hot 354 / 690 / 1489 (staged at capacity 1024: 518 / 980 / 2203), 1024 rows 388 / 826 / 1920, 2048 rows (capacity 2048/4096) 635 / 1418 / 3920.Revision 6420f64 (also the first 7 commits of [FlyDSL] [CI] [MoE] MegaMoEV2: fully fused A4W4 routes, A8W4 performance optimizations, capacity 32768, rank-shared AOT #8623, which stacks A4W4 on this PR): review cleanups with unchanged kernels (the small-input kernels of every token bucket are byte-identical to 9dd5047's, offline gfx950 build; on 8x MI355X the stacked head is bitwise identical to main on the 142 asmval points): the entry names say what they are now (
DispatchSlot.LAUNCH_EPOCH,launch_epoch,cta), the m-tile and unit-group lookups share one ballot helper, the unusednum_wavesargument of the token prefetch goes, rawreadlane/ballotcalls carry their reason, the docs list EP8 V4.1-Flash at 1024..16384, and the commit messages state each change's measurement and bitwise check.Not covered: timing on V4-Pro EP8 and V4.1-Flash EP4/EP2 (changes 2-5 apply there too; their bitwise equality is by construction and covered only through the shared code on EP8); the timing above was taken on the same code as this revision before it was rebased onto main (the MegaMoE files are identical).
PR-specific question
Which workload keys consume the config change, and do other shapes keep their selection? Only the fused small-input configs of EP8 DeepSeek-V4.1-Flash (world 8, model_dim 5120, inter_dim 2304, 384 experts, top-6, a8w4;
_tune_v41_flash_ep8_small) change, at the 16- and 32-token buckets (GEMM1tile_n256, GEMM2block_n256).tests/test_mega_moe_gfx950_route_plan.py::test_v41ep8_fused_configs_unchangedpins the EP8 table; its digest diff is exactly those two buckets, and every other layout, bucket and the large-input configs keep their previous selection (the other config tests pass unchanged). The kernel changes (dispatch, slot interleave, entry) apply to every small-input layout; outputs stay bitwise identical because each row's GEMM math and K order are unchanged, slot order within an expert was already decided by racing atomics, and the combine reduces each token over its top-k slots in a fixed k order.Changed op tests
op_tests/multigpu_tests/test_mega_moe_v2.py: the MegaMoEV2 multi-GPU accuracy/route test. The epoch-wraparound case now presets the small-input runtime's epoch word directly because the entry ticket counter it used to preset is removed by this PR (the next launch still runs at base+1 across the int32 wrap). It is the only test that launches the fused routes across ranks and checks the epoch wraparound, so it is not redundant.Motivation
A single-launch EP8 MoE kernel outside AITER is faster than MegaMoEV2's small-input route at several sizes. ATT traces of both showed where this kernel lost time in dispatch, scheduling and its entry; these changes recover 1-8% at every point measured without changing outputs.
Test Plan
See "Validation and unverified scope".
🤖 Generated with Claude Code