Skip to content

Feature(quantization): add KIVI KV-cache quantization for exact-preifx reuse#4

Open
forLG wants to merge 8 commits into
Tele-AI:mainfrom
forLG:feature/kivi-quant
Open

Feature(quantization): add KIVI KV-cache quantization for exact-preifx reuse#4
forLG wants to merge 8 commits into
Tele-AI:mainfrom
forLG:feature/kivi-quant

Conversation

@forLG

@forLG forLG commented Jul 17, 2026

Copy link
Copy Markdown

Summary

  • Add reusable KV-cache quantization primitives under cacheseek/quant, including KIVI int4/int8 codecs and Triton kernels.
  • Integrate opt-in KIVI quantization into exact-prefix reuse, with encode-on-commit, decode-on-materialize, quantization fingerprinting, and quant-aware cache sizing.
  • Persist quantized KV-cache metadata through the store layer while keeping storage backends opaque to quantization internals.
  • Add KV quantization design docs, diagrams, example updates, and a LingBot exact-reuse benchmark for comparing quantized reuse, unquantized reuse, and cold fork baselines.

Testing

  • Added benchmarks/kvcache_quantization/lingbot_exact_reuse.py for 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.

forLG added 8 commits July 17, 2026 14:12
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant