TL;DR
TriForce is a hierarchical speculative decoding system designed to accelerate long-sequence generation in Large Language Models (LLMs) without any loss in model quality. By combining a lightweight draft model with a novel retrieval-based partial Key-Value (KV) cache strategy, TriForce mitigates the severe memory bottlenecks of long-context inference, achieving up to 2.31× speedup on an A100 GPU and up to 7.78× speedup in GPU-CPU offloading scenarios.
What Problem Does This Paper Address?
As LLMs are increasingly deployed to process massive contexts (such as entire books, long codebases, or hours of video), serving them efficiently has become a major engineering challenge. The primary culprit is the Key-Value (KV) cache. To avoid recomputing past tokens during generation, LLMs store their intermediate states in memory. However, this KV cache grows linearly with sequence length.
Because LLMs generate text token-by-token (autoregressively), the entire massive KV cache must be reloaded from memory for every single token generated. This creates a severe memory bandwidth bottleneck, leaving GPU computational cores idling and causing high latency.
Existing solutions generally fall into two camps, both with major drawbacks:
- KV Cache Eviction (Lossy): Methods like StreamingLLM or $H_2O$ permanently discard older or less "important" tokens to keep the cache size fixed. This saves memory but causes permanent information loss, leading to hallucinations and poor performance on tasks requiring long-range dependencies.
- Speculative Decoding: This leverages a smaller, faster "draft" model to predict tokens, which the larger "target" model verifies in parallel. However, training a small draft model that can handle 100K+ context windows is computationally prohibitive, and training-free draft methods suffer from low token acceptance rates as context scales.
Methods
TriForce introduces Hierarchical Speculative Decoding to tackle the dual bottlenecks of model weights and KV cache size sequentially. Instead of a single draft model, TriForce sets up a two-level speculation hierarchy:
- Level 1 (Drafting the Draft): A tiny, lightweight model (e.g., Llama-68M) utilizing a strict, small eviction cache (StreamingLLM) quickly generates initial token candidates. This addresses the model weights bottleneck.
- Level 2 (The Intermediate Draft): The target model (e.g., Llama2-7B) runs these candidates through a partial, retrieval-based KV cache. This serves as a high-quality intermediate draft layer.
- Final Verification: The target model verifies the tokens using its full KV cache. Because the final step uses the complete cache, the system remains mathematically lossless—the output distribution is identical to standard autoregressive decoding.
Crucially, TriForce replaces standard cache eviction with Retrieval-based Drafting. It divides the full KV cache into small chunks. During the retrieval phase, it calculates the attention between the current query and the average key within each chunk, dynamically pulling only the most relevant context into the intermediate draft layer.
Datasets
The authors evaluated TriForce across several long-context benchmarks:
- PG-19 test set: A benchmark consisting of long books, used to evaluate long-sequence language modeling.
- NarrativeQA: A reading comprehension dataset based on entire movie scripts and books.
- Needle-in-a-Haystack (Needle Retrieval): A synthetic task designed to test whether a model can retrieve a specific piece of information hidden deep within a long context window.
Key Insights and Ideas
- Dual Memory Bottlenecks: The authors quantified that while model weights dominate memory bottlenecks at shorter context lengths, the KV cache scales up to occupy the vast majority of GPU memory (up to 80%+) as context lengths reach 128K.
- Extreme Attention Sparsity: The paper reveals that in a 120K token context, over 96% of the total attention score is concentrated in just 4K tokens. This means a tiny fraction of the KV cache is sufficient to achieve a high speculative acceptance rate.
- Contextual Locality: The authors discovered that the context tokens required by adjacent generated tokens are highly similar. This allows TriForce to construct its retrieval cache once and reuse it across multiple decoding steps, drastically amortizing the overhead of cache selection.
Key Results
- On-Chip Speedups: For Llama2-7B-128K on a single NVIDIA A100 GPU, TriForce delivers up to a 2.31× speedup over the standard Hugging Face autoregressive baseline.
- Offloading Breakthroughs: On consumer hardware (two RTX 4090 GPUs) where the full KV cache must be offloaded to CPU memory, TriForce achieves an impressive 7.78× speedup for Llama2-7B-128K and 7.94× speedup for Llama2-13B-128K. It generates tokens at 0.108 seconds per token—only half as slow as an A100 running standard autoregression.
- Outperforming DeepSpeed: On a single RTX 4090, TriForce runs 4.86× faster than DeepSpeed-ZeRO-Inference.
- Temperature Robustness: While vanilla speculative decoding performance degrades at higher sampling temperatures, TriForce maintains a stable token acceptance rate above 0.9 even at a temperature of 1.0.
Limitations and Future Work
- Draft-Target Capacity Gap: The acceptance rate of the very first speculation phase can be limited by the massive capability gap between the tiny 68M draft model and the 7B target model.
- Tree-Based Speculation: The current implementation relies on chain-based speculation. The authors note that integrating TriForce with tree-based speculative decoding structures (like Sequoia) could allow the system to validate multiple candidate paths simultaneously, unlocking even higher speedups under larger speculation budgets.
Summary updated