Speculative Decoding with Draft Models: Principles, Training, and Deployment
Learn how draft models accelerate large language model inference through speculative decoding. This article covers draft-and-verify generation, model design and distribution alignment, training workflows, KV cache management, deployment metrics, and practical evaluation considerations for sparse-attention models and long-context workloads.
1. Why Inference Acceleration Matters
As large language models grow, autoregressive decoding—generating one token at a time—becomes a major source of latency. Each new token requires a forward pass through the model. Even with extensive optimization, generation speed can remain unsatisfactory, especially with long contexts.
For online services, time to first token and subsequent generation speed directly affect the user experience. For offline batch workloads, insufficient throughput increases compute cost per token.
Accelerating generation without changing the target model’s weights or output distribution is therefore an important engineering goal. One widely used approach is draft-model acceleration, commonly known as speculative decoding.
2. How Speculative Decoding Works
2.1 The Core Idea: Draft, Then Verify
Speculative decoding follows a draft-and-verify loop:
- A small, fast draft model generates several candidate tokens from the current context.
- The target model processes those candidates in a single parallel verification pass.
- The verification procedure checks candidates against the target model’s distribution, accepting a valid prefix and stopping at the first rejection.
- A correction token is produced at that position, and the next drafting round begins.
Modern inference systems can process multiple token positions more efficiently than they can execute the same number of sequential decoding steps. As a result, verifying several candidates together can cost less than generating them individually with the target model.
If the draft model’s acceptance rate is high enough, this can substantially improve throughput. With the appropriate verification and correction procedure, speculative decoding preserves the target model’s output distribution.
This distinction matters: preserving the output distribution does not necessarily mean producing an identical token sequence in every stochastic run.
2.2 Why It Can Benefit Sparse-Attention Models
Sparse-attention models, including DSA-style models, substantially reduce attention computation for long contexts. However, autoregressive decoding still has sequential dependencies, which can leave compute resources underutilized.
Speculative decoding combines several decoding steps into one parallel verification pass, addressing this bottleneck. It can therefore be particularly useful for long-context workloads, although the actual benefit depends on acceptance rates and execution overhead.
Draft models designed for sparse-attention targets and long contexts act as acceleration components alongside the main model. They neither replace the target model nor modify its weights.
3. Draft Model Design and Engineering Requirements
3.1 A Non-Invasive Acceleration Component
An effective draft-model system should meet three requirements:
- Leave the target model unchanged: No weight modifications, retraining, or fine-tuning of the target model should be required.
- Preserve output behavior: Verification should preserve the target model’s output distribution under the same sampling configuration. For deterministic decoding, output sequences can be compared directly.
- Support optional activation: The acceleration component should be easy to enable or disable for fallback and A/B testing.
This sidecar-style design allows teams to iterate on inference acceleration independently of the quality assurance process for the deployed target model.
3.2 Choosing a Draft Model Architecture
Common options include:
- A smaller model with a similar architecture: It uses the same tokenizer and a related architecture, but fewer layers or smaller hidden dimensions, making output alignment easier.
- A shallower or reduced-dimension variant: It may reuse selected target-model layers for initialization, followed by distillation.
- An independent lightweight model: It offers greater architectural flexibility but generally requires more alignment work.
The main trade-off is between drafting speed and acceptance rate. A weak draft model may generate quickly but have too many rejected tokens. A stronger draft model may improve acceptance while taking enough time to erase the verification gains.
As a rough design heuristic, draft models ranging from a few times smaller to more than ten times smaller than the target model can offer a useful balance. The appropriate size must still be validated for the actual workload.
3.3 Aligning the Interface with the Target Model
For direct token-level verification, the draft and target models should use the same vocabulary and tokenizer.
The draft model should also account for the target model’s generation settings, such as temperature and top-p, so that its drafting distribution remains close to the distribution used during verification.
If the target model uses sparse attention or specialized positional encoding, the draft model’s context handling should remain compatible during both training and inference.
4. Training Data and Workflow
Making draft-model training code available allows developers to adapt the acceleration component to their own models and domains. A typical workflow includes the following stages.
4.1 Data Sources
Common sources include:
- Target-generated responses: Run the target model on a large collection of instruction or conversation prompts, then use its responses as supervision for the draft model.
- High-quality public corpora: Select general-purpose and domain-specific data close to the target model’s training distribution.
- Long-context examples: Construct tasks such as long-document question answering and long-range reasoning to cover the context lengths expected in deployment.
4.2 Training Objectives
The basic objective is next-token prediction. However, the goal is not simply to fit a text corpus: it is to align the draft model with the target model’s behavior.
A response-based distillation loop can be expressed as:
# Pseudocode: distillation training using target-model responsesfor batch in dataloader:prompt, target_response = batch["prompt"], batch["response"]# Draft-model forward passlogits = draft_model(prompt, target_response[:, :-1])loss = cross_entropy(logits, target_response[:, 1:])loss.backward()optimizer.step()
When full target-model logits are available at each position, a KL-divergence distillation loss can provide closer distribution alignment:
soft_loss = kl_div(log_softmax(draft_logits / T),softmax(target_logits / T),) * (T * T)
4.3 Long-Context Training Considerations
- Increase context length in stages, starting with shorter sequences to manage memory consumption and training stability.
- Use compatible attention optimizations, such as Ring Attention or FlashAttention, to reduce long-sequence training overhead.
- Reserve very long examples for validation and track how acceptance rates change across context-length ranges.
5. Inference Integration and Deployment
5.1 Integration Pattern
A common deployment pattern places the draft model and target model in the same inference service process, with coordinated KV cache management.
The following pseudocode illustrates the control flow:
while not finished:draft_tokens = draft_model.generate(current_tokens, num_draft=K)outputs = target_model.verify(current_tokens, draft_tokens)accepted = outputs.accepted_lengthcurrent_tokens = outputs.tokens[: accepted + 1]finished = outputs.finished
This is a conceptual interface rather than a framework-specific API.
5.2 Key Engineering Parameters
- Draft length,
K: A large value can waste computation on rejected candidates, while a small value limits parallel verification. It can be adjusted dynamically using recent acceptance rates. - KV cache management: The draft and target models maintain their own caches. When verification rejects a candidate, speculative cache entries must be rolled back to the accepted prefix.
- Batching compatibility: In continuous batching environments, requests may be in different drafting and verification phases. Scheduling must coordinate these phases to avoid idle execution gaps.
5.3 Production Metrics
Monitor the following after deployment:
- Average accepted length: The number of draft tokens accepted per verification pass.
- End-to-end tokens per second and time to first token: These capture throughput and user-visible latency.
- Output consistency checks: Compare generation with acceleration enabled and disabled, using checks appropriate to deterministic or stochastic decoding.
- Memory usage and scheduling overhead: These reveal whether the acceleration component introduces a new resource bottleneck.
6. Evaluation and Common Pitfalls
Evaluate correctness and performance separately.
For direct sequence comparisons, use deterministic decoding, such as greedy decoding, and compare results with speculative decoding enabled and disabled. Fixed random seeds can improve reproducibility, but a fixed temperature alone does not make sampling deterministic, and identical seeds do not necessarily produce identical sequences across different stochastic decoding procedures.
Under production sampling settings, evaluate preservation of the target distribution alongside throughput and latency gains.
A simplified speedup estimate is:
Speedup ≈ (1 + average accepted length)/ (1 + draft overhead coefficient × draft length)
This is a rough model rather than a performance guarantee. Its usefulness depends on how well the overhead coefficient represents the deployed system.
Common pitfalls include:
- Testing only short contexts: Acceptance rates may deteriorate at longer context lengths, changing the overall benefit.
- Evaluating the draft model only as a standalone model: Its independent response quality is less important than its alignment with the target distribution.
- Making the draft model too large: Higher acceptance rates may not compensate for slower drafting, turning the draft stage into a new bottleneck.
7. Conclusion
Draft-model acceleration uses speculative decoding to speed up autoregressive inference without modifying the target model’s weights. With a correct verification procedure, it preserves the target model’s output distribution and can be particularly valuable for sparse-attention models and long-context workloads.
Successful production deployment depends on the full draft–verify–rollback loop: training data construction, distribution alignment, inference integration, KV cache management, and acceptance-rate monitoring.
Where draft-model weights and training code are openly available, they provide a practical starting point for adapting and optimizing the approach for a team’s own target model and workload.
