Skip to content

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

Merged
zcnrex merged 1 commit into
sgl-project:devfrom
weireweire:mega-moe-decode-block-m
Nov 2, 2026
Merged

zcnrex merged 1 commit into
sgl-project:devfrom
weireweire:mega-moe-decode-block-m

Conversation

@weireweire

@weireweire weireweire commented Nov 2, 2026 •

Copy link
Copy Markdown

Motivation

SM100 Mega MoE sizes block_m from the mean tokens per expert plus one sigma, which assumes near-uniform routing. Decode routing is skewed: a few hot experts per rank take a large share of the rank's tokens. With 16- or 32-row tiles, a hot expert's tokens split into several M blocks, and each extra block streams that expert's weights again. Decode Mega MoE is bound by weight streaming, so the extra blocks cost real time.

sgl-project/sglang#46593 raised these tiles from the SGLang side through DG_MEGA_MOE_TILES (16/32 -> 64 in decode CUDA graphs) for DeepSeek-V4.1-Flash on GB300, with DSpark speculative decoding:

  • Without EPLB, decode step time dropped 2-10% at DEP4 and 2-6% at DEP16.
  • With dynamic EPLB (DEP16, ~15 requests per rank), step time dropped 1-3%, and p90 interactivity rose 4% at the same throughput.
  • With dynamic EPLB at ~24 requests per rank, results were neutral.

Change

Between 2 and 24 expected tokens per expert, get_block_config_for_mega_moe picks block_m = 64 instead of 16 (up to 10) or 32 (up to 24). At 2 or fewer expected tokens it keeps 16, where 64 rows lose under any routing. Loads above 24 expected tokens are unchanged. This is the rule from #121.

get_block_m_for_mega_moe goes through the same heuristic, so callers that lay out shared-expert scale factors from it stay consistent without a change.

Validation

GB300 (sm_103a), CUDA 13.0. DeepSeek-V4.1-Flash shapes: 384 experts, top-6, hidden 5120, intermediate 2304, EP4, one fused shared expert.

  • sgl_deep_gemm/tests/test_mega_moe.py, checked against the DeepEP baseline, passes for fp8xfp4, fp8xfp8 and bf16xbf16 at 32, 198 and 342 tokens per rank, 20 iterations each. 32 tokens stays at 16; 198 and 342 move from 32 to 64.
  • sgl_deep_gemm/tests/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. Routing was uniform, and a synthetic skew with one hot expert per rank at about 6x the local mean (the hottest-expert skew measured after dynamic EPLB settles in sglang#46593).

Kernel time with synthetic routing, slowest rank, old -> new:

tokens/rank expected/expert block_m uniform hot expert ~6x
2 0.1 16 -> 16 +0.5% +0.4%
32 2.0 16 -> 16 +0.1% +0.0%
48 3.0 16 -> 64 +2.8% +2.8%
64 4.0 16 -> 64 +1.5% +1.4%
96 6.0 16 -> 64 +0.9% +0.3%
128 8.0 16 -> 64 +0.7% -0.1%
160 10.0 16 -> 64 -0.2% -0.9%
192 12.0 32 -> 64 -0.2% -0.6%
256 16.0 32 -> 64 +1.6% +1.3%
342 21.4 32 -> 64 +0.5% -0.2%

With one moderately hot expert per rank, the kernel is within -1% to +3% of the old tiles; it loses most at 3-4 expected tokens. The end-to-end gains below, and the faster kernel times #121 reported when replaying captured serving routing, come from the heavier skew of real routing.

End to end

DeepSeek-V4.1-Flash on GB300, SGLang nightly 2026-10-30, disaggregated serving with DSpark speculative decoding (real acceptance), InferenceX AgentX trace, 1200 s per run. Stock is sgl_deep_gemm 0.2.3.post2; patched is the same release with this commit, installed as a wheel. Both arms ran at the same time on the same trace. No DG_MEGA_MOE_TILES and no SGLang change. Decode step is per DP rank, binned by running requests per rank.

DEP4 decode (one node, 96 local experts per rank), 6x DEP2 prefill, no EPLB:

metric c200 stock c200 patched change c600 stock c600 patched change
output tok/s per GPU 563.0 565.2 +0.4% 744.5 768.9 +3.3%
interactivity mean, tok/s 222.6 229.3 +3.0% 29.7 30.5 +2.8%
interactivity p90, tok/s 203.2 214.5 +5.5% 23.7 25.2 +6.2%
TPOT p90, ms 4.92 4.66 -5.3% 42.1 39.7 -5.9%
requests per rank 0-3 4-7 8-11 12-15 16-19 20-23 24-27
c200 step, stock -> patched, ms 11.97 -> 11.73 12.61 -> 12.79 14.61 -> 14.29 15.28 -> 14.68 16.09 -> 15.31 17.04 -> 16.18
c600 step, stock -> patched, ms 16.76 -> 15.83 17.20 -> 16.00 17.55 -> 16.30 17.95 -> 16.87

c600 is past this topology's capacity on both arms (TPOT about 40 ms with 16-18 ms steps), so read it as a relative comparison only.

DEP16 decode (four nodes) with dynamic EPLB (16 redundant experts, rebalance every 15000 iterations), 5x DEP2 prefill, c1400:

metric stock patched change
output tok/s per GPU 2371.8 2372.6 +0.0%
interactivity mean, tok/s 259.2 262.4 +1.2%
interactivity p90, tok/s 252.4 256.2 +1.5%
TPOT p90, ms 3.96 3.90 -1.5%

After EPLB settles (480-1200 s, 6-7 rebalances), decode step p50 is within -0.4% to +1.0% in every bin from 4 to 27 requests per rank, and within 0.4% in the busy 8-23 bins. Before the first rebalance, bins 0-15 are 1.3-2.1% faster. So the gain comes from expert imbalance: large without EPLB, small once dynamic EPLB has evened out the ranks, and no regression in either case.

GSM8K (sgl-eval 0.1.3, 1319 questions) with the patched build, DEP16 with EPLB: 96.89%, vs 96.82% on stock.

Related

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
sgl-project#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.
@kpham-sgl

Copy link
Copy Markdown

@zcnrex

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.

3 participants