Repository navigation
[Fix] Avoid duplicate residual in LongCat MoE shortcut - #40799
Conversation
9ed3f77 to
6057b34
Compare
ch-wan
left a comment
There was a problem hiding this comment.
Reviewed by agent.
Summary
Passing a zero residual to MoE shortcut postprocessing is correct: the dense branch already owns that residual, and the shortcut folds the argument into its output only when gathering scattered tokens on the final layer. The new test locks that case. Fifteen of the sixteen subtests still pass if residual.clone() is restored, so they do not guard the double-add.
Issue counts by severity
- bugs: 0
- suggestions: 2
- nits: 1
|
|
||
| class TestLongcatShortcut(unittest.TestCase): | ||
| def test_shortcut_contributes_only_moe_output(self): | ||
| for tp in (1, 2): |
There was a problem hiding this comment.
[suggestion] Only tp=2, scattered=True, terminal=True, rows=4 fails on the unfixed forward. CommunicateSummableTensorPairFn.get_fn adds the residual solely in _gather, which requires SCATTERED and TP_ATTN_FULL to have different group sizes. FULL is given the same size as TP_ATTN_FULL, and tp=1 collapses SCATTERED to that size too, so those cells hit _trivial and ignore the residual. target treats every non-scattered layer as terminal (terminal or not scattered), so that axis is duplicated. rows=0 is empty, and assert_close accepts any values of the same shape.
Suggestion: Keep the one cell that goes from 16 to 21 under residual.clone(). Drop the duplicated non-scattered pairs, and do not count the empty or _trivial cells as coverage of this bug.
|
|
||
|
|
||
| class TestLongcatShortcut(unittest.TestCase): | ||
| def test_shortcut_contributes_only_moe_output(self): |
There was a problem hiding this comment.
[suggestion] This is a bug regression, and the test no longer states the behavior that must not come back. The method name is the only hint.
Suggestion: Add a one-line docstring that the MoE shortcut must not carry the dense branch's residual.
| register_cpu_ci(est_time=3, suite="base-a-test-cpu") | ||
|
|
||
|
|
||
| class TestLongcatShortcut(unittest.TestCase): |
There was a problem hiding this comment.
[nit] New registered tests should subclass CustomTestCase, not unittest.TestCase. This case starts no server, so the gap is the CI retry wrapper, not a leaked process.
Suggestion: Use sglang.test.test_utils.CustomTestCase.
1a66b01 to
6057b34
Compare
6057b34 to
f63f0a1
Compare
f63f0a1 to
d9a28a0
Compare
This PR is part of a stack (oldest at bottom):
Motivation
With scattered MoE tokens, LongCat's final-layer postprocessing gathers
moe_output + residual. The dense branch already owns that residual, so merging the shortcut adds it twice. A regression example that should produce 16 instead produces 21.Modifications
Pass a zero residual to MoE shortcut postprocessing, leaving the residual with the dense branch. Add a regression through the actual decoder forward and communicator postprocessing, covering TP1/TP2, full/scattered tokens, terminal/nonterminal layers, and empty inputs.
Accuracy Tests
Stacking and comment cleanup preserve the executable AST of the tested revisions.
The GPU probe uses synthetic Attention/MoE/dense outputs to isolate residual ownership. Full-checkpoint inference has not been run.
Speed Tests and Profiling
No performance benchmark. The fix replaces one residual clone with a same-sized zero allocation and adds no collective.
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): 🚫 Run #35923572261
Latest PR Test (Extra): 🚫 Run #35923571941
Latest PR Test (AMD ROCm 10): ❌ Run #35923571921