Online Speculative Decoding

Xiaoxuan Liu, Lanxiang Hu, Peter Bailis, Alvin Cheung, Zhijie Deng, Ion Stoica, Hao Zhang

TL;DR

Speculative decoding speeds up LLM inference by using a tiny "draft" model to guess tokens, but these guesses often fail when user queries shift away from the draft's training data. Online Speculative Decoding (OSD) solves this by continuously fine-tuning the draft model in real-time using the target model's corrections, boosting token acceptance rates and delivering up to a 2.17x speedup.

What Problem Does This Paper Address?

Large Language Models (LLMs) are notoriously slow because they generate text autoregressively—one token at a time—requiring a full, computationally expensive pass for every single word. Speculative Decoding (SD) was introduced to fix this bottleneck: a small, fast "draft" model guesses a sequence of tokens, and the large "target" model verifies them all in a single parallel step.

However, there is a catch. If the draft model’s guesses are wrong (resulting in a low "acceptance rate"), the target model has to throw them out and recompute, wasting time. Most draft models are static; they are trained once and never change. In the real world, user queries are diverse and shift over time (e.g., moving from coding questions to creative writing). A static draft model cannot adapt to these shifts, leading to poor performance and minimal speedups.

Methods

The authors introduce Online Speculative Decoding (OSD), a framework that turns the inference process into a continuous learning loop.

Online Speculative Decoding Architecture
  1. Online Knowledge Distillation (KD): During the verification step, the target model (the "teacher") naturally provides the correct token distributions. OSD captures this "free" information and uses it to fine-tune the draft model (the "student") on the fly.
  2. Periodic Updates: Instead of updating after every token, OSD stores (draft, target) probability pairs in a replay buffer. Once the buffer reaches a certain size or time limit, the draft model is updated using distance metrics like KL Divergence.
  3. Specialized Draft Models & Routing: Recognizing that one small model cannot be an expert in everything, OSD can maintain multiple specialized draft models (e.g., one for Python, one for Law). It uses a lightweight router to send each query to the most relevant specialist.
  4. Computational Efficiency: Because the draft models are tiny (often 20x–50x smaller than the target), the cost of updating them is negligible compared to the cost of running the target model.

Datasets

The researchers evaluated OSD using a mix of synthetic benchmarks and real-world data:

  • Benchmarks: Spider (Text-to-SQL), GSM8k (Grade school math), Code-search-Python, and Alpaca-finance.
  • Real-World Data: A 10,000-record subset of the LMSYS-Chat-1M (Arena) dataset, which contains actual human-chatbot interactions across 150+ languages.

Key Insights and Ideas

  • The "Free" Training Signal: The most elegant part of OSD is that it requires no new labeled data. The target model's corrections are the labels. Speculative decoding inherently generates the data needed to improve itself.
  • Rapid Adaptation: OSD is remarkably resilient to "distribution shifts."
Adaptation to Distribution Shifts

As shown above, when the query type suddenly changes (e.g., from GSM8k math to Spider SQL), the acceptance rate initially dips but rebounds almost immediately as the draft model absorbs the new patterns.

  • Specialization > Generalization: The paper shows that routing queries to multiple specialized draft models provides a significantly higher acceptance rate than using a single, larger general-purpose draft model, even when the total parameter count is similar.
  • Bandwidth Savings: Since LLM inference is often bottlenecked by memory bandwidth (loading weights from VRAM), OSD's higher acceptance rate means the massive target model is loaded fewer times per generated sequence, leading to massive efficiency gains.

Key Results

  • Acceptance Rate Boost: OSD increased the token acceptance rate by 0.1 to 0.65 across various tasks compared to static models.
  • Latency Reduction: This translated to a 1.42x to 2.17x speedup in wall-clock time.
  • Medusa Integration: When combined with Medusa (a popular tree-style speculative decoding method), OSD further improved performance, showing it is complementary to other state-of-the-art acceleration techniques.
  • Language & Topic Performance: In the Arena dataset, OSD was particularly effective for languages like Japanese and topics like "Computer" and "Social," where it achieved acceptance rates near 0.9.

Limitations and Future Work

  • Routing Overhead: While the routing process is efficient, identifying the optimal number of specialized models and the best routing strategy remains an open research question.
  • Memory Management: Maintaining multiple draft models in GPU memory increases overhead. While manageable (about 10% of the target model's size in their tests), it could become a constraint for extremely memory-limited environments.
  • Update Hyperparameters: The frequency of updates and the eviction policy for the replay buffer (which data to keep vs. throw away) were not exhaustively explored and likely vary by use case.

Summary updated

BibTeX
@inproceedings{liu2024online,
  author = {Xiaoxuan Liu and Lanxiang Hu and Peter Bailis and Alvin Cheung and Zhijie Deng and Ion Stoica and Hao Zhang},
  title = {{Online Speculative Decoding}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=BPQHXwVNvl},
}
Figure