Speculative Decoding in Practice: How Draft Models Speed Up LLM Inference

    This article explains why autoregressive decoding limits large language model inference speed and how speculative decoding uses a small draft model to propose candidate tokens that the target model verifies in one forward pass. It covers the accept-and-resample rule, the conditions that keep the output distribution unchanged, how to choose the candidate length K, draft model distillation, and engineering concerns such as KV cache rollback, batching, monitoring, fallback, and benchmark reporting.

    1. Why Autoregressive Decoding Is Slow

    A large language model generates text one token at a time. Each new token requires a full forward pass of the target model, which reads the model weights and the KV cache once per step. Larger models read more data at each step. The GPU’s compute capacity often goes underused, so the latency per step is high and overall throughput stays low.

    Speculative decoding addresses this problem. A small, fast draft model first predicts K candidate tokens in a row. The target model then processes these K candidates appended to the original context in a single forward pass, and checks each candidate in order. If the first few candidates are accepted, one call to the target model produces several tokens.

    2. Three Steps and the Accept-Reject Rule

    The first step is drafting. The draft model takes the current context as input and autoregressively generates K candidate tokens, x1 through xK. It records the probability q(xi) that the draft model assigns to each candidate.

    The second step is parallel verification. The context and the candidate sequence are concatenated and fed into the target model. One forward pass produces the target distribution p at every position.

    The third step is acceptance and resampling. The system checks each position i in order. It accepts token xi with probability min(1, p(xi)/q(xi)). Once a position is rejected, checking stops. The system then samples a replacement token from the normalized distribution max(0, p - q) to fill that position, and discards all candidates after it. If all K candidates are accepted, the system samples one extra token from the target model’s distribution at the final position.

    Leviathan et al. (2023) and Chen et al. (2023) proposed this scheme. With sampling-based decoding, the distribution of the output tokens matches the distribution produced by decoding with the target model alone, one token at a time.

    This equivalence depends on three conditions. All three must hold.

    1. The accept-and-resample rule must be implemented exactly as described. Replacing it with a check on whether the highest-probability tokens match holds only for greedy decoding.
    2. Sampling parameters such as temperature, top-k, and top-p must apply to both the draft distribution and the target distribution. Otherwise, the probability ratio loses its meaning.
    3. The order in which random numbers are consumed changes. As a result, the exact token-by-token output under the same random seed may differ from the original method. The equivalence holds at the level of the distribution, not for each individual sample.

    Greedy decoding (temperature 0) uses a simpler rule. If a draft token equals the target model’s argmax at that position, the system accepts it. Otherwise, the system replaces it with the argmax. In this case, the output matches the greedy output of the original target model exactly.

    Both the draft model and the target model must maintain KV caches. After verification, the system keeps only the cache entries for the accepted prefix and rolls back the rest. Many implementations contain bugs at this step.

    3. Choosing the Candidate Length K

    The speedup depends on the acceptance rate. Let α be the probability that a single candidate token is accepted, and assume the positions are approximately independent. The average number of tokens produced per target model call, including the extra final token, is:

    E = (1 - α^(K+1)) / (1 - α)

    When α approaches 1, E approaches K + 1. When α is 0, E equals 1, which matches the output of standard decoding.

    Let c be the ratio of the time needed for one draft model step to the time needed for one target model forward pass. The theoretical speedup is approximately E / (cK + 1). This formula ignores batching, memory bandwidth, and scheduling overhead, so use it only for a rough estimate.

    For example, suppose α is 0.8, K is 4, and c is 0.05. Then E is about 3.36, cK + 1 is 1.2, and the theoretical speedup is about 2.8. This is an estimate from the formula. Measure the actual numbers in your own environment.

    K does not have to stay fixed. The system can track the acceptance rate over a rolling window of recent steps, for example the last 64 steps. If the acceptance rate stays above a threshold, such as 0.8, increase K by 1. If it stays below another threshold, such as 0.5, decrease K by 1. Limit K to a range from 1 to 8. These thresholds and window sizes are only starting points. Calibrate them using your own workload.

    You can measure the “context confidence” by using the entropy or the maximum probability of the draft model’s distribution at the final position. When entropy is low, candidates are more likely to be accepted, so K can be increased somewhat. This is a heuristic and does not replace acceptance rate statistics. If the acceptance rate stays below about 0.3 for a long period, the verification overhead may outweigh the benefit. In that case, switch back to standard decoding.

    4. Distilling the Draft Model

    Draft models are usually trained by distillation so that their output distribution approximates that of the target model. A common approach minimizes the KL divergence or cross-entropy between the two distributions. Some methods weight high-probability tokens more heavily or use temperature scaling during training to improve the fit in high-probability regions.

    A lower training loss does not guarantee faster inference. Use the online acceptance rate and end-to-end latency as the final criteria. Also check output quality on a fixed dataset.

    5. Boundaries of Prepackaged Components

    Packaging the draft model, target model, verification logic, and scheduling policy into standard components lowers the barrier to adoption. However, automatic configuration can also hide problems. Before integrating, confirm three things. First, the draft model and the target model must use the same tokenizer and vocabulary. Second, the inference framework must support incremental loading of the draft model. Third, the GPU memory budget must be large enough to hold both models and their KV caches.

    When automatic tuning finishes, the component should report the final K value, the acceptance rate, and the memory usage so that users can check the results.

    6. Engineering Essentials

    Memory and Weight Sharing

    The draft model uses extra GPU memory. To share weights with the target model, such as the embedding layer, three conditions must hold. Both models must use the same tokenizer and vocabulary. Their hidden sizes must match. The framework must support binding one copy of the weights to both models. If any condition is not met, you cannot share the weights directly. Instead, load the models separately or use a quantized draft model.

    Sharing weights changes the draft distribution, so measure the acceptance rate again and check output quality after sharing. For KV caches with variable lengths, paged allocation can reduce memory fragmentation.

    Batch Scheduling

    With many concurrent requests, each request has a different draft length and a different number of accepted tokens. The implementation must track the accepted length, KV cache position, and attention mask separately for each request. During verification, the system can combine the candidate sequences from multiple requests into one batch. It must use masks to isolate each request so that the requests do not affect one another.

    Logging and Monitoring

    Record the acceptance rate, the current K value, draft latency, verification latency, and the number of fallback events. If you use Prometheus or a similar tool, use fixed, low-cardinality labels, such as the model name and the instance ID. Do not use request IDs as labels, because they create an explosion of time series.

    Store only numeric metrics. Do not record user prompts or generated content. If troubleshooting requires that data, redact it first, and follow your data retention period and access control requirements.

    Failure Recovery and Fallback

    If the draft model times out, runs out of memory, or produces abnormal output, the system should automatically switch to standard autoregressive decoding. The switch should happen inside the framework so the client sees no difference. Log the reason for the fallback to support later investigation. Before falling back, discard any candidates that were not accepted and roll back the KV cache correctly. Otherwise, the output may be wrong.

    7. Verifying That the Speedup Is Real

    Performance results are useful only when the test conditions are fully documented. At minimum, a report should specify the GPU model and count, the parallel configuration, the sizes of the target and draft models, the batch size, the context length, the output length, the sampling parameters such as temperature and top-p, the baseline standard decoding configuration, the measurement tools, and the number of repeated runs.