Skip to content
Cosvexa – Cosvexa home

Research · Inside modern models

Speculative decoding: faster generation with a draft model

Speculative decoding is a technique that speeds up text generation by letting a small, fast draft model guess several next tokens, which the large target model then checks in a single parallel pass. Correct guesses are kept, and a special acceptance rule guarantees that the output follows exactly the same distribution as the large model alone. Its authors reported speedups of about two to three times.

Cosvexa team · Published

Abstract illustration of a small, quick beam of light racing ahead along a path and laying down glowing stepping stones, which a larger, broad beam behind it checks and lights up.

Key points

  • Generating text token by token is slow because each step must read all of a large model's weights from memory.
  • A cheap draft model proposes several tokens; the target model verifies all of them in one forward pass.
  • A modified rejection-sampling rule keeps the output distribution identical to the target model's.
  • Speedup depends on how often the draft is right; papers reported roughly 2–3× at small batch sizes.
  • Variants replace the separate draft model with extra prediction heads, internal features or text copied from the prompt.

What speculative decoding is

A large language model generates text one token at a time: it predicts a distribution over the next token, picks one, appends it and repeats. Producing K tokens takes K sequential runs of the model. Speculative decoding breaks this chain by guessing ahead. A small draft model quickly proposes a short continuation, and the large target model scores all proposed tokens at once. Tokens the target model agrees with are accepted for the price of one target-model pass.

The idea was published independently by two groups. Yaniv Leviathan, Matan Kalman and Yossi Matias at Google posted "Fast Inference from Transformers via Speculative Decoding" in November 2022 (presented at ICML 2023), and Charlie Chen and colleagues at DeepMind posted "Accelerating Large Language Model Decoding with Speculative Sampling" in February 2023. Both build on blockwise parallel decoding by Mitchell Stern, Noam Shazeer and Jakob Uszkoreit (NeurIPS 2018), which predicted several future tokens and kept the longest prefix a scoring model validated, but only for greedy decoding. The name comes from speculative execution in processors, which runs work ahead of time and discards it if a guess turns out wrong.

Why generation is slow in the first place

For a single user, generating one token requires reading every weight of the model from the accelerator's main memory, but performing only a couple of arithmetic operations per weight. Modern GPUs can compute far faster than they can move data, so this step is memory-bandwidth bound: the arithmetic units sit mostly idle while weights stream in. (The KV cache avoids recomputing past tokens but does not change this.)

The key observation is that checking several tokens costs almost the same as generating one. When the target model processes five proposed tokens in one forward pass, it reads its weights once and uses them five times. The extra arithmetic is nearly free because the hardware had spare compute. Speculative decoding turns that idle capacity into accepted tokens.

How it works, step by step

  1. 1

    Draft

    The draft model generates a short block of γ tokens (for example 4 or 5) autoregressively. It is small, so this is fast. It records its own probability q(x) for each token it chose.

  2. 2

    Verify in parallel

    The target model runs one forward pass over the prompt plus all γ draft tokens. This gives its own probability p(x) for each drafted token, plus a distribution for the position after the last one.

  3. 3

    Accept or reject, left to right

    Each drafted token x is accepted with probability min(1, p(x) / q(x)). If the target model gives the token at least as much probability as the draft did, it is always accepted.

  4. 4

    Correct the first rejection

    At the first rejected position, a replacement token is sampled from the leftover distribution, proportional to max(0, p(x) − q(x)), and everything after it is discarded.

  5. 5

    Bonus token

    If all γ tokens are accepted, one more token is sampled from the target model's distribution for the next position, which was computed in the same pass. Each round therefore yields between 1 and γ + 1 tokens.

The acceptance rule is the clever part. Both papers prove that this modified rejection sampling produces tokens distributed exactly as if they had been sampled from the target model alone, at any temperature or top-p setting applied to both models. With greedy decoding the rule reduces to a simple check: keep draft tokens while they match the target model's top choice. The output is the same as without speculation, up to floating-point rounding.

A worked example

Suppose the prompt is "The capital of France is" and the draft proposes "Paris . It is". The target model scores all four positions in one pass. For "Paris" the draft gave probability 0.90 and the target 0.95: since p ≥ q, it is accepted. For "." the draft gave 0.60 and the target 0.70: accepted. For "It" the draft gave 0.50 but the target only 0.20, so it is accepted with probability 0.20 / 0.50 = 0.4. If it is rejected, a token is sampled from the leftover distribution, perhaps "The", and "is" is thrown away. This round produced three tokens ("Paris", ".", "The") for one target-model pass instead of three.

How much faster, and what the papers reported

Leviathan and colleagues define the acceptance rate α as the expected probability that a draft token is accepted. If acceptances were independent, the expected number of tokens per round would be (1 − α^(γ+1)) / (1 − α). With α = 0.8 and γ = 5, that is about 3.7 tokens per target pass. The real speedup is lower, because the draft model also costs time and a longer draft wastes more work after a rejection; there is an optimal γ for each pair of models.

MethodSetupResults as reported by the authors
Speculative decoding (Leviathan et al., 2022)T5-XXL (11B) target, T5-small (77M) draft2–3× faster than the standard T5X implementation with identical outputs; 3.4× on English–German translation with greedy decoding
Speculative sampling (Chen et al., 2023)Chinchilla 70B target, 4B draft trained for low latency2–2.5× decoding speedup in a distributed setup, without changing sample quality
Medusa (Cai et al., 2024)Extra decoding heads on the target model, tree-based verificationOver 2.2× for Medusa-1 (frozen backbone); 2.3–3.6× for Medusa-2 (heads trained jointly)
EAGLE (Li et al., 2024)Lightweight draft head predicting the target's internal features2.7–3.5× latency speedup for LLaMA2-Chat 70B, preserving the output distribution

