Abstract
The increasing context window size in Large Language Models (LLMs), such as the GPT and LLaMA series, has improved their ability to tackle complex, long-text tasks, but at the cost of inference efficiency, particularly regarding memory and computational complexity. Existing methods, including selective token retention and window-based attention, improve efficiency but risk discarding important tokens needed for future text generation. In this paper, we propose an approach that enhances LLM efficiency without token loss by reducing the memory and computational load of less important tokens, rather than discarding them. We address two challenges: 1) investigating the distribution of important tokens in the context, discovering recent tokens are more important than distant tokens in context, and 2) optimizing resources for distant tokens by sharing attention scores across layers. The experiments show that our method saves 35% KV cache without compromising the performance.
Introduction: The Memory Wall in Long-Context LLMs
As Large Language Models (LLMs) scale to handle massive context windows (128k tokens or more), they hit a "memory wall." To avoid recomputing everything at every step, LLMs use a KV (Key-Value) Cache to store previous token data. However, this cache grows linearly with the length of the text, quickly consuming all available GPU memory.
Existing solutions usually rely on token eviction—simply throwing away "unimportant" tokens. The danger here is significant: if the model discards a specific piece of information (the "needle") buried in a long document (the "haystack"), it can no longer answer questions about it. This performance degradation is particularly visible in methods like StreamingLLM and H2O when evidence is located in distant tokens.
The POD Framework
To address these limitations, we introduce POD (Proximal tokens over Distant tokens), a framework that reduces LLM memory usage by up to 35% without sacrificing performance. Unlike existing methods that delete tokens to save space, POD keeps all tokens but compresses the KV cache by sharing key states across redundant layers for distant context, while maintaining full precision for critical "proximal" tokens.
Methodology
The POD approach operates in three distinct stages:
- Offline Exploration: We use Jensen-Shannon divergence to measure how similar attention scores are between layers. By detecting these similarities, we group consecutive layers into "blocks" that exhibit high redundancy.
- Attention Sharing: Within these blocks, the model stores the full KV cache for proximal tokens (recent context and initial sinks). For distant tokens, however, multiple layers share a single set of keys. This drastically reduces the memory footprint of the middle-context tokens.
- Lightweight Adaptation: Because the model wasn't originally trained to share keys across layers, we perform a brief "post-training" phase (using approximately 5B tokens) to help the model adapt to this hybrid architecture.
Experimental Evaluation
We evaluated POD using a variety of rigorous benchmarks to ensure both long-context retrieval and general reasoning capabilities:
- Retrieval & Long Context: Needle in a Haystack (synthetic retrieval), LongBench, LEval, and InfiniteBench (testing up to 128K context lengths).
- General Intelligence: Standard benchmarks such as MMLU, Hellaswag, and HumanEval were used to ensure compression did not degrade general reasoning or coding abilities.
Key Insights and Results
- "Soft" Compression vs. "Hard" Pruning: By storing distant tokens in a compact, shared form, the model retains the ability to "see" the whole context without the massive memory overhead of full-precision storage for every layer.
- Memory and Throughput: POD achieved a 35% reduction in KV cache memory usage. This allows for significantly larger batch sizes (e.g., increasing from 25 to 33 on specific GPU configurations), directly translating to higher serving throughput.
- Performance Retention: On the Needle in a Haystack task, POD maintained 98.9% accuracy. In contrast, popular eviction methods like StreamingLLM and H2O saw accuracy drop to ~56% because they discarded the critical "needle" tokens.
- Orthogonality: POD is compatible with token-selection methods like SnapKV. Users can employ POD to share layers and simultaneously use SnapKV to prune tokens within those shared layers for cumulative savings.
Limitations and Future Work
While POD offers substantial efficiency gains, it requires a lightweight post-training step, which adds a one-time computational cost for model developers. Additionally, while it saves memory, there is a slight latency overhead compared to the fastest token-eviction methods since POD still processes all tokens. Future work will explore the synergy between POD and KV cache quantization (e.g., 4-bit storage) to further push the boundaries of long-context inference.
Summary updated