Repository navigation
[Perf] dsv41: Let Mega-mHC write the MegaMoE input under MegaGate - #46163
Merged
Merged
Conversation
With MegaGate routing in MegaMoE's buffer, the Mega-mHC kernel emits the next MoE layer's FP8 rows and its routed and shared-expert scales straight into that buffer, so the per-layer pre-dispatch quantize is skipped. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
kpham-sgl
marked this pull request as ready for review
October 23, 2026 21:42
kpham-sgl
requested review from
BBuf,
DarkSharpness,
Edwardf0t1,
Fridge003,
HaiShaw,
HydraQYH,
Ying1123,
celve,
ch-wan,
ispobock,
merrymercy and
yuan-luo
as code owners
October 23, 2026 21:42
Collaborator
Author
|
/rerun-test test/registered/kernels/ops/moe/test_mega_gate.py test/registered/unit/layers/moe/test_mega_moe_deepgemm_api.py test/registered/unit/layers/test_dsv41_late_layer_tail_readers.py test/registered/e2e/models/test_deepseek_v41_flash_gb300_dp2ep2.py |
Contributor
|
🚀 🚀 🚀 |
Collaborator
Author
|
Correctness, head aca8787, DeepSeek-V4.1-Flash on GB300 (the
|
4 of 5 tasks
Open
5 tasks
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.
Motivation
With MegaGate on (
SGLANG_OPT_DEEPGEMM_MEGA_GATE=1) the gate writes the routing into MegaMoE's buffer, but every MoE layer still runsmega_moe_pre_dispatchto quantize its input: one pass over the bf16 rows per layer that writes the FP8 rows, the per-row routed scales and the paged shared-expert scales. On SM100 those rows come out of the Mega-mHC kernel, which can already emit them as FP8 in both scale layouts (deep_gemm.mega_mhctakesy_routed_sf,y_shared_sfandshared_sf_block_m). Follow-up to #43262 and #46071.Modifications
mega_moe.py:mega_moe_input_targetresolves the MoE's buffer views for a batch that will take the MegaGate path (fp8xfp4 with fused shared experts);MegaMoeInput.marktags the normed rows;run_mega_routed_expertsskips the pre-dispatch when the routing is in the buffer and the rows carry the tag for that buffer and row count.deepseek_v4_mhc.py:HcNextBoundary.mega_moe_input;_post_fusionasks the next MoE for its target and hands the views tomhc_mega_boundary.deepseek_v4_boundary.py: the MoE-side read boundary carries the resolver with its forward batch.mhc_mega.py:moe_inputthrough todeep_gemm.mega_mhc.No change with MegaGate off. Prefill, non-fused shared experts, routing that stays out of the buffer and narrowed rows all keep the pre-dispatch.
Accuracy Tests
GSM8K 5-shot, 1,314 examples, native acceptance, DP attention + EP 4 on GB300, MegaGate +
v41_new+--enable-fp32-lm-head: 0.9711 with this PR and 0.9711 on the base commit. The GB300dp2ep2andtp2ep2e2e test files pass (GSM8K 0.975 both, MMMU-Pro 0.815 / 0.79).Speed Tests and Profiling
Performance neutral: 0.02 to 0.05 ms per decode step (0.1 to 0.4%), at the edge of what one pair of runs resolves.
DeepSeek-V4.1-Flash decode, DP attention + EP 8 on two GB300 nodes, MegaGate +
v41_new+--enable-fp32-lm-head, forced balanced routing, one cached 126,976-token prefix plus 4,096 own tokens per request, 3 drafts at simulated acceptance 3.25, a fixed batch of N requests per rank; step time per rank in ms from the scheduler's own per-step record over a 120 s window, same commit with and without this PR:GPU traces (20 steps, rank 0) show why:
mega_moe_pre_dispatch_kerneldrops from 42 to 3 launches per cycle (the 3 are the DSpark draft MoE layers), 0.103 -> 0.007 ms at 64 per rank and 0.207 -> 0.012 at 256; but the FP8-emittingsm100_mega_mhc_impltemplate is slower than the bf16-only one at 256 rows, 1.192 -> 1.313 ms per cycle over 39 layers (about 3 us per launch), and equal at 64 rows (0.600 -> 0.585). Net kernel time -0.11 ms per cycle at 64 per rank and -0.07 at 256. The gain would be about 0.2 ms per step at 256 per rank if the FP8-emitting template cost the same as the bf16 one.Checklist
🤖 Generated with Claude Code
CI States
Latest PR Test (Base): ❌ Run #40028315844
Latest PR Test (Extra): ❌ Run #40028315489
Latest PR Test (AMD ROCm 10): ❌ Run #40028315589