Speculative Decoding: Definition and Examples
Inference acceleration technique for large language models (LLMs) that uses a small fast model to generate candidate tokens, which are then verified in parallel by the main model, thereby reducing generation time without affecting response quality.
Full definition
Speculative Decoding is an optimization method designed to accelerate text generation by large language models. The principle is based on a simple observation: standard autoregressive generation, where each token is produced one by one, massively underutilizes GPU hardware because each step requires a full forward pass through the model. Speculative decoding bypasses this bottleneck by introducing a "draft then verify" mechanism.
Concretely, a smaller, faster auxiliary model (called the draft model) speculatively generates a sequence of candidate tokens. Then, the main model (the target model, larger and more accurate) verifies all these tokens in a single forward pass, in parallel. Accepted tokens are kept, and generation resumes from the first rejected token. This verification leverages the fact that evaluating multiple tokens simultaneously costs almost as much as evaluating a single token on a modern GPU.
The mathematical elegance of this approach lies in its guarantee: thanks to a carefully designed acceptance-rejection scheme, the final probability distribution is exactly identical to that of the target model alone. In other words, Speculative Decoding produces results that are strictly equivalent in quality, but 2 to 3 times faster. The gain depends on the acceptance rate, i.e., the ability of the small model to correctly predict what the large model would have generated.
This technique has become a standard in production systems of major AI providers. Variants exist, such as self-speculative decoding (where the model uses its own intermediate layers as a draft), Medusa (which adds parallel prediction heads), or tree-based speculative decoding, which explores multiple possible continuations simultaneously to maximize the acceptance rate.
Etymology
The term combines "speculative", borrowed from computer science where speculative execution refers to performing a calculation before knowing whether it will be necessary (as in modern processors), and "decoding", which refers to the process of generating text token by token in language models. The concept was formalized in 2022-2023 by teams from Google DeepMind (Leviathan et al.) and independently by Chen et al., drawing directly from branch prediction in CPUs.
Concrete examples
Deploying a chatbot in production requiring low latency
Configure the vLLM inference server with speculative decoding using a Llama 3 8B draft model to accelerate the main model Llama 3 70B, with a speculation length of 5 tokens.
Optimizing a code generation pipeline with an LLM
Enable speculative decoding to reduce the response time of my programming assistant. The source code has a restricted vocabulary, so the acceptance rate should be high.
Comparing inference acceleration strategies for an enterprise project
Compare the performance gains between INT8 quantization, speculative decoding, and continuous batching for our 70B parameter model deployed on 2 A100 GPUs.
Practical usage
In prompt engineering, Speculative Decoding does not directly affect prompt writing since it operates at the inference infrastructure level. However, understanding this technique allows better communication with infrastructure teams to optimize the latency of AI applications. When choosing an API provider or deploying an open-source model, checking whether speculative decoding is supported can cut response time by 2 to 3 times without any compromise on quality.
Related concepts
FAQ
Does Speculative Decoding degrade the quality of the model's responses?
What speed improvement can be expected with Speculative Decoding?
Is a specific auxiliary model required to use Speculative Decoding?
See also
How to use this prompt
- Copy the prompt with the button above.
- Paste it into ChatGPT, Claude or your favorite AI assistant.
- Replace the bracketed variables with your details, then refine the result.
About Prompt Guide
Prompt Guide is a free library of 2500+ ready-to-use prompts for ChatGPT, Claude and other AIs, with guides to learn prompting and tools to build and optimize your own prompts.
More definitions
Speech To Text: Definition and Examples
Speech To Text (STT), or voice recognition, is an artificial intelligence technology that converts human speech into written text, allowing
Stability AI: Definition and Examples
Stability AI is a company specializing in generative artificial intelligence, best known for developing Stable Diffusion, an open-source model for generating images from text descriptions.
Step Back Prompting: Definition and Examples
Prompt engineering technique that involves first asking a more general or abstract question before addressing the specific question, allowing the model to
Stop Sequence: Definition and Examples
A stop sequence is a predefined string of characters that tells the language model to stop generating text as soon as it produces it.
Streaming: Definition and Examples
Streaming is a technique for transmitting AI model responses in real time, token by token, rather than waiting for the complete generation before
Structured Output: Definition and Examples
A structured output is a response generated by an AI model in a predefined, machine-readable data format such as JSON, XML, or YAML.
Get new prompts every week
Join our newsletter.