AI Engineering · Inference Speed

Speculative Decoding

LLMs generate one word at a time — each word costs a full forward pass. Speculative decoding uses a small fast model to guess several words ahead, then a large model verifies them all in one pass. Result: 1.87× faster with mathematically identical output.

1.87×
Measured speedup
71%
Mean acceptance rate
K=5
Optimal draft length
0
Quality loss (lossless)
The technique
Why this is non-obvious

A large model (e.g., GPT-4o, 70B parameters) is slow but accurate. A small draft model (e.g., GPT-2, 124M parameters) is fast but sometimes wrong. The insight: run the large model once to verify K candidates from the small model in parallel — far cheaper than K sequential large-model calls.

How verification works (rejection sampling)

For each draft token t, compute α = min(1, p_target(t) / p_draft(t)). Accept with probability α. On rejection, sample a corrected token from (p_target − α·p_draft).clamp(0). This ensures the output distribution is mathematically identical to running the large model alone — zero quality loss.

The bonus token

When all K draft tokens are accepted, the large model's final forward pass generates one extra "bonus" token for free — since we already have its output distribution. This increases throughput beyond the naive speedup estimate.

How to explore

No API key or GPU needed. "Step Visualizer" shows token-by-token acceptance/rejection. "Benchmark" shows speedup vs draft length K. "The Math" shows the rejection sampling proof.