SpecInfer: Accelerating Large Language Model Serving with Tree-based Speculative Inference and Verification

Xupeng Miao, Gabriele Oliaro, Zhihao Zhang, Xinhao Cheng, Zeyu Wang, Zhengxin Zhang, Rae Ying Yee Wong, Alan Zhu, Lijie Yang, Xiaoxiang Shi, Chunan Shi, Zhuoming Chen, Daiyaan Arfeen, Reyna Abhyankar, Zhihao Jia

TL;DR

This paper introduces SpecInfer, a novel system that significantly accelerates the serving of large language models (LLMs) by employing tree-based speculative inference and verification. By using smaller "speculator" models to predict multiple potential token sequences organized in a tree, and then verifying these sequences in parallel with the main LLM, SpecInfer achieves substantial speedups without sacrificing output quality.

What Problem Does This Paper Address?

Serving large language models (LLMs) like GPT-3 and GPT-4 is computationally expensive and slow due to their massive size (billions of parameters) and the sequential nature of token generation. Existing methods, like incremental decoding, process tokens one by one, leading to underutilized hardware and high latency. While speculative decoding has been proposed to speed this up, it typically relies on a single predicted sequence, which often fails to align with the LLM's output, limiting its effectiveness. The challenge is to accelerate LLM serving efficiently while maintaining the quality and accuracy of generated text.

Methods

SpecInfer tackles this problem with two core innovations:

  • Tree-based Speculative Inference: Instead of predicting just one token sequence, SpecInfer uses smaller, specialized models (SSMs) to generate a tree of candidate token sequences. This tree structure allows for exploring a much wider range of possibilities, increasing the chances of finding a sequence that aligns with the LLM's output. Two methods are used to construct this tree:
  • Expansion-based: Generates multiple tokens from a single SSM at each step, leveraging the fact that LLM-selected tokens are often within the top-k predictions of SSMs.
  • Merge-based: Combines outputs from multiple SSMs to create a more diverse set of candidates.
  • Tree-based Parallel Decoding and Verification: The LLM is used as a "verifier" rather than a direct decoder. SpecInfer employs a novel "tree-based parallel decoding" mechanism that efficiently computes attention scores for all tokens in the speculative tree simultaneously. This allows the LLM to verify multiple speculated tokens in a single pass, drastically reducing the number of LLM inference steps required. This is achieved through techniques like depth-first search for key-value cache updates and a topology-aware causal mask to handle the tree structure.

Datasets

The paper evaluates SpecInfer on five datasets:

  • Chatbot Instruction Prompts (CIP)
  • ChatGPT Prompts (CP)
  • WebQA
  • Alpaca
  • PIQA

These datasets are used to simulate real-world conversation traces for evaluating LLM generation. No new benchmarks were introduced.

Key Insights and Ideas

  • Tree structure is key to speculative success: Organizing speculative predictions into a tree, rather than a single sequence, dramatically increases the probability of successful verification against the LLM. This is because it allows for exploring a richer set of possibilities and leveraging shared prefixes more effectively.
  • LLM as a verifier, not just a decoder: Shifting the LLM's role to verification, coupled with parallel processing of speculative candidates, is more efficient than using it for direct, sequential decoding.
  • Parallelism is paramount: The core of SpecInfer's speedup comes from its ability to parallelize the verification process across multiple speculative branches, making much better use of available hardware resources.
  • Balancing speculation and verification: The "width" of the speculative token tree is a critical parameter. Too narrow, and it's like existing methods; too wide, and the verification overhead can increase. Finding the right balance is crucial for optimal performance.

Key Results

SpecInfer demonstrates significant performance improvements:

  • Distributed LLM Inference: Achieves 1.5-2.8× speedup compared to existing systems like vLLM and HuggingFace TGI.
  • Offloading-based LLM Inference: Achieves 2.6-3.5× speedup compared to systems like FlexGen, which is crucial for serving LLMs on limited hardware.
  • Verification Success: The tree-based approach significantly improves the token verification success rate, from 52-57% to 96-97% for stochastic decoding.
  • Quality Preservation: SpecInfer provably preserves the generative performance and output distribution of the original LLM.

Limitations and Future Work

  • Dynamic Tree Expansion: The paper acknowledges that dynamically expanding the token tree based on real-time performance is an open research problem and leaves it as future work. The current approach uses a static expansion configuration.
  • Ensemble Learning Methods: While merge-based tree construction is discussed, other ensemble learning methods for combining SSMs are mentioned as future exploration.
  • Hardware Utilization: The performance gains are most pronounced with larger batch sizes and when there are "spare" GPU resources to leverage for speculative verification. The benefit might be less pronounced in highly saturated environments.

Summary updated

BibTeX
@inproceedings{miao2024specinfer,
  author = {Xupeng Miao and Gabriele Oliaro and Zhihao Zhang and Xinhao Cheng and Zeyu Wang and Zhengxin Zhang and Rae Ying Yee Wong and Alan Zhu and Lijie Yang and Xiaoxiang Shi and Chunan Shi and Zhuoming Chen and Daiyaan Arfeen and Reyna Abhyankar and Zhihao Jia},
  title = {{SpecInfer: Accelerating Large Language Model Serving with Tree-based Speculative Inference and Verification}},
  booktitle = {ASPLOS},
  year = {2024},
  doi = {10.1145/3620666.3651335},
}
Figure