Sub topic 18
Speculative decoding for lower latency
This chapter assumes you understand autoregressive decoding, the KV cache, and basic vLLM benchmarking. Speculative decoding is an inference method that can reduce time per generated token when a smaller draft model can predict tokens that a larger target model will accept.
How speculative decoding works
A target model normally generates one token at a time. Each step runs the large model, updates its KV cache, and repeats.
Speculative decoding adds a draft model:
- The draft model quickly proposes several next tokens.
- The target model evaluates those proposals in one forward pass.
- The target accepts the matching prefix and rejects the first incorrect proposal.
- Generation continues from the rejection point.
The target model remains responsible for the final output. The draft model only proposes candidates, so speculative decoding does not intentionally reduce answer quality.
The useful speedup depends on the acceptance rate. If the draft model often predicts the target model’s choices, the target produces multiple tokens per expensive step. If proposals are usually rejected, the extra draft-model work and memory can make serving slower.
Enabling it in vLLM
Use a smaller model from the same model family when possible. Similar tokenizers and training behavior usually improve acceptance. The exact option names depend on the installed vLLM version, so check vllm serve --help before deployment.
vllm serve Qwen/Qwen2.5-32B-Instruct \
--speculative-model Qwen/Qwen2.5-1.5B-Instruct \
--num-speculative-tokens 5 \
--max-model-len 8192 \
--gpu-memory-utilization 0.85Here, --num-speculative-tokens 5 asks the draft model to propose up to five tokens per step. Start with a small value and benchmark it. A larger value increases possible gains but also increases verification work and draft-model memory use.
| Workload condition | Likely result |
|---|---|
| Long outputs and high draft acceptance | Lower decode latency |
| Short outputs dominated by prompt processing | Little benefit |
| Low draft acceptance or GPU memory pressure | No benefit or slower serving |
Choosing when to use it
Speculative decoding mainly targets the decode phase. It does not remove the cost of prefill, which processes the prompt. It also differs from continuous batching: batching improves GPU utilization across requests, while speculation tries to produce more tokens for one request per target-model pass.
Measure both time to first token and time per output token. Use the same prompts, output limits, concurrency, and sampling settings for the baseline and speculative configurations. Watch GPU memory and request throughput as well as latency.
Exercise
Why can a draft model improve latency without changing which model determines the final tokens?
Show answer
The draft model only proposes tokens. The target model verifies those proposals and emits the final accepted tokens or corrections.