Introduction
Large Language Model (LLM) inference is fundamentally constrained by its autoregressive nature. To generate text, a model must predict tokens sequentially, necessitating the repeated loading of billions of parameters from memory for every single token produced. This "memory wall" often results in hardware idling while waiting for data transfers, leading to significant latency in real-world applications.
Speculative decoding has emerged as a promising solution, typically employing a small, fast "draft model" to predict multiple future tokens that the larger "target model" then verifies in parallel. However, training and maintaining these draft models is complex, as they must be specifically aligned with the target model's vocabulary and distribution. REST (Retrieval-Based Speculative Decoding) addresses this by replacing the neural draft model with a non-parametric datastore lookup, offering a training-free acceleration method that leverages the inherent repetitiveness of language.
The REST Framework
REST accelerates inference by retrieving common token sequences from a large corpus and verifying them using the target LLM. The process is divided into three distinct stages:
- Retrieval: Using the longest suffix of the current generation context as a query, REST performs an exact-match search within a datastore (indexed via a suffix array). This identifies multiple historical continuations that have followed this context in the reference corpus.
- Trie Construction: The retrieved sequences are aggregated into a Trie (prefix tree). Each node represents a potential token, and the structure allows the system to propose multiple branching paths of varying likelihoods.
- Verification with Tree Attention: To verify these candidates efficiently, REST utilizes a specialized tree attention mask. This allows the LLM to process all branches of the Trie simultaneously in a single forward pass. If the LLM's top prediction matches a path in the Trie, those tokens are accepted instantly, effectively "skipping" several autoregressive steps.
Experimental Evaluation
The authors evaluated REST across two primary domains to test its versatility:
- Code Generation: A 27GB datastore was constructed from Python code in The Stack. Performance was measured on the HumanEval benchmark using CodeLlama (7B and 13B).
- General Conversation: A 12GB datastore was built from UltraChat. Evaluation was conducted on MT-Bench using Vicuna (7B and 13B).
Key Results and Performance
REST demonstrates substantial speedups across all tested models and benchmarks without requiring any fine-tuning or additional parameters. The method is particularly effective in code generation, where patterns are highly structured and repetitive.
As shown in the results table, REST achieves speedups of up to 2.36x for CodeLlama on HumanEval and up to 1.77x for Vicuna on MT-Bench. Notably, the overhead introduced by the datastore search and Trie construction is minimal, typically accounting for less than 6% of the total inference time (under 1ms per token).
Insights and Future Directions
The success of REST highlights that LLMs often regenerate patterns already present in their training data. By "retrieving" rather than "re-calculating" these sequences, REST provides a plug-and-play acceleration layer for any off-the-shelf model.
One significant finding is the scaling property of the datastore: increasing the datastore size from 0.9GB to 27GB improved the speedup from 1.83x to 2.36x, suggesting that larger, more diverse datasets can further drive performance. Future work may explore dense retrieval (using embeddings) to improve match rates for unique contexts and datastore compression techniques to reduce the storage footprint.
Summary updated