Speculative Decoding

A small model guesses, a big model checks, and answers arrive two to three times faster.

🔴 advanced5 min readinference
Speculative decoding makes a big model answer faster without changing what it says. A small, fast model guesses the next few words. The big model then checks all those guesses at once, in a single pass, keeping every guess that matches what it would have written and correcting the first one that does not. Checking several words at once is much cheaper for the big model than writing them one by one. You typically get two to three times the speed, with exactly the same output.

The Speculative Execution Paradigm

Step 1: Small Draft Model (1B) generates γ = 4 draft tokens rapidly:
        "The" ──► "capital" ──► "of" ──► "France"

Step 2: Large Target Model (70B) evaluates ALL 4 tokens IN 1 SINGLE PARALLEL FORWARD PASS:
        Matches: "The" (OK) ──► "capital" (OK) ──► "of" (OK) ──► "France" (OK)

Step 3: Target Model accepts all 4 tokens AND generates 5th token "is"!
        Result: 5 tokens produced in time of ~1 target forward pass! (5x speedup iteration)
                             Speculative Decoding Loop
┌───────────────────────────┐         γ Draft Tokens        ┌───────────────────────────┐
│ Draft Model (e.g. 1B)     │ ────────────────────────────► │ Target Model (e.g. 70B)   │
│ Fast, 1-by-1 generation   │                               │ 1 Parallel Verification   │
└───────────────────────────┘                               └─────────────┬─────────────┘
                                                                          │
                                                                          ▼
                                                             Accept n Tokens + 1 Extra
                                                             Rejection Sampling Check

Modified Rejection Sampling Scheme

To guarantee the output distribution matches the Target Model exactly:

For draft token xx with draft probability q(x)q(x) and target probability p(x)p(x):

Psample(x)=max⁡(0,p(x)−q(x)1−∑ymin⁡(p(y),q(y)))P_{\text{sample}}(x) = \max\left( 0, \frac{p(x) - q(x)}{1 - \sum_y \min(p(y), q(y))} \right)

This mathematical trick guarantees zero quality degradation—the output text distribution is 100% identical to running the 70B target model alone!

Performance Factors

Say this out loud

"Speculative Decoding accelerates LLM inference by 2x-3x with zero loss in output quality. A fast, small draft model predicts gamma candidate tokens speculatively. The large target model verifies all candidate tokens in a single parallel forward pass. Using modified rejection sampling P_accept = min(1, p/q), accepted tokens are kept, maintaining exact mathematical equivalence to sampling from the target LLM alone."

Follow-ups to expect

Check yourself

Question 1 of 3

Why is evaluating γ draft candidate tokens in a single target model forward pass faster than generating γ tokens autoregressively?

More in LLMs & GenAI

See all →
Pretraining → SFT → RLHF5 minFine-Tune vs RAG vs Prompt: Choosing5 minRetrieval-Augmented Generation5 min