mirror of
https://github.com/kvcache-ai/sglang.git
synced 2026-11-05 01:07:39 +00:00
[PR #83] [MERGED] fix(dsv4): honor --max-total-tokens for the compressed-attention pool #82
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/sglang#82
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/kvcache-ai/sglang/pull/83
Author: @05yuki
Created: 8/27/2026
Status: ✅ Merged
Merged: 9/10/2026
Merged by: @yyj6666667
Base:
main← Head:fix/dsv4-compressed-kv-pool-sizing📝 Commits (1)
206600efix(dsv4): honor --max-total-tokens for the compressed-attention pool📊 Changes
1 file changed (+15 additions, -1 deletions)
View changed files
📝
python/sglang/srt/model_executor/model_runner_kv_cache_mixin.py(+15 -1)📄 Description
For DeepSeek V4, init_memory_pool() seeds self.max_total_num_tokens with
profile_max_num_token(), which estimates capacity from the generic KV
cell size. set_num_tokens_hybrid_swa_compress() then profiles the real
compressed layout via DSv4MemoryCalculator, but when --max-total-tokens
was passed explicitly it also treats the already-seeded
self.max_total_num_tokens as a ceiling and falls back to
get_pool_sizes_by_configuration() with it.
The ceiling therefore comes from a layout the model never uses. On a
2x16 GB SM120 setup with KT CPU experts, a configured 1M-token context
was clamped to roughly 143K tokens even though the compressed pool fits
the full 1M.
Seed the ceiling with the configured value instead when the model uses
compressed attention and --max-total-tokens was given. The dedicated
calculator still profiles available VRAM and still reduces the pool when
it does not fit, and the configuration path is only ever taken to shrink
below the profiled size, so a large configured value cannot inflate the
pool past what profiling allows.
Runs that do not pass --max-total-tokens are unaffected: the ceiling is
never consulted there, and profile_max_num_token() keeps seeding the
value that max_running_requests is derived from.
Verified on DeepSeek-V4-Flash MXFP4: full_max_total_num_tokens reaches
1,048,576 with mem_fraction_static 0.985 and decoding stays coherent.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.