Introduction
Generative AI is currently hitting a "memory wall." When interacting with a Large Language Model (LLM), the model processes the entire conversation history. To avoid re-calculating mathematical representations (tokens) at every step, LLMs utilize a Key-Value (KV) Cache. However, this cache grows linearly with conversation length. For long-context applications like document summarization, the KV cache can become larger than the model weights themselves, creating a massive bottleneck in memory bandwidth where data movement outpaces processing.
Existing solutions like "Window Attention" (focusing only on recent tokens) often lose global context, leading to inaccuracies. Other pruning methods fail to account for how attention distributions shift when tokens are removed.
Keyformer: Intelligent KV Cache Reduction
Keyformer is a plug-and-play inference-time strategy that intelligently decides which tokens to retain in the cache. It is built on three main pillars:
- Mixed Attention: It maintains a small "recent window" of tokens for local context alongside a set of "key tokens" selected from the past to preserve global context.
- Gumbel Logit Adjustment: Removing tokens distorts the standard Softmax function. Keyformer adds Gumbel-distributed noise to attention scores (logits) before selection. This regularization helps identify crucial tokens even in noisy or unfamiliar contexts.
- Dynamic Temperature ($\tau$): As generation progresses and more tokens are discarded, a temperature parameter increases to make the scoring function more robust, ensuring the model doesn't over-focus on the wrong tokens.
Key Insights
- The 90/10 Rule: Approximately 90% of attention weight is concentrated on just 10% of tokens. Most of the KV cache is "dead weight."
- Softmax Distortion: Pruning the cache artificially inflates the scores of remaining tokens. Keyformer’s Gumbel noise specifically addresses this uneven distribution.
- Preserving Position: Maintaining original positional indices is vital; re-indexing tokens after pruning significantly degrades accuracy.
- Initial Bias: LLMs have a natural "sink" bias toward initial prompt tokens. Keyformer favors these "anchor" tokens while remaining flexible for middle-context selection.
Evaluation and Results
The researchers evaluated Keyformer across diverse benchmarks (CNN/DailyMail, GovReport, SODA) and models (GPT-J, Cerebras-GPT, MPT-7B).
- Efficiency: Keyformer reduced inference latency by 2.1× and improved token throughput by 2.4×.
- Memory: It reduced KV cache size by 50% while maintaining 99% to 99.9% of baseline accuracy, meeting strict MLPerf standards.
- Superiority: It consistently outperformed baselines like H2O and StreamingLLM. On the GovReport summarization task, Keyformer maintained high ROUGE scores where other methods failed at the same cache budget.
- Scalability: In the MPT-7B-storywriter model, Keyformer enabled processing of long sequences that would otherwise cause "Out of Memory" (OOM) errors.
Conclusion
Keyformer offers a significant leap in LLM efficiency by slashing memory requirements without sacrificing accuracy or requiring retraining. Future work will focus on integration with modern architectures like Multi-Query Attention (MQA) and Group-Query Attention (GQA), as well as exploring training-time sparsity.
Summary updated