Support per_token KV Cache eviction#1
Open
l-bat wants to merge 16 commits into
Open
Conversation
There was a problem hiding this comment.
Pull Request Overview
Adds per-token KV cache eviction support (SnapKV, H2O) by defining new compression parameters and a compressor that hooks into model attention layers.
- Introduce
KVCacheCompressionModeenum andKVCacheCompressionParametersdataclass for eviction configuration - Implement
KVCacheCompressorwith scoring, index selection, and cache pruning logic intorch_backend.py - Update
.ci/cspell_dict.txtto recognize the new “snapkv” term
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/nncf/quantization/algorithms/kv_cache_management/torch_backend.py | Adds KVCacheCompressor class, scoring, index selection, and hook logic |
| src/nncf/quantization/algorithms/kv_cache_management/init.py | Add license header |
| src/nncf/quantization/advanced_parameters.py | Define KVCacheCompressionMode enum and KVCacheCompressionParameters |
| .ci/cspell_dict.txt | Add “snapkv” to the custom spell‐check dictionary |
Comments suppressed due to low confidence (3)
src/nncf/quantization/advanced_parameters.py:472
- The docstring lists supported values as 'sum' and 'max', but the code accepts 'sum' and 'norm_sum'. Please update the documentation to match the implemented options.
when determining least important tokens for eviction from cache. Supported values are 'sum' and 'max'.
src/nncf/quantization/algorithms/kv_cache_management/torch_backend.py:185
- The docstring parameters (module, hidden_states, attentions) do not match the method signature (layer_idx, keys, values, kwargs). Please synchronize the docstring with the actual arguments.
The core logic of the compression method.
src/nncf/quantization/algorithms/kv_cache_management/torch_backend.py:23
- [nitpick] The new
KVCacheCompressorintroduces significant logic for score computation and pruning. Please add unit tests to cover its key behaviors (e.g., scoring, index selection, and compression).
class KVCacheCompressor:
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.
Features:
Usage example: