Repository navigation
[Bugfix][HiSparse] Adopt GPU prefix copies after the hit's allocation - #59274
Closed
MatthewBonanni wants to merge 1 commit into
Closed
MatthewBonanni wants to merge 1 commit into
MatthewBonanni wants to merge 1 commit into
Conversation
A HiSparse host-prefix hit re-pins free GPU copies of its pages. Admission counts those copies as free blocks, but adoption pinned them before the hit's own allocation, which could then run the pool dry and crash the engine with "Cannot get N free blocks from the pool". Adopt the copies after the allocation instead, from update_residency, so the allocation always gets the blocks admission counted. To keep the copies the allocation does not need, unpinned blocks now form a true last-resort segment at the tail of the free queue, behind every later-freed block, and HiSparse releases a prefix's pages tail first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
Member
Author
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.
Purpose
Fix an engine crash (
Cannot get N free blocks from the pool) on a HiSparse host-prefix hit under GPU memory pressure. This is an alternative to #57457.A host-prefix hit re-pins free GPU copies of its pages so the prefix comes back GPU-resident. Admission counts those copies as free blocks, but adoption pinned them before the hit's own allocation (hot region and new pages), which could then run the pool dry.
#57457 fixes this by charging the pins at admission. That mixes host and GPU accounting in
HiSparseSourceManager.get_num_blocks_to_allocate, and under pressure it defers a request that could run by reading its prefix from host, just to keep an optimization.Changes
commit_computed_blocksrecords the pages to adopt, andupdate_residency(incache_blocks, afterallocate_new_blocks) adopts the copies that survived. The allocation always gets what admission counted, so no admission accounting is needed. A copy the allocation reuses is dropped by its reuse watcher and never adopted.BlockPool.unpin_blocksdocuments unpinned blocks as last-resort eviction candidates, but blocks freed afterwards were appended behind them, so an allocation evicted a prefix's copies before blocks nobody would reuse.FreeKVCacheBlockQueuenow keeps a last-resort segment at its tail that later appends stay in front of, andunpin_blocksuses it.free_blocks' convention, so pressure trims a prefix from its end.Replaying #57457's scenario (a resumed 3-page host prefix hit,
free_blocksleft in the pool):free_blocksTest Plan
test_hisparse_prefix_hit_under_pressure_adopts_surviving_copies[7, 9, 10]: exact adopted pages, and no block shared between adopted copies and fresh allocations.7fails without the adoption timing,9without tail-first release, and10without the last-resort segment.test_free_kv_cache_block_queue_last_resort_stays_behind: later appends stay ahead of the segment after its first block is removed or popped.tests/v1/core/test_prefix_caching.pyandtests/v1/core/test_kv_cache_utils.py, withCpuPlatformselected:Test Result
fixture 'caplog_vllm' not found, from running outside the top-level conftest, and are identical on main.No GPU or model run: the change is scheduler-side block bookkeeping.
AI assistance (Claude Code) was used for the investigation, implementation, tests, and this description.
🤖 Generated with Claude Code