Feature(quantization): add KIVI KV-cache quantization for exact-preifx reuse#4
Open
forLG wants to merge 8 commits into
Open
Feature(quantization): add KIVI KV-cache quantization for exact-preifx reuse#4forLG wants to merge 8 commits into
forLG wants to merge 8 commits into
Conversation
generation quality.
KV cache quantization is introduced as a common CacheSeek component, with each strategy deciding whether to enable it. - introduce torch-free quant payload schemas and `KVLayerCodec` protocol. - add KIVI int4/int8 encode/decode with grouped stats, padding and int4 packing to int32 NOTE: - codec is kernel-free recently, `cacheseek/quant/kernel.py` is a placeholder.
Modified `cacheseek/store/tier.py` to store quantized KV-cache layer metadata as sidecar payloads.
- modified `cacheseek/reuse/exact_prefix/config.py` to support KV quant config. - modified `cacheseek/reuse/exact_prefix/manager.py`, KVManager will inital a KVCodec and encode KV before ingest, decode after materialize. - modified `cacheseek/reuse/exact_prefix/telefuse_lingbot`, the computation of root hash now includes quant fingerprint. - modified `examples/exact_prefix_reuse/` to support KV quant. NOTES: - replace caller-provided byte counts with manager-side accounting so stored payload sizes reflect optional quantization. `cacheseek/reuse/manager.py` and `cacheseek/reuse/strategy.py`
Move exact-prefix KV device placement from the LingBot binding into WorldKVManager. Raw KV is cloned to CPU only for non-quantized storage, while quantized KV stays on GPU before encode so the quant codec can avoid an extra CPU round trip. With quantization running directly on GPU, quantized ingest is now nearly the same speed as the non-quantized path.
Add optional Triton kernels for grouped KIVI quant/dequant and int4 pack/unpack, with torch fallback paths for CPU, CUDA without Triton, and non-Triton environments. Normalize quantized KV data movement around compact payloads, see `cacheseek/quant/kivi.py` for details: - Encoding runs on the tensor's current source device. - Encoded qdata/scale/offset are moved back to CPU before being storred. - Decoding moves only compact qdata/scale/offset to target device before dequantization, avoiding a full-precision CPU decode followed by GPU transfer. Also add a `device()` property to `RollingWindow` class for better data device control.
See `benchmarks/kvcache_quantization/README.md` for detailed information. NOTES: Performance measurment is undergoing.
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
cacheseek/quant, including KIVI int4/int8 codecs and Triton kernels.Testing
benchmarks/kvcache_quantization/lingbot_exact_reuse.pyfor measuring qantization exact-prefix reuse latency, speedup, cache behavior, and output-quality drift in end-to-end Telefuser Lingbot inference. Further performance measurment is undergoing.