Skip to content
AI & Machine Learning

Speculative Decoding

Definition

Speculative decoding speeds up a large language model by having a small, fast model guess the next several tokens and the large model check them all at once, keeping the guesses it agrees with. The output is the same as the large model would have produced alone; it just arrives sooner.

Diagram

Small model drafts
  1. The
  2. order
  3. ships
  4. today
  5. and
Large model checks all five at once
  1. The
  2. order
  3. ships
  4. today → on
  5. and

Result of one large-model pass: The order ships on, four tokens instead of one.

The large model keeps every drafted token up to the first one it disagrees with, swaps in its own choice there and drops the rest. The text is exactly what the large model would have written alone. The speedup depends on how often the small model guesses right, so it is largest for predictable text.

Case study

Worked example