fix prefix caching#4700
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes SSM prefix-cache KV eviction to avoid evicting trie leaves whose SSM state checkpoints are still pinned (e.g., by an in-flight save/restore), preventing release_state_checkpoint() from raising on pinned checkpoints and allowing eviction to succeed once pins are released.
Changes:
- Update
BlockTrie.evict()to skip KV eviction for leaves with pinned SSM checkpoints (state_ref_count > 0). - Avoid calling the allocator free-path when no blocks were actually evicted (e.g., all candidates were skipped).
- Add a regression test ensuring eviction returns
0while pinned, preserves the node, then evicts after releasing the save pin.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lmdeploy/pytorch/paging/block_trie.py | Skips pinned SSM checkpoint leaves during KV eviction and returns early when nothing is evicted. |
| tests/pytorch/paging/test_block_trie.py | Adds regression coverage for KV eviction behavior when an SSM checkpoint is pinned by a producer save ref. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lvhan028
approved these changes
Jun 23, 2026
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.
Fix SSM prefix-cache KV eviction so it does not release checkpoints that are still pinned by an in-flight save/restore.
Previously,
BlockTrie.evict()selected leaves only by KV block refcount. For SSM nodes, a leaf could have an idle KV block (ref_count == 1) while its state checkpoint was still protected bystate_ref_count > 0. Evicting that leaf calledrelease_state_checkpoint()and hit the invariant error:The fix makes KV eviction skip pinned SSM checkpoint leaves for the current eviction attempt. The node remains in
self.leaves, so once the save/restore pin is released, a later eviction can reclaim it normally. It also avoids freeing an empty eviction list when all candidates are skipped.Added a regression test covering the pinned-checkpoint case: eviction returns
0while the checkpoint is pinned, keeps the node cached, then successfully evicts it after the producer pin is released.