Repository navigation
[Fix] Release consumed residual contributions - #41749
Merged
Merged
Conversation
After the next stage's prepare consumed a pending contribution, the caller's handle still referenced its tensors until the next layer returned. Under attention DP a deferred FFN sum therefore kept its gathered rows alive through the whole next layer, which raises prefill CUDA graph memory. Writing the residual now drops the consumed contribution's tensors; stale handles were already rejected.
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/hot-fix/release-consumed-contribution
branch
from
September 29, 2026 20:00
85357f5 to
be31274
Compare
Collaborator
Author
|
/rerun-test test_residual_stream.py |
Contributor
|
Results for 🚀 |
This was referenced Sep 30, 2026
This was referenced Sep 30, 2026
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
Under attention DP, prefill CUDA graph capture uses about 62 MiB more memory than before the layer boundary refactor (#41547–#41557). The FFN all-reduce of a dense layer is now deferred to the next layer's input, so the unreduced output — gathered over the DP ranks, 2N rows for N local tokens — is stored in the residual stream's pending contribution. The next stage's
prepare()consumes it, but the model loop still holds the returned handle until the next layer returns, and the handle keeps the tensor alive. Inside the graph memory pool that block cannot be reused.Modifications
Contribution.release()drops a contribution's tensors.ResidualStream.write()releases the contribution it replaces. It is called only where a pending contribution is consumed: a successfulprepare(),fold()and branch merge.complete_output(),snapshot()and export (to_pp(), the final norm) do not release. Stale handles were already rejected by the stream, so nothing can read a released contribution.Accuracy Tests
B200,
--tp-size 2 --dp-size 2 --enable-dp-attention,python -m sglang.benchmark.one_batch --correctness-test: the printed prefill logits and all three generations are identical to the parent commit for Qwen3-0.6B and for Qwen1.5-MoE-A2.7B.Speed Tests and Profiling
Prefill CUDA graph capture memory, same B200 configuration (58 capture shapes, 4–8192 tokens):
6582425854)f731e82f09)Qwen1.5-MoE-A2.7B, same flags: 2.51 GB on the parent (the same on a repeat run), 2.26 GB with this PR, 2.26 GB before the refactor.
For Qwen3-0.6B the graph pool size after every shape equals the pre-refactor tree. Kernels and collectives are unchanged, so 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 #36623301447
Latest PR Test (Extra): ❌ Run #36623301195
Latest PR Test (AMD ROCm 10): ❌ Run #36623301173