Home Knowledge Base Speculative Decoding

Speculative Decoding

What is Speculative Decoding? Speculative decoding uses a smaller, faster "draft" model to generate candidate tokens, then verifies them in parallel with the larger "target" model. This can significantly reduce latency.

How It Works

Standard Autoregressive

Target Model: [token1] → [token2] → [token3] → [token4]
              (slow)     (slow)     (slow)     (slow)
Total: 4 sequential forward passes

Speculative Decoding

Draft Model: [t1, t2, t3, t4]  (fast, one pass)
                ↓
Target Model: Verify all 4 in one parallel pass
                ↓
Accept: [t1, t2, t3] ✓, Reject: [t4] ✗
                ↓
Resume from [t3] with new speculation

Key Components

Draft Model

Verification Target model runs single forward pass over all draft tokens:

Acceptance Rate

FactorImpact on Acceptance
Draft qualityHigher quality → more accepted
Task difficultyEasier tasks → more accepted
Draft sizeLarger draft → more accurate
Speculation lengthLonger → lower average acceptance

Typical acceptance rates: 70-90% for well-matched pairs.

Implementation in vLLM

python -m vllm.entrypoints.openai.api_server
    --model meta-llama/Llama-2-70b-chat-hf
    --speculative-model meta-llama/Llama-2-7b-chat-hf
    --num-speculative-tokens 5

Self-Speculative Decoding Use earlier layers of the same model as draft:

Performance Gains

SetupSpeedup
7B target + 68M draft2-3x
70B target + 7B draft2-4x
Self-speculative (13B)1.5-2x

Trade-offs

AspectConsideration
MemoryNeed to load draft model too
BatchingLess effective with large batches
Task dependencyWorks best for predictable outputs
Draft trainingMay need custom draft model

Speculative decoding is most beneficial for latency-sensitive, low-batch scenarios.

speculative decodingdraft model

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.