Abstract
The Key-Value (KV) cache introduces substantial memory overhead during large language model (LLM) inference. Although existing vector quantization (VQ) methods reduce KV cache usage and provide flexible representational capacity across bit-widths, they suffer severe performance degradation at ultra-low bit-widths due to key cache outliers that hinder effective codebook utilization. To address this challenge, we propose VecInfer, a novel VQ method for aggressive KV cache compression while enabling efficient inference. By applying smooth and Hadamard transformations, VecInfer suppresses outliers in the key cache, enabling the codebook to comprehensively cover the original data distribution and thereby reducing quantization difficulty. To facilitate efficient deployment, we design an optimized CUDA kernel that fuses computation with dequantization to minimize memory access overhead. Extensive evaluations demonstrate that VecInfer consistently outperforms existing quantization baselines across both long-context understanding and mathematical reasoning tasks. With only 2-bit quantization, VecInfer achieves performance comparable to full precision, while delivering up to 2.7× speedup in large-batch self-attention computation and 8.3× reduction in single-batch end-to-end latency on Llama-3.1-8B with a 196k sequence length.
The KV Cache Bottleneck
As Large Language Models (LLMs) scale to process massive contexts (100k+ tokens), the Key-Value (KV) cache becomes a critical memory bottleneck. The KV cache stores previous token states to avoid redundant computation during decoding, but its size grows linearly with sequence length. While quantization is a standard solution, ultra-low bit-widths (e.g., 2-bit) typically lead to severe performance degradation. The primary obstacle is the presence of outliers—extreme values in the key cache vectors that lie far outside the range of standard quantization codebooks, leading to massive reconstruction errors.
Methodology: Outlier-Suppressed Vector Quantization
VecInfer introduces a two-pronged approach to make low-bit VQ viable for LLM inference by transforming the data distribution into a more "quantization-friendly" state.
1. Dual Transformation for Outlier Suppression
To address the "spiky" nature of the key cache, VecInfer applies two key transformations:
- Smooth Transformation: Channel-wise scaling balances the magnitudes across different dimensions of the key cache, preventing specific channels from dominating the quantization error.
- Hadamard Transformation: A Walsh-Hadamard rotation is applied to keys and queries. This redistributes the energy of outliers across all dimensions, making the data distribution more Gaussian. This transformation is computationally invariant, meaning it does not change the final attention result but significantly improves codebook utilization.
2. Hardware-Efficient Fused Kernel
Standard VQ often incurs a "dequantization tax" where the overhead of looking up codebook entries cancels out the memory savings. VecInfer implements a fused dequantization-computation CUDA kernel. It uses fine-grained tiling and asynchronous pipeline execution (via memcpy_async) to overlap memory transfers from global memory to shared memory with the actual attention calculations, maximizing hardware utilization.
Key Insights
- Redistribution over Removal: Instead of clipping or ignoring outliers, VecInfer "smears" them across dimensions using the Hadamard transform. This preserves information while making the vector easier to represent with a finite codebook.
- Task-Independent Codebooks: Once the data is transformed to be more uniform, the VQ codebook becomes largely task-independent. A codebook trained on one dataset generalizes well to others, simplifying deployment across different LLM applications.
- Sensitivity Asymmetry: The Key cache is significantly more sensitive to quantization than the Value cache. VecInfer allows for mixed-precision strategies to optimize the accuracy-efficiency trade-off.
Performance and Results
VecInfer was evaluated across models like Llama-3.1-8B and Mistral-7B using benchmarks such as LongBench and various mathematical reasoning tasks (GSM8K, AIME24).
- Accuracy: At 2-bit precision, VecInfer loses only 2.1% average accuracy on LongBench, significantly outperforming VQ baselines like MILLION, which often collapse at such low bit-widths.
- Reasoning: On complex Chain-of-Thought tasks like AIME24, VecInfer maintained coherent reasoning where other 2-bit methods failed entirely.
- Efficiency: The system achieves an 8.3× reduction in single-batch end-to-end latency for Llama-3.1-8B with a 196k sequence length on an H100 GPU. It enables running massive context lengths on hardware that would otherwise encounter Out-of-Memory (OOM) errors using standard FP16 or 4-bit methods.
Conclusion
VecInfer demonstrates that ultra-low bit KV cache quantization is achievable without sacrificing accuracy. By combining mathematical transformations to suppress outliers with optimized CUDA kernels, it provides a scalable solution for the memory challenges of long-context LLM inference. Future work includes integrating VecInfer into mainstream serving frameworks like vLLM and exploring synergies with sparse attention patterns.
Summary updated