# Fast Inference from Transformers via Speculative Decoding

> Uses a small model to draft several tokens and a large model to verify them in one parallel pass. A rejection-sampling rule keeps outputs identical in distribution while decoding T5-XXL 2 to 3.4 times faster.

- arXiv: https://arxiv.org/abs/2211.17192
- Authors: Yaniv Leviathan, Matan Kalman, Yossi Matias
- Published: 2022-11-30
- Topic: Inference & systems
- Visual carousel: https://instaxiv.com/p/2211.17192
- Explanation by InstaXiv, a secondary educational summary. Cite the original paper for exact results. InstaXiv is not affiliated with or endorsed by arXiv or Cornell University.

## A small model drafts, a big one verifies: same outputs, 2–3× faster

**3.4×** faster T5-XXL translation, outputs unchanged

## Decoding is serial and memory-bound

**Standard decoding:** One full forward pass of the large model per token. The GPU mostly waits on memory reads while its compute sits idle.

**Speculative decoding:** A cheap model guesses several tokens ahead. The large model scores all guesses in one parallel pass and keeps the longest valid prefix.

Spare compute buys fewer serial steps.

## Accepted drafts in green, rejections in red

![Figure 1](https://cdn.instaxiv.com/figures/2211.17192/figure1.webp)

Each line is one iteration. The small model proposes tokens; the target model accepts the green ones, rejects the red, and supplies a correction in blue. (Figure 1)

## Speculative sampling keeps the exact distribution

1. **Draft $\gamma$ tokens**: The approximation model $M_q$ samples $\gamma$ tokens one by one; it is cheap and fast.
2. **Verify in parallel**: The target $M_p$ scores all $\gamma + 1$ positions in a single forward pass.
3. **Accept or resample**: Keep each draft with probability $\min(1, p/q)$; at the first rejection, sample from the adjusted residual and stop.

## The acceptance rule that guarantees identical outputs

$$
\begin{gathered} \Pr[\text{accept } x] = \min\!\left(1,\ \frac{p(x)}{q(x)}\right) \\ x' \sim \mathrm{norm}\big(\max(0,\ p - q)\big) \end{gathered}
$$

Where the draft overestimates a token it is sometimes rejected; sampling from the residual fills the gap, so outputs follow the target exactly.

- $p(x)$: Target model's probability
- $q(x)$: Draft model's probability
- $\max(0, p - q)$: Mass the draft under-proposed, used on rejection

## The smallest draft model gives the biggest speedup

| Method | Greedy | Sampling |
| --- | --- | --- |
| T5-large draft | 1.7× | 1.4× |
| T5-base draft | 2.8× | 2.4× |
| **T5-small draft (77M params)** | **3.4×** | **2.6×** |

_T5-XXL (11B) target on WMT English-German. Greedy is temperature 0; sampling is temperature 1._

## Speed depends on how well the draft guesses

- **Needs a matched draft**: Speedup depends on the acceptance rate; a draft that diverges from the target wastes work.
- **Extra arithmetic**: Total operations rise because rejected drafts are computed and discarded. It pays only when compute is idle.
- **Latency, not throughput**: Gains target single-request latency; with large batches the GPU is already busy.

Best used when: Serving latency-sensitive generation with spare GPU compute and a well-matched small model.

## Key takeaways

- Speculative sampling provably preserves the target model's output distribution, so no quality is traded.
- It works with off-the-shelf models: no retraining or architecture changes.
- Draft-and-verify now powers fast decoding in major LLM serving stacks.

## Links

- arXiv: https://arxiv.org/abs/2211.17192
- PDF: https://arxiv.org/pdf/2211.17192

## Citation

```bibtex
@article{leviathan2022fast,
  title   = {Fast Inference from Transformers via Speculative Decoding},
  author  = {Leviathan, Yaniv and Kalman, Matan and Matias, Yossi},
  journal = {arXiv preprint arXiv:2211.17192},
  year    = {2022},
  url     = {https://arxiv.org/abs/2211.17192}
}
```
