KVSlimmer: Theoretical Insights and Practical Optimizations for Asymmetric KV Merging
Authors: Lianjun Liu, Hongli An, Weiqi Yan, Xin Du, Shengchuan Zhang, Huazhong Liu, Yunshan Zhong
Organizations: School of Information and Communication Engineering, Hainan University, Haikou, China · School of Cyberspace Security, Hainan University, Haikou, China · MAC Lab, Department of Artificial Intelligence, School of Informatics, Xiamen University, Xiamen, China · School of Computer Science and Technology, Hainan University, Haikou, China
The growing computational and memory demands of the Key-Value (KV) cache significantly limit the ability of Large Language Models (LLMs). While KV merging has emerged as a promising solution, existing methods that rely on empirical observations of KV asymmetry and gradient-based Hessian approximations lack a theoretical foundation and incur suboptimal compression and inference overhead. To bridge these gaps, we establish a theoretical framework that characterizes this asymmetry through the spectral energy distribution of projection weights, demonstrating that concentrated spectra in Query/Key weights induce feature homogeneity, whereas dispersed spectra in Value weights preserve heterogeneity. Then, we introduce KVSlimmer, an efficient algorithm that captures exact Hessian information through a mathematically exact formulation, and derives a closed-form solution utilizing only forward-pass variables, resulting in a gradient-free approach that is both memory- and time-efficient. Extensive experiments across various models and benchmarks demonstrate that KVSlimmer consistently outperforms SOTA methods. For instance, on Llama3.1-8B-Instruct, it improves the LongBench average score by 0.92 while reducing memory costs and latency by 29% and 28%, respectively.Code is available at https://github.com/lianjunl13-sudo/KVSlimmer.
Figures & tables
Figure 1: Comparison between AsymKV and KVSlimmer for KV cache merging.
Figure 2: Layer-wise QKV similarity and spectral analysis. Left column: Mean adjacent-token cosine similarity for Query (Q), Key (K), and Value (V), averaged over attention heads. Middle column: Eigenvalue distributions of the projection matrices WQ , WK , and WV , sorted in descending order. Right column: Mode-wise contribution coefficients ci (Eq. 8 ), plotted according to the eigenvalue index. The first two rows show results from Llama-3.1-8B-Instruct , while the last two rows show results from Mistral-7B-Instruct-v0.3 .
Figure 3: Head-level mean alignment relationships at Layer 2 of Llama-3.1-8B-Instruct on 2WikiMQA. Each point corresponds to one attention head, positioned by its global mean cosine alignment.
Single-Doc
Multi-Doc
Sum
Few-shot
Synthetic
Code
Avg.
Llama3.1-8B-Instruct
Full Context
43.73
44.49
29.12
69.36
53.56
50.95
48.07
StreamingLLM
28.15
27.19
25.15
63.17
16.33
52.15
35.50
LongCache
28.98
27.84
25.35
64.73
19.68
51.61
36.46
H 2 O
33.30
34.43
26.60
66.23
14.75
52.65
38.53
LLMLingua-2
32.02
32.24
24.99
27.87
17.67
50.07
30.43
Table 1: Performance on LongBench. KVSlimmer outperforms its baselines on most settings.
Model
Overall
Easy
Hard
Short
Medium
Long
Full Context
30.02
30.73
29.58
35.00
27.91
25.93
StreamingLLM
27.04
27.60
26.69
32.78
23.26
25.00
LongCache
28.43
28.13
28.62
32.78
25.58
26.85
H 2 O
28.23
28.12
28.29
31.67
26.98
25.00
CaM
28.23
28.64
27.97
31.67
26.98
25.00
AsymKV
30.02
30.23
29.90
32.78
27.44
28.85
Table 2: Performance on LongBenchV2.
Figure 4: Relative runtime of KVSlimmer compared to AsymKV across LongBench datasets.
Figure 5: Inference efficiency of decoder stage.
Figure 6: Peak GPU memory of KVSlimmer and AsymKV across different chunk sizes.
Figure 7: Results on different compression ratios.
Appendix figures & tables7 assets
Supplementary material from the paper’s appendix.
Appendix
Figure 8: Layer-wise QKV similarity and spectral analysis for Llama-3.1-8B-Instruct . Left column: Mean adjacent-token cosine similarity for Query (Q), Key (K), and Value (V), averaged over attention heads. Middle column: Eigenvalue distributions of the projection matrices WQ , WK , and WV , sorted in descending order. Right column: Mode-wise contribution coefficients ci (Eq. 8 ), plotted according to the eigenvalue index.
Figure 9: Layer-wise QKV similarity and spectral analysis for Mistral-7B-Instruct-v0.3 . Left column: Mean adjacent-token cosine similarity for Query (Q), Key (K), and Value (V), averaged over attention heads. Middle column: Eigenvalue distributions of the projection matrices WQ , WK , and WV , sorted in descending order. Right column: Mode-wise contribution coefficients ci (Eq. 8 ), plotted according to the eigenvalue index.
Figure 10: Head-level mean alignment relationships at Layer 5 of Llama-3.1-8B-Instruct on 2WikiMQA. Each point corresponds to one attention head, positioned by its global mean cosine alignment.
Figure 11: Head-level mean alignment relationships at Layer 22 of Llama-3.1-8B-Instruct on 2WikiMQA. Each point corresponds to one attention head, positioned by its global mean cosine alignment.
Figure 12: Head-level mean alignment relationships at Layer 9 of Mistral-7B-Instruct-v0.3 on 2WikiMQA. Each point corresponds to one attention head, positioned by its global mean cosine alignment.
Figure 13: Head-level mean alignment relationships at Layer 15 of Mistral-7B-Instruct-v0.3 on 2WikiMQA. Each point corresponds to one attention head, positioned by its global mean cosine alignment.
Figure 14: Head-level mean alignment relationships at Layer 20 of Mistral-7B-Instruct-v0.3 on 2WikiMQA. Each point corresponds to one attention head, positioned by its global mean cosine alignment.
Large language models (LLMs) with extended context lengths rely on the key-value (KV) cache to support attention over prior tokens. However, maintaining the KV cache incurs substantial memory overhead, motivating KV-cache compression methods that enforce a fixed budget through eviction and merging. Modern eviction methods increasingly adopt span-based retention because preserving contiguous spans is empirically effective and better preserves semantic coherence. Yet, when combined with post-eviction merging, span-based retention concentrates merges onto a small set of span-boundary carrier tokens, producing a highly imbalanced merge pattern that exacerbates over-merging and increases information loss. To address this imbalance, we propose GRKV (Global Regression for KV Cache), a training-free KV-cache merging method that directly minimizes the discrepancy between compressed-cache and full-cache attention outputs. GRKV uses ridge-regression-based merge steps to distribute information from evicted tokens across retained tokens, while regularizing the updates to prevent over-smoothing. Across the LongBench and RULER long-context benchmarks, GRKV is the only merging method that improves overall performance with minimal overhead. Our code is available at https://github.com/pjunjie/GRKV.
Junjie Peng, You Wu, Haoyi Wu +4
School of Computer Science and Engineering, Sun Yat-sen University · School of Information Science and Technology, ShanghaiTech University · Shanghai Engineering Research Center of Intelligent Vision and Imaging +2
Long-context inference in Large Language Models (LLMs) is bottlenecked by the linear growth of Key-Value (KV) cache memory. Existing KV cache compression paradigms are fundamentally limited by heuristics: heuristic budgeting relies on statistical priors rather than task objectives, causing resource misallocation, while heuristic selection relies on coupled query-key interactions or static inductive biases (e.g., attention sinks). To address this limitation, we introduce LKV (Learned KV Eviction), which formulates KV compression as an end-to-end differentiable optimization problem. LKV integrates LKV-H to learn task-optimized global budgets, and LKV-T to derive intrinsic KV importance without materializing attention matrices. This design bypasses heuristic proxies, strictly aligning compression with task objectives. Extensive evaluations demonstrate that LKV achieves state-of-the-art performance on both LongBench and RULER benchmarks at high compression rates. In particular, on LongBench, LKV achieves near-lossless performance with only 15% KV cache retention. Crucially, our analysis identifies learned budgeting as the dominant driver of fidelity, demonstrating that data-driven allocation is essential to overcome the limitations of hand-crafted heuristics.
Enshuai Zhou, Yifan Hao, Chao Wang +7
University of Science and Technology of China, Hefei, China · State Key Lab of Processors, Institute of Computing Technology, CAS, Beijing, China · University of Chinese Academy of Sciences, Beijing, China
Efficient key-value (KV) cache management is crucial for the practical deployment of large language models (LLMs), yet existing compression techniques often incur a trade-off between performance degradation and computational overhead. We propose a novel gating-based KV cache eviction method for frozen-weight LLMs that achieves high compression ratios with negligible computational cost. Our approach introduces lightweight sink-attention gating modules to identify and retain critical KV pairs, and integrates seamlessly into both the prefill and decoding stages. The proposed gate training algorithm relies on forward passes of an LLM, avoiding expensive backpropagation, while achieving strong task generalization through a task-agnostic reconstruction objective. Extensive experiments across the Qwen2.5-1M, Qwen3, and Gemma3 families show that our method maintains near-lossless performance while evicting up to 70% of the KV cache. The results are consistent across a wide range of tasks, including long-context understanding, code comprehension, and mathematical reasoning, demonstrating the generality of our approach.