Large Language Models (LLMs) have revolutionized natural language processing, but their auto-regressive generation process remains a significant bottleneck. Generating a sequence of $N$ tokens requires $N$ sequential forward passes of the model, which is computationally expensive and slow. Speculative Decoding (SD) has emerged as a promising solution, typically employing a smaller "draft model" to predict future tokens that the larger "target model" then verifies in parallel. However, draft models introduce additional complexity, including memory overhead and the need for specialized training.
Retrieval-based speculative decoding offers a training-free alternative by sourcing draft tokens directly from the existing context (e.g., the prompt or previous turns). Yet, these methods often rely on simple n-gram matching, which fails when the exact sequence has not appeared before. This paper introduces LogitSpec, a "plug-and-play" method that leverages the target model's internal logits to guide retrieval, significantly enhancing the accuracy and efficiency of speculative decoding without requiring external models.
Methodology
LogitSpec is built on the observation that the logit distribution used to predict the next token ($x_{i+1}$) also contains significant information about the subsequent token ($x_{i+2}$). By analyzing the top-$k$ candidates for this "next-next" token, LogitSpec can more intelligently search the available context for potential draft sequences.
The process consists of three main stages:
- Next-Next Token Speculation: Instead of just predicting the most likely next token, the model identifies a set of likely candidates for the token after that.
- Guided Retrieval: The system searches the context for sequences that match the predicted next token followed by any of the speculated next-next tokens. This filtering mechanism ensures that retrieved drafts are more likely to be accepted by the target model.
- Draft Tree Verification: The retrieved sequences are structured into a draft tree, allowing the LLM to verify multiple potential paths in a single parallel forward pass using a specialized attention mask.
Crucially, LogitSpec is highly efficient. Implementation details such as hash-based retrieval ensure that the overhead is minimal, with the core model forward pass still accounting for approximately 94% of the total inference time.
Evaluation and Results
The authors evaluated LogitSpec across a diverse set of benchmarks, including Spec-Bench (multi-turn chat, RAG, math), GSM8K (reasoning), HumanEval (code), and CNN/DM (summarization). Experiments were conducted using various model architectures and sizes, including Vicuna (7B, 13B, 33B), Llama-2, Llama-3.1, and Qwen-2.5.
LogitSpec consistently outperformed existing draft-model-free methods such as Prompt Lookup Decoding (PLD) and REST across all tasks and model sizes.
Key findings include:
- Significant Speedups: LogitSpec achieved up to a 2.61× speedup on the CNN/DM benchmark with Vicuna-7B.
- High Acceptance Rates: The Mean Accepted Tokens (MAT) reached 3.28 on summarization tasks, indicating that the model generates over three tokens per forward pass on average.
- Task Robustness: Unlike traditional retrieval methods that struggle with non-repetitive tasks like math or translation, LogitSpec maintains high performance by tapping into the model's inherent linguistic predictions.
- Model Agnostic: The "next-next token" property was found to be consistent across different model families and scales, making LogitSpec a versatile tool for LLM acceleration.
Conclusion
LogitSpec demonstrates that the internal states of LLMs contain untapped potential for self-acceleration. By using logit-based speculation to guide context retrieval, it provides a robust, training-free, and highly effective method for speeding up inference. While its performance is currently tied to the richness of the local context, future work exploring external retrieval databases could further expand its utility in low-repetition scenarios.
Summary updated