Abstract
The rapid growth in the parameters of large language models (LLMs) has made inference latency a fundamental bottleneck, limiting broader application of LLMs. Speculative decoding represents a lossless approach to accelerate inference through a guess-and-verify paradigm, leveraging the parallel capabilities of modern hardware. Some speculative decoding methods rely on additional structures to guess draft tokens, such as small models or parameter-efficient architectures, which need extra training before use. Alternatively, retrieval-based train-free techniques build libraries from pre-existing corpora or by n-gram generation. However, they face challenges like large storage requirements, time-consuming retrieval, and limited adaptability. Observing that candidate tokens generated during the decoding process are likely to reoccur in future sequences, we propose Token Recycling. This approach stores candidate tokens in an adjacency matrix and employs a breadth-first search (BFS)-like algorithm on the matrix to construct a draft tree. The tree is then validated through tree attention. New candidate tokens from the decoding process are then used to update the matrix. Token Recycling requires <2MB of additional storage and achieves approximately 2x speedup across all sizes of LLMs. It significantly outperforms existing train-free methods by 30% and even a training method by 25%. It can be directly applied to any existing LLMs and tasks without the need for adaptation.
Introduction
Large Language Models (LLMs) have revolutionized natural language processing, but their auto-regressive generation process—producing one token at a time—remains a significant bottleneck for real-time applications. Speculative decoding has emerged as a standard solution, where a smaller "draft" model predicts several future tokens that the main LLM then verifies in parallel.
However, traditional speculative decoding often discards the "rejected" candidate tokens—high-probability tokens that the LLM considered but did not select for the final sequence. This paper introduces Token Recycling (TR), a training-free framework that treats this discarded information as "treasure." By recycling these tokens into a compact adjacency matrix, TR creates a dynamic, high-performance retrieval library that adapts to the current generation context in real-time.
Methodology
Token Recycling is a plug-and-play framework designed to be integrated into any existing LLM without additional training. The process is divided into three primary stages:
- Adjacency Matrix Initialization: TR maintains a compact adjacency matrix $M$ of size $|V| imes k$, where $|V|$ is the vocabulary size and $k$ is the number of top candidate tokens stored for each entry. This matrix acts as a lightweight, persistent memory of token transitions, requiring less than 2MB of storage.
- Draft Tree Retrieval: At each decoding step, the system uses a Breadth-First Search (BFS) algorithm to traverse the adjacency matrix and construct a "draft tree." This tree structure is designed to be static yet imbalanced, prioritizing deeper exploration of the most probable token paths to maximize the hit rate during verification.
- Verification and Update: The LLM verifies the entire draft tree in a single forward pass using tree attention. Crucially, the system then extracts the top-$k$ candidate tokens from the output distributions of every token in the draft tree—including those that were rejected for the final sequence—and uses them to update the adjacency matrix.
Additionally, TR employs a "Hot Start" strategy where the adjacency matrix persists across different queries. This allows the model to leverage common language patterns and task-specific commonalities learned from previous generations.
Experimental Evaluation
The researchers evaluated Token Recycling across several benchmarks and model sizes (7B, 13B, and 33B/34B):
- SpecBench: A diverse benchmark covering tasks such as translation, summarization, QA, and mathematical reasoning.
- MBPP (Mostly Basic Python Problems): A dataset for code generation, characterized by high token redundancy.
- Models: The Vicuna series was used for general tasks, while Code Llama was utilized for programming benchmarks.
Key Results and Discussion
Token Recycling demonstrates superior performance and efficiency compared to both training-free and training-based baselines:
- Significant Acceleration: TR consistently achieves approximately a 2x speedup across all tested LLM sizes. In structured domains like code generation (MBPP), speedups reached up to 2.34x.
- Superior to Existing Methods: TR outperforms established training-free methods like REST and PLD by over 30%. More impressively, it outperforms Medusa-1, a popular training-based method, by approximately 25%, despite requiring zero training overhead.
- Minimal Resource Footprint: With a memory requirement of less than 2MB, TR is highly suitable for deployment on consumer-grade hardware where VRAM is often limited.
- Dynamic Adaptability: Unlike static retrieval libraries, TR’s real-time updates allow it to adapt to the specific style and content of a query as it progresses, turning what was once computational "trash" into a valuable predictive asset.
Conclusion
Token Recycling offers a simple yet powerful paradigm shift in speculative decoding. By recognizing that rejected tokens contain valuable information about future sequences, TR provides a training-free, low-overhead method to significantly accelerate LLM inference. Future work will explore dynamic tree structures and more sophisticated matrix update strategies to further enhance the efficiency of this "trash-to-treasure" approach.
Summary updated