Paper notes

Fast Inference from Transformers via Speculative Decoding

In speculative decoding a small draft model guesses several tokens, the large model verifies them in one parallel pass, and a sampling rule keeps the output distribution unchanged. This post reads the paper's formulas, recomputes its Tables 1 and 4, and explains the 1.4x to 3.4x measured on T5-XXL.

Published Updated 20 min read

On this page
  1. Background: why decoding is slow and what came before
  2. Method: speculative sampling and one round of decoding
  3. Casting every sampling method as the same thing
  4. What one round does
  5. Why the output distribution does not change
  6. Analysis: what determines the speedup
  7. Recomputation: are the paper’s numbers right?
  8. Experiments: 1.4x to 3.4x on T5-XXL
  9. Setup
  10. Results
  11. Easy-to-miss details
  12. Limits, and what came after
  13. What to take away from this paper
  14. Further reading
  15. FAQ

The paper by Leviathan, Kalman and Matias (on arXiv in November 2022, an oral at ICML 2023) answers one concrete question: can a large model decode faster without changing the model, without retraining, and without changing the output distribution? Its answer is speculative decoding. A small, fast draft model first guesses γ\gamma tokens, the large model verifies those candidates in one parallel forward pass, each candidate is accepted with a probability, and at the first rejected position a token is resampled from a corrected distribution. Every call to the large model produces at least 1 token and at most γ+1\gamma+1. On T5-XXL (11B) the paper measures speedups of 1.4x to 3.4x (batch size 1, a single TPU-v4, against the standard T5X implementation).

This page reads the paper itself: its assumptions, its formulas, its experiments and the places where it is less than clear. If you would rather start with intuition and an interactive lab, read the wiki page on speculative decoding first.

Background: why decoding is slow and what came before

An autoregressive model needs KK serial runs to generate KK tokens, because each token depends on the previous one. The paper builds on two observations. First, a single inference step of a large model is often limited not by arithmetic but by memory bandwidth and communication, so the accelerator often has spare compute (a worked example is in KV Cache and Inference Performance and on the wiki page above). Second, not every step is hard: difficult generation tasks contain many easy subtasks that a small model approximates well.

Earlier speedups fall into two groups. One lowers the cost of every token equally: distillation, sparsification, quantization, architecture changes. The other is adaptive computation, which spends less on easy steps, for example early exit. The paper points out that these usually need a different architecture, a different training procedure or retraining, and that the outputs change. The two closest earlier works each have a limitation. Blockwise Parallel Decoding (Stern et al., 2018) also decodes several tokens in parallel, but it supports only greedy decoding (temperature 0), needs an extra custom-trained model, and aims at preserving downstream quality rather than guaranteeing identical outputs. Shallow Aggressive Decoding (Sun et al., 2021) can only copy the input into the output, which suits tasks like grammatical error correction where the output is nearly the input, and it does not support general stochastic sampling.

The starting point is an old trick in processors, speculative execution: start a task in parallel before it is known whether it is needed, and win concurrency if the guess was right. The paper generalizes it to stochastic sampling and makes two contributions: a new sampling method called speculative sampling, and a mechanism that uses it to accelerate autoregressive models, called speculative decoding.

Method: speculative sampling and one round of decoding

Casting every sampling method as the same thing

Greedy, top-kk, nucleus sampling and temperature are usually handled separately at the logits level. The paper (Section 2.2) observes that all of them can be seen as standard sampling from an adjusted distribution: greedy, for instance, zeroes out every probability except the maximum and renormalizes. So only two distributions, already adjusted for the sampling method, need to be handled: p(x)p(x) from the target model MpM_p and q(x)q(x) from the draft model MqM_q (the paper calls it the approximation model). In the experiments the draft distribution always receives the same adjustment as the target’s.

