Skip to content

[FlyDSL] [MoE] MegaMoE: EP8 V4.1-Flash with the shared expert as each rank's 49th expert - #8664

Closed
yhl-amd wants to merge 2 commits into
ROCm:ghu/mega_small_m_speedup_20261125from
yhl-amd:mega-v41-ep8-shared-49th
Closed

yhl-amd wants to merge 2 commits into
ROCm:ghu/mega_small_m_speedup_20261125from
yhl-amd:mega-v41-ep8-shared-49th

Conversation

@yhl-amd

@yhl-amd yhl-amd commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Stacked on #8633 (base branch ghu/mega_small_m_speedup_20261125, rebased onto its head 6420f64ab); only the last two commits are this PR's. It will be rebased onto main once #8633 lands, and CI runs after that.

DeepSeek-V4.1-Flash's shared expert can run inside MegaMoE as one more local expert of every EP rank (49 experts a rank, topk 7, the shared slot taken with weight 1). No MegaMoE layout covered that table, so it fell back to the staged route with the generic config.

  1. feat(mega_moe): a layout of its own, V41_FLASH_EP8_SHARED_LAYOUT (8, 49, 5120, 2304), topk 7:
    • FUSED_LAYOUTS: the small- and large-input fused routes serve it, at the large-input capacities of the 48-expert EP8 layout.
    • FIXED_SLOT_EXPERTS_PER_RANK = (48, 49): one place lists the EP8 expert widths that dispatch into fixed slots at the small capacities; selectors, the Stage1 geometry check and the small-input kernel read it (same name as [FlyDSL] [DSV41] MegaMoE improvements for DEP8 #8186 / ATOM#3726 read).
    • Its own staged / small-input / large-input tune entry points, starting from the 48-expert EP8 tunes; the narrow final-A Stage1 schedule applies.
  2. tune(mega_moe): per-bucket small-input knobs for that layout, plus FusedStage1Knobs.en_order (default 0): (expert, n)-major order of the GEMM1/GEMM2 units of an expert's m-tile run inside an XCD slice so the run shares weight tiles in L2. The remap is a bijection on the slice's units; GEMM1 order is refused together with pair_tiles and needs plan_local; the expert lookup reuses [FlyDSL] [MoE] MegaMoEV2: faster small-input route (bitwise identical), EP8 V4.1-Flash large-input route at every capacity #8633's expert_ballot(). Other layouts keep en_order 0 and their pinned config digests do not change.

Status (draft)

Performance

All measured on 8x MI355X (gfx950), DeepSeek-V4.1-Flash DEP8, InferenceX AgentX c512, on stacks before #8633 (none on this PR's base). The per-bucket table is a placeholder until it is re-searched on #8633, so the numbers below are indicative only.

Shared expert as the 49th expert (first commit, with the ATOM side that routes the shared expert into MegaMoE, which is not part of this PR; 48-expert tune reused). 900 s, 1 run each, same machine, against the same stack with the shared expert run separately:

separate shared expert 49th expert change
total throughput / GPU (tok/s) 264,669 270,795 +2.3%
interactivity p50 (tok/s/user) 103.4 113.5 +9.8%
TPOT p50 9.67 ms 8.81 ms -8.9%
TTFT p50 1.88 s 1.93 s +2.7%

GSM8K 0.9249 (0.9257 without the change). MegaMoE gets slower per layer (128 rows 180 -> 192 us, 190 rows 203 -> 213 us, 16384 rows 4805 -> 5403 us), but the separate shared-expert GEMM / activation / quant kernels (about 1.8 ms of GPU time per decode step) go away.

Per-bucket table (second commit). 8-GPU replay of all 40 layers with recorded routing, CUDA-graph timing, median of 7 interleaved rounds, us per layer, against the default path of that stack. The table column is the local table this placeholder comes from (en_order plus per-bucket knobs; the placeholder drops the knobs #8633 no longer has). Outputs bit-identical.

rows per rank (bucket) default table change
240 (256) 272.6 248.2 -8.9%
336 (256, capacity 512) 335.9 296.0 -11.9%
432 (512) 393.0 341.7 -13.1%
150 (128) 236.0 209.7 -11.1%
72 (64) 142.1 129.5 -8.9%
36 (32) 98.8 88.5 -10.4%

End-to-end was only measured with that table plus three knobs ported from #8360 (g2_pipe / g1_v2 / comb_v2, not in this PR): 900 s per run, runs alternating with / without / without / with, on two machines: total throughput per GPU +2.69% (303,843 vs 295,893 tok/s) and +2.64% (304,654 vs 296,813); interactivity p90 +5.65% (136.5 vs 129.2) and +4.8% (136.5 vs 130.3). GSM8K 0.9181.

🤖 Generated with Claude Code

yhl-amd and others added 2 commits November 25, 2026 16:27
…49th expert

DeepSeek-V4.1-Flash's shared expert can run inside MegaMoE as one more local
expert of every EP rank, which each token of the rank takes as a seventh slot
with weight 1 (re-quantized to MXFP4 by the caller). That table is 49 experts a
rank and topk 7, which no MegaMoE layout covered, so it fell back to the
staged route with the generic config everywhere.

Make it a layout of its own, V41_FLASH_EP8_SHARED_LAYOUT (8, 49, 5120, 2304)
with topk 7:
- FUSED_LAYOUTS: the small- and large-input fused routes serve it, at the
  large-input capacities of the 48-expert EP8 layout.
- FIXED_SLOT_EXPERTS_PER_RANK: one place lists the EP8 expert widths that
  dispatch into fixed slots at the small capacities (48 and 49 experts a rank;
  the receive capacity is one row a source token and slot either way). The
  config selectors, the Stage1 geometry check and the small-input kernel read
  it, and so can a caller that sizes its decode capacities the same way.
- Its own tune entry points (staged, small-input, large-input), which start
  from the 48-expert EP8 tunes; the large-input per-token combine wait stays
  off for its payload memory.
- The narrow final-A Stage1 schedule of the 48-expert layout applies to it.

Tests: tests/test_mega_moe_v41_shared_layout.py (layout gate, route for every
max_tokens including each capacity's boundary, fixed-slot dispatch and its
receive-capacity check, large-input 32-bit offsets with seven slots, the
small-input protocol across buckets, the tune selection);
op_tests/multigpu_tests/test_mega_moe_v2.py gains --network v41_flash_shared,
whose seventh slot is the sender rank's shared expert, for the routes suite
and the size suite.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…hared-expert layout

With the shared expert as each rank's 49th expert, every rank runs about one
more expert's worth of rows, all rank-local. Two things pay off for those rows
on the small-input kernel:

- 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, so only the order changes. The
  GEMM1 order runs on m-tile units, so it is refused together with pair_tiles;
  it reads the experts from the local plan, so it needs plan_local.
- _V41_FLASH_EP8_SHARED_SMALL: the per-bucket knobs on top of the 48-expert
  EP8 tune (en_order, wider GEMM1 tiles and streamed W1 at the larger
  buckets, the lean GEMM1 / GEMM2 epilogues, dispatch CUs and waves per EU),
  searched before the small-input route changes this builds on and to be
  re-searched on them. None of them changes what ranks and launches
  exchange.

Other layouts keep en_order 0: their kernels and configs are unchanged (the
pinned config digests take en_order only when set).

Tests: tests/test_mega_moe_v41_shared_layout.py checks each bucket is the
48-expert tune plus exactly its table entry, and that every small-input
config with en_order is buildable (plan_local, no GEMM1 order with
pair_tiles).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@yhl-amd
yhl-amd force-pushed the mega-v41-ep8-shared-49th branch from 1560e2e to cbdf0f1 Compare November 25, 2026 08:29
@yhl-amd

yhl-amd commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

GPU validation of this head (cbdf0f173, on its #8633 base 6420f64ab, not rebased to main), 8x MI355X (gfx950), rocm/atom-dev:nightly_202611241524 container (FlyDSL 0.5.3):

#8633 base 6420f64ab this PR
tests/test_mega_moe_v41_shared_layout.py, tests/test_mega_moe_gfx950_route_plan.py (CPU) - 139 passed
torchrun --nproc-per-node 8 test_mega_moe_v2.py --suite routes --network v41_flash_shared --check-time-acc - ALL PASS (every ACC case, relL2 vs reference 0.0516-0.0582; ALT / WRAP / GRAPH pass)
--suite size --network v41_flash_shared --bs-list 1,16,32,64,128 - pass, relL2 0.0519-0.0526, graph replay pass
--suite routes --network v41_flash --check-time-acc (48 experts) ALL PASS ALL PASS; all 93 accuracy lines (relL2, mismatch counts) identical to the base

Not covered: end-to-end accuracy (the ATOM side that routes the shared expert into MegaMoE is not part of this PR) and re-searching the per-bucket table on this base.

Result: pass at the op level.

@yhl-amd

yhl-amd commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Closing: for the SemiAnalysis InferenceX submission the shared expert must not be re-quantized to MXFP4, so the 49th-expert FP4 layout is not usable there. The FP8 shared-expert path (in the spirit of #8491 / DeepGEMM's separate shared stage) is being pursued instead. Branch kept for reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant