Speculative Decoding for Faster LLM Inference: Semi-Autoregressive Drafting and Dynamic Verification
This article explains why autoregressive decoding is slow and underutilizes hardware, then breaks down speculative decoding as the mainstream fix. It covers two root bottlenecks—slow or low-quality drafts and invalid candidates crowding out verification resources—and two solutions: semi-autoregressive draft generation and dynamic verification with scheduling. A reusable engineering pipeline, practical tips, and common pitfalls are included for improving throughput and latency under real production load.
1. The Starting Point: Why LLMs Generate Tokens Slowly
Autoregressive decoding in large language models is inherently sequential: each step depends on the output of the previous step before it can predict the next token. This leads to two direct consequences.
First, latency grows roughly linearly with output length. The time to the first token may be acceptable, but when generating long text, waiting token by token quickly becomes a poor user experience.
Second, compute utilization is extremely low. Single-step decoding processes only one token, so it cannot keep the parallel compute units of modern accelerators busy. Memory bandwidth becomes the main bottleneck, and expensive compute sits largely idle.
The goal of inference optimization, therefore, is not to make a single forward pass faster, but to break the sequential dependency so that one forward pass produces multiple tokens.
2. The Mainstream Approach: The Speculative Decoding Paradigm
The widely adopted approach is speculative decoding: a lightweight draft model first “guesses” a sequence of candidate tokens, and the target large model verifies them all in a single parallel pass. Accepted tokens are adopted directly; at the first mismatch, the sequence is truncated and recomputed.
Its correctness comes from a key property: the verification step guarantees that the final output distribution matches decoding with the target model alone, so the speedup does not come at the cost of generation quality.
The core metric for measuring its benefit in practice is acceptance length (the average number of candidates accepted per verification). The higher the acceptance length, the more effective tokens are produced per unit of time.
3. Two Root-Cause Bottlenecks
Early drafting schemes had two structural problems, which have become the main focus of recent optimization.
3.1 The draft is too slow or too low-quality
- Sequential drafting: the draft model generates token by token, inheriting all the drawbacks of sequential decoding, so the time saved is eaten up by drafting overhead.
- Fully parallel drafting: all positions are predicted at once, which is very fast, but candidates lack contextual correlation, so later positions are more likely to “fabricate” tokens and get rejected in batches by the target model, causing acceptance length to plummet.
3.2 Verification resources are crowded out by invalid candidates
Regardless of draft quality, all candidates are sent to the target model for verification. This is fine when the system is idle; but under full load, candidates that are doomed to be discarded take up valuable batch slots and memory bandwidth, causing overall throughput to drop instead of rise. This is the root cause of “acceleration techniques slowing down the cluster at peak times.”
4. Solution One: Semi-Autoregressive Draft Generation
The idea is to strike a balance between “fully sequential” and “fully parallel”:
- Keep the main body parallel to preserve generation speed;
- Attach an extremely lightweight sequential module at the end to inject contextual dependency into the candidate sequence, so later candidates can “see” the results of earlier ones.
Illustrative pseudocode:
# Parallel backbone: get all candidates in one forward passhidden = draft_backbone(prefix_state) # parallel, speed firstlogits = draft_head(hidden) # independent prediction per position# Lightweight sequential correction: inject contextual dependencydraft = []for i in range(K):ctx = fuse(logits[i], draft) # generated candidates as contextdraft.append(sample(ctx))return draft # handed to the target model for one parallel verification
The result is that parallel throughput is preserved while the hit rate of later positions rises significantly, making acceptance length more stable.
5. Solution Two: Dynamic Verification and Scheduling
To address invalid candidates crowding out resources, viable strategies include:
- Confidence filtering: tail candidates whose draft-model probability falls below a threshold are discarded and do not enter the verification batch.
- Adaptive draft length: dynamically adjust the number of candidates based on real-time load, shortening drafts at peak times to prioritize valid requests.
- Continuous batching coordination: bring draft generation and verification into the same scheduler, avoiding reserving slots for invalid candidates.
- Admission control and fallback: automatically fall back to ordinary decoding under overload to keep tail latency under control.
6. The Full Engineering Pipeline: From Data to Production
A reusable speculative decoding framework typically has four layers of capability:
- Data preparation: sample training pairs from the target model’s real distribution, covering multiple domains and lengths, to avoid the draft model overfitting only on short text.
- Draft model implementation: support multiple structures such as semi-autoregressive, parallel, and tree-based candidates for easy comparison experiments.
- Training pipeline: focus on distillation/alignment to the target model’s distribution, with a loss function that constrains both first-position hit rate and later-position consistency.
- Evaluation scripts: uniformly measure acceptance length, time to first token, and end-to-end throughput, with regression testing under different concurrency levels.
7. Practical Tips and Common Pitfalls
- Establish a baseline first: without acceptance length and throughput baselines, no optimization can be attributed.
- The draft model should not be too large, or its own overhead will cancel out the gains.
- Acceptance length must be re-evaluated after sampling parameters (such as temperature) change.
- Always load-test full-load scenarios before launch and verify the fallback path.
- If deploying on a cloud container platform, use monitoring, alerting, and logging services to observe latency percentiles.
8. Conclusion
The value of speculative decoding is turning “sequential generation” into “parallel guessing plus one verification.” Semi-autoregressive drafting solves quality, and dynamic scheduling solves resources; only by combining both can throughput and latency be improved together under real production load. In inference practice on platforms such as Baidu AI Cloud, this kind of general optimization approach applies equally well to a wide range of large model serving scenarios.
