Abstract
Large Language Models (LLMs) are increasingly required to process long-context inputs, yet the linear growth of the Key-Value (KV) cache creates a significant "memory wall." We introduce Selective Compression Attention (SCA), a training-free, "plug-and-play" method that expands the context window by intelligently shrinking the KV cache. By treating cache management as a matrix compression problem, SCA employs a greedy algorithm to retain the most representative vectors. Our evaluation shows that SCA enables models to handle sequences up to 16x their original limit with minimal performance loss, frequently outperforming models specifically fine-tuned for long contexts.
Introduction: The KV Cache Memory Wall
As LLMs are deployed for tasks involving massive documents or codebases, the memory required to store previous token keys and values—the KV cache—becomes a bottleneck. For a 7B parameter model, the KV cache grows linearly with sequence length, quickly exhausting GPU VRAM. Existing solutions, such as sparse attention or retrieval-based methods, often discard vital information or require expensive retraining.
SCA addresses this by exploiting the inherent redundancy within the KV cache. In models like Llama-2-7B, the average redundancy of the Key matrix is approximately 0.88–0.89, suggesting that a vast majority of stored information is duplicative and can be safely compressed.
Methods: Selective Compression as Matrix Optimization
The core of SCA is a greedy selection algorithm that manages the KV cache as a matrix compression problem. Rather than relying on simple heuristics like recency, SCA selects tokens based on their contribution to the overall distribution of information.
- Redundancy Metric: Redundancy is defined via cosine similarity. SCA identifies vectors that are highly similar to others already in the cache.
- Greedy Selection: The algorithm iteratively selects tokens that, when added to the retained set, result in the lowest overall redundancy, ensuring maximum "coverage" of the original vector space.
- Key & Value Integration: SCA considers both Key (attention scores) and Value (content) vectors to ensure the selection is representative of both context and meaning.
- Layer Sharing: To minimize computational overhead, the selection is calculated for the final layer and applied across all layers, a strategy found to maintain high accuracy.
As illustrated in the figure above, while methods like StreamingLLM focus on a fixed sliding window and initial "attention sinks," SCA maintains a more holistic and diverse representation of the entire context window by selecting representative vectors across the sequence.
Key Results and Insights
SCA was evaluated across diverse benchmarks, including short-text tasks (IMDB, RACE), language modeling (PG19, ArXiv), and long-context retrieval (Passkey Retrieval, L-Eval).
- Context Extension: SCA successfully extended the context of Llama-2-13B from 4k to 12k tokens with 100% accuracy on passkey retrieval, whereas baselines like StreamingLLM saw accuracy drop to near zero at that length.
- Memory Efficiency: On 15,000-token sequences, SCA achieved a 54.8% reduction in memory usage compared to full attention.
- Performance Stability: On the L-Eval benchmark, SCA improved the average accuracy of Llama-2-7B-Chat by 2.8 points and Vicuna-1.5-7B by 4.2 points when expanding the window to 16k tokens.
- Distribution vs. Importance: While previous methods like $H_2O$ prioritize "heavy hitter" tokens with high attention scores, SCA's focus on diversity allows it to preserve the holistic meaning of the context more effectively.
Conclusion and Future Work
SCA provides a robust, training-free mechanism for extending LLM context windows by leveraging KV cache redundancy. By focusing on distributional diversity rather than just local recency or attention scores, it maintains high performance even at extreme sequence lengths. Future work will explore the application of SCA to multimodal contexts and further optimize the computational latency of the greedy selection process.
Summary updated