Large Language Models (LLMs) face a significant bottleneck during inference: the massive memory demands of the autoregressive Key-Value (KV) cache. As context windows expand, the KV cache grows linearly, rapidly consuming tens or hundreds of gigabytes of VRAM. To mitigate this memory wall, less critical tokens must be evicted from the cache. However, current eviction strategies rely on brittle heuristics that limit model performance.
This paper introduces KV Policy (KVP), a novel framework that reframes KV cache eviction as a reinforcement learning (RL) problem. By training lightweight agents to rank tokens based on their predicted future utility, KVP achieves state-of-the-art performance on long-context tasks with negligible computational overhead.
The Flaws of Current Heuristics
Existing cache eviction methods rely heavily on backward-looking proxies. For example, methods like StreamingLLM prioritize recency (keeping the most recent tokens), while TOVA and SnapKV retain tokens that received high attention scores in the past.
The problem with these approaches is twofold:
- Poor Proxies for the Future: A token that was highly attended to five sentences ago might be entirely irrelevant for generating the next word.
- Computational Overhead: Many heuristic methods require re-calculating attention scores on the fly, which introduces latency.
The authors ask a fundamental question: Can we instead learn to predict which tokens will be useful in the future using only the data already stored in the cache?
Introducing KV Policy (KVP)
KVP abandons hand-crafted rules in favor of a learning-to-rank approach. The architecture and training pipeline are defined by several key innovations:
- Per-Head Specialization: Different attention heads serve distinct functions—some track syntax, while others retrieve specific facts or act as "attention sinks." Instead of applying a single global policy, KVP trains a distinct, tiny Multi-Layer Perceptron (MLP) for every individual attention head.
- Attention-Free Inference: KVP agents make eviction decisions using only the Key (K) vector, Value (V) vector, and the token's position. Because they do not require the current Query (Q) or past attention scores, the agents operate extremely fast.
- Reinforcement Learning Training: The agents are trained offline using pre-computed generation traces. They utilize a stochastic ranking policy (the Plackett-Luce model) optimized via RL.
- Budget-Agnostic Global Reward: The "secret sauce" of KVP is its reward function, which is based on Future Attention Importance—the actual attention the model would have paid to those tokens in future generation steps. The reward trains the agents to produce an optimal ranking regardless of the user's specific memory budget (e.g., whether keeping 100 or 1,000 tokens).
Key Findings and Performance
The researchers trained KVP agents on traces from RULER-4k (a synthetic long-context benchmark) and OASST2-4k (multi-turn dialogues), yielding impressive results across several dimensions:
- Length Extrapolation: Surprisingly, agents trained on short 4,000-token sequences generalized remarkably well to 128,000-token contexts. This suggests that a token's future importance is largely determined by local features encoded in its Key/Value vectors, rather than the absolute length of the document.
- Superior Accuracy on Strict Budgets: On the RULER benchmark, KVP consistently outperformed all baselines. At tight memory budgets where heuristic methods (like Random or K-Norm) collapsed to near-zero accuracy, KVP maintained high performance.
- Zero-Shot Generalization: Even though KVP was not trained on specific downstream tasks, it successfully transferred its learned utility predictions to unseen benchmarks. It outperformed specialized heuristics on standard tasks like BoolQ, ARC-Challenge, MMLU, HellaSwag, and LongBench (Passage Retrieval, GovReport).
- High Efficiency: KVP adds only about 1% computational overhead to the prefill stage (processing the initial prompt). During the actual decoding phase, it adds zero overhead, as the ranking is computed just once after the prompt is processed.
Limitations and Future Directions
While KVP represents a major step forward for adaptive KV cache management, the authors note a few areas for future improvement. Currently, KVP allocates a uniform token budget across all attention heads. Because some heads are inherently more critical than others, a non-uniform budget allocation could squeeze even more performance out of the same memory footprint.
Additionally, the per-head agents operate independently. Jointly training all heads could capture cross-head dependencies, though it would increase training costs. Finally, while the logic is highly efficient, integrating KVP into optimized hardware kernels like FlashAttention will be necessary to realize maximum real-world speedups.
Summary updated