Skip to content
MAMasterAI Now
Fundamentals15 min read

Speculative Decoding Explained: How LLMs Generate Tokens Faster

Discover how speculative decoding speeds up LLM inference using draft models, parallel verification, and efficient token generation without changing output quality.

By MasterAI Now Team

Speculative Decoding Explained: How LLMs Generate Tokens Faster

Large language models generate text one token at a time. Even when a model can process thousands of tokens in a single prompt, producing the response is usually an autoregressive process.

The model predicts the next token, adds it to the sequence, and then predicts another token using the updated context.

This approach works well, but it creates a performance bottleneck.

A large language model may contain billions of parameters. Running a forward pass to generate every individual token can be expensive, especially when the GPU spends a significant amount of time moving model weights rather than performing useful calculations.

This is where speculative decoding becomes interesting.

Instead of asking a large model to generate every token individually, speculative decoding allows a smaller model to propose several possible future tokens. The larger model then checks those proposals in parallel and accepts the tokens that meet its verification criteria.

The result can be faster generation without changing the target model's output distribution when the algorithm is implemented with exact sampling correction.

This technique is particularly useful for inference systems where memory bandwidth, model execution latency, and token generation speed are important.

Why Do Large Language Models Generate Tokens Slowly?

Most decoder-only Transformer models use autoregressive generation.

Suppose a model receives the following prompt:

Artificial intelligence is changing

It predicts the next token:

the

The updated sequence becomes:

Artificial intelligence is changing the

The model then predicts another token:

way

The process continues until the response is complete.

The important detail is that each new token depends on the previous sequence.

In a conventional generation loop, the next prediction cannot be finalized until the preceding token has been selected.

This creates a sequential dependency.

Even when a GPU can process large batches of operations efficiently, autoregressive generation often requires repeated model execution for individual output tokens.

For large models, this can be expensive.

The problem is especially noticeable when:

  • The model has billions of parameters.
  • The output contains hundreds or thousands of tokens.
  • The GPU is limited by memory bandwidth.
  • Requests require low latency.
  • Many users generate responses simultaneously.

A smaller model can often produce predictions much faster, although it may not provide the same quality as the larger model.

Speculative decoding combines these characteristics.

What Is Speculative Decoding?

Speculative decoding is an inference optimization that uses a smaller draft model to predict several future tokens before asking a larger target model to verify them.

The draft model proposes a sequence of tokens.

The target model evaluates the proposed sequence and determines which tokens can be accepted.

If the draft model makes accurate predictions, multiple tokens can be accepted during a single verification step.

Instead of requiring a separate target-model generation step for every output token, the system may produce several tokens from one target-model pass.

There are two main components:

Draft model: A smaller, faster model that proposes candidate tokens.

Target model: The larger model responsible for verifying the proposed tokens and preserving the desired output distribution.

A simplified workflow looks like this:

User Prompt
    |
    v
Draft Model
    |
    v
Propose Several Tokens
    |
    v
Target Model
    |
    v
Verify Candidates
    |
    +------ Accepted tokens
    |
    +------ Rejected token
                |
                v
          Corrective Sampling
                |
                v
          Continue Generation

The draft model does not need to be as powerful as the target model.

Its job is to predict tokens that the larger model is likely to generate.

How Does Speculative Decoding Work Step by Step?

Let's examine a simplified example.

Imagine a target model generating the following sentence:

Machine learning models can recognize patterns in data.

After processing the initial prompt, the draft model proposes:

models can recognize patterns

The target model then evaluates the candidate tokens using its own probability distributions.

Conceptually, the process works as follows.

Step 1: The draft model proposes tokens

The smaller model generates several candidate tokens based on the existing context.

For example:

models can recognize patterns

These candidates are speculative. They are not automatically accepted.

Step 2: The target model verifies the candidates

The larger model processes the proposed sequence.

Because Transformer models can calculate predictions for multiple positions in a sequence during one forward pass, the target model can evaluate several candidate positions together.

