Fix KV cache pool sized far too small when weight-loading memory is still referenced - #36583
Merged
Merged
Conversation
alisonshao
requested review from
Ying1123,
alphabetc1,
hanming-lu,
hnyls2002,
huangtingwei9988,
hzh0425,
ispobock,
merrymercy,
xiezhq-hermann and
yizhang2077
as code owners
August 27, 2026 00:46
saturn-acc
pushed a commit
to saturn-acc/sglang
that referenced
this pull request
Aug 31, 2026
nzr-niu
pushed a commit
to nzr-niu/sglang
that referenced
this pull request
Sep 1, 2026
5 tasks
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.
The KV pool budget is measured right after weights load, from currently-free GPU memory.
get_available_gpu_memory()callsempty_cache(), but that only returns unreferenced blocks — loader temporaries that are still referenced count as used, so the budget can come out orders of magnitude too small while GPU memory sits idle. Collecting before the measurement drops those references first.Reproduced on 4×H200 with memory held back to emulate 80 GB cards, TP4 + EAGLE,
--mem-fraction-static 0.8 --context-length 65536:max_total_num_tokensBefore the fix a 3000-word prompt is rejected with
Input length (3034 tokens) exceeds the maximum allowed length (1735 tokens); after it, 3000- and 12000-word prompts both complete normally.CI States
Latest PR Test (Base): ✅ Run #33030917002
Latest PR Test (Extra): ✅ Run #33030916853
Latest PR Test (AMD ROCm 7.2): ❌ Run #33030916968