Skip to content

[FlyDSL] [MoE] MegaMoEV2: EP8 V4.1-Flash DSpark draft MoE on the small-input route, BF16 return on every draft route (on #8758) - #8759

Merged
yhl-amd merged 2 commits into
ROCm:ghu/mega_small_m_speedup_20261125from
yhl-amd:mega-v41-ep8-draft-fused
Nov 28, 2026
Merged

yhl-amd merged 2 commits into
ROCm:ghu/mega_small_m_speedup_20261125from
yhl-amd:mega-v41-ep8-draft-fused

Conversation

@yhl-amd

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

Copy link
Copy Markdown
Contributor

Summary

DeepSeek-V4.1-Flash's DSpark draft MoE with the shared expert computed apart (EP8: 16 routed experts a rank, topk 3) takes MegaMoE's fused small-input route instead of the staged route, and every route of this layout returns BF16 rows. Default behaviour (no switch, no environment variable).

  • V41_FLASH_EP8_DRAFT_LAYOUT (8, 16, 5120, 2304) / topk 3 joins FUSED_LAYOUTS; SMALL_M_ONLY_LAYOUTS keeps it off the large-input kernel (large_m_mtprs_for(..., experts_per_rank=) gives it no capacity), so calls above 512 rows a rank stay staged.
  • Fixed-slot dispatch in the small-input kernel, as for 48 experts a rank.
  • Tune: the 48-expert EP8 small-input tune (without [FlyDSL] [MoE] MegaMoEV2: per-bucket small-input knobs for EP8 V4.1-Flash (48 experts a rank, on #8633) #8758's table) plus bf16_rows_always (new FusedStage1Knobs field, default off): every rank sends BF16 GEMM2 rows instead of the rows-received FP8/BF16 choice.
  • BF16_RETURN_LAYOUTS (the draft layout only): the staged route's p2p_quant="auto" resolves to "none" (BF16) at every MTPR, including the 16384-token draft instance, where auto picked fp8_blockwise_1x32 before. 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, including the 48-expert target layout, keeps its configs (pinned digests unchanged; bf16_rows_always enters them only when set).

Why BF16 (SemiAnalysis InferenceX Check 13)

The first version of this PR forced an FP8 (1x32 E8M0) return to match the staged route. That FP8 return is not the draft's shipped precision:

  • The default MoE backend is standard. Its MoRI combine returns BF16, and the signed-off DeepSeek-V4.1 recipe says "combine stays BF16". The mega backend is opt-in.
  • The staged route returns FP8 only because the draft instance's capacity (16384 tokens a rank) is at or above P2P_FP8_MIN_MTPR. A draft MoE that returns FP8 where the default path returns BF16 runs the draft at a lower activation precision than the default, and Check 13 can flag that.

This version returns BF16 on both draft routes, small-input and staged. Without it, the mega backend's draft (staged, FP8 return) has the same problem, so this PR fixes main's draft path as well.

Numerics

--suite routes --network v41_flash_draft --staged-rtol 0.005 (8 GPUs, gfx950):

  • 48 cases, 1-512 rows a rank (uniform, uneven, idle, padded): relL2 to the staged route is 0.000000 on every case (both return BF16). relL2 to the fp32 reference is 0.0519-0.0521, down from 0.0582-0.0584 with the FP8 return.
  • New [BF16RET] checks:
    • Every staged bucket has p2p_quant=none and every small-input config has bf16_rows_always.
    • Skewed routes (hot60 at 128/448, one_rank at 64, hot100 at 512) match the staged route at relL2 0.000000. Under the rows-received choice, the hot rank sent FP8 rows; an FP8 return is about 0.027 away and fails the 0.005 gate.
    • Staged calls at 640/2048/4096 rows a rank (the MTPR class where auto is FP8 elsewhere) are within --rtol of the fp32 reference (0.0519).
  • Graph replay matches eager bit for bit. Alternation with staged calls and the epoch wrap pass.

Performance

DeepSeek-V4.1-Flash, MI355X DEP8, InferenceX AgentX c512, 900 s per run after a 900 s warm-up, SA-compliant serving config on the mega MoE backend (48 routed experts a rank / topk 6, FP8 shared expert computed apart, draft not fused, dynamic EPLB), one machine, order A, B, B, A. The arms run the same stack and differ only in the draft MoE return. A: fused small-input route with FP8 return (previous version of this PR) and staged FP8 return. B: this version, BF16 on every draft route.

run 1 run 2 mean total tok/s/GPU interactivity p90 (mean)
A: draft FP8 return 300,876 301,213 301,045 140.30
B: draft BF16 return (this PR) 299,902 300,196 300,049 (-0.33%) 139.85 (-0.32%)
  • Cost of the BF16 return against the FP8 one: -0.33% throughput, -0.32% p90.
  • The fused route's gain holds with BF16. In an earlier three-arm run on the same machine and stack (staged route as in main, FP8 return), fused + BF16 return measured +0.10% throughput / +0.94% p90 over staged, and fused + FP8 return +0.85% / +1.48%.
  • In-server probe (GSM8K run, 8 ranks):
    • Draft calls at 10 and 280 rows a rank take the small-input route with BF16 rows on every bucket.
    • Draft calls at 640 rows a rank (prefill steps) take the staged route with p2p_quant=none.
    • The target layout's staged route stays fp8_blockwise_1x32 at MTPR 16384 and its small-input configs are unchanged.

Accuracy of B (GSM8K 5-shot, no golden acceptance length): 0.9363 ± 0.0067. Draft acceptance 0.4884 (78,144 / 160,000), 3.44 tokens/forward. In the earlier run: FP8 return 0.9310 / 0.4901, staged as in main 0.9325 / 0.4895. All within noise.

Dependencies / merge order

Tests

  • tests/test_mega_moe_v41_ep8_draft_layout.py (CPU) covers:
    • the layout gate and no large-input capacity;
    • the route for every max_tokens;
    • each bucket's config (EP8 tune + bf16_rows_always) and one launch protocol;
    • BF16 staged return at every capacity, with the explicit p2p_quant kept;
    • the other layouts' returns unchanged, the knob default off, and fixed-slot dispatch.
  • With tests/test_mega_moe_gfx950_route_plan.py (pinned digests) and tests/test_mega_moe_v41_ep8_small_knobs.py: 139 passed.
  • op_tests/multigpu_tests/test_mega_moe_v2.py --suite routes --network v41_flash_draft --staged-rtol 0.005 (8 GPUs): ALL PASS.
  • --suite routes --network v41_flash --compare-untuned on this branch: ALL PASS (48-expert layout unchanged; its hot ranks still pick FP8 rows by rows received).

🤖 Generated with Claude Code

@yhl-amd

yhl-amd commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

GPU validation on top of #8758 / #8633 (head 6420f64), gfx950 / MI355X, 8 GPUs; details in the description.

Stays draft until #8758 merges.

@yhl-amd
yhl-amd force-pushed the mega-v41-ep8-draft-fused branch from 504bc7b to 0b4d003 Compare November 27, 2026 05:04
@yhl-amd yhl-amd changed the title [FlyDSL] [MoE] MegaMoEV2: EP8 V4.1-Flash DSpark draft MoE on the small-input route with the FP8 return (on #8758) [FlyDSL] [MoE] MegaMoEV2: EP8 V4.1-Flash DSpark draft MoE on the small-input route, BF16 return on every draft route (on #8758) Nov 27, 2026
@yhl-amd

yhl-amd commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Updated (force-pushed 0b4d003): the draft MoE now returns BF16 rows on every route, no longer FP8.

  • Why: the default MoE backend (standard) returns BF16 from its MoRI combine, and the signed-off DeepSeek-V4.1 recipe says "combine stays BF16". The FP8 return of the previous version (and of the staged route at the 16384-token draft capacity, which is what main's mega backend runs today) would run the draft below its default precision, which is a SemiAnalysis Check 13 risk.
  • Small-input route: fp8_rows_always is replaced by bf16_rows_always (default off; set only for the draft layout), so every rank sends BF16 GEMM2 rows, hot ranks included. The rest of the draft tune is the 48-expert EP8 tune, BF16 head tokens included.
  • Staged route: new BF16_RETURN_LAYOUTS (the draft layout only). There p2p_quant="auto" resolves to "none" at every MTPR, and the FP8-only aligned-pair Stage2 falls back to the plain Stage2. An explicit p2p_quant is kept. This also covers draft calls above 512 rows a rank (prefill steps), which still take the staged route.
  • Target (48-expert) layout and every other layout: unchanged (pinned digests pass; its hot ranks still pick FP8 rows by rows received, its staged route stays FP8 from MTPR 1024).
  • No new environment variables.
  • Tests:
    • New CPU tests: BF16 staged return at every capacity, bf16_rows_always on every draft bucket, other layouts unchanged.
    • New [BF16RET] op-test checks: skewed routes against the staged route at relL2 0.000000 (an FP8 return is about 0.027 and fails --staged-rtol 0.005); staged calls at 640/2048/4096 rows against the fp32 reference.
    • --network v41_flash_draft and --network v41_flash --compare-untuned: ALL PASS.
  • Measured cost of BF16 against FP8 return: c512 DEP8, A,B,B,A, 900 s runs. Throughput -0.33%, interactivity p90 -0.32%. GSM8K 0.9363, draft acceptance 0.4884, both within noise of the FP8 version. Details are in the updated description.

Still a draft until #8758 merges.

@yhl-amd
yhl-amd marked this pull request as ready for review November 27, 2026 06:08
@yhl-amd

yhl-amd commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

Update (ac81354): extend the BF16 return to the V4.1-Flash DSpark draft MoE on every EP width.

BF16_RETURN_LAYOUTS only listed the EP8 draft layout, so the EP4/EP2/EP1 draft layouts (32/64/128 experts a rank) took the staged route with p2p_quant=auto, which resolves to FP8 at the draft capacity. They are now all BF16-return layouts and _fused_config sets bf16_rows_always for them; target-model layouts and the EP8 draft config are unchanged field for field. No new environment variables.

Checks:

  • Config diff: only the EP1/2/4 draft return precision changes.
  • Draft layout + route-plan tests: 165 passed. EP4 draft staged test on 4 GPUs: relL2 vs fp32 reference 0.0517–0.0527 (same as the EP8 BF16 path, 0.0519; FP8 return was 0.058). EP2 draft and EP4 target --compare-untuned pass.
  • DEP4 serving (DeepSeek-V4.1-Flash, MI355X): every draft call reports p2p_quant=none, zero FP8 draft calls; GSM8K 0.9325. AgentX c64 900 s: throughput −0.19%, interactivity p90 −1.4% (within about 1% run-to-run).

V4-Pro draft and target share the (8, 48, 7168, 3072) layout and cannot be told apart by layout; that needs an instance-level flag from the caller and is not covered here.

yhl-amd and others added 2 commits November 28, 2026 16:28
…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]>
@yhl-amd
yhl-amd force-pushed the mega-v41-ep8-draft-fused branch from ac81354 to 045f0bd Compare November 28, 2026 08:29
@yhl-amd

yhl-amd commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto the base branch now that #8758 is in it (2824eb1): dropped the old copy of the #8758 commit; this PR's two commits are unchanged.

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