Repository navigation
Conversation
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]>
3 tasks done
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SM100 Mega MoE picks
block_m = 64when 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_mfrom 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_107aandsm_103a:sm_107a), replayed throughfp8_fp4_mega_moeat 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.tests/test_mega_moe.pypasses onsm_103awith this branch forfp8xfp4,fp8xfp8andbf16xbf16at 32, 198 and 342 tokens per rank (16 at 32 tokens, 64 above).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_mfromget_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_mfrom the SGLang side throughDG_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
🤖 Generated with Claude Code