Repository navigation
[Bugfix] Fix top-1 MoE routing with non-unit scaling - #40187
Merged
BBuf merged 1 commit intoSep 18, 2026
Merged
Conversation
BBuf
requested review from
Edwardf0t1,
Fridge003,
HaiShaw,
Ying1123,
ch-wan,
ispobock and
merrymercy
as code owners
September 18, 2026 13:30
Collaborator
Author
|
/tag-run-ci-label |
Collaborator
Author
|
/tag-and-rerun-ci |
Collaborator
Author
|
/rerun-test test/registered/moe/test_fused_moe.py |
Contributor
|
Results for 🚀 |
This was referenced Sep 18, 2026
guapisolo
added a commit
that referenced
this pull request
Sep 21, 2026
Keep the down-projection output in intermediate_cache3 when routed scaling is non-unit. The scaled reduction otherwise reads an unwritten buffer after the kernel has already written directly to the final output. Backport the one-file upstream fix from #40187. Preserve the existing test_single_expert_routing assertions and unit-scaling fast path. (cherry picked from commit 7714b18)
Leoyzen
pushed a commit
to Leoyzen/sglang
that referenced
this pull request
Sep 23, 2026
(cherry picked from commit 7714b18)
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
TestFusedMOE.test_single_expert_routingintermittently fails on H100 fortopk=1withrouted_scaling_factor=1.5(for example,this scheduled CI job).
For top-1 routing,
_use_intermediatewas false regardless of the routedscaling factor, so the down-projection kernel wrote directly to
out_hidden_states. The non-unit scaling path then reducedintermediate_cache3, which had never been populated, overwriting the validoutput with uninitialized memory. This made the failure allocator-dependent.
Regression history
Bottom line: the regression that remained in
mainwas reintroduced by #6970, authored by @BBuf. #6220, also authored by @BBuf, had first introduced the same mismatch, but it was fully reverted by #6968. #22660 only added the test coverage that eventually exposed the bug; it did not introduce the production issue.top-1 direct-output fast path. This was valid at the time because the path
did not perform post-GEMM routed scaling.
routed_scaling_factorto the reduction path without updating thedown-projection output selection for top-1 routing. It introduced this exact
mismatch, but was reverted by
#6968.
routed-scaling implementation. This is where the bug that remained in the
current codebase came from.
#23019 subsequently
refactored and moved the code while preserving the faulty condition.
test_single_expert_routing, including coverage for scaling factors1.0and
1.5; it did not introduce the production bug. Because the invalid pathreads uninitialized memory, the test failure was intermittent.
Modification
Keep the intermediate path enabled for non-unit routed scaling factors. The
down-projection kernel now populates
intermediate_cache3before the existingscaled reduction. The unit-scaling top-1 fast path is unchanged.
The existing
test_single_expert_routingcoverage already exercises both1.0and1.5scaling factors.Tests
test_fused_moe.pypassed, includingtest_single_expert_routingpython3 -m compileall -q python/sglang/srt/layers/moe/moe_runner/triton_utils/fused_moe.pypre-commit run --files python/sglang/srt/layers/moe/moe_runner/triton_utils/fused_moe.pyChecklist
CI States
Latest PR Test (Base): ⏳ Run #35350658659
Latest PR Test (Extra): ❌ Run #35350780246
Latest PR Test (AMD ROCm 10): ❌ Run #35350658582