TLDR: Expected Attention is a novel, training-free method for compressing the Key-Value (KV) cache in large language models (LLMs). It estimates the importance of KV pairs by predicting how future queries will attend to them, leveraging the distributional properties of LLM activations. This approach enables significant memory savings (up to 60% compression) without performance degradation, outperforming existing state-of-the-art methods in both prefilling and decoding phases. The method is released as part of the KVPress library, a comprehensive framework for benchmarking KV cache compression techniques.
Large Language Models (LLMs) have transformed how we interact with technology, powering advanced applications from multi-round dialogues to complex agentic workflows. However, as these models process increasingly vast amounts of information, a critical bottleneck emerges: the memory consumption of the Key-Value (KV) cache. This cache stores essential information for efficient attention computation during text generation, but its memory footprint grows linearly with the length of the input, quickly overwhelming even powerful GPUs.
Traditional approaches to tackle this memory challenge often fall short. Some methods require architectural changes or extensive retraining, limiting their applicability to already deployed LLMs. Others rely on heuristics or past attention scores, which are often unavailable in modern, efficient implementations like Flash Attention.
Introducing Expected Attention
A new, training-free compression method called Expected Attention offers a compelling solution. Developed by researchers at Sapienza University of Rome and NVIDIA, this innovative technique estimates the importance of KV pairs by predicting how future queries will attend to them. Instead of looking backward or using simple rules, Expected Attention looks forward, leveraging the inherent statistical properties of LLM activations to calculate ‘expected attention scores’ for each KV pair.
The core idea is remarkably intuitive: not all pieces of information in the KV cache are equally important for future predictions. By understanding which KV pairs are likely to be attended to by upcoming queries, the model can intelligently prune the less critical ones. This process is achieved by analyzing the distributional properties of LLM activations, which have been observed to loosely follow a Gaussian distribution. This allows for the computation of expected unnormalized attention scores in a closed form, providing a principled way to rank and remove KV pairs.
How It Works
Expected Attention quantifies the significance of each KV pair by isolating its contribution within the model’s ‘residual stream’ – essentially, its impact on the model’s output. The method then estimates how much future queries will attend to each token in the context. This estimation is crucial because actual future attention scores are not available during compression. By approximating the positional embeddings and creating a position-averaged query distribution, Expected Attention can analytically compute the expected unnormalized attention score for any given key.
This expected attention score, combined with the magnitude of the transformed value vector, provides a robust measure of each KV pair’s expected contribution. The compression algorithm then simply evicts a specified percentage of KV pairs with the lowest expected contributions, minimizing the impact on the model’s overall performance.
Performance and Efficiency
Expected Attention has been rigorously tested across various benchmarks and models, consistently outperforming state-of-the-art baselines. It demonstrates superior performance in both the ‘prefilling’ phase (processing the initial prompt) and the ‘decoding’ phase (generating tokens sequentially). For instance, on benchmarks like LongBench, Ruler, and Needle in a Haystack, Expected Attention maintains high scores even at significant compression ratios, such as 50% or more.
The memory savings are substantial. For a Llama3.1-8B model, Expected Attention can achieve up to a 2x reduction in KV cache size with no accuracy loss, leading to significant reductions in peak memory usage, especially for long contexts. This efficiency is vital for deploying LLMs in scenarios requiring extensive contextual information, where hardware constraints often limit the practical context length.
KVPress: A Research Framework
To foster further research and development in KV cache compression, the authors have released KVPress, a comprehensive PyTorch-based library. This framework integrates seamlessly with Hugging Face transformers, allowing researchers to easily implement, test, and benchmark novel compression techniques. KVPress already includes over 20 state-of-the-art compression methods and provides a public leaderboard for standardized evaluation, ensuring fair and reproducible comparisons. You can find more details about this research in the paper: Expected Attention: KV Cache Compression by Estimating Attention from Future Queries Distribution.
Also Read:
- Adaptive KV Cache for Faster, Better Language Models
- Enhancing Diffusion LLM Performance with Adaptive Block Sizing
Looking Ahead
While Expected Attention marks a significant step forward, the researchers acknowledge certain limitations. Its performance, being a training-free method, may not match that of trainable methods that require extensive computational resources for pre-training. Additionally, users currently need to manually specify compression ratios, and the current PyTorch implementation prioritizes readability over production-level efficiency. Future work aims to explore combining this theoretical framework with lightweight fine-tuning and developing automated compression mechanisms.
Expected Attention offers a powerful and practical solution to the KV cache memory bottleneck, making long-context LLM inference more accessible and efficient without compromising performance.


