Repository navigation
[DSV4][BCG] Optimize the heavy memory use of C4 Indexer when BCG is enabled - #36534
Merged
Merged
Conversation
…model's max_context_length in C4 Indexer
SYChen123
requested review from
Fridge003,
HaiShaw,
Qiaolin-Yu,
Ying1123,
hebiao064,
hnyls2002,
ispobock,
merrymercy and
xiezhq-hermann
as code owners
August 26, 2026 16:22
SYChen123
requested review from
ByronHsu,
Duyi-Wang,
ShangmingCai and
sogalin
as code owners
August 27, 2026 03:26
SYChen123
force-pushed
the
context-bucket
branch
from
August 27, 2026 03:37
e427503 to
48f9c97
Compare
Oasis-Git
reviewed
Aug 31, 2026
2. only deepseek v4 backend supports max context size.
Oasis-Git
approved these changes
Sep 10, 2026
Collaborator
|
Let's run ci |
Collaborator
|
/rerun-failed-ci |
Collaborator
|
/rerun-failed-ci |
1 similar comment
Collaborator
|
/rerun-failed-ci |
Collaborator
Collaborator
|
/rerun-failed-ci |
Collaborator
Leoyzen
pushed a commit
to Leoyzen/sglang
that referenced
this pull request
Sep 16, 2026
…nabled (sgl-project#36534) Co-authored-by: Yuwei An <ayw.sirius19@gmail.com> (cherry picked from commit c9a8fba)
This was referenced Sep 16, 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.
Motivation
When enabling BCG on deepseek v4, C4 indexer leads to heavy memory pressure. The root reason is that the indexer logits with shape of [N, context_length] is padded to [N, max_position_embeddings]. For deepseek v4, model's max_position_emb is 1048576. When N=8192, the logits itself will cost 8192 * 1048576 // 4 * 4 = 8GB.
Therefore, we propose to add a new parameter named --cuda-graph-prefill-max-context and the logit is padded to the user-specified max context size instead model's maximum context.
Modifications
Accuracy Tests
gsm8k test on deepseek-v4-flash-0731 is good.

Speed Tests and Profiling
Memory usage reduction
Before this pr, capture will cost 43GB when --cuda-graph-max-bs-prefill=16384.

With this pr, the capture memory cost is reduced to 18GB. 58% memory reduction.

E2E test on deepseek-v4-flash-0731
E2E latency has 10% performance gains with BCG enabled. Without this pr, the server will OOM when chunk-prefill-size and max-captured-size are both set to 16384.
Server launching and benchmark commands are shown below.
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): ✅ Run #34568924841
Latest PR Test (Extra): ✅ Run #34568924736
Latest PR Test (AMD ROCm 10): ➖ No AMD PR run found for this commit.