Abstract
Large Language Models (LLMs) face a significant memory bottleneck due to the linear growth of the Key-Value (KV) cache in long-context tasks. Traditional quantization methods often hit a precision floor at 2 bits, leading to catastrophic model degradation. We present Cache Sparse Representation (CSR), a novel framework that treats KV cache compression as a sparse coding problem. By utilizing a learned dictionary (NeuralDict) to represent KV vectors as sparse indexes and weights, CSR achieves performance comparable to 4-bit quantization while pushing the effective bitrate down to 1 bit per channel with minimal accuracy loss.
The KV Cache Bottleneck
As LLMs are increasingly used for long-context applications like document summarization and Retrieval-Augmented Generation (RAG), the KV cache becomes a primary constraint. To avoid recomputing attention for every new token, models store previous "Keys" and "Values" in memory. This cache grows linearly with sequence length, quickly consuming dozens of gigabytes of GPU VRAM. While existing solutions like Multi-Query Attention (MQA) or 4-bit quantization provide some relief, they eventually reach a limit where further compression destroys model utility. CSR addresses this by exploiting the inherent redundancy in KV vectors, decomposing dense vectors into a few "basis atoms" from a pre-trained dictionary.
Methodology: Cache Sparse Representation (CSR)
The CSR framework replaces traditional floating-point storage with a small number of indexes and coefficients. During inference, it employs the Matching Pursuit (MP) algorithm to identify the best atoms in a dictionary to approximate the original KV vector.
NeuralDict and Optimization
To create the dictionary, the authors developed NeuralDict, a neural network-based training method. By passing a calibration dataset through the model, a dictionary matrix is trained to minimize the Mean Squared Error (MSE) between original vectors and their sparse reconstructions. Key optimizations include:
- Offline/Online Hybrid: The dictionary uses a large "offline" part learned from data and a small "online" part sampled during inference to handle outliers.
- Layer Merging: Adjacent transformer layers often share similar KV spaces, allowing them to share dictionaries and further reduce memory overhead.
- Pre-RoPE Processing: Compression is performed before applying Rotary Positional Embeddings (RoPE) to ensure vector stability across positions.
Key Results and Analysis
The framework was evaluated on the LongBench benchmark using models such as Llama2-7B and Llama3-8B.
Performance at Ultra-Low Bitrates
CSR-16 (equivalent to 4-bit) outperformed state-of-the-art quantization methods like KIVI and GEAR across several tasks. Most notably, at CSR-4 (the 1-bit equivalent), the model maintained robust performance with only an ~8% drop in average score compared to full FP16 precision. In contrast, standard 1-bit quantization typically renders models unusable.
Memory Efficiency
CSR significantly flattens the memory growth curve associated with long sequences. For a sequence length of 32k tokens on Llama3-8B, CSR-4 requires roughly 1/10th the memory of the original FP16 cache.
Conclusion
CSR shifts the paradigm of KV cache compression from "bits per number" to "atoms per vector." By achieving the 1-bit milestone, it enables the processing of significantly longer contexts on existing hardware. Future work will focus on reducing the training overhead for NeuralDict and optimizing the Matching Pursuit algorithm to minimize inference latency during the prefill stage.
Summary updated