What one round does

  1. Guess. MqM_q samples γ\gamma candidates x1,…,xγx_1,\dots,x_\gamma autoregressively and records its distribution qiq_i at each step.
  2. Verify. MpM_p runs on the prefix extended by 0,1,…,γ0,1,\dots,\gamma candidates, in parallel, which gives p1,…,pγ+1p_1,\dots,p_{\gamma+1} at γ+1\gamma+1 positions.
  3. Accept. Draw ri∼U(0,1)r_i\sim U(0,1) for each candidate; xix_i is accepted if ri≤pi(xi)/qi(xi)r_i\le p_i(x_i)/q_i(x_i). Counting from the left, let nn be the number of candidates accepted before the first rejection, that is n=min⁡({ i−1∣ri>pi(xi)/qi(xi) }∪{γ})n=\min\big(\{\,i-1\mid r_i>p_i(x_i)/q_i(x_i)\,\}\cup\{\gamma\}\big).
  4. Add one token. Sample a token tt from p′p'. If n<γn<\gamma, p′=norm(max⁡(0, pn+1−qn+1))p'=\mathrm{norm}\big(\max(0,\,p_{n+1}-q_{n+1})\big), the corrected distribution; if n=γn=\gamma, p′=pγ+1p'=p_{\gamma+1}. The round outputs x1,…,xn,tx_1,\dots,x_n,t.

The target model contributes at least one token per round (the last one), so in the worst case its number of serial calls is no higher than in ordinary decoding; with luck a round yields γ+1\gamma+1 tokens. Figure 1 of the paper gives an example: a 97M-parameter GPT-like target model trained on lm1b, a 6M-parameter draft, a sentence of 38 tokens, and the target model ran serially only 9 times, about 4.2 tokens per run.

Why the output distribution does not change

Look at a single position. Let β=∑xmin⁡(p(x),q(x))\beta=\sum_x\min\big(p(x),q(x)\big) be the total probability that a drafted token is accepted (Theorem 3.5); the normalizing constant of the corrected distribution is exactly 1−β1-\beta. The probability of outputting x′x' is “proposed and accepted” plus “rejected and then filled in”:

