Fast Inference from Transformers via Speculative Decoding

Yaniv Leviathan, Matan Kalman, Yossi Matias

2023 · ICML

Fast Inference from Transformers via Speculative Decoding

Problem

Framing

Autoregressive Transformer latency scales linearly with the number of decoded tokens because each token needs one serial target-model pass. The paper closes this with speculative decoding: a small draft model proposes γ\gamma tokens, the large model verifies them in parallel, and exact output distribution is preserved while reaching roughly 2×2\times3×3\times speedups on T5-XXL and Chinchilla-class models.

Currently Used Methods

Direct antecedents

Proposed Method

Architecture

Two autoregressive models share the same tokenizer and sampling standardization: a large target model MpM_p and a much cheaper approximation model MqM_q. Each step lets MqM_q draft γ\gamma continuations autoregressively, then runs MpM_p once on the prefix plus drafted tokens to verify several positions in parallel.

Speculative decoding example: the draft model proposes token blocks, accepted tokens remain, and rejected tokens are corrected by the target model.

Loss / Objective

The paper is algorithmic.It defines an adjusted fallback distribution after rejection:

p(x)=norm(max(0,p(x)q(x)))p'(x) = \operatorname{norm}(\max(0, p(x) - q(x)))

Sampling Rule / Algorithm

Accept each drafted token with a modified rejection rule; on rejection, resample from the residual of pp over qq.

Pr[accept xxq]=min ⁣(1,p(x)q(x))\Pr[\text{accept } x \mid x \sim q] = \min\!\left(1, \frac{p(x)}{q(x)}\right) E[# generated tokens]=1αγ+11α\mathbb{E}[\#\text{ generated tokens}] = \frac{1-\alpha^{\gamma+1}}{1-\alpha} improvement=1αγ+1(1α)(γc+1)\text{improvement} = \frac{1-\alpha^{\gamma+1}}{(1-\alpha)(\gamma c + 1)}

Training Procedure

Evaluation

Datasets

Metrics

Headline results

Ablations

Results plots: left shows optimal draft length \gamma versus acceptance rate \alpha for different cost ratios c; right shows predicted speedup and operation count versus \alpha for multiple \gamma.

Method Strengths and Weaknesses

Strengths

Weaknesses

Suggestions from the authors

Links

Prior Papers

Further Papers