This is different from ordinary autoregressive generation, where each accepted output token normally requires another generation iteration.

Step 3: Accept valid candidates

The verification algorithm determines whether each proposed token can be accepted.

If the draft model's predictions are compatible with the target model's probability distribution, the token may be accepted.

The accepted tokens become part of the output sequence.

Step 4: Handle rejected candidates

If a candidate is rejected, the system uses a correction procedure to sample from the appropriate remaining probability distribution.

The generation process then continues from the corrected sequence.

This is an important detail.

Speculative decoding is not simply a system that accepts a draft token whenever the larger model agrees with its most likely prediction.

Exact speculative sampling uses probability-based acceptance and rejection rules to preserve the target model's distribution.

How Does Parallel Verification Work?

One of the most interesting aspects of speculative decoding is that it takes advantage of how Transformers process sequences.

A decoder-only Transformer can evaluate multiple positions in a sequence during a single forward pass using causal attention.

Causal attention ensures that a token can only attend to earlier positions and itself, not future positions.

For example:

Token 1: Machine
Token 2: learning
Token 3: models
Token 4: recognize

When evaluating this sequence, the model can calculate the relevant next-token distributions for multiple positions using parallel tensor operations.

The attention mask prevents future tokens from influencing earlier predictions.

This means the target model can verify a proposed block of tokens without generating each one through a separate autoregressive loop.

However, parallel verification does not mean that the model predicts an entire sentence independently.

Each candidate position is evaluated using the appropriate preceding context.

This distinction is essential to understanding why speculative decoding works.

How Does the Acceptance and Rejection Algorithm Work?

Speculative decoding can preserve the output distribution of the target model when the appropriate sampling correction is used.

Let's introduce two probability distributions:

  • (p(x)): The target model's probability distribution.
  • (q(x)): The draft model's probability distribution.

Suppose the draft model proposes a token (x).

The probability of accepting that token is:

[ P(\text{accept }x)=\min\left(1,\frac{p(x)}{q(x)}\right) ]

This equation provides an important property.

If the draft model assigns a high probability to a token relative to the target model, the token is more likely to be accepted.

If the draft model assigns a much higher probability than the target model, the acceptance probability decreases.

When a token is rejected, a correction distribution can be constructed:

[ r(x)=\frac{\max(0,p(x)-q(x))}{Z} ]

Where (Z) is the normalization constant that makes the probabilities sum to one.

The correction distribution ensures that rejected proposals do not introduce an unintended bias into the final output.

The exact implementation also depends on the sampling procedure and how candidate distributions are calculated.

For developers, the important takeaway is that speculative decoding is designed to preserve the target model's sampling behavior, not merely approximate its answers.

Why Does Speculative Decoding Improve Inference Speed?

The main benefit comes from reducing the number of expensive target-model generation iterations.

Consider a simplified example.

Without speculative decoding:

Target model:
Generate token 1
Generate token 2
Generate token 3
Generate token 4
Generate token 5

With speculative decoding:

Draft model:
Propose tokens 1–5

Target model:
Verify multiple candidates

Output:
Accept the valid sequence

If several candidates are accepted, the system can generate multiple output tokens during one target-model verification step.

This can be especially beneficial when the target model is limited by memory bandwidth.

Loading or accessing the large model's weights repeatedly can be expensive. Verifying several tokens together can make better use of the computation performed during a target-model pass.

However, speed improvements depend on several factors:

  • Draft model speed.
  • Draft model accuracy.
  • Number of proposed tokens.
  • Target model architecture.
  • GPU memory bandwidth.
  • Batch size.
  • Verification overhead.
  • Output length.

Speculative decoding does not guarantee faster generation in every environment.

If the draft model frequently proposes incorrect tokens, the additional verification and correction work may reduce or eliminate the performance benefit.

What Is the Role of the Draft Model?

The draft model determines how effectively speculative decoding can work.

A good draft model should be significantly cheaper to execute than the target model while still producing useful candidate tokens.