Pr⁡[x=x′]=min⁡(p(x′),q(x′))⏟proposed and accepted+(1−β)⋅p(x′)−min⁡(p(x′),q(x′))1−β⏟rejected, then filled in=p(x′)\Pr[x=x']=\underbrace{\min\big(p(x'),q(x')\big)}_{\text{proposed and accepted}}+\underbrace{(1-\beta)\cdot\frac{p(x')-\min\big(p(x'),q(x')\big)}{1-\beta}}_{\text{rejected, then filled in}}=p(x')

That is the whole proof in Appendix A.1. It holds for any pp and qq, so however poor the draft model is, the output distribution does not change; only the speed does. Appendix A.1 proves the single-position statement; every token that is output is drawn after the tokens already output, from the target model’s conditional distribution, so the statement holds for the whole sequence as well. A step-by-step derivation and a runnable numerical check are on the wiki page on speculative decoding.

Analysis: what determines the speedup

Section 3 of the paper explains the speedup with a handful of formulas. Here is the overview, followed by how to read each item.

QuantityFormulaWhereNote
Acceptance rate β\betaβ=Ex∼qmin⁡(1,p(x)q(x))=∑xmin⁡(p(x),q(x))=1−DLK(p,q)\beta=\mathbb E_{x\sim q}\min\big(1,\tfrac{p(x)}{q(x)}\big)=\sum_x\min\big(p(x),q(x)\big)=1-D_{LK}(p,q)Definition 3.1, Theorem 3.5Probability that a drafted token is accepted for a given prefix; the paper’s DLKD_{LK} is the total variation distance
Mean acceptance rate α\alphaα=E(β)\alpha=\mathbb E(\beta)Corollary 3.6Depends only on the two models and the task, not on hardware
Expected tokens per round1−αγ+11−α\dfrac{1-\alpha^{\gamma+1}}{1-\alpha}Equation (1)Assumes the β\beta of different positions are i.i.d.; the count is a geometric variable capped at γ+1\gamma+1
Cost coefficient cctime of one draft step ÷ time of one target stepDefinition 3.7Depends on hardware and implementation
Speedup1−αγ+1(1−α)(γc+1)\dfrac{1-\alpha^{\gamma+1}}{(1-\alpha)(\gamma c+1)}Theorem 3.8Assumes enough compute to run γ+1\gamma+1 positions in parallel at no extra time
Growth of total operations(1−α)(γc^+γ+1)1−αγ+1\dfrac{(1-\alpha)(\gamma\hat c+\gamma+1)}{1-\alpha^{\gamma+1}}Theorem 3.11c^\hat c is the ratio of operations per token, draft to target
  • Two numbers decide everything: α\alpha and cc. α\alpha is a property of the models and the task, cc a property of the hardware and the implementation. A bigger draft has a higher α\alpha and a higher cc, which is the central trade-off. When the draft is almost free (the paper’s negligible-cost approximation models, c≈0c\approx0) the speedup is bounded by 1/(1−α)1/(1-\alpha), and a larger γ\gamma comes closer to it.
  • A speedup requires α>c\alpha>c (Corollary 3.9). For γ=1\gamma=1 the speedup is exactly (1+α)/(1+c)(1+\alpha)/(1+c). The paper proves that if some γ\gamma gives a speedup, every smaller γ\gamma does too, so if γ=1\gamma=1 is not faster there is no point in trying longer drafts; conversely, when α>c\alpha>c some γ\gamma always gives a speedup of at least (1+α)/(1+c)(1+\alpha)/(1+c).
  • Operations go up, memory accesses go down. The target model computes γ+1\gamma+1 positions in parallel each round and rejected candidates waste work, so the total number of operations exceeds that of ordinary decoding (Theorem 3.11). But the target model’s weights and KV cache are read once per round, so the number of reads per generated token shrinks by the factor 1−α1−αγ+1\dfrac{1-\alpha}{1-\alpha^{\gamma+1}}. Latency falls because more arithmetic buys fewer reads, which only works when decoding really is memory-bound and compute is spare.
  • γ\gamma is an integer, so solve for it numerically. Given α\alpha and cc, the best γ\gamma is the integer that maximizes the speedup (Figure 3 of the paper). If the β\beta of each position could be predicted and γ\gamma adapted on the fly, a round would yield 1/(1−α)1/(1-\alpha) tokens in expectation; the paper estimates that, for typical α\alpha and cc and unbounded compute, this could be up to about 60% higher than the speedup with a fixed γ\gamma, and leaves it to future work.
  • The draft does not have to be a neural network. Section 3.6 lists several kinds: off-the-shelf small models of the same architecture, where about two orders of magnitude smaller usually worked best in the experiments; n-gram models, where evaluation is a table lookup and c≈0c\approx0; heuristics that find a matching prefix in the context and copy what follows, which suits summarization and editing where the output repeats the input; non-autoregressive models, called once in place of the draft loop; and even a “draft” that picks tokens at random, which still guarantees a very small speedup.
  • Classical rejection sampling is worse than speculative sampling. Appendix A.2 compares it: its per-step acceptance probability is at most α\alpha and can be much lower.

Recomputation: are the paper’s numbers right?

The script below writes Theorems 3.8 and 3.11 as three functions and checks the paper’s Table 1 (assuming c=c^=0c=\hat c=0), the expected column of Table 4 (EXP) and a few numbers quoted in the text.

def tokens(a, g):
    """Equation (1): expected tokens per run of the target model."""
    return (1 - a ** (g + 1)) / (1 - a)


def speed(a, g, c):
    """Theorem 3.8: walltime improvement factor."""
    return tokens(a, g) / (g * c + 1)


def ops(a, g, c_hat):
    """Theorem 3.11: growth of the total number of arithmetic operations."""
    return (g * c_hat + g + 1) / tokens(a, g)


# Table 1 of the paper (c = c_hat = 0): alpha, gamma, operations, speed
TABLE1 = [(0.6, 2, 1.53, 1.96), (0.7, 3, 1.58, 2.53), (0.8, 2, 1.23, 2.44),
          (0.8, 5, 1.63, 3.69), (0.9, 2, 1.11, 2.71), (0.9, 10, 1.60, 6.86)]
same = all(round(ops(a, g, 0), 2) == o and round(speed(a, g, 0), 2) == s
           for a, g, o, s in TABLE1)
print("Table 1, all 12 numbers reproduced:", same)

# Table 4: task, draft model, temperature, gamma, alpha, c, EXP, EMP
TABLE4 = [
    ("EnDe", "small", 0, 7, 0.75, 0.02, 3.2, 3.4),
    ("EnDe", "base", 0, 7, 0.80, 0.04, 3.3, 2.8),
    ("EnDe", "large", 0, 7, 0.82, 0.11, 2.5, 1.7),
    ("EnDe", "small", 1, 7, 0.62, 0.02, 2.3, 2.6),
    ("EnDe", "base", 1, 5, 0.68, 0.04, 2.4, 2.4),
    ("EnDe", "large", 1, 3, 0.71, 0.11, 2.0, 1.4),
    ("CNNDM", "small", 0, 5, 0.65, 0.02, 2.4, 3.1),
    ("CNNDM", "base", 0, 5, 0.73, 0.04, 2.6, 3.0),
    ("CNNDM", "large", 0, 3, 0.74, 0.11, 2.0, 2.2),
    ("CNNDM", "small", 1, 5, 0.53, 0.02, 1.9, 2.3),
    ("CNNDM", "base", 1, 3, 0.55, 0.04, 1.8, 2.2),
    ("CNNDM", "large", 1, 3, 0.56, 0.11, 1.6, 1.7),
]
print("task  draft  T  mine   EXP  EMP  range if alpha, c are rounded")
for task, m, t, g, a, c, exp, emp in TABLE4:
    ends = [speed(a + da, g, c + dc)
            for da in (-0.005, 0.005) for dc in (-0.005, 0.005)]
    print(f"{task:5s} {m:5s} {t}  {speed(a, g, c):4.2f}  {exp:4.1f} {emp:4.1f}"
          f"  {min(ends):.2f} to {max(ends):.2f}")

print("bigram draft: alpha=0.2, c=0, gamma=3 ->", round(speed(0.2, 3, 0), 3))
print("gamma=1, alpha=0.75, c=0.02:", round(speed(0.75, 1, 0.02), 3),
      "and (1+alpha)/(1+c) =", round(1.75 / 1.02, 3))
for c in (0.01, 0.05, 0.1):
    best = {a: max(range(1, 40), key=lambda g: speed(a, g, c))
            for a in (0.6, 0.7, 0.8, 0.9)}
    print(f"c={c}, best gamma and speed:",
          {a: (g, round(speed(a, g, c), 2)) for a, g in best.items()})


# Appendix A.5, lenience l = 1, 0.5, 0.3, 0.1, with c = 0.015
def best(a):
    return max(speed(a, g, 0.015) for g in range(1, 60))


print("T=0, gamma=8:", [round(speed(a, 8, 0.015), 1)
                      for a in (0.75, 0.75, 0.80, 0.87)])
print("T=1, best gamma:", [round(best(a), 1) for a in (0.62, 0.71, 0.76, 0.84)])

Output:

Table 1, all 12 numbers reproduced: True
task  draft  T  mine   EXP  EMP  range if alpha, c are rounded
EnDe  small 0  3.16   3.2  3.4  3.02 to 3.30
EnDe  base  0  3.25   3.3  2.8  3.12 to 3.39
EnDe  large 0  2.50   2.5  1.7  2.41 to 2.59
EnDe  small 1  2.26   2.3  2.6  2.17 to 2.36
EnDe  base  1  2.35   2.4  2.4  2.27 to 2.42
EnDe  large 1  1.93   2.0  1.4  1.90 to 1.97
CNNDM small 0  2.40   2.4  3.1  2.32 to 2.48
CNNDM base  0  2.62   2.6  3.0  2.54 to 2.71
CNNDM large 0  2.02   2.0  2.2  1.99 to 2.06
CNNDM small 1  1.89   1.9  2.3  1.83 to 1.95
CNNDM base  1  1.80   1.8  2.2  1.77 to 1.84
CNNDM large 1  1.54   1.6  1.7  1.51 to 1.57
bigram draft: alpha=0.2, c=0, gamma=3 -> 1.248
gamma=1, alpha=0.75, c=0.02: 1.716 and (1+alpha)/(1+c) = 1.716
c=0.01, best gamma and speed: {0.6: (7, 2.3), 0.7: (9, 2.97), 0.8: (14, 4.23), 0.9: (24, 7.49)}
c=0.05, best gamma and speed: {0.6: (4, 1.92), 0.7: (6, 2.35), 0.8: (8, 3.09), 0.9: (13, 4.67)}
c=0.1, best gamma and speed: {0.6: (3, 1.67), 0.7: (4, 1.98), 0.8: (6, 2.47), 0.9: (10, 3.43)}
T=0, gamma=8: [3.3, 3.3, 3.9, 4.9]
T=1, best gamma: [2.3, 2.9, 3.4, 4.8]
  • All 12 numbers of Table 1 are reproduced: the growth in operations and the speedup for six pairs (α,γ)(\alpha,\gamma). For example α=0.8,γ=5\alpha=0.8,\gamma=5 spends 1.63x the operations for 3.69x the speed, and α=0.9,γ=10\alpha=0.9,\gamma=10 spends 1.60x for 6.86x.
  • The expected column of Table 4 is Theorem 3.8. Plugging in the α\alpha and cc of the table, 9 of the 12 rows agree with the paper’s value (one decimal) and 3 rows (the temperature-1 English-German rows for T5-base and T5-large, and the temperature-1 summarization row for T5-large) differ by 0.05 to 0.07. The α\alpha and cc in the table have only two decimals; when each is moved by up to 0.005 up or down, the recomputed range (last column) overlaps the paper’s value (read as a ±0.05\pm0.05 interval) in every row, so there is no hidden correction term.
  • Bigram draft: α=0.2,c=0,γ=3\alpha=0.2,c=0,\gamma=3 gives 1.248x, matching the paper’s “about 1.25x”.
  • The lower bound at γ=1\gamma=1: α=0.75,c=0.02\alpha=0.75,c=0.02 gives 1.716x, equal to (1+α)/(1+c)(1+\alpha)/(1+c).
  • Best γ\gamma: the smaller cc and the larger α\alpha, the longer it pays to guess. At c=0.05c=0.05 the best γ\gamma is 8 for α=0.8\alpha=0.8 (3.09x) and 13 for α=0.9\alpha=0.9 (4.67x); at c=0.01c=0.01, α=0.9\alpha=0.9 needs γ=24\gamma=24 (7.49x).

Experiments: 1.4x to 3.4x on T5-XXL

Setup

The target model MpM_p is T5-XXL (11B, T5 v1.1) on two tasks from the T5 paper: English-German translation fine-tuned on WMT EnDe, and summarization fine-tuned on CNN/DM. The draft models MqM_q are existing checkpoints: T5-large (800M), T5-base (250M) and T5-small (77M). On a single TPU-v4 at batch size 1, the paper compares wall time against the standard implementation in the T5X codebase, for greedy decoding (temperature 0) and standard sampling (temperature 1).

Results

The table merges the paper’s Tables 2 and 4: besides the measured speedup it lists the cost coefficient cc and the expected speedup from Theorem 3.8.

TaskDraft modelTemperatureγ\gammaα\alphaccExpected speedupMeasured speedup
English-German translationT5-small070.750.023.23.4
English-German translationT5-base070.800.043.32.8
English-German translationT5-large070.820.112.51.7
English-German translationT5-small170.620.022.32.6
English-German translationT5-base150.680.042.42.4
English-German translationT5-large130.710.112.01.4
SummarizationT5-small050.650.022.43.1
SummarizationT5-base050.730.042.63.0
SummarizationT5-large030.740.112.02.2
SummarizationT5-small150.530.021.92.3
SummarizationT5-base130.550.041.82.2
SummarizationT5-large130.560.111.61.7
Speculative decoding: expected vs measured speedup (T5-XXL, Table 4) Expected speedup from Theorem 3.8 versus the speedup measured in the paper, for 12 settings. With the larger draft models on EnDe translation the measured speedup is below the expectation; on summarization it never is. Expected (EXP) Measured (EMP) EXP → EMP 1.0 1.5 2.0 2.5 3.0 3.5 1.0 = no speedup Speedup (×) EnDe · small · T=0 · γ=7 3.2 → 3.4 +0.2 EnDe · base · T=0 · γ=7 3.3 → 2.8 −0.5 EnDe · large · T=0 · γ=7 2.5 → 1.7 −0.8 EnDe · small · T=1 · γ=7 2.3 → 2.6 +0.3 EnDe · base · T=1 · γ=5 2.4 → 2.4 0.0 EnDe · large · T=1 · γ=3 2.0 → 1.4 −0.6 CNN/DM · small · T=0 · γ=5 2.4 → 3.1 +0.7 CNN/DM · base · T=0 · γ=5 2.6 → 3.0 +0.4 CNN/DM · large · T=0 · γ=3 2.0 → 2.2 +0.2 CNN/DM · small · T=1 · γ=5 1.9 → 2.3 +0.4 CNN/DM · base · T=1 · γ=3 1.8 → 2.2 +0.4 CNN/DM · large · T=1 · γ=3 1.6 → 1.7 +0.1
Table 4 of the paper: the expected speedup from Theorem 3.8 (hollow dots, with α and c taken from the table) and the speedup measured on T5-XXL (filled dots, batch size 1, one TPU-v4, against the standard T5X implementation). small, base and large are the draft models T5-small (77M), T5-base (250M) and T5-large (800M); T is the sampling temperature, γ the draft length, and the number on the right is measured minus expected. The three rows where the measurement is lower are all EnDe translation; on summarization none of the six rows is lower.
  • The smallest draft is the fastest. T5-small has cc of only 0.02 and a decent α\alpha, and gives the largest speedup (English-German, temperature 0: 3.4x). T5-large accepts most often (0.82) but, with c=0.11c=0.11, is too expensive and gives only 1.7x. The paper attributes this to the balance between α\alpha and cc; T5-small is the best of the drafts tested.
  • Greedy decoding gains more than standard sampling. For the same draft, α\alpha is higher at temperature 0: the paper observes that the sharper the adjusted distribution, the easier it is for the draft to guess right. On English-German, T5-small’s α\alpha rises from 0.62 to 0.75 and the speedup from 2.6x to 3.4x.
  • Theory and measurement agree broadly, with systematic deviations. Measured minus expected ranges from −0.8x to +0.7x. All six summarization rows are at or above the expectation; on English-German, the larger drafts (T5-base and T5-large with greedy decoding, −0.5 and −0.8; T5-large at temperature 1, −0.6) fall clearly below it. In Appendix A.3 the paper attributes the gaps to two things: optimization differences between its implementation and the baseline, and the i.i.d. assumption on β\beta being only an approximation.

The paper also measured α\alpha in more settings (Section 4.2, Table 3), estimating the expectation of Corollary 3.6 on 10K tokens generated by the target model.

Target model and taskDraft modelα\alpha (temperature 0)α\alpha (temperature 1)
GPT-like 97M, lm1b unconditional generationUnigram0.030.03
GPT-like 97M, lm1b unconditional generationBigram0.050.05
GPT-like 97M, lm1b unconditional generationGPT-like 6M0.880.89
T5-XXL, English-German translationUnigram0.080.07
T5-XXL, English-German translationBigram0.200.19
T5-XXL, English-German translationT5-small0.750.62
T5-XXL, English-German translationT5-base0.800.68
T5-XXL, English-German translationT5-large0.820.71
T5-XXL, CNN/DM summarizationUnigram0.130.08
T5-XXL, CNN/DM summarizationBigram0.230.16
T5-XXL, CNN/DM summarizationT5-small0.650.53
T5-XXL, CNN/DM summarizationT5-base0.730.55
T5-XXL, CNN/DM summarizationT5-large0.740.56
LaMDA 137B, dialogLaMDA 100M0.610.57
LaMDA 137B, dialogLaMDA 2B0.710.71
LaMDA 137B, dialogLaMDA 8B0.750.74
  • For drafts about two orders of magnitude smaller than the target, α\alpha is mostly between 0.5 and 0.9. This is the paper’s summary (“tend to produce α values between 0.5 and 0.9”). Every neural draft in the table has an α\alpha between 0.53 and 0.89: T5-small is about 140 times smaller than T5-XXL, LaMDA 100M more than a thousand times smaller than 137B, and the GPT-like 6M draft is only 16 times smaller than its 97M target yet has the highest α\alpha (0.88 and 0.89).
  • Almost free drafts are useful too. A unigram or bigram model is evaluated by table lookup and has an α\alpha between 0.03 and 0.23, which is not zero. On English-German the bigram model has α≈0.2\alpha\approx0.2, and with c=0c=0 and γ=3\gamma=3 the speedup is 1.25x, far below T5-small’s 3.4x but needing no neural network at all.
  • Temperature affects the neural drafts consistently. For the three neural drafts on T5-XXL, α\alpha at temperature 0 is 0.11 to 0.18 higher than at temperature 1.
  • LaMDA’s outputs went through a top-40 filter. The footnote of Table 3 says this has no effect on greedy decoding and some effect on standard sampling. LaMDA was only measured for α\alpha; the method was not implemented for it.

Easy-to-miss details

  • The lenience variant (Appendix A.5). Multiply q(x)q(x) by a lenience factor l∈[0,1]l\in[0,1] before comparing it with p(x)p(x). The acceptance rate rises, but the output distribution is no longer exactly pp: what is guaranteed is only that no token is sampled with probability above p(x)/lp(x)/l. With l=1/10l=1/10, for example, no token can be inflated by more than 10x and extremely rare tokens stay extremely rare; there is no guarantee on a lower bound of the probability, so the diversity of samples may suffer. The paper’s main results use the strictest version. In Table 5, for English-German with standard sampling, a T5-small draft has α\alpha of 0.62, 0.71, 0.76 and 0.84 at l=1,0.5,0.3,0.1l=1,0.5,0.3,0.1, and T5-base 0.68, 0.80, 0.83 and 0.90. Greedy decoding has a similar relaxation, with α\alpha of 0.75, 0.75, 0.80 and 0.87; with c=0.015c=0.015 and γ=8\gamma=8 the speedups are 3.3x, 3.3x, 3.9x and 4.9x, and the script above reproduces these numbers. For standard sampling the paper gives 2.5x, 3.1x, 3.6x and 5x; with Theorem 3.8, the best γ\gamma and c=0.015c=0.015 I only get 2.3x, 2.9x, 3.4x and 4.8x, for reasons I could not find, so I do not quote those four.
  • Beam search (Appendix A.4). It can be used, at some performance cost: run beam search with the draft model at a wider beam width u≥wu\ge w for γ\gamma steps, check all candidates in parallel with the target model (a budget of w+uγw+u\gamma target runs), and accept as long as the target’s top ww candidates are inside the draft’s top uu; the result then equals that of beam search with the target alone. The paper leaves the analysis to future work.
  • “Identical outputs” in the conclusion means distribution. The abstract says “identical outputs”; precisely, the output distribution is identical. At temperature 0 it is the same greedy sequence (up to floating-point differences); with sampling it is the same distribution, not the same sample path.

Limits, and what came after

The limits the paper states itself: latency is improved through increased concurrency at the cost of more arithmetic operations, so the method does not help in configurations without spare compute; it was implemented only for T5, and for other models only α\alpha was measured; only text was tested; the draft model and γ\gamma are fixed during decoding; the main results do not use lenience, and the analysis for beam search is left to later work.

Two further cautions are the reader’s, not the paper’s. First, the 1.4x to 3.4x are for batch size 1, a single TPU-v4 and the T5X baseline. Online serving usually packs many requests into a large batch, where decoding no longer has spare compute and the gain shrinks; an estimate is on the wiki pages on speculative decoding and serving. Second, the paper’s α\alpha was measured on text generated by the target model itself; another task or sampling setting changes it (on T5-XXL, α\alpha at temperature 0 and 1 already differs by 0.11 to 0.18).

The idea has been widely reused since. Chen et al. at DeepMind (2023) independently implemented the same idea as speculative sampling and report 2x to 2.5x on Chinchilla 70B; the paper’s related-work section mentions it. Later, Medusa added decoding heads on top of the target model and EAGLE drafts at the feature level, so neither needs a separate draft model, and DeepSeek-V3 reuses its training-time multi-token-prediction module as the draft. The wiki page on speculative decoding compares these, and the DeepSeek-V3 report post also discusses the acceptance rate.

What to take away from this paper

  1. It exploits the fact that decoding is memory-bound with spare compute. Verifying γ+1\gamma+1 positions in parallel is nearly free, so it pays to compute a little more in order to call the large model fewer times.
  2. Speculative sampling keeps the distribution unchanged for any draft model. The draft only affects speed, and the proof is one line: an accepted token contributes min⁡(p,q)\min(p,q) and a rejection adds p−min⁡(p,q)p-\min(p,q).
  3. Two numbers decide everything: α\alpha belongs to the models and the task, cc to the hardware and the implementation. At γ=1\gamma=1 the speedup is (1+α)/(1+c)(1+\alpha)/(1+c), so it is worth trying only when α>c\alpha>c; a bigger draft has a higher α\alpha but also a higher cc, and in the experiments a draft two orders of magnitude smaller worked best.
  4. The price is more arithmetic. The 1.4x to 3.4x was bought by spending compute on latency, and the numbers belong to a batch-size-1 T5-XXL experiment; do not extrapolate them directly to large-batch serving.

Further reading

FAQ

How does speculative decoding speed up autoregressive inference?
A small, fast draft model first guesses γ tokens, and the large model verifies all of them in a single parallel forward pass. Accepted tokens are confirmed at once; at the first rejected position the large model resamples one token from a corrected distribution. Each round produces at least 1 and at most γ+1 tokens, so the number of serial calls to the large model is never higher than in ordinary decoding. On T5-XXL (11B) the paper measures speedups of 1.4x to 3.4x (batch size 1, one TPU-v4, against the standard T5X implementation).
Does speculative decoding change the output distribution?
No. A drafted token is accepted with probability min(1, p/q) and a rejected one is replaced by a sample from norm(max(0, p−q)), so the distribution at every position is exactly the target model's p, for any draft model q (Appendix A.1 of the paper). The draft model only affects speed. With temperature 0 the result is the target model's own greedy sequence, up to floating-point differences. The exception is the optional lenience variant of Appendix A.5, which trades some distribution change for a higher acceptance rate; the paper's main experiments do not use it.
What determines the speedup, and how is it computed?
Three quantities: the acceptance rate α (the average probability that a drafted token is accepted), the cost coefficient c (the time of one draft step divided by the time of one target step) and the draft length γ. The speedup is (1−α^(γ+1)) / ((1−α)(γc+1)) (Theorem 3.8). For γ=1 it is (1+α)/(1+c), so a speedup is only possible when α>c. In the paper's Table 4 the measured speedup differs from this expectation by −0.8x to +0.7x.
How should the draft model be chosen, and what acceptance rate is typical?
The paper used off-the-shelf small models of the same architecture and found that a draft about two orders of magnitude smaller than the target usually works best, because α and c have to be balanced; for such drafts α is mostly between 0.5 and 0.9. On T5-XXL the 77M T5-small was fastest (α=0.75 and a 3.4x speedup for English-German translation with greedy decoding), while the larger T5-large accepted more often (α=0.82) but gave only 1.7x. Even a trivial unigram or bigram model has a nonzero α (about 0.2 for a bigram model on translation, which gives 1.25x at γ=3).
When is speculative decoding not worth it?
The paper states that it buys lower latency with more concurrency, so the total number of arithmetic operations goes up (Table 1: with a free draft, α=0.8 and γ=5 spend 1.63x the operations to get 3.69x the speed). It does not help when there is no spare compute. If α≤c no choice of γ gives a speedup, and a draft that is too expensive or too inaccurate makes decoding slower.