Support KV cache quantization with continuous batching#941
Open
ochafik wants to merge 1 commit intoml-explore:mainfrom
Open
Support KV cache quantization with continuous batching#941ochafik wants to merge 1 commit intoml-explore:mainfrom
ochafik wants to merge 1 commit intoml-explore:mainfrom
Conversation
Add QuantizedKVCache.merge() which dequantizes to float and delegates to BatchKVCache.merge(), enabling quantized caches to participate in batch generation. Add quantize_config parameter to BatchKVCache.extract() so extracted caches can be re-quantized for memory-efficient LRU storage. Wire kv_bits/kv_group_size through BatchGenerator so callers can opt into quantized cache storage while using float batch computation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Member
|
This is interesting albeit a bit weird. Basically all the computation is done in fp16 but the storage is done quantized. Could be useful but generally speaking there should be a BatchQuantizedKVCache that also does the computation quantized a) so that perf doesn't degrade after every turn b) so that long context (largely memory bound) is faster. |
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
QuantizedKVCache.merge()— dequantizes to float, delegates toBatchKVCache.merge(), enabling quantized caches to participate in batch generationquantize_configparameter toBatchKVCache.extract()— extracted caches can be re-quantized asQuantizedKVCachefor memory-efficient LRU storagekv_bits/kv_group_sizethroughBatchGeneratorso callers can opt into quantized cache storageQuantizedKVCache.size()for consistency with other cache typesCurrently
QuantizedKVCacheandBatchGeneratorare mutually exclusive (theis_batchableguard rejectskv_bits). This PR adds the missingmerge()support so they can work together. The approach keeps batch computation in float (short-lived, needed for padding/concatenation) and only quantizes on extract (long-lived LRU storage), which is where memory savings matter most.Test plan
size()tests/test_prompt_cache.py)🤖 Generated with Claude Code