TL;DR
OmniKV is a training-free inference method that enables Large Language Models (LLMs) to handle massive context lengths (up to 450K tokens on a single A100) with a 1.68x speedup. Unlike previous methods that permanently discard "unimportant" tokens to save memory, OmniKV dynamically selects a small subset of the KV cache for each generation step, ensuring no information is lost while reducing GPU memory usage by up to 75%.
What Problem Does This Paper Address?
As LLMs move toward processing hundreds of thousands of tokens, they hit a "memory wall." The Key-Value (KV) cache, which stores intermediate computations to speed up generation, grows linearly with sequence length. For a model like Llama-3-8B at 128K context, the KV cache alone can swallow 134GB of VRAM—far exceeding the capacity of a standard 80GB A100 GPU.
Existing solutions often use "token dropping," where they identify and permanently delete tokens with low attention scores. However, the authors argue this is fundamentally flawed for complex reasoning. A token that seems "unimportant" during the first step of a Chain-of-Thought (CoT) process might become critical ten steps later. Once a token is dropped, it's gone forever, leading to performance degradation in multi-step reasoning tasks.
Methods
OmniKV introduces a token-dropping-free approach that combines dynamic selection with CPU offloading. It is built on two key observations:
- Inter-Token Attention Variability: The set of "important" tokens changes between different generation steps.
- Inter-Layer Attention Similarity: Within a single generation step, the tokens that are important for layer $i$ are highly likely to be important for layer $i+1$.
The system architecture consists of two main modules:
- Context Bank: Stores the full KV cache in CPU memory. It asynchronously pre-fetches and loads only the necessary token subsets into GPU memory.
- Context Selector: Operates on a few designated "filter" layers. These layers perform full attention to identify the top-$k$ most important tokens for the current step. This selection is then propagated to subsequent "non-filter" layers, which only compute sparse attention on that specific subset.
By using asynchronous transfers, OmniKV overlaps the time spent moving data from CPU to GPU with the actual computation time on the GPU, effectively hiding the latency of offloading.
Key Insights and Ideas
- Dynamic vs. Static Sparsity: Static methods (dropping tokens once) fail because relevance is a moving target. OmniKV treats relevance as a dynamic property that is re-evaluated at every single token generation step.
- The "Filter" Layer Discovery: The paper identifies that certain layers have a much stronger "filtering" ability than others. By placing the Context Selector at these strategic points, the model can accurately predict what the rest of the network needs to see.
- Inter-Layer Similarity: Even layers multiple steps apart share a high degree of attention similarity (often >0.85-0.90). This justifies using a single "filter" layer's decision to guide multiple subsequent layers.
Datasets
The authors evaluated OmniKV across several rigorous long-context benchmarks:
- InfiniteBench: A benchmark with an average length of 145K tokens.
- LongBench: 18 tasks covering summarization, QA, and few-shot learning.
- Needle-in-a-Haystack: Testing retrieval accuracy up to 1M tokens.
- 2StageRetr (New): A custom benchmark designed to expose the failures of token-dropping. It requires the model to solve an equation, then use that result to look up a value in a long dictionary. This forces the model to "recall" tokens that might have had low attention scores initially.
Key Results
- Efficiency: Achieved a 1.68x speedup in decoding at 128K context on a single A100 compared to the original model.
- Memory: Reduced KV cache GPU memory footprint by 75%. This allowed Llama-3-8B to run with a 450K context on a single A100, whereas the original model OOMs (Out of Memory) at 128K.
- Performance: On LongBench and InfiniteBench, OmniKV consistently outperformed other memory-saving baselines like H2O and InfLLM, often matching the performance of "Full Attention" (the theoretical upper bound).
- Multi-Step Reasoning: In the 2StageRetr task, OmniKV maintained high accuracy while token-dropping methods like H2O failed because they discarded the dictionary keys before the model "knew" it needed them.
Limitations and Future Work
While OmniKV significantly improves decoding, the authors note that prefill acceleration (the initial processing of the prompt) is still a challenge. Although they proposed a modified prefill strategy that achieves a 1.90x reduction in latency, it currently relies on standard libraries rather than highly optimized custom kernels like those in specialized systems (e.g., MInference).
Future work includes integrating OmniKV with KV cache quantization (like KIVI or SmoothQuant) to further compress the memory footprint, potentially pushing context limits even further. The authors also plan to explore more optimized engine integrations beyond the Hugging Face Transformers library.
Summary updated