TL;DR
Reasoning models like DeepSeek-R1 achieve breakthrough accuracy through long chain-of-thought (CoT) outputs, but this creates massive key-value (KV) caches that bottleneck inference memory and throughput. This paper introduces R-KV, a training-free compression method that eliminates redundant tokens by jointly scoring token importance and semantic similarity. R-KV reduces KV cache size by up to 90% while maintaining or even exceeding full-cache accuracy.
What Problem Does This Paper Address?
Modern reasoning LLMs generate extensive chain-of-thought traces, self-reflections, and corrections. While this behavior significantly improves accuracy on complex tasks, it results in outputs that are 8–14× longer than standard models. This causes the KV cache to balloon during decoding, dominating memory usage and severely limiting serving throughput.
Existing KV cache compression methods (like SnapKV) prune tokens based purely on attention weights. However, the authors observe that these methods fail when applied to reasoning models. Because reasoning models frequently repeat phrases or re-evaluate steps, these repetitive text segments generate high attention signals for themselves. As a result, standard attention-guided methods over-retain redundant text loops and accidentally discard sparse but critical reasoning steps.
Methods
R-KV operates entirely during the decoding phase, compressing the KV cache at fixed intervals (e.g., every 128 tokens) without requiring any model retraining. It introduces a hybrid token selection strategy consisting of three main components:
- Importance Scoring: Measures contextual importance using attention weights derived from the most recent tokens (observation tokens). It supports both Multi-Head Attention (MHA) and Grouped-Query Attention (GQA) via a max-pooling aggregation step.
- Redundancy Estimation: Computes the cosine similarity between key vectors to identify semantically repetitive tokens. Crucially, it protects the $\beta$ most recent similar tokens from eviction, ensuring that immediate context needed for local coherence is preserved.
- Joint Selection Strategy: Combines the importance score ($I$) and the normalized redundancy score ($R$) using a balancing hyperparameter $\lambda$: $$Z = \lambda I - (1 - \lambda) R$$ Tokens with the highest joint score $Z$ are retained in the cache, ensuring a cache state that is both highly informative and diverse.
Datasets
The authors evaluated R-KV across two popular mathematical reasoning benchmarks using distilled variants of DeepSeek-R1 (specifically the 8B Llama and 14B Qwen distillations):
- MATH-500: A subset of the MATH dataset used to evaluate multi-step mathematical problem-solving.
- AIME 2024: Problems from the American Invitational Mathematics Examination, representing highly complex reasoning tasks that demand long generation lengths.
Key Insights and Ideas
- Attention is Blind to Repetition: Pure attention-based pruning suffers from a positive feedback loop in reasoning models: redundant self-reflections trick the attention mechanism into scoring them highly, leading to severe cache bloat.
- Pruning as a Regularizer: Remarkably, compressing the KV cache with R-KV sometimes improves accuracy over using the full uncompressed cache. The authors hypothesize that evicting older, repetitive text loops prevents the model from getting stuck in infinite "thinking traps" or circular reasoning.
- Protecting Recent Redundancy: While long-term repetition is wasteful, short-term repetition is often necessary for local syntax and immediate logic. Explicitly protecting the most recent similar tokens ($\beta$) is vital to prevent model breakdown.
Key Results
- Lossless Compression at 10% Cache: On the AIME-24 dataset using DeepSeek-R1-Distill-Llama-8B, R-KV maintains full KV cache accuracy using just 10% of the cache budget, whereas the standard SnapKV baseline drops to roughly 60% of full performance.
- Super-Linear Performance: At a 16% cache budget on AIME-24, R-KV achieves 105% of the uncompressed model's accuracy.
- Massive Efficiency Gains: By drastically shrinking the memory footprint per request, R-KV enables much larger inference batch sizes, delivering up to 90% memory savings and a 6.6× throughput improvement over standard full-cache decoding at a 16K sequence length.
Limitations and Future Work
- Paged Attention Compatibility: R-KV is currently not natively compatible with advanced virtual memory management mechanisms like paged attention. Adapting the dynamic eviction strategy to work seamlessly with paged blocks remains an open challenge.
- Framework Integration Overhead: In serving frameworks that lack native, flexible interfaces for KV cache compression, the overhead of manually reallocating and copying tensors to store the compressed cache can partially offset the computational speedups gained from reduced attention blocks.
Summary updated