fix(vllm): floor max cached blocks at 1 for sub-block-size budgets (#343)#380
Open
SuperMarioYL wants to merge 1 commit into
Open
fix(vllm): floor max cached blocks at 1 for sub-block-size budgets (#343)#380SuperMarioYL wants to merge 1 commit into
SuperMarioYL wants to merge 1 commit into
Conversation
_get_max_cached_blocks derived the block budget as MAX_CACHED_TOKENS // block_size. A positive KVCACHED_MAX_CACHED_TOKENS smaller than block_size (e.g. 8 tokens with a 16-token block) floored to 0, which is the same value the == 0 'disabled' sentinel produces, so prefix caching was silently turned off instead of capped at a small budget. Floor the positive branch at one block and log a warning explaining the effective granularity, so a small non-zero budget keeps prefix caching enabled. Negative (unlimited), zero (disabled), and >= block_size budgets are unchanged. Adds tests/test_get_max_cached_blocks.py (GPU-free, mirrors test_make_cache_key.py) covering the sentinel boundaries and the sub-block regression. Fixes ovg-project#343
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.
Summary
Fixes #343.
_get_max_cached_blocks(kvcached/integration/vllm/patches.py) converts theunified
KVCACHED_MAX_CACHED_TOKENSconfig into a block budget with:When
KVCACHED_MAX_CACHED_TOKENSis a small positive value below one KVblock (e.g.
8with a16-tokenblock_size), integer division floors to0.That is the exact value the
== 0"disabled — evict on free" sentinelproduces, so a user who asked for a small non-zero cache gets prefix caching
silently turned off instead of a small cap.
Fix
Handle the sentinels explicitly and floor the positive branch at one block:
smallest viable unit (1 block), which the consumer at
ElasticBlockPool(max_cached_blocks >= 0 and len(evictable) > max_cached_blocks)treats as a valid cap of one evictable block.
warningreports the effectivegranularity and points at
KVCACHED_MAX_CACHED_TOKENS=0for explicit disable.< 0(unlimited),== 0(disabled), and>= block_sizebudgets arebyte-for-byte unchanged; the only behavioral change is the previously
broken
0 < tokens < block_sizecase.Tests
Adds
tests/test_get_max_cached_blocks.py— GPU-free (novmm_ops, GPU, orinstalled vLLM), mirroring the existing
tests/test_make_cache_key.py. Coversthe
-1 / 0 / sub-block / exact-multiple / non-multiple / largeboundaries, the#343regression (0 < tokens < block_sizenever collapses to the disabledsentinel), and the warn-on-clamp / no-warn-on-full-block behavior.