The speedup is not constant. Chen and colleagues found it varied by task: code generation was easier to predict than summarization, and the speedup plateaued or got worse as the draft length grew. Predictable text, such as code, boilerplate or text that repeats the prompt, gives high acceptance rates; creative or unusual text gives lower ones.

Variants: where the draft comes from

  • A separate small model. The original recipe. The draft must share the target's tokenizer and should imitate it well, which is why drafts are often smaller models from the same family or trained by knowledge distillation from the target.
  • Extra heads on the target model. Medusa adds several small prediction heads that guess tokens 2, 3, 4 and more steps ahead, and verifies a tree of candidate continuations at once with a special attention mask. No second model needs to be served.
  • Feature-level drafting. EAGLE trains a light head that predicts the target model's next internal feature vector rather than the next token, which its authors found easier to predict accurately.
  • Self-speculation. The draft is the target model itself with some layers skipped, so no extra weights are needed.
  • Retrieval or prompt lookup. For tasks like editing or summarizing, the next tokens are often copied from the input. Simple n-gram matching against the prompt can propose drafts for free.

Popular inference libraries support several of these. In the Hugging Face Transformers library, for instance, passing a smaller model of the same family as an assistant enables the basic draft-and-verify scheme, which the library calls assisted generation:

Assisted generation in Hugging Face Transformers
# target and draft: two causal LMs that share a tokenizer
outputs = target.generate(
    **inputs,
    assistant_model=draft,   # proposes tokens, target verifies them
    max_new_tokens=200,
)

Why it matters

Latency per token is what users feel in chat, coding assistants and agents that chain many model calls. Speculative decoding lowers it without retraining the target model, without changing its outputs and without approximations, which makes it unusually easy to adopt: it is a pure systems optimization. It is now a standard feature of major serving engines and is one of the levers behind the speed differences between providers serving the same open model, as discussed in what drives LLM cost and latency.

Limits and common misconceptions

  • "It changes the model's answers." Done correctly, it does not: the acceptance rule preserves the target distribution. Approximate variants that relax the rule to accept more tokens do trade some fidelity for speed, so check which mode a system uses.
  • "It reduces total compute." It increases it. The draft model runs, and rejected tokens are wasted work for the target. It saves time by using idle hardware, not by doing less arithmetic.
  • "It always helps." Gains shrink at large batch sizes, where the hardware is already busy and extra verification work is no longer free. Servers under heavy load may disable or limit speculation.
  • "Any small model will do." The draft must use the same vocabulary and agree with the target often. A poorly matched draft can make generation slower than plain decoding.
  • Memory and complexity. A separate draft model needs its own memory and KV cache, and tree-based schemes add engineering complexity to batching and scheduling.

Where it is going

Research is moving the draft closer to the target. Some models are now trained with extra heads that predict several future tokens, which can later serve as built-in drafters. Tree-based verification explores several guesses at once, and adaptive schemes change the draft length on the fly based on how confident the draft is. Speculation also combines with other inference techniques such as quantization, better attention kernels and continuous batching. As reasoning models generate ever longer outputs, cutting per-token latency without changing results has become one of the most valuable optimizations in serving.

Frequently asked questions

What is speculative decoding in simple terms?

A small, fast model guesses the next few words and the large model checks all the guesses at once. Correct guesses are kept, so the large model produces several tokens per step instead of one. A special acceptance rule ensures the result is the same as the large model would produce on its own.

Does speculative decoding reduce output quality?

No, not in its standard form. Leviathan et al. and Chen et al. proved that the modified rejection-sampling rule preserves the target model's output distribution exactly, up to floating-point rounding. Some approximate variants relax this to gain speed.

How much faster is speculative decoding?

The original papers reported about 2–3× faster generation, for example 2–2.5× on Chinchilla 70B. Later methods reported up to about 3.5× (EAGLE, on LLaMA2-Chat 70B) and 3.6× (Medusa-2). Actual gains depend on the task, the draft model, the hardware and the batch size.

What makes a good draft model?

It must share the target model's tokenizer, run much faster than the target, and agree with it as often as possible. Smaller models from the same family, or drafts distilled from the target, usually work best.

Why does speculative decoding help less at large batch sizes?

With many requests in a batch, the GPU's compute is already busy, so verifying extra draft tokens is no longer nearly free. The time saved per accepted token shrinks, and rejected tokens become a real cost.

References

  1. Stern, Shazeer and Uszkoreit (2018). Blockwise Parallel Decoding for Deep Autoregressive Models
  2. Leviathan, Kalman and Matias (2022). Fast Inference from Transformers via Speculative Decoding
  3. Chen et al. (2023). Accelerating Large Language Model Decoding with Speculative Sampling
  4. Cai et al. (2024). Medusa: Simple LLM Inference Acceleration Framework with Multiple Decoding Heads
  5. Li et al. (2024). EAGLE: Speculative Sampling Requires Rethinking Feature Uncertainty

More in this section

Start free: 50 Cosvexa-1 questions a day

Every major model in one workspace; on the Free plan Cosvexa-1 answers 50 questions a day. No card needed to start.