Skip to content

[SM100] Mega MoE: use block_m 64 for decode-sized loads - #121

Closed
zcnrex wants to merge 2 commits into
sgl-project:devfrom
zcnrex:mega-moe-skewed-routing-block-m
Closed

zcnrex wants to merge 2 commits into
sgl-project:devfrom
zcnrex:mega-moe-skewed-routing-block-m

Conversation

@zcnrex

@zcnrex zcnrex commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

SM100 Mega MoE picks block_m = 64 when the expected tokens per expert are between 2 and 24, instead of 16 (up to 10) or 32 (up to 24). At most 2 expected tokens keeps 16. Loads above 24 expected tokens are unchanged. No env switch.

Motivation

The heuristic sizes block_m from the mean tokens per expert plus one sigma, which assumes routing is close to uniform. Real decode routing is skewed: in DeepSeek-V4.1-Flash serving traffic, one hot expert per layer receives a large fraction of a rank's routed tokens, while many local experts get few or none. With 16/32-row blocks, a hot expert's tokens split into many M blocks, and each block's tasks reload that expert's full weight tiles.

64 rows cover hot experts in far fewer blocks. Cold experts have too few tokens for the extra padding to matter. An earlier revision of this PR also used 128 rows between 16 and 24 expected tokens; 128 lost under uniform routing while gaining little over 64 under skewed routing, so it was dropped. At 2 or fewer expected tokens per expert, 64 rows lose under both routings, so 16 stays there.

Validation

DeepSeek-V4.1-Flash shapes (384 experts, top-6, hidden 5120, intermediate 2304), EP4, CUDA 13.4, on sm_107a and sm_103a:

  • Routing captured from a serving run with real-text prompts (plus random-token prompts on sm_107a), replayed through fp8_fp4_mega_moe at 2 to 342 tokens per rank. Outputs are bitwise identical to the old tiles, and the kernel is faster at every tested size where the new rule picks 64, on both architectures.
  • The same replay with synthetic uniform routing: within about 2% either way where the rule picks 64, with the small losses at the low end of that range.
  • tests/test_mega_moe.py passes on sm_103a with this branch for fp8xfp4, fp8xfp8 and bf16xbf16 at 32, 198 and 342 tokens per rank (16 at 32 tokens, 64 above).
  • End to end in SGLang on sm_107a (the earlier opt-in revision, at the sizes where it picked 64): decode throughput improves, GSM8K unchanged.

SGLang derives the fused shared-expert block_m from get_block_m_for_mega_moe(), which uses the same heuristic, so callers stay consistent without a change.

Related

sgl-project/sglang#46593 raises decode block_m from the SGLang side through DG_MEGA_MOE_TILES (16/32 -> 64 and 64 -> 96 in decode CUDA graphs). Its remap is keyed on DeepGEMM's choice, so with this PR it would see 64 for decode-sized loads and raise them to 96. The two need reconciling before both land.

Not covered

  • Larger loads (above 24 expected tokens), where #46593 reports gains from 96 rows.
  • SM90 Mega MoE (separate heuristic).

🤖 Generated with Claude Code

zcnrex and others added 2 commits October 23, 2026 08:42
DG_MEGA_MOE_SKEWED_ROUTING=1 picks block_m 64 (up to 16 expected tokens per
expert) or 128 (up to 24) instead of 16/32. With hot-expert routing, small
blocks split a hot expert into many blocks that each reload its weight tiles.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…itch

Between 2 and 24 expected tokens per expert, always pick 64 rows. The 128-row
choice is removed: it loses under uniform routing and gains little over 64
under skewed routing. Loads of at most 2 expected tokens keep 16 rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zcnrex zcnrex changed the title [SM100] Mega MoE: opt-in block_m for skewed decode routing [SM100] Mega MoE: use block_m 64 for decode-sized loads Oct 27, 2026
@zcnrex zcnrex closed this Oct 27, 2026
zcnrex pushed a commit that referenced this pull request Nov 2, 2026
Root cause: up to 24 expected tokens per expert the heuristic picks
block_m 16 (<= 10) or 32 from the uniform-routing mean. Real decode routing
concentrates on a few hot experts per rank, which those tiles split into
several M blocks, and every extra block re-streams the expert's weights.

Fix: pick 64 between 2 and 24 expected tokens; keep 16 at <= 2, where 64
rows lose under any routing. Loads above 24 are unchanged. Same rule as
#121.

Validation (GB300, CUDA 13.0, DSv4.1 shapes 384 experts / top-6 / hidden
5120 / intermediate 2304, EP4, fused shared expert):
- sgl_deep_gemm/tests/test_mega_moe.py against the DeepEP baseline passes for
  fp8xfp4, fp8xfp8 and bf16xbf16 at 32/198/342 tokens per rank (20
  iterations each); test_mega_moe_global_tokens.py passes.
- fp8_fp4_mega_moe outputs are bitwise identical to the old tiles at 2-342
  tokens per rank, uniform and one-hot-expert-per-rank (~6x) routing.
- Kernel time with synthetic routing: -0.9% to +2.8% (largest loss at 3-4
  expected tokens). The decode gains come from real routing skew: SGLang
  DSv4.1 decode step -2% to -10% without EPLB and -1% to -3% with dynamic
  EPLB in sgl-project/sglang#46593, which applied this mapping through
  DG_MEGA_MOE_TILES.

Co-authored-by: weireweire <[email protected]>
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