Speculative Decoding: The Principles and Engineering Practices Behind Multi-Fold LLM Inference Speedups

    Speculative decoding lets a large language model generate tokens several times faster without changing hardware or compressing the model, by having a small "draft" model propose candidate tokens that the large target model verifies in a single pass. This article explains why autoregressive decoding is memory-bandwidth bound, how the draft-and-verify structure preserves the exact output distribution, how the speedup is governed by token acceptance rate and two other parameters, how to choose and tune a draft model, what alternative drafting strategies exist, and why the gains shrink as concurrency rises. It closes with a pre-launch checklist and the scenarios in which speculative decoding should not be enabled.

    1. Why Token-by-Token Generation Starts at a Disadvantage

    When you run an LLM locally, a common puzzle is this: the GPU still has compute headroom to spare, yet generation speed refuses to go up. To understand why speculative decoding helps, you first need to see the two phases inside a single inference pass.

    Prefill phase: Once the prompt enters the model, it is processed in parallel as a whole. The model computes attention for every input position and builds the key-value cache (KV Cache). This phase handles hundreds or thousands of tokens at once, with large matrices and heavy data reuse, so it is primarily a test of raw compute (FLOPs).

    Decode phase: The model now generates tokens one at a time, processing only a single new position per step. Its execution pattern changes fundamentally: to produce one token, the GPU must first read all model weights from memory into the compute units, then write the new key-value pairs back to the cache. Dozens to hundreds of gigabytes of weights yield a single token.

    You can characterize this difference with arithmetic intensity (the number of floating-point operations performed per byte of data moved). The arithmetic intensity of the decode phase is extremely low, making it a classic memory-bandwidth-bound workload: what determines speed is not the nominal TFLOPS figure, but how fast VRAM can shuttle the weights over.

    This leads to an important corollary: on the same GPU, reading the weights once is almost enough to compute only one token. The cost of moving weights is charged “per pass,” and it barely matters whether that pass computes 1 position or 5. This explains why the decode-phase bottleneck has nothing to do with compute, and it also points to speculative decoding’s opening: make a single weight pass produce multiple tokens.

    2. How Speculative Decoding Works: The Small Model Proposes, the Large Model Verifies

    Speculative decoding splits token generation into two roles:

    • Draft model: Usually only a fraction to one-tenth or one-twentieth the size of the target model. It decodes very quickly and is responsible for consecutively “guessing” several candidate tokens.
    • Target model: Left unchanged, not compressed, not swapped for a different GPU. It verifies all the candidates in one parallel pass.

    For example, suppose the prompt contains “The cat.” The draft model consecutively guesses sat → on → my → lap. The target model then feeds all 4 positions into a single forward pass and obtains, for each position, “what the correct next token should be.” If the first 3 are accepted and the 4th is rejected, the target model supplies a corrected token at that position and the loop begins again.

    Work that the original model needs 4 decode steps to complete is compressed into 1 target-model forward pass + 4 draft-model forward passes.

    Key point: One verification is almost equal to one decode

    Because the target model’s forward pass computes 4 (or γ+1) positions at once while the weights are moved only once. Arithmetic intensity rises from “1 token amortizing all weights” to “4 tokens amortizing all weights,” and the workload shifts from the bandwidth-bound region toward the compute-bound region. As long as compute is not yet truly saturated, the wall-clock time of this one verification stays close to that of an ordinary decode step.

    Correctness is not “approximation” but distributional equivalence

    This is the essential difference between speculative decoding and empirical tricks like “using a large model to correct a small one.” There are two acceptance rules:

    Greedy decoding (temperature 0): A candidate token is accepted only if it equals the target model’s argmax at that position; otherwise it is replaced by the target model’s result.

    Sampling decoding (temperature > 0): Let the draft model give candidate $x$ with probability $q(x)$, and the target model assign it $p(x)$. Accept it with probability $\min\left(1, \frac{p(x)}{q(x)}\right)$. On rejection, resample from the residual distribution $\mathrm{norm}\left(\max(0,\, p(x)-q(x))\right)$ as the output for that position.

    It can be proven that the token sequence produced by this “accept–reject–residual-correction” process has a probability distribution exactly identical to direct sampling from the target model. In other words, speculative decoding changes only the way computation is done, not the output distribution — and this is the precondition that lets it be adopted in production systems.

    A sketch of the implementation logic:

    1. def speculative_generate(target, draft, prompt_ids, gamma=5, temperature=0.0):
    2. # 1. Prefill: build two KV caches
    3. t_prefix = target.prefill(prompt_ids)
    4. d_prefix = draft.prefill(prompt_ids)
    5. while not finished:
    6. # 2. Draft phase: the small model runs autoregressively for gamma steps, cost ≈ gamma × c (c is relative cost)
    7. drafts, draft_logits = draft.propose(d_prefix, gamma)
    8. # 3. Verification phase: gamma+1 positions in a single forward pass, weights moved only once
    9. logits = target.forward(t_prefix, drafts) # shape: [gamma+1, vocab]
    10. # 4. Judge token by token, stop at the first rejection
    11. n_accept = 0
    12. for i, x in enumerate(drafts):
    13. p, q = logits[i], draft_logits[i]
    14. if temperature == 0:
    15. ok = (x == p.argmax())
    16. else:
    17. p_x = softmax(p / temperature)[x]
    18. q_x = softmax(q / temperature)[x]
    19. ok = random() < min(1.0, p_x / q_x)
    20. if not ok:
    21. x = sample(residual(p, q)) # residual distribution correction
    22. if not ok:
    23. break
    24. emit(x)
    25. n_accept += 1
    26. # 5. The verification position itself "comes with" one token, a free bonus
    27. emit(sample(logits[n_accept]))
    28. # 6. Rollback: truncate to the last accepted position to prevent cache pollution
    29. t_prefix.rollback(n_accept + 1)
    30. d_prefix.rollback(n_accept)

    Step 5 is often overlooked: each verification round produces at least 1 token (the target model’s sample at the rejected position or the final position), so even if every draft is wrong, you are no slower than the original approach — unless the draft step itself takes up too large a share of the time.

    3. Quantifying the Gains: Speedup Depends on Three Parameters

    The metric that truly governs the speedup is the average acceptance length: how many draft tokens the target model accepts per round on average. Let the per-token acceptance rate be $\alpha$, the draft length per round be $\gamma$, and the ratio of one draft-model forward pass to one target-model forward pass be $c$. Then:

    • Expected tokens produced per round: $\dfrac{1-\alpha^{\gamma+1}}{1-\alpha}$
    • Expected time per round (with one target-model decode as 1 unit): $\gamma c + 1$
    • Speedup: $\text{Speedup} = \dfrac{1-\alpha^{\gamma+1}}{(1-\alpha)(\gamma c + 1)}$

    Plugging in different parameter combinations (assuming we remain in the bandwidth-bound region):

    Per-token acceptance rate α Draft cost c γ=3 γ=5 γ=7
    0.6 0.05 1.70× 1.84× 1.80×
    0.7 0.05 2.20× 2.35× 2.33×
    0.8 0.05 2.57× 2.69× 2.93×
    0.9 0.03 3.16× 3.56× 4.31×

    Three conclusions you can act on directly:

    1. α is decisive. Raising α from 0.6 to 0.8 pushes the speedup from about 1.8× to about 2.9×; every optimization gain from the draft model ultimately shows up as a higher α.
    2. γ has an optimal value. Too small, and acceptance length is capped; too large, and the rejected tail of the draft is pure waste. In the table, at α=0.6, γ=7 already underperforms γ=5, and the lower the α, the smaller the optimal γ. In practice, engineers usually pick 3–8, together with an “adaptive draft length” strategy that adjusts dynamically based on the real-time acceptance rate.
    3. c must be small enough. If a single draft-model forward pass costs one-fifth of the target model (c=0.2), then at γ=5 the denominator becomes 2.0 and the speedup degrades to roughly 1.5×. Picking a draft model that is too large is digging your own grave.

    4. Choosing and Tuning a Draft Model

    Prefer the same family and vocabulary. The draft model and target model should ideally come from the same model family and share the same tokenizer. When vocabularies differ, $p(x)/q(x)$ cannot be aligned token by token, verification logic becomes far more complex, and in practice it is rarely worth it.

    Distill from the target model’s outputs. The essence of the acceptance rate is the overlap between the two models’ output distributions. Fine-tuning the draft model on text generated by the target model over real corpora (especially your own business data) typically yields a clear improvement over using its original weights directly. This step is not expensive, yet it can significantly improve α.

    A rule of thumb for size matching. The draft model’s parameter count is generally 1/10 to 1/20 of the target model’s. The goal is to finish γ draft steps within the time of one target-model decode, with headroom to spare. You can start by working backward from c ≈ 0.02–0.05.

    Budget VRAM explicitly. Two sets of weights plus two KV caches mean higher VRAM usage. With long contexts, the KV Cache may become the main increment. If you were already running right at the VRAM ceiling, speculative decoding is likely to be impossible to enable — do the VRAM math first, then talk about speed.

    Calibrate your sampling parameters. The higher the temperature and the looser the top-p, the flatter the output distribution and the harder the draft model finds it to guess, so α drops accordingly. Greedy decoding at temperature 0 has the highest acceptance rate. For “low-entropy” tasks such as code generation, structured output, and summarization/rephrasing, α is often markedly higher than for “high-entropy” tasks like creative writing and brainstorming. The same draft model can produce speedups that differ by a factor of two across different tasks.

    5. Beyond a Standalone Draft Model: Other Approaches

    A draft model is not the only form. Several alternatives are lighter to deploy:

    Retrieval-based / n-gram drafting: Retrieve recurring fragments from the history context or prompt as candidates. Zero extra model, zero extra VRAM, and highly cost-effective in high-redundancy scenarios such as long-document summarization, RAG question answering, and code completion — but nearly useless for open-ended generation.

    Self-speculation: Skip a number of layers in the target model and use a “crippled version of itself” as the draft. No extra weights are needed, but it requires the inference engine to support per-layer pruning, making the modification fairly invasive.

    Auxiliary lightweight prediction heads: Train several tiny extra heads on the target model to predict the next several positions in one shot. Small VRAM increment, manageable training cost — an area that has been fairly active in recent years.

    Tree / multi-candidate drafting: Instead of a single chain in the draft phase, retain top-k branches to form a candidate tree; the target model verifies multiple paths at once and takes the longest accepted path. Higher acceptance length, but wider verification and higher implementation complexity — suited to offline or near-line scenarios that chase extreme latency.

    6. Why Gains Shrink Under Concurrency

    A phenomenon you must communicate to stakeholders upfront: speculative decoding delivers its biggest gains in single-request, small-batch scenarios; as concurrency rises, the speedup decays noticeably.

    The reason goes back to arithmetic intensity. At low concurrency the target model’s compute sits idle, so computing γ extra positions is nearly free; at high concurrency the batch is already large, decoding itself approaches compute-bound, and computing γ extra positions carries a real compute cost, while the draft model’s extra overhead piles on at the same time.

    The order of magnitude given by public technical demos: single-request generation speed increases by nearly 4×, and after concurrency pressure rises there is still roughly a 2× throughput improvement. Behind this shift is not degraded implementation, but the inevitable consequence of the workload sliding from bandwidth-bound to compute-bound.

    This yields a practical capacity-planning principle:

    • Low-concurrency / single-user / interactive scenarios (local assistants, single-machine IDE plugins, personal knowledge-base Q&A): prioritize enabling speculative decoding, which directly reduces the latency of every token after the first (TPOT).
    • High-concurrency / online-service scenarios: first use continuous batching to saturate compute, then evaluate whether speculative decoding still yields a net benefit — capacity assumptions should generally use a more conservative multiple.

    Also note that speculative decoding does not improve time to first token (TTFT). TTFT is determined by the prefill phase, while speculative decoding acts on the decode phase that follows. If the user’s pain point is “I hit send and nothing happens for ages,” the optimization direction should be prompt length, prefix-cache hit rate, and model size — not the draft model.

    7. How It Composes with Quantization and Caching

    Speculative decoding points in the same direction as weight quantization and can be stacked: quantization reduces the weight data moved per token and by itself speeds up decoding; speculative decoding further makes a single weight pass produce more tokens. The two do not conflict, but keep in mind that once quantization has already made decoding faster, the relative headroom for speculative decoding is compressed somewhat — measure it rather than assume.

    For structured output, JSON mode, and constrained-decoding scenarios, one extra thing is worth doing: apply the grammar/format constraints to the draft phase as well. A draft token that violates the format will certainly be rejected; filtering it out early directly raises α.

    8. Pre-Launch Checklist

    Look at the metrics first, then tune the parameters. At minimum, collect four: average acceptance length, output tokens per second per user, TPOT distribution (P50/P95), and peak VRAM. Average acceptance length is the most direct tuning signal — if it stays low over time, the draft model does not match the task, and tuning γ only treats the symptom.

    Roll out with an A/B comparison; do not switch everything at once. With the same model and the same prompt set, run an A/B test with speculative decoding on and off. Focus on comparing whether output quality stays consistent (theoretically it should be distribution-equivalent, though in practice you must guard against implementation bugs) and whether P95 latency actually drops.

    Leave a switch for the degraded path. During high-concurrency periods, for very-long-context requests, or when the VRAM level crosses a threshold, the system should be able to automatically fall back to ordinary decoding. It is advisable to make γ and the draft-model toggle hot-updatable configuration items.

    Wire observability into your existing stack. For cloud deployments, use a container platform to host the inference service and the draft-model replicas, use a logging service to aggregate per-round acceptance lengths and rollback counts, and use monitoring and alerting to set thresholds on P95 latency and VRAM level — this is what gives tuning a data basis. Cloud platforms such as Baidu AI Cloud typically already have corresponding products in these general capability categories, so the integration cost is low.

    9. When Not to Enable It

    Honestly listing unsuitable scenarios is more valuable than exaggerating the benefits:

    • VRAM is already tight and cannot fit a second set of weights and KV Cache;
    • The task is high-entropy creation, the draft model’s acceptance rate stays below 0.5 over time, and the speedup is under 1.3×;
    • The service runs at high concurrency, compute is already near saturation, and the primary goal is throughput rather than single-request latency;
    • The team lacks the supporting metrics collection and canary-release capabilities, and cannot tell whether the change is a gain or a burden;
    • Scenarios with strict requirements on numerical-path consistency, which need extra verification that the implementation truly preserves the output distribution.

    Conclusion

    The value of speculative decoding lies in the fact that it asks no one to swap GPUs or compress the model; instead it changes the way tokens are generated: from “one weight pass for one token” to “one weight pass to verify multiple tokens.” That is also why it has been absorbed, one after another, by mainstream inference frameworks — it is an orthogonal optimization layer, stacked on top of quantization, continuous batching, and prefix caching, rather than competing with them.

    But it is no free lunch. The speedup is entirely determined by the acceptance rate, and the acceptance rate is jointly determined by the draft model’s quality, the task’s entropy, and the sampling parameters. Real engineering skill lies not in “knowing this technique exists,” but in being able to measure the α and optimal γ under your own business workload, and on that basis to decide whether to enable it, how large to make it, and when to turn it off.