mlgenerate.comVisual Generative ML
All Models/text/Speculative Decoding

Speculative Decoding

Autoregressive2023 · Google Research / DeepMind

Draft-then-verify parallel acceleration breaking the memory-bandwidth decode bottleneck

Execution Paradigm:Speculative Draft-and-Verify Rejection Sampling Loop
2x–3x Wall-Clock Speedup (Zero Quality Loss)

Intuition & Key Idea

ELI5 Guide

Why this model was invented and how it transforms generation

The 30-Second Core Idea

"A tiny, super-fast draft model rapidly guesses 4 to 8 words ahead, and the giant flagship model verifies all of them in a single parallel check."

Real-World Metaphor

A fast junior assistant drafting an email quickly, followed by a senior executive who reads the whole paragraph at once and stamps approval in 2 seconds.

Key Superpowers & Values
Speedup MultiplierFree Speed
2.0x – 3.2x Faster

Multiplies throughput on identical hardware with zero quality loss.

Mathematical ParityZero Degradation
100% Identical

Modified rejection sampling preserves exact target probability distribution.

Draft AcceptanceHigh Hit Rate
70% – 85% Accepted

Most natural language tokens are easily predicted by the draft model.

Cost EfficiencyHigh ROI
Up to 60% Savings

Drastically reduces GPU server time per completed user request.

1. Fast Draft Model Generates γ Speculative Tokens

The small draft model autoregressively generates γ (e.g. 4–5) candidate tokens x̃_1..x̃_γ using its lightweight weights and compact KV-cache.

Key Insight:

Draft model runs quickly because loading its 1.1B weights takes a fraction of the memory bandwidth of the 8B target.

Interactive Stage (INFERENCE)Draft model proposes γ candidate tokens in lightweight rapid serial steps.
Phase 1: Prompt PrefillProcessing prompt tokens in one parallel batch to initialize KV cache
Step 1 of 3
The Autoregressive Loop Explained Simply
1
Read KV Cache
Fetch previous tokens
→
2
Load 16GB Weights
HBM memory bottleneck
→
3
Emit 1 Token
Sample from logits
↺
Repeat for next word
Active Token Stream & Memory AllocationTotal Tokens: 3
Prompt"The"K, V cached
Prompt"cat"K, V cached
Prompt"sat"K, V cached
GPU High Bandwidth Memory (HBM) — KV Cache Pool
Avoids O(T²) recomputation · Memory Bandwidth Bound
Slot 0
"The"
[K_cache, V_cache]
Slot 1
"cat"
[K_cache, V_cache]
Slot 2
"sat"
[K_cache, V_cache]
Slot 3
"on"
Unallocated
Slot 4
"the"
Unallocated
Slot 5
"mat"
Unallocated
⚠️ Memory Bandwidth Bottleneck:During autoregressive decoding, the GPU must stream tens of gigabytes of weights and cached KV vectors from VRAM to compute the next token distribution for a single token query. Generating 1,000 tokens requires 1,000 serial rounds of memory reads.
Hardware & Weights InspectorStep 1: Fast Draft Model Generates γ Speculative Tokens
Execution Bottleneck
Memory-Bandwidth Bound
Draft memory bandwidth ceiling
Arithmetic Intensity
1.2 FLOPs/Byte (Lightweight Draft GEMV)
Ratio of math operations (FLOPs) to memory traffic (Bytes)
Dominant GPU Kernel
FlashDecoding Draft GEMV
Optimized CUDA / Triton kernel launched

GPU Memory Hierarchy & HBM Traffic for this Step

HBM ↔ SRAM on-chip

Reads small 2.2 GB draft weights from VRAM

Hardware Insight: Small model size allows draft generation in ~5ms total for all γ tokens.

Active Tensor Dimensions & Memory Shapes

prompt[B, P]
Current prefix context
draft_tokens[B, \gamma]
Speculatively proposed token candidate IDs
speculative_decode_engine.py
1
def speculative_generate(prompt, target_model, draft_model, gamma=5):
2
while not done:
3
# 1. Draft model proposes gamma speculative tokens
4
draft_tokens, draft_probs = draft_model.generate_gamma(prompt, gamma)
5
# 2. Target model verifies all gamma tokens in ONE forward pass
6
target_probs = target_model.forward_multi(prompt, draft_tokens)
7
# 3. Modified rejection sampling guarantees exact distribution
8
for i in range(gamma):
9
r = torch.rand(1)
10
if r < min(1, target_probs[i] / draft_probs[i]):
11
prompt.append(draft_tokens[i]) # Accepted!
12
else:
13
bonus = sample(clamp_min(target_probs[i] - draft_probs[i], 0))
14
prompt.append(bonus); break # Rollback & stop
Click code line to jump to corresponding stepPyTorch Reference
Why This Architecture Matters

Eliminates the GPU memory-bandwidth bottleneck during inference without retraining or quantizing the target LLM. Widely deployed in production inference engines like vLLM, TensorRT-LLM, and TGI.

Runtime Complexity & Bottlenecks

Training Objective:KL Divergence Distillation: D_KL(P_target || P_draft) or pre-trained draft alignment

Inference Bottleneck:O(T / α) target passes where α is average accepted token length (2–3x faster)