Accelerating LLM Inference with Staged Speculative Decoding

Benjamin Frederick Spector, Christopher Re

TL;DR

Large Language Models (LLMs) are computationally expensive, especially for real-time, on-device applications. This paper introduces "staged speculative decoding," a novel approach that significantly speeds up LLM inference by using multiple, progressively smaller models to predict tokens in parallel. This method achieves a 3.16x speedup on a GPT-2 Large model without sacrificing output quality, making LLMs more accessible for low-latency and privacy-sensitive scenarios.

What Problem Does This Paper Address?

Modern LLMs, while incredibly powerful, demand substantial computational resources for inference. This poses a significant challenge for applications requiring low-latency responses or operating on resource-constrained devices (like smartphones or laptops), where sending data to the cloud for processing is not feasible due to latency or privacy concerns. A key bottleneck in LLM inference, particularly in small-batch or single-user scenarios, is the low "arithmetic intensity" – meaning the computation per byte of memory accessed is low. This leads to GPUs spending more time waiting for data than performing calculations. Existing methods like speculative decoding help, but their performance gains plateau quickly.

Methods

The paper proposes "staged speculative decoding," which builds upon existing speculative decoding techniques. Here's what's new:

  • Tree-Structured Batches: Instead of a linear sequence of predicted tokens, the speculative decoding process is organized into a tree. This allows the system to explore multiple potential token sequences simultaneously, increasing the chances of correctly predicting more tokens per batch and improving parallelism.
  • Second Stage of Speculation: The core idea is to use not just one, but two draft models. A primary, faster draft model predicts tokens, and then a second, even smaller draft model (like an N-gram model) is used to speculatively decode the first draft model's predictions. This "staged" approach further accelerates the prediction process.

Essentially, the system uses a large "oracle" model, a medium-sized "draft" model, and a tiny "draft²" model (e.g., an N-gram model) to predict tokens. The tree structure helps manage the complexity of multiple predictions, and the staged speculation ensures that even the draft model's predictions are accelerated.

Datasets

The paper uses the HumanEval dataset for evaluation. The models themselves are described as:

  • Oracle Model: A GPT-2 Large (762M parameters) fine-tuned on the Python subsection of "The Pile" dataset.
  • Draft Model: A smaller (40M parameters) GPT-2 model trained on the same data.
  • Draft² Model: A Katz backoff trigram model, generated by running the draft model for two hours at a sampling temperature of 1.5 to produce 120M tokens.

Key Insights and Ideas

  • Arithmetic Intensity is King for Small Batches: The paper strongly emphasizes that for small-batch LLM inference, the bottleneck is memory bandwidth, not raw compute. Any method that increases the effective arithmetic intensity (more computation per memory access) will yield significant speedups.
  • Speculative Decoding Gains Saturate: Standard speculative decoding, while effective, hits a performance ceiling because the probability of a draft model correctly predicting long sequences of tokens decreases exponentially. The proposed tree structure and staged approach are designed to overcome this limitation.
  • Democratizing AI: The authors believe that efficient local LLM inference is crucial for democratizing AI, enabling individuals with limited computational resources to leverage powerful models without relying on expensive cloud infrastructure.
  • Entropy and LLM Performance: The paper speculates that the performance gains of LLMs are often isolated to a few "critical" tokens, while much of the generated text has low entropy (e.g., whitespace) and can be predicted efficiently by smaller models.

Key Results

  • 3.16x Speedup: The staged speculative decoding method achieved an average speedup of 3.16x over standard single-batch decoding with a GPT-2 Large (762M parameter) model.
  • 1.36x Speedup over Standard Speculative Decoding: The proposed method also outperformed existing speculative decoding techniques by 1.36x.
  • Preserved Output Quality: Crucially, these speedups were achieved while perfectly preserving the output quality of the oracle model.
  • Reduced Memory Bandwidth: Table 1 shows that staged speculative decoding significantly reduces memory bandwidth consumption compared to baseline and standard speculative methods.
  • Performance Varies: The speedup can range from 2x to 10x depending on the prompt and the "denseness" or "sparseness" of difficult content, with highly indented code yielding greater benefits.

Limitations and Future Work

  • Python Overhead: The current implementation has a 35% overhead due to Python infrastructure, which could be reduced with a more efficient implementation.
  • Range of Performance: The performance benefits can vary significantly, from 2x to 10x, depending on the nature of the text being generated.
  • Larger Models: The authors suggest that running with larger models (e.g., 20B parameters with 8-bit quantization) could enable even more stages of speculation and greater performance boosts.
  • Better Lowest-Level Draft Models: Investigating draft models that are faster than N-gram models but still perform well could further improve the system.
  • Speculative Sampling: Exploring faster ways to speculatively sample with temperatures greater than zero is also a promising avenue.

Summary updated

BibTeX
@inproceedings{spector2023accelerating,
  author = {Benjamin Frederick Spector and Christopher Re},
  title = {{Accelerating LLM Inference with Staged Speculative Decoding}},
  booktitle = {ES-FoMO @ ICML},
  year = {2023},
  url = {https://openreview.net/forum?id=RKHF3VYjLK},
}
Figure