Abstract
Despite the remarkable progress of Large Language Models (LLMs), the escalating memory footprint of the Key-Value (KV) cache remains a critical bottleneck for efficient inference. While dimensionality reduction offers a promising compression avenue, existing approaches typically either necessitate prohibitively expensive pre-training from scratch or suffer from severe performance deterioration under high compression regimes. In this work, we propose DynaKV, a novel post-training framework for low-rank KV cache compression. To the best of our knowledge, DynaKV is the first method to dynamically allocate compression rates to individual tokens according to their semantic meaning, which allows it to achieve better fidelity at aggressive compression ratios. Extensive experiments demonstrate that our method consistently outperforms existing state-of-the-art compression techniques, achieving significant memory reduction while maintaining competitive generation quality. Furthermore, our approach is orthogonal to sequence-level pruning methods. When integrated with SnapKV, DynaKV retains only 6% of the KV cache while maintaining 94% of the baseline performance on the LongBench benchmark.
The KV Cache Bottleneck
As Large Language Models (LLMs) handle increasingly long contexts, the Key-Value (KV) cache—the memory used to store previous token states to avoid re-computation—becomes a massive bottleneck. This cache grows linearly with sequence length, often exhausting GPU memory before the model's compute limits are reached. Existing solutions generally fall into two categories: architectural changes that require expensive training from scratch, or static compression methods (like Palu or ASVD) that apply a uniform low-rank reduction to every token.
DynaKV addresses the sub-optimality of static compression by recognizing that language has non-uniform information density. A rare, content-heavy word requires a larger "memory budget" than a common functional word. DynaKV allows the model to decide, token-by-token, how much information to retain.
Methodology
DynaKV introduces a three-stage pipeline for token-adaptive compression:
- Spectral Projection: Using Principal Component Analysis (PCA), KV states are transformed into a "spectral space" where dimensions are ordered by their contribution to the signal's energy. This ensures that pruning trailing dimensions results in minimal information loss.
- Differentiable Gating: A lightweight learnable gating mechanism predicts a probability distribution over possible truncation points for every token.
- Soft-to-Hard Masking: During training, a continuous "soft mask" allows gradients to flow through the truncation operation. At inference, this is converted into a binary "hard mask," physically discarding redundant dimensions to save memory.
Key Insights and Semantic Sensitivity
DynaKV's adaptive mechanism reveals several critical behaviors of LLMs:
- Attention Sinks: The model automatically learns to assign the highest retention rates to the initial "BOS" (Beginning of Stream) token, confirming the "attention sink" hypothesis where the first token acts as a crucial anchor.
- Semantic Awareness: The gating mechanism distinguishes between high-value tokens (technical terms, rare words) and low-value ones (stopwords like "the" or "to"). The former are kept at high fidelity, while the latter are aggressively compressed.
- Hierarchical Compression: Early layers require higher retention to capture syntactic structure, while deeper layers dealing with abstract concepts can be compressed more aggressively.
Experimental Results
DynaKV demonstrates superior stability compared to state-of-the-art baselines. At a 20% retention rate on Llama-3-8B, DynaKV maintains a perplexity of 12.51, whereas methods like Palu and MatryoshkaKV suffer total model collapse (perplexity >110). On short-context benchmarks, DynaKV at 20% retention outperformed the best baseline by over 14%.
Furthermore, DynaKV is orthogonal to sequence-level pruning. When integrated with SnapKV, it achieved a 6% total retain rate while maintaining 94% of baseline performance on the LongBench benchmark, effectively pushing the boundaries of memory-constrained long-context processing.
Conclusion
DynaKV offers a robust, post-training solution to the KV cache bottleneck by moving beyond "one-size-fits-all" compression. By dynamically allocating memory based on token importance, it achieves unprecedented compression ratios with minimal performance loss. Future work will explore extending this adaptive strategy to head-wise compression for even greater efficiency.
Summary updated