Repository navigation
[Fix] Step-3.5: build the shared expert without TP under all-to-all MoE backends - #41754
Merged
Merged
Conversation
ch-wan
requested review from
BBuf,
Edwardf0t1,
Fridge003,
HaiShaw,
Ying1123,
ispobock and
merrymercy
as code owners
September 29, 2026 19:50
This was referenced Sep 29, 2026
ch-wan
force-pushed
the
cheng/refactor/glm5-next-mhc-pp
branch
from
September 29, 2026 20:00
6a85001 to
1540944
Compare
ch-wan
force-pushed
the
cheng/refactor/ffn-output-parts
branch
from
September 29, 2026 20:00
31e28f5 to
452fd60
Compare
Collaborator
Author
|
/tag-and-rerun-ci |
ch-wan
force-pushed
the
cheng/refactor/glm5-next-mhc-pp
branch
from
September 29, 2026 20:29
1540944 to
91e9577
Compare
ch-wan
requested review from
1am9trash,
Jiminator,
YAMY1234,
fzyzcjy,
hnyls2002,
hubertlu-tw,
iforgetmyname,
kkHuang-amd,
ping1jing2 and
rainj-me
as code owners
September 29, 2026 20:29
ch-wan
requested review from
JustinTong0323,
sogalin,
whybeyoung,
wisclmy0611 and
zijiexia
as code owners
September 29, 2026 20:29
ch-wan
force-pushed
the
cheng/refactor/ffn-output-parts
branch
from
September 29, 2026 20:29
452fd60 to
0b2b00b
Compare
ch-wan
force-pushed
the
cheng/refactor/glm5-next-mhc-pp
branch
from
September 29, 2026 23:48
91e9577 to
88e2d70
Compare
ch-wan
force-pushed
the
cheng/refactor/ffn-output-parts
branch
from
September 29, 2026 23:48
0b2b00b to
ace594b
Compare
ch-wan
force-pushed
the
cheng/refactor/glm5-next-mhc-pp
branch
from
September 29, 2026 23:56
88e2d70 to
4e0b589
Compare
ch-wan
force-pushed
the
cheng/refactor/ffn-output-parts
branch
from
September 29, 2026 23:56
ace594b to
78705b2
Compare
This was referenced Sep 29, 2026
ch-wan
force-pushed
the
cheng/refactor/ffn-output-parts
branch
from
September 30, 2026 00:17
78705b2 to
ec1cb47
Compare
ch-wan
force-pushed
the
cheng/refactor/glm5-next-mhc-pp
branch
from
September 30, 2026 00:33
4e0b589 to
e5270f4
Compare
ch-wan
force-pushed
the
cheng/refactor/ffn-output-parts
branch
from
September 30, 2026 00:33
ec1cb47 to
92c25f0
Compare
ch-wan
force-pushed
the
cheng/refactor/glm5-next-mhc-pp
branch
from
September 30, 2026 01:01
e5270f4 to
5e2f6c7
Compare
ch-wan
force-pushed
the
cheng/refactor/ffn-output-parts
branch
from
September 30, 2026 01:01
92c25f0 to
515f650
Compare
Contributor
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
…ends Step-3.5 adds its routed and shared experts before one TP all-reduce. That holds when both parts are TP partial sums. Under DeepEP, fuseep and the other all-to-all backends the combine already returns each token's routed output in full, on the rank that owns the token, while the shared expert stayed TP-sharded: the all-reduce then summed the routed output again, and the shared expert's partial sums were added across ranks that hold different tokens. Build the shared expert with TP size 1 under those backends, as DeepSeek-V2 and GLM-4-MoE do, and add it inside the MoE block: before reduce_moe_output() on the TP path, and to the combined output on the DeepEP path. The decoder no longer forces the MoE to skip its reduction or all-reduces by hand. Without an all-to-all backend the same single all-reduce runs on the same sum.
ch-wan
force-pushed
the
cheng/refactor/ffn-output-parts
branch
from
September 30, 2026 04:11
515f650 to
e543340
Compare
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.
This PR is part of a stack (oldest at bottom):
Motivation
Step-3.5 adds the outputs of its routed experts and its shared expert, then runs one TP all-reduce on the sum. That is correct when both parts are TP partial sums. Under DeepEP, fuseep and the other all-to-all MoE backends, the combine already returns each token's routed output in full, on the rank that owns the token, but the shared expert stayed TP-sharded:
DeepSeek-V2 and GLM-4-MoE avoid both by building the shared expert with TP size 1 under these backends.
Modifications
share_expertwithtp_size=1under the backends GLM-4-MoE uses for this: DeepEP, Mooncake, NIXL, MORI, Ascend fuseep, the FlashInfer and FlashInfer MegaMoE all-to-all, and the FlashInfer CUTLASS FP4 all-gather.Step3p5MoEMLPtakes the shared expert's output and adds it in place, without allocating a third tensor: into the routed output beforereduce_moe_output()on the TP path; on the DeepEP path, where nothing is left to sum, the combined routed output is added into the shared expert's output.reduce_moe_output()as for the other MoE models.Accuracy Tests
H200,
stepfun-ai/Step-3.5-Flashcut to its first five layers (three dense, two MoE):--tp-size 2,python -m sglang.benchmark.one_batch --correctness-test: identical to the parent commit, and to a second run of the parent.--tp-size 4, greedysglang.Engineruns with per-step logits: all 99 steps bitwise identical to the parent.--tp-size 4 --ep-size 4 --moe-a2a-backend deepep --moe-runner-backend deep_gemm, against the TP4 run as the reference. The DeepEP forward does not applymoe_router_scaling_factor(3.0 here), which this PR does not change, so the comparison also applies it with a test hook in both trees:main.Speed Tests and Profiling
Without an all-to-all backend the same kernels and collectives run. Under the all-to-all backends each rank now runs the whole shared expert on its own tokens instead of a TP shard of it on the same tokens, as in DeepSeek-V2 and GLM-4-MoE; no latency run was made.
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): 🚫 Run #36667714896
Latest PR Test (Extra): 🚫 Run #36667714664
Latest PR Test (AMD ROCm 10): ❌ Run #36667714975