LLMs & GenAI

Speculative Decoding

Accelerating LLM inference by 2x–3x using a small draft model to generate candidate tokens verified in parallel by the target LLM.

🔴 advanced5 min readinference
Speculative Decoding (Leviathan et al., 2023; Chen et al., 2023) speeds up LLM inference without altering output token distributions. A fast, small Draft Model (e.g. 1B model) autoregressively predicts γ candidate tokens speculatively. The large Target Model (e.g. 70B model) then evaluates all γ candidate tokens in a single parallel forward pass using a modified rejection sampling scheme. Because parallel verification is compute-bound while sequential generation is memory-bound, Speculative Decoding achieves 2x-3x speedup with zero loss in generation quality.

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 $x$ with draft probability $q(x)$ and target probability $p(x)$:

$$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