LLM Inference Acceleration: Draft Models and Speculative Decoding Explained

    This article explains why large language model inference needs acceleration and how speculative decoding with a draft model works. It covers the two-phase draft-and-verify flow, why the approach speeds up decoding without changing the output distribution, how to design a well-aligned draft model, the main verification and acceptance strategies (greedy matching, sampling-based rejection, tree candidates), and the engineering concerns around KV cache management, dynamic speculation length, quantization and batching, and observability. Readers will also find guidance on expected gains and the scenarios where speculative decoding pays off.

    1. Background: Why LLM Inference Needs Acceleration

    As model parameter counts keep growing, the compute and memory cost of a single inference pass keeps climbing. Under autoregressive generation, the model predicts output one token at a time, and every token requires a full forward pass. This serial process creates two problems: the decode phase is bounded by memory bandwidth rather than compute, so GPU utilization stays low; and for long outputs, the per-token latency after the first token accumulates noticeably, hurting the interactive experience.

    The industry has developed several acceleration techniques, including operator optimization, quantization, KV cache management, and batch scheduling. This article focuses on the draft model plus speculative decoding approach. The core idea: a small, fast draft model first guesses several candidate tokens, then the main model verifies them all in a single parallel pass. Accepted candidates are adopted directly, turning serial per-token decoding into a guess-then-batch-verify parallel flow.

    2. How Speculative Decoding Works

    Two phases: draft and verify

    The typical flow is:

    1. Draft phase — the lightweight draft model uses the current context to generate K candidate tokens at very low per-step cost, forming a candidate sequence.
    2. Verify phase — the main model takes the context plus the candidate sequence as input and produces the output distributions for all K positions in one forward pass.
    3. Accept or roll back — candidate tokens are compared position by position against the main model’s distributions. A candidate that meets the acceptance condition is kept; otherwise the sequence is rolled back to the first mismatch, where the main model resamples.

    Illustrative pseudocode:

    1. while not finished:
    2. # 1. Draft model quickly generates K candidate tokens
    3. draft_tokens = draft_model.generate(context, num_tokens=K)
    4. # 2. Main model verifies all positions in one parallel pass
    5. target_logits = target_model.forward(context + draft_tokens)
    6. # 3. Check position by position, accept the longest valid prefix
    7. accepted = verify_and_accept(draft_tokens, target_logits)
    8. context += accepted # Rejected portion is filled in by sampling from the main model

    Why it is faster without quality loss

    Verifying K candidate positions in one forward pass of the main model costs little more than generating a single token, because the decode phase is bottlenecked by weight loading rather than per-token compute. As long as the draft model’s hit rate is high enough, each verification round accepts multiple tokens on average, which effectively produces more tokens per unit of time.

    Under strict verification (for example, rejection-sampling-based checks), the final output distribution is mathematically identical to independent sampling from the main model, so the speedup does not come at the cost of generation quality. Some engineering implementations relax the acceptance threshold, trading a slight distribution shift for higher throughput; this tradeoff should be weighed against how much determinism the workload requires.

    3. Designing the Draft Model

    Draft model quality directly determines the speedup ratio. In practice, a few points matter:

    Distribution alignment. The draft model should approximate the main model’s output distribution as closely as possible. A common approach is to share the vocabulary and tokenizer with the main model and to distill the draft model on the main model’s outputs, so it imitates the main model’s wording habits and reasoning style and achieves a higher acceptance rate.

    Balancing size and speed. A draft model that is too large slows down the draft phase; one that is too small does not hit often enough. As a rule of thumb, the draft model is far smaller than the main model — typically a fraction on the order of one to several tens — so draft time is a small share of the whole loop.

    Context and task fit. For code generation, dialogue, long-document summarization and other tasks, the draft model’s training data and context length should match the target scenario. Some approaches also add a head layer or lightweight prediction module paired with the main model to reduce draft cost further.

    Standalone small model vs. self-drafting. Besides a separate draft model, there are schemes where the main model guesses multiple candidates itself (for example, reusing hidden-layer information to predict the next token). These avoid deploying an extra model but usually have a lower hit rate and weaker scalability than a purpose-trained draft model. For online services that need a stable speedup ratio, a paired draft model is often the more controllable choice.

    4. Verification and Acceptance Strategies

    Greedy matching. A draft token is accepted when it matches the main model’s greedy result. Simple to implement and deterministic, it suits scenarios with strict output stability requirements.

    Sampling-based verification. Acceptance is decided by rejection sampling against the main model’s distribution, preserving distributional consistency for random sampling. This fits dialogue and other scenarios that need diversity.

    Tree candidates. A single candidate sequence verifies only one path per round. More advanced implementations have the draft model expand multiple candidates by confidence into a tree, let the main model score multiple paths in parallel, and accept the best branch, further increasing the average accepted length per round.

    5. Key Engineering Considerations

    KV cache management. The verify phase pre-writes cache entries for candidate positions, and rollback must truncate the cache correctly to avoid state pollution. In multi-turn serving, cache truncation also has to stay correct under batch scheduling.

    Dynamic speculation length K. Too large a K wastes verification compute; too small a K caps the speedup. Mature implementations adapt K based on recent acceptance rates, automatically extending the guess on high-hit-rate workloads.

    Combining with quantization and batching. Draft models are often paired with low-precision quantization to reduce memory footprint. Under high-concurrency batching, requests have different accepted lengths, so the scheduler needs proper padding and pipeline alignment to avoid load imbalance within a batch.

    Observability. Monitor metrics such as average accepted length, per-round verification time, and the share of time spent in the draft vs. main model. These directly reflect the acceleration effect and serve as the basis for capacity planning and parameter tuning.

    6. Typical Gains and Suitable Scenarios

    The speedup ratio depends on the acceptance rate and the characteristics of the workload. On high-determinism tasks such as code completion and formatted text generation, draft hit rates are usually high and decode throughput can improve by several times. In high-entropy scenarios such as open-ended creative writing, gains shrink but generally remain positive. For latency-sensitive online services such as AI coding tools and chat assistants, the approach can significantly improve response speed without changing the final model’s capability, making it a highly cost-effective part of the inference optimization stack.

    7. Summary

    A draft model plus speculative decoding is essentially trading cheap guessing for parallelized expensive verification. Successful deployment comes down to three things: training a lightweight draft model with aligned distributions, designing sound verification and acceptance strategies, and handling the systems engineering of caching and scheduling. When the three work together, decode latency drops substantially while output quality is preserved. When deploying inference services on general-purpose LLM platforms such as Baidu AI Cloud, the same approach can be used to design acceleration schemes and evaluate their effect.