Support for quantized kv cache (compressed-tensors) #6028
+185
−50
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.
Feature description
Adding the logic for loading quantized models with additional kv cache quantization, generated using
compressed-tensors
framework.Notable changes:
CompressedTensorsConfig
right now expect to read an optionalkv_cache_scheme
argument. As of the nextcompressed-tensors
release, the key contains the information about the properties of the quantized kv cache.BaseKVCacheMethod
and its implementationCompressedTensorsKVCacheMethod
, to preparekv_scale
attribute ofAttention
layer on the model initializationCurrent limitations
Currently, the loading of the kv cache scales happens inside the
load_model
method of the model (in this PR only LLaMa model), which is a bit ugly (we need to copy and paste the helper function into every model to make it read quantized kv cache). Something to think about after the initial round of reviews.Also
compressed-tensors
assume separate value fork_scale
andv_scale
, which is not directly compatible withvLLM
. I added minimal logic to reconciles the requirement for scales to be recomputed for "kv tensor".The UX for the user would not change, however, they will be able to automatically load the
compressed-tensors
model with this new feature.