KeepKV: Achieving Periodic Lossless KV Cache Compression for Efficient LLM Inference
Yuxuan Tian, Zihan Wang, Yebo Peng, Aomufei Yuan, Zhiming Wang, Bairen Yi, Xin Liu, Yong Cui, Tong Yang
TL;DR
This paper tackles the memory bottleneck in LLM inference caused by expanding KV caches by proposing KeepKV, a theoretically grounded KV cache merging framework. It introduces Electoral Votes to record merge history and ZIP-Merging to achieve lossless, current-step compression, with EMA-based predictions to bound multi-step perturbations. The authors provide formal analysis of output perturbation, derive guarantees for single-step losslessness, and offer bounded multi-step error, extending the approach to long-context generation. Empirically, KeepKV delivers over 2x throughput gains and maintains high generation quality across standard and long-context benchmarks, outperforming both eviction and existing merging methods.
Abstract
Efficient inference of large language models (LLMs) is hindered by an ever-growing key-value (KV) cache, making KV cache compression a critical research direction. Traditional methods selectively evict less important KV cache entries, which leads to information loss and hallucinations. Recently, merging-based strategies have been explored to retain more information by merging KV pairs that would be discarded; however, these existing approaches inevitably introduce inconsistencies in attention distributions before and after merging, causing degraded generation quality. To overcome this challenge, we propose KeepKV, a novel adaptive KV cache merging method designed to preserve performance under strict memory constraints, achieving single-step lossless compression and providing error bounds for multi-step compression. KeepKV introduces the Electoral Votes mechanism that records merging history and adaptively adjusts attention scores. Moreover, it further leverages a novel Zero Inference-Perturbation Merging method, compensating for attention loss resulting from cache merging. Extensive experiments on various benchmarks and LLM architectures demonstrate that KeepKV substantially reduces memory usage while successfully retaining essential context information, achieving over 2x inference throughput improvement and maintaining superior generation quality even with only 10% KV cache budgets.
