Abstract
Deploying large language models (LLMs) is challenging due to their high memory and computational demands, especially during long-context inference. While key-value (KV) caching accelerates inference by reusing previously computed keys and values, it also introduces significant memory overhead. Existing KV cache compression methods such as eviction and merging typically compress the KV cache after it is generated and overlook the eviction of hidden states, failing to improve the speed of the prefilling stage. Additionally, applying a uniform compression rate across different attention heads can harm crucial retrieval heads in needle-in-a-haystack tasks due to excessive compression. In this paper, we propose UNComp, an uncertainty-aware compression scheme that leverages matrix entropy to estimate model uncertainty across layers and heads at the token sequence level. By grouping layers and heads based on their uncertainty, UNComp adaptively compresses both the hidden states and the KV cache. Our method achieves a 1.6x speedup in the prefilling stage and reduces the KV cache to 4.74% of its original size, resulting in a 6.4x increase in throughput and a 1.4x speedup in inference with only a 1.41% performance loss. Remarkably, in needle-in-a-haystack tasks, UNComp outperforms the full-size KV cache even when compressed to 9.38% of its original size. Our approach offers an efficient, training-free Grouped-Query Attention paradigm that can be seamlessly integrated into existing KV cache schemes.
Introduction
As Large Language Models (LLMs) are increasingly deployed for tasks involving massive contexts—such as analyzing entire codebases or long legal documents—they encounter a significant "memory wall." The standard optimization to mitigate redundant computation is the Key-Value (KV) cache. However, for long sequences, the KV cache itself becomes a primary bottleneck, often exceeding the available GPU memory.
Existing solutions typically focus on evicting or merging tokens based on attention scores after the cache is generated. These methods often ignore the structured sparsity inherent in the model's hierarchy and fail to address the computational overhead of the prefilling stage. UNComp addresses these limitations by introducing an uncertainty-aware framework that exploits information density to compress both hidden states and the KV cache dynamically.
Methodology: The UNComp Framework
UNComp is built upon the principles of Matrix Information Theory, treating information density as a measure of model uncertainty. The framework operates in two primary stages: a preparation stage for calibration and an inference stage for dynamic compression.
Truncated Matrix Entropy
The core innovation of UNComp is the use of Truncated Matrix Entropy to identify structured sparsity. By analyzing the spectrum (eigenvalues) of the token covariance matrices, the researchers identified a consistent "elbow point." This point represents a threshold where the most critical information ends and noise or redundancy begins.
By truncating the entropy calculation at this elbow point, UNComp can quantify the "effective rank" of a layer or head. This metric allows the system to distinguish between high-information components and those that are naturally sparse or redundant.
Two-Stage Compression Strategy
- Layer-Group Compression: Unlike traditional methods that only target the KV cache, UNComp compresses the hidden states during the prefill stage. By identifying layers with low entropy reduction (indicating they are less critical for the specific context), the model can discard redundant internal representations, speeding up the initial prompt processing by approximately 60%.
- Head-Group Compression: UNComp recognizes that attention heads are specialized. It automatically categorizes heads into "retrieval heads" (which require more memory to maintain factual accuracy) and "streaming heads" (which handle general linguistic flow). Different compression ratios are then applied to these groups, ensuring that critical retrieval capabilities are preserved even under high compression.
Experimental Evaluation
The authors evaluated UNComp across a diverse set of benchmarks, including LongBench for general long-context understanding, Needle in a Haystack for targeted retrieval, and InfiniteBench/RULER for extreme context lengths (up to 100k+ tokens). Calibration was performed using the Wikitext2 dataset during a brief preparation stage that typically takes less than two minutes.
Key Results
- Efficiency Gains: UNComp reduces the KV cache to just 4.74% of its original size. This leads to a 6.4x increase in total throughput and a 1.6x speedup in the prefilling stage.
- Performance Retention: Despite extreme compression, the model maintains near-lossless performance. On the GSM8K math benchmark, UNComp remained stable while competing methods like CHAI experienced significant performance degradation.
- Enhanced Retrieval: In "Needle in a Haystack" tests, UNComp at a 9.38% compression ratio actually outperformed the full-size baseline. This suggests that the uncertainty-aware pruning effectively removes "noise," allowing the model to focus more clearly on relevant tokens.
Key Insights and Discussion
Sparsity as Information Deficiency
A central insight of this work is viewing sparsity not merely as numerical zeros, but as a lack of information density. LLMs naturally exhibit "spontaneous compression" in certain layers; UNComp provides the mathematical tools to exploit this phenomenon without requiring expensive retraining.
The Role of GQA
The researchers found that models utilizing Grouped-Query Attention (GQA), such as Llama 3, exhibit highly predictable entropy patterns across head groups. This structural regularity makes the head-grouping strategy in UNComp exceptionally stable and effective for modern LLM architectures.
Conclusion and Future Work
UNComp represents a significant step toward efficient long-context LLM inference. By leveraging matrix entropy to guide compression across both layers and heads, it breaks the memory wall while maintaining high reasoning accuracy. Future research may focus on refining entropy thresholds for tasks requiring dense, context-dependent dependencies and exploring the application of these uncertainty measures during the model training phase to encourage even greater inherent sparsity.
Summary updated