Skip to content

AI Speculative Decoding: LLM Latency Optimization

CoreConceptAugust 1, 20263 min read

Large Language Model inference is notoriously memory-bandwidth bound. Generating tokens autoregressively requires loading all 70B parameter weights from GPU VRAM to compute units for every single token, resulting in high Time-To-First-Token (TTFT) and slow inter-token latency.

Speculative Decoding solves this memory bandwidth bottleneck. By pairing a small, fast Draft Model (e.g., Llama 3B) with a large Target Model (e.g., Llama 70B), speculative decoding achieves up to 2x–3x faster token generation without changing the mathematical output distribution of the target model.

LLM streaming lifecycle: visible tokens, tool events, gates, cancellation, and traces
LLM streaming lifecycle: visible tokens, tool events, gates, cancellation, and traces

Draft Model Generation & Target Model Verification

Instead of running the expensive Target Model one token at a time, Speculative Decoding operates in a two-stage loop:

1. Draft Phase: The small Draft Model quickly speculates $K$ candidate tokens (e.g., $K=5$) sequentially in low-latency RAM. 2. Verification Phase: The large Target Model processes all $K$ candidate tokens in a single parallel forward pass, accepting valid tokens and rejecting any divergence using modified rejection sampling.

Quick reference

  • Speculative Decoding produces mathematically identical token outputs to running the Target Model alone.
  • Parallel verification converts $K$ sequential memory reads into a single batched matrix operation.
  • Acceptance Rate: If the draft model aligns well with target predictions, generation speed increases by 2x–3x.
Conceptual Speculative Decoding Loop (Python)
1# Conceptual Speculative Decoding Loop inside LLM Serving Engine2def speculative_step(draft_model, target_model, prompt_tokens, K=5):3    # 1. Draft model generates K candidate tokens fast4    candidate_tokens = []5    curr_input = prompt_tokens6    for _ in range(K):7        next_token = draft_model.generate_next_token(curr_input)8        candidate_tokens.append(next_token)9        curr_input = torch.cat([curr_input, next_token])10 11    # 2. Target model evaluates ALL K tokens in ONE parallel forward pass12    target_logits = target_model.forward_parallel(prompt_tokens + candidate_tokens)13    14    # 3. Accept matching tokens, reject divergence, append 1 correction token15    accepted_tokens = verify_and_sample(candidate_tokens, target_logits)16    return accepted_tokens
Enabling Speculative Decoding in vLLM
1# Launch vLLM server with speculative draft model configuration2python3 -m vllm.entrypoints.openai.api_server \3  --model meta-llama/Meta-Llama-3-70B-Instruct \4  --speculative-model meta-llama/Meta-Llama-3-8B-Instruct \5  --num-speculative-tokens 5 \6  --gpu-memory-utilization 0.90

Remember this

Speculative decoding accelerates LLM generation speed by using a draft model to speculate tokens verified in parallel.

Draft Model Selection & Self-Speculative Architectures

For maximum speedup, the Draft Model must share the same vocabulary and tokenizer as the Target Model (e.g., Llama 8B drafting for Llama 70B).

Alternative architectures like Medusa or EAGLE eliminate separate draft models entirely by attaching lightweight prediction heads directly to the target model's top transformer layers.

Quick reference

  • Medusa: Adds multiple decoding heads to predict several future tokens simultaneously.
  • EAGLE: Predicts feature vectors at the top hidden state level for higher token acceptance rates.
  • Compare with vLLM vs Ollama vs TGI and Model Context Protocol.

Remember this

Choosing aligned draft models or Medusa heads maximizes token acceptance and cuts inference latency.

Inference Latency Optimization Decision Matrix

Selecting latency optimizations depends on your deployment batch sizes and GPU memory availability.

For related guides, see our articles on GPU vs CPU Inference and AI Gateway Routing.

Quick reference

  • Use Speculative Decoding for low-concurrency, interactive real-time tasks (chatbots, terminal agents) where single-stream latency matters.
  • Use High-Concurrency Continuous Batching when serving thousands of simultaneous requests where throughput > single-stream latency.
  • Combine Speculative Decoding with FP8/INT4 weight quantization for maximum speedup.

Remember this

Deploy Speculative Decoding to cut single-stream response times in half for interactive AI applications.

Key takeaway

Speculative decoding transforms LLM serving economics, unlocking 2x–3x faster generation speeds without sacrificing output quality.

Share:

Related Articles

In enterprise AI applications, system instructions, database schemas, codebases, and retrieval contexts are frequently r

Read

Deploying open-weights foundation models (such as DeepSeek-R1, Llama 3, and Qwen 2.5) requires choosing a high-performan

Read

With the release of OpenAI's reasoning model series (such as o3-mini), developers gain direct control over inference-tim

Read

Keep learning

Follow a structured path or browse all courses to go deeper.