Skip to main content
QUICK REVIEW

[Paper Review] Fast Inference from Transformers via Speculative Decoding

Yaniv Leviathan, Matan Kalman|arXiv (Cornell University)|Nov 30, 2022
Parallel Computing and Optimization TechniquesComputer Science34 citations
TL;DR

The paper introduces speculative decoding with speculative sampling to accelerate autoregressive Transformer inference by running a smaller approximation model in parallel and reusing its outputs while preserving the target model’s output distribution, achieving 2x-3x walltime speedups on T5-XXL without retraining.

ABSTRACT

Inference from large autoregressive models like Transformers is slow - decoding K tokens takes K serial runs of the model. In this work we introduce speculative decoding - an algorithm to sample from autoregressive models faster without any changes to the outputs, by computing several tokens in parallel. At the heart of our approach lie the observations that (1) hard language-modeling tasks often include easier subtasks that can be approximated well by more efficient models, and (2) using speculative execution and a novel sampling method, we can make exact decoding from the large models faster, by running them in parallel on the outputs of the approximation models, potentially generating several tokens concurrently, and without changing the distribution. Our method can accelerate existing off-the-shelf models without retraining or architecture changes. We demonstrate it on T5-XXL and show a 2X-3X acceleration compared to the standard T5X implementation, with identical outputs.

Motivation & Objective

  • Motivate faster inference for large autoregressive Transformers where decoding is sequential and slow.
  • Propose a method to run an approximation model in parallel with the target model to generate speculative tokens.
  • Ensure that the final outputs match the target model’s distribution without retraining or architecture changes.
  • Provide theoretical guidance and empirical evidence across tasks showing practical speedups on real models.

Proposed method

  • Define a target model Mp and a smaller approximation model Mq for the same task.
  • Generate gamma candidate tokens from Mq and evaluate them in parallel with Mp using speculative sampling to preserve Mp’s distribution.
  • Use a sampling adjustment to ensure the final output distribution remains identical to Mp’s, potentially emitting up to gamma+1 tokens per step.
  • Analyze speedups under an alpha measure (acceptance probability) and cost coefficient c for Mq, deriving an optimal gamma.
  • Demonstrate that walltime improvement follows a formula depending on alpha, gamma, and c, and identify when speedups are realized.
  • Empirically validate on tasks (translation, summarization, dialog) and compare against T5X baseline on T5-XXL.

Experimental results

Research questions

  • RQ1How much can speculative decoding accelerate inference of large Transformer models without changing outputs?
  • RQ2What is the relationship between approximation quality (alpha) and speedup, and how should gamma be chosen?
  • RQ3How do walltime and computational resource trade-offs behave with different approximation models and sampling settings?

Key findings

  • Empirically achieves 2x-3x walltime speedups on T5-XXL compared to T5X with identical outputs.
  • Speedups correlate with the acceptance rate alpha; higher-quality approximations (larger alpha) yield greater gains for suitable gamma.
  • Negligible-cost approximations (e.g., unigram/bigram) still provide measurable speedups, though smaller than larger approximation models.
  • Theoretical analysis provides formulas for expected generated tokens and walltime improvement, guiding choice of gamma given alpha and hardware cost c.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.