Abstract
The growing context length of Large Language Models (LLMs) enlarges the Key-Value (KV) cache, limiting deployment in resource-limited environments. Prior training-free approaches for KV cache compression typically rely on low-rank approximation or scalar quantization, which fail to simultaneously achieve high compression ratios and high reconstruction fidelity. We propose VQKV, a novel, training-free method introducing vector quantization (VQ) to obtain highly compressed KV representations while preserving high model fidelity, allowing for the representation of thousands of floating-point values with just a few integer indices. As a result, VQKV achieves an 82.8% compression ratio on LLaMA3.1-8B while retaining 98.6% of the baseline performance on LongBench and enabling 4.3x longer generation length on the same memory footprint.
Introduction
As Large Language Models (LLMs) move toward processing "infinite" context windows, the Key-Value (KV) cache has become a critical physical bottleneck. For every token processed, the model must store high-dimensional "Key" and "Value" vectors for future attention mechanisms. As sequence lengths increase, this cache consumes massive amounts of GPU VRAM, often exceeding the capacity of standard hardware and limiting long-document processing or multi-turn conversations.
Existing compression strategies generally fall into three categories: token eviction (dropping "unimportant" tokens), scalar quantization (reducing individual numerical precision), and architectural changes (e.g., Multi-Query Attention). However, these methods often trade off accuracy for compression or require expensive model retraining. VQKV addresses these challenges by providing a training-free, high-fidelity solution that achieves significant compression ratios.
Methodology: Vector Quantization for KV Caches
The core innovation of VQKV is the application of Vector Quantization (VQ)—specifically Residual Simple Vector Quantization (RSimVQ)—to the KV cache. Unlike scalar quantization, which processes numbers individually, VQ treats groups of numbers as single units, capturing intrinsic correlations between dimensions.
Technical Components
- Residual Design: RSimVQ employs multiple codebooks where each successive book quantizes the residual error from the previous one, allowing for progressively finer reconstruction.
- RoPE Robustness: The residual structure effectively handles the complex frequency variations introduced by Rotary Positional Embeddings (RoPE).
- Hybrid Storage: VQKV utilizes a hybrid approach, maintaining the initial and most recent (local) tokens in full precision while compressing the massive intermediate cache.
- Custom FlashAttention Kernel: To mitigate decompression overhead, a customized Triton kernel integrates decompression directly into the attention computation.
Experimental Setup
The authors evaluated VQKV on LLaMA3.1-8B and LLaMA3.2-3B. Codebooks were trained once using a 0.1% sample of the OpenWebText corpus, requiring no fine-tuning of the LLM itself. Performance was measured across several benchmarks:
- LongBench: For long-context understanding.
- Needle-In-A-Haystack (NIAH): For specific fact retrieval within massive contexts.
- RULER: To probe effective context length across retrieval and aggregation tasks.
Key Results and Performance
VQKV demonstrates superior performance compared to existing training-free compression methods.
Compression and Fidelity
On LLaMA3.1-8B, VQKV achieved an 82.8% compression ratio while retaining 98.6% of the baseline performance on LongBench. Notably, the method maintained a perfect 100% score on the NIAH test up to 32K context, significantly outperforming competitors like ASVD and Palu.
Memory and Efficiency
Using a single NVIDIA RTX 4090, VQKV extended the maximum generation length from approximately 190k tokens to over 824k tokens, representing a 4.3x increase in memory efficiency.
Discussion and Conclusion
VQKV proves that joint quantization of entire vectors is more effective than scalar approaches because it preserves the "meaning" of representations by capturing inter-dimensional correlations. Interestingly, the quantization process may even act as a form of denoising, occasionally leading to performance that exceeds the uncompressed baseline.
While VQKV offers substantial gains, future work will focus on further optimizing the computational overhead of VQ lookups in the decoding stage and exploring the limits of the method on models exceeding 70B parameters.
Summary updated