NVIDIA/kvpress
LLM KV cache compression made easy
What it solves
Deploying long-context Large Language Models (LLMs) is expensive because the key-value (KV) cache grows linearly with the number of tokens. For instance, processing 1 million tokens with Llama 3.1-70B in float16 can require up to 330GB of memory. KVPress reduces these memory requirements and increases decoding speed by compressing the KV cache.
How it works
KVPress implements a variety of "presses"—compression methods that prune or merge KV pairs during the prefilling phase or periodically during the decoding phase. It integrates with the Hugging Face transformers library, providing a custom KVPressTextGenerationPipeline to handle tokenization and chat templates.
Compression is achieved through several strategies:
- Scorer-based pruning: Using importance scores (e.g., random, inverse norm, or attention weights) to evict the least important KV pairs.
- Structural compression: Maintaining specific cache patterns, such as pyramid-like sizes across layers or keeping only initial and recent tokens (StreamingLLM).
- Dimensionality reduction: Compressing the dimensions of keys based on channel attention scores.
- Advanced techniques: Using CUR decomposition, context reconstruction (KVzip), or merging evicted tokens into surviving neighbors.
Who it’s for
Researchers and developers working on long-context LLM efficiency who need a standardized framework to implement, benchmark, and deploy KV cache compression methods.
Highlights
- Extensive Library: Supports a wide array of training-free compression methods including SnapKV, StreamingLLM, and KVzip.
- Flexible Pipeline: Offers a custom transformers pipeline for easy integration and evaluation.
- Dual-Phase Compression: Supports compression during both the prefilling phase and the decoding phase (via
DecodingPress). - Quantization Support: Compatible with
QuantizedCachefor further memory reduction. - Benchmarking Tools: Includes a CLI and notebooks to measure accuracy, peak memory usage, and total time gain.
Related
- Dispatch
- Project
- Project
- Project
- Dispatch