Abstract
Large Language Models (LLMs) face significant memory bottlenecks due to the linear growth of the Key-Value (KV) cache in long-context scenarios. Traditional compression methods often rely on sparse, token-wise eviction that disrupts semantic coherence and ignores task-specific requirements. We present WindowKV, a task-adaptive KV cache compression framework that utilizes semantic windows and intra-group layer sharing. By dynamically adjusting selection strategies based on task type—Information Localization versus Information Aggregation—and leveraging layer redundancy, WindowKV maintains performance comparable to a full KV cache while utilizing only 12% of the memory. Experimental results on LongBench and Needle-in-a-Haystack demonstrate superior retrieval accuracy and throughput compared to existing state-of-the-art methods.
Introduction
As Large Language Models (LLMs) evolve to process massive contexts—reaching up to 200K tokens—they encounter a critical hardware limitation: the Key-Value (KV) cache. To maintain efficiency during generation, LLMs store previous token states in GPU memory. However, this memory requirement scales linearly with sequence length. For instance, a LLaMA2-7B model processing a 100K token context requires over 50GB of VRAM, exceeding the capacity of most consumer-grade and many enterprise GPUs.
Existing compression techniques attempt to mitigate this by evicting "unimportant" tokens based on attention scores. However, these methods suffer from two primary drawbacks. First, they often result in a "Swiss cheese" context, where isolated tokens are retained while their neighbors are discarded, breaking semantic coherence. Second, they are typically task-agnostic, applying the same eviction strategy regardless of whether the model is performing a high-precision retrieval task or a high-level summarization task.
Methodology
WindowKV addresses these limitations by shifting the focus from individual tokens to semantic windows of consecutive tokens.
Task-Adaptive Window Selection
WindowKV employs a BERT-based classifier (achieving a 94.7% F1 score) to categorize incoming prompts into two distinct task types:
- Information Localization: Tasks like fact retrieval or specific QA that require high local detail. In these cases, the model retains entire windows of consecutive tokens to preserve local context.
- Information Aggregation: Tasks like summarization or few-shot learning that require a global "gist." Here, the model selects the most important tokens within those windows.
Intra-Group Layer Sharing and Dynamic Budgeting
Calculating attention importance for every layer is computationally expensive. WindowKV leverages the observation that adjacent layers often exhibit similar attention patterns. By grouping layers (e.g., in sets of 8) and sharing selection indices within each group, the method significantly reduces overhead. Furthermore, WindowKV adopts a "pyramid" budget allocation strategy, providing more KV cache capacity to lower layers—which require denser attention—and tapering the budget for higher, more sparse layers.
Experimental Setup
The researchers evaluated WindowKV across several benchmarks:
- LongBench: A comprehensive suite for long-context understanding (QA, summarization, few-shot learning).
- Needle-in-a-Haystack: A standard test for retrieving specific information hidden within long sequences.
- Backbone Models: Evaluations were conducted using Qwen2.5-1.5B-Instruct and LLaMA3-8B-Instruct.
Key Results
WindowKV demonstrates a remarkable balance between efficiency and performance. It achieves results comparable to a full KV cache while using only 12% of the original memory.
Retrieval and Accuracy
In the "Needle-in-a-Haystack" test at an 8K context window, WindowKV maintained an accuracy of 97.9%. This significantly outperforms popular baselines such as H2O (40.6%) and StreamingLLM (40.7%), which struggle with the loss of semantic coherence caused by isolated token eviction.
Throughput and Latency
Practical implementation on an NVIDIA A100 GPU showed that WindowKV increased throughput by 117 tokens/second and reduced per-token latency by 0.17 ms compared to the vanilla LLaMA3-8B model. It consistently ranked at the top of the LongBench leaderboard across different backbone architectures.
Conclusion
WindowKV proves that semantic coherence is vital for long-context LLM performance. By utilizing task-adaptive window selection and intra-group layer sharing, it overcomes the limitations of previous token-wise eviction methods. Future work will explore adaptive window sizes based on text complexity and the integration of head-wise pruning to achieve even greater compression ratios.
Summary updated