Speculative Decoding in Practice: Accelerating Local Inference with Draft Models

    This article explains how speculative decoding accelerates local LLM inference by using a small draft model to propose candidate tokens that a target model verifies in a single forward pass. It covers the decoding bottleneck, the core accept/reject mechanism, the key metric of average acceptance length, practical strategies for choosing draft models and draft length, concurrency considerations, evaluation checklists, and deployment caveats.

    Speculative Decoding in Practice: Accelerating Local Inference with Draft Models

    When running large language models locally, the performance bottleneck is not always raw compute. During autoregressive generation, the model reads the full set of model weights and the existing KV cache for every single token it produces, then writes the new key-value data back to the cache. The process repeats for the next token. With model weights often reaching tens of gigabytes or more, the cost of moving data per decoding step is high. Memory bandwidth and cache access efficiency frequently have a more direct impact on generation speed than the number of compute units. Speculative decoding has drawn attention precisely because it does not replace hardware or further compress the target model—it changes how tokens are generated and verified.

    1. The Decoding Bottleneck: Why Per-Token Generation Struggles to Saturate

    An LLM inference run typically has two phases: prefill and decoding. The prefill phase processes the entire user input at once, computes attention, and builds the KV cache. Because it handles many tokens in a single step, it can better exploit parallel compute. In the decoding phase, the model emits only one token at a time. The compute per token seems small, but the model must repeatedly read the full weights and cache. In practice, compute units often stall waiting for data, making memory bandwidth, cache hit rate, and data movement efficiency the critical constraints.

    The draft-model idea assigns the easier part of the prediction task to a smaller, faster model. For example, after the user input “the cat sat”, a draft model might propose “on”, “the”, “mat”. The target model then verifies these candidates in one forward pass: accepted prefixes that match the target model’s probability distribution are kept, the first rejected candidate causes all subsequent candidates to be discarded, and the target model generates a correction token. What previously required multiple target-model passes can sometimes be compressed into a single verification pass. Because the draft model is small, the cost of generating candidates is usually far lower than the cost of the target model reading its full weights multiple times.

    2. Core Mechanism: Draft Proposes, Target Verifies

    Speculative decoding does not let the draft model decide the final output. The target model retains final authority. The draft model proposes; the target model verifies and corrects. For greedy decoding, the target model’s argmax can be compared directly with each candidate token. For stochastic sampling, a rejection sampling rule is commonly used so that the output distribution matches the target model: for each candidate token, compute the target probability p and the draft probability q, accept the candidate with a certain probability, and if rejected, resample from a corrected distribution. The goal is to accelerate the generation path while keeping output quality under the target model’s control.

    A simplified pseudocode outline follows. It is illustrative and not tied to any specific API:

    1. speculative_decode(prompt, target, draft, K, max_new):
    2. target_cache = target.prefill(prompt)
    3. draft_cache = draft.prefill(prompt)
    4. output = []
    5. while len(output) < max_new:
    6. candidates = []
    7. tmp_cache = draft_cache.clone()
    8. for i in range(K):
    9. logits = draft.forward(tmp_cache)
    10. token = sample_or_argmax(logits)
    11. candidates.append(token)
    12. tmp_cache.append(token)
    13. verify_logits = target.forward_verify(target_cache, candidates)
    14. accepted = []
    15. for i in range(K):
    16. p = target.prob(verify_logits[i], candidates[i])
    17. q = draft.prob(draft_logits[i], candidates[i])
    18. if accept_rule(p, q, candidates[i]):
    19. accepted.append(candidates[i])
    20. else:
    21. corrected = sample_from_corrected(p, q)
    22. accepted.append(corrected)
    23. break
    24. if len(accepted) == K:
    25. extra = sample(verify_logits[K])
    26. accepted.append(extra)
    27. target_cache.append(accepted)
    28. draft_cache = resync(draft_cache, accepted)
    29. output.extend(accepted)
    30. yield accepted

    Two engineering details are easy to overlook. First, when the target model verifies K candidates in one pass, it must produce K+1 distributions so that if all candidates are accepted, it can immediately generate one extra token. Second, the draft cache and the target cache must stay synchronized: after verification, only the accepted prefix is kept, and any unaccepted suffix must be rolled back. A common approach is to roll back the draft cache and replay the accepted tokens, or to retain only the confirmed prefix. Poor cache synchronization can introduce extra overhead or even correctness issues.

    3. Acceptance Length: The Key Metric That Determines Speedup

    Speculative decoding may look like a “free lunch”, but the real determinant of speedup is the average acceptance length—how many draft tokens the target model accepts per verification round on average. Let T be the cost of one target forward pass, cT the cost of one draft forward pass, and K the number of draft tokens proposed per round. If the average number of accepted tokens is A, and ignoring scheduling and cache overhead, the cost per round is roughly T + KcT, and the forward progress is about A+1 tokens. The approximate speedup is:

    1. S ≈ (A + 1) / (1 + Kc)

    When the draft model is small enough (c is low) and A/K is high, S can be meaningfully greater than 1. If the draft model guesses wrong often, the target model rejects and corrects repeatedly, and the extra computation can slow generation overall. Writing more draft tokens does not always mean faster: a larger K can increase the potential forward progress but also raises draft generation cost and wasted verification. A larger K is not always better, and a very small K makes the target model run too often. In practice, tuning should start with a small K and adjust dynamically based on observed acceptance length instead of fixing a large draft length.

    4. Draft Model Selection and Draft Length Strategy

    Choose a draft model with three principles in mind: distribution closeness, low cost, and tokenizer alignment. The closer the draft distribution is to the target, the more likely candidates will be accepted. A larger draft model may improve acceptance but also increases the per-proposal cost. If the vocabulary and tokenizer do not match, you incur mapping overhead and possible semantic drift. In practice, consider a smaller model from the same family, a domain-adapted small model, or a distilled assistant model. Ensure that sampling parameters—temperature, top-p, and others—are consistent with the target model’s verification logic. You can also quantize the draft model to reduce memory footprint, but must re-evaluate acceptance length and output quality regressions.

    Draft length can be adaptive. Track the recent average acceptance length. If acceptance stays low, reduce K or switch draft models. If acceptance is high and target verification cost dominates, increase K moderately. For long-context scenarios, also pay attention to the draft model’s own context window and KV cache usage, so that the acceleration does not crowd out the target model’s cache.

    5. Concurrency, Batching, and Throughput

    In single-request scenarios, speculative decoding primarily reduces repeated reads of the target model’s weights and cache, so it is easier to observe a clear speedup. As concurrent requests increase, the target model can amortize weight reads through batching, while the extra compute from the draft model becomes a larger share of the total work. The per-request speedup may drop, but overall throughput can still improve with good scheduling. Engineering attention should go to continuous batching, alignment of draft lengths across sequences, padding waste during verification, and bandwidth contention between the draft and target models. Evaluation should not rely only on single-request peak speed. Track P95/P99 tail latency, throughput, memory usage, and energy consumption as well.

    6. Evaluation and Tuning Checklist

    Fix the hardware, batch size, sampling parameters, and prompt set. Compare a baseline of the target model running alone against the target model plus the draft model. Record at least the following:

    • Single-request generation speed, first-token latency, and tail latency;
    • Throughput and error rates at different concurrency levels;
    • Average acceptance length, draft hit rate, and tokens progressed per round;
    • Memory usage for both target and draft models, plus cache rollback overhead;
    • Output quality regressions, long-context behavior, and safety filter results;
    • A sweep over different draft lengths K, plus the effect of adaptive strategies.

    If you build an evaluation environment with a general container platform, object storage, log services, and monitoring alerts (for example, on Baidu AI Cloud), include the draft and target models in the same metrics dashboard. Do not observe only the single-request peak and ignore tail latency or resource contention.

    7. Deployment Considerations

    Speculative decoding suits bandwidth-constrained, single-request or low-to-medium concurrency scenarios where output quality matters. It is not an unconditional accelerator. Before rollout, keep a fallback switch and validate with gradual traffic. Ensure tokenizer and vocabulary alignment, sync sampling parameters, handle cache rollback and batch alignment carefully, and apply a unified safety and content filter to the final output. Only by incorporating acceptance length, draft cost, concurrency scheduling, and quality regressions into evaluation can a draft model become a stable and practical acceleration method for local inference instead of appearing attractive only on paper.