For example, an inference system might use a large target model and a smaller model trained or selected to predict similar continuations.

The draft model does not necessarily need to have the same architecture as the target model.

However, its tokenization and output vocabulary must be compatible with the verification method being used.

There are several approaches to selecting a draft model.

Smaller models from the same family

A smaller model from the same model family may produce predictions that are reasonably aligned with the larger model.

This can make it a practical starting point.

Specialized draft models

Some systems use draft models specifically optimized to predict the outputs of a larger target model.

These can provide better acceptance rates than an unrelated small model.

Self-speculative decoding

In some approaches, the target model itself is used to generate cheaper draft predictions.

For example, early-exit strategies can use intermediate Transformer layers to produce candidate tokens before the full model verifies them.

This avoids maintaining a completely separate draft model, although implementation details and quality trade-offs differ.

Speculative Decoding vs Traditional Autoregressive Generation

The two approaches solve the same generation problem using different execution strategies.

FeatureAutoregressive generationSpeculative decoding
Token proposalsTarget modelSmaller draft model
VerificationNot separately requiredTarget model verifies candidates
Generation processSequentialDrafting plus parallel verification
Model requirementsOne modelUsually draft and target models
Extra overheadLowerDrafting and verification overhead
Potential speedBaselineFaster when speculation is effective
Output distributionTarget modelCan preserve target distribution

Traditional autoregressive generation remains simpler and may be more efficient for workloads where the target model is already generating tokens quickly.

Speculative decoding is particularly interesting when the target model has expensive individual generation steps and the draft model can produce useful proposals cheaply.

What Is the Difference Between Speculative Decoding and Medusa?

Medusa is another approach to improving LLM generation speed.

Instead of relying exclusively on a separate smaller draft model, Medusa adds multiple prediction heads to a language model.

These heads predict possible future tokens at different positions.

The system then verifies candidate continuations using the model's verification process.

This allows multiple candidate paths to be explored during inference.

The approaches have different architectural requirements:

Speculative decoding: Usually uses a separate draft model to propose tokens.

Medusa: Uses additional prediction heads associated with the target model to generate candidate continuations.

Both techniques aim to reduce the sequential bottleneck of autoregressive generation.

Neither approach guarantees the same performance across all models and workloads.

What Is the Difference Between Speculative Decoding and Lookahead Decoding?

Lookahead decoding is another technique that attempts to reduce the number of sequential generation steps.

Rather than relying on a conventional separate draft model, lookahead methods use parallel n-gram generation and verification strategies.

The system explores possible token continuations and verifies them against the target model.

The distinction matters because not every speculative inference technique requires the same model architecture or auxiliary components.

For inference engineers, these methods represent different ways to exploit parallel computation while maintaining the correctness requirements of language model generation.

When Should Developers Use Speculative Decoding?

Speculative decoding is not automatically the best choice for every deployment.

It is worth evaluating when the target model is relatively expensive to execute and the draft model can generate useful candidates at low cost.

Some suitable scenarios include:

Local LLM inference

Users running larger models on constrained hardware may benefit when the draft model can efficiently predict the target model's output.

Interactive AI applications

Applications such as coding assistants and conversational agents can benefit from reduced generation latency.

High-throughput inference servers

Systems that process many requests can evaluate speculative decoding as part of their throughput optimization strategy.

Long-form generation

Long responses create more opportunities for accepted speculative tokens to reduce repeated target-model execution.

However, the actual benefit depends on the workload and implementation.

For short responses, the overhead of maintaining and running a draft model may outweigh the benefits.

How to Benchmark Speculative Decoding

If you are developing an inference system, you should evaluate speculative decoding against a standard autoregressive baseline.

Use the same target model, prompt set, hardware, and generation configuration.

Measure the following metrics.

1. Tokens per second

Measure how many output tokens the system generates per second.

This is one of the most useful metrics for comparing generation performance.

2. Time to first token

The draft model introduces additional work before or during generation.

