Skip to content

Fix KV cache pool sized far too small when weight-loading memory is still referenced - #36583

Merged
alisonshao merged 3 commits into
mainfrom
fix/kv-budget-gc-before-profile
Aug 28, 2026
Merged

alisonshao merged 3 commits into
mainfrom
fix/kv-budget-gc-before-profile

Conversation

@alisonshao

@alisonshao alisonshao commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

The KV pool budget is measured right after weights load, from currently-free GPU memory. get_available_gpu_memory() calls empty_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_tokens free memory left unused
before 1,741 46.9 GB
after 349,377 17.0 GB

Before 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

@JustinTong0323 JustinTong0323 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alisonshao
alisonshao merged commit 23cb11a into main Aug 28, 2026
239 of 275 checks passed
@alisonshao
alisonshao deleted the fix/kv-budget-gc-before-profile branch August 28, 2026 16:47
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
Jiminator pushed a commit that referenced this pull request Sep 5, 2026
Jiminator pushed a commit that referenced this pull request Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants