Speculative Decoding for Faster LLM Inference: Principles and Engineering Practices

    This article explains why autoregressive decoding is slow and how speculative decoding reduces latency by proposing multiple candidate tokens and verifying them in a single forward pass. It compares two main approaches—an embedded draft module and a standalone lightweight draft model—covering their coupling, per-step cost, draft depth, and optimization goals. It also outlines key metrics such as acceptance rate, average accepted length, draft overhead, and batch-size effects, along with common pitfalls and practical deployment recommendations.

    1. Why Autoregressive Decoding Is Slow

    LLM inference has two phases: prefill and decode. Prefill processes the entire prompt in parallel and achieves high compute utilization. Decode generates tokens one by one, and every step moves all weights from memory to the compute units. This is a memory-bound workload: compute sits largely idle while latency is dominated by per-step weight movement and synchronization overhead.

    The core insight behind speculative decoding is that verifying several candidate tokens costs roughly the same as generating one token, because both require a single forward pass. A single round can therefore propose multiple candidates and verify them all at once, compressing the number of serial steps. Two roles are involved: a draft model that produces candidates, and a main model (the target model) that verifies them.

    2. Two Main Technical Routes

    Route 1: Embedded Draft Module

    The embedded approach adds the draft capability as an auxiliary module bundled with the main model and trained alongside it. It takes hidden states from the end of the main network, applies an additive mix with projected and embedded representations, and feeds them into a structurally complete heavy block. Because features come from the same source, alignment is good and single-step draft quality is high. The drawback is that one draft step can cost on the order of one percent of a main-model step, so production systems typically run only one draft step, producing just one extra token per round and limiting the speedup.

    Sketch (pseudocode):

    1. # Embedded draft: one draft step + one verification
    2. h = main_model.hidden_states # hidden states at the end of the main network
    3. d = draft_module(h, embed(last_token)) # heavy block, cost is not negligible
    4. cand = [sample(d)] # only one candidate is affordable
    5. out = main_model.verify(cand) # verify and produce a new token along the way

    Route 2: Standalone Lightweight Draft Model

    The standalone approach trains a small model outside the main model. It typically extracts intermediate features from several layers at different depths of the main model, concatenates them to preserve information from both the embedding space and the hidden space, and then runs a single decoding block with a very small parameter count (on the order of hundreds of millions). One step can cost as little as one thousandth of a main-model step, so multiple draft steps can be unrolled serially (for example, 5–7 steps) while total latency may still be lower than a single step of the embedded approach.

    1. # Standalone draft: multi-step serial drafting + one verification
    2. feats = [main_model.layers[i].output for i in (8, 16, 24, 32, 40)]
    3. ctx = fuse(concat(feats)) # lightweight fusion, single decoding block
    4. cands = []
    5. for _ in range(K): # K steps of autoregressive drafting
    6. ctx = draft_layer(ctx)
    7. cands.append(sample(ctx))
    8. out = main_model.verify(cands) # verify K candidates in one forward pass

    Core Differences Between the Two Routes

    • Coupling: the embedded route is tightly bound to the main model and hard to swap once the main model is fixed; the standalone route can be post-trained, giving draft capability without touching the main model.
    • Per-step cost: embedded is heavy, standalone is light.
    • Draft steps that can be unrolled: typically 1 for embedded, multiple for standalone.
    • Optimization target: embedded optimizes single-step hit rate; standalone optimizes expected accepted length per unit of latency.

    3. Key Metrics: Do Not Look at Speedup Alone

    Let α be the probability that a draft token is accepted and K the number of draft steps. The expected number of tokens produced per round is roughly (1 − α^(K+1)) / (1 − α). This shows two things: gains from a higher α compound, and K has an optimal value beyond which decaying acceptance probability cancels out the benefit.

    Engineering practice requires tracking all of the following:

    • Acceptance rate and average accepted length (tokens produced per verification round);
    • Share of time spent in the draft phase, to tell whether the bottleneck is drafting or verification;
    • Time to first token and end-to-end throughput (the two often move in opposite directions);
    • Behavior under batching: latency gains are clear at small batch sizes, while at large batch sizes the main model is already near compute saturation and speculative decoding gains are diluted or even turn negative.

    4. Common Pitfalls

    1. Making the draft model as large as possible. The draft must be light enough, or the cost of serial multi-step drafting will eat the gains.
    2. Ignoring sampling consistency. If the output distribution must match the main model exactly, verification needs an unbiased accept-and-resample rule rather than simply taking the first matching prefix.
    3. Evaluating on a single task. Acceptance rates are high for low-entropy tasks such as code and math, and drop significantly in high-entropy scenarios such as open-ended conversation, so data should be reported per scenario.
    4. Overlooking memory and operational cost. An extra draft model adds memory usage and version-management complexity; this must be included in capacity planning, with logging services and monitoring alerts to observe the real acceptance rate in production.

    5. Deployment Recommendations

    • Profile the baseline first: confirm that the decode phase is indeed memory-bound before introducing speculative decoding.
    • Start with the post-trainable lightweight draft route, which requires no changes to the main model and has a low rollback cost.
    • Make K and batch size configurable and adjust them dynamically based on traffic patterns; container platforms with elastic scaling and message queues can help smooth peaks.
    • Set up dual-track validation with an offline evaluation set and online canary releases, using average accepted length and end-to-end throughput as admission thresholds.
    • When deploying on cloud platforms such as Baidu AI Cloud, reuse common capabilities like container platforms, object storage, logging services, and monitoring alerts to handle draft model distribution, evaluation, and observability instead of building infrastructure in-house.