Measure whether this affects the time users wait before seeing the first output token.

3. Average accepted tokens

Measure how many speculative tokens are accepted during each verification cycle.

A higher acceptance rate can indicate that the draft model is predicting useful continuations.

4. Drafting overhead

Measure how much time is spent generating speculative candidates.

A draft model that is too expensive may reduce the benefits of speculation.

5. GPU memory usage

Running an additional draft model can increase memory requirements.

Compare total memory consumption rather than looking only at target-model execution.

6. Output correctness

For exact speculative sampling, verify that the implementation preserves the intended target-model distribution.

For practical benchmarking, compare generation settings, output distributions, and representative task performance.

A useful experiment compares:

ExperimentConfiguration
BaselineTarget model only
Test ATarget + small draft model
Test BTarget + optimized draft model
Test CTarget + alternative speculation method

Do not assume that the configuration with the highest acceptance rate will always deliver the best throughput.

The speed of drafting and verification matters just as much.

Common Mistakes When Implementing Speculative Decoding

Assuming every accepted token is free

Draft tokens still require computation. The target model must also verify them.

The technique reduces expensive sequential target-model generation work; it does not eliminate computation.

Using an unrelated draft model

A draft model that predicts very different continuations may have a low acceptance rate.

The relationship between draft and target models is important.

Ignoring GPU memory overhead

A separate draft model requires additional memory for its weights and execution.

On a memory-constrained GPU, this may create a new bottleneck.

Confusing speed with model quality

Speculative decoding is an inference optimization, not a method for making a smaller model as capable as a larger one.

The target model remains responsible for the final output distribution.

Testing only short prompts

Speculative decoding performance can change depending on prompt length, output length, and batch size.

A realistic benchmark should include different request types.

Frequently Asked Questions

What is speculative decoding in LLMs?

Speculative decoding is an inference technique that uses a smaller draft model to propose multiple tokens and a larger target model to verify them. It can reduce sequential generation steps and improve inference speed.

Does speculative decoding change the output of an LLM?

When implemented with exact speculative sampling and appropriate correction, it preserves the target model's output distribution. Individual sampled outputs may still differ between runs because language model generation is probabilistic.

Does speculative decoding require two models?

Conventional speculative decoding typically uses a draft model and a target model. However, alternative approaches such as self-speculative decoding can use parts of the target model to produce candidate tokens.

Is speculative decoding always faster?

No. Performance depends on draft model quality, acceptance rate, hardware, batch size, and verification overhead. Some workloads may see little improvement or even become slower.

What is the acceptance rate in speculative decoding?

The acceptance rate describes how frequently proposed draft tokens pass the target model's verification procedure. It is an important metric for understanding how effectively the draft model predicts useful continuations.

Can speculative decoding work with local LLMs?

Yes. It can be used with supported local inference engines and model configurations. Hardware compatibility, model pairing, and implementation support should be checked before deployment.

Does speculative decoding reduce GPU memory usage?

Not necessarily. A separate draft model introduces additional model weights and runtime overhead. Its main purpose is to improve generation efficiency, not directly reduce memory consumption.

What is the difference between speculative decoding and Medusa?

Conventional speculative decoding generally uses a separate draft model. Medusa adds multiple prediction heads to a target model to generate candidate future tokens for verification.

Final Thoughts

Speculative decoding addresses one of the fundamental performance limitations of autoregressive language model generation: the need to repeatedly execute a large model to produce individual tokens.

By allowing a smaller model to propose several tokens and using the target model to verify them, inference systems can reduce expensive sequential generation work.

The technique is especially interesting for developers optimizing local LLMs, interactive applications, and production inference servers.

However, the benefits depend on more than the number of proposed tokens. Draft model quality, GPU memory, verification overhead, and workload characteristics all influence performance.

The important idea is simple: instead of making a large model predict every token individually, let a cheaper process propose several possibilities and use the large model to verify them efficiently.

That is the foundation of speculative decoding.