Speculative Decoding for LLM Inference: A Practical Acceleration Guide
This article explores why single-concurrency decoding becomes a bottleneck in large model inference and how speculative decoding addresses it. It explains the core mechanism of draft candidate generation and parallel verification, outlines a minimal control-flow example, and highlights three design points that determine real-world gains: draft length k, the acceptance strategy, and the choice of draft model. The content is intended for engineers looking to reduce latency at low concurrency while preserving throughput at high concurrency.
1. The Starting Point: Why Single-Concurrency Decoding Becomes a Bottleneck
Once large models enter a phase of continuous iteration, training and inference are no longer separate pipelines. Instead, they form a closed loop through data generation, environment feedback, and parameter updates. Within this loop, latency on the inference side directly determines the length of the feedback cycle, as well as how tightly coupled engineering concerns such as resource scheduling, data management, and computation consistency become.
Autoregressive decoding is inherently serial: for every token generated, the entire current context must pass through a full forward pass. When the context length reaches around 32k, the share of per-step computation that actually goes toward “producing the next token” is extremely small. A large amount of compute is spent repeatedly reading the KV cache and recomputing the existing prefix. This leads to two typical symptoms:
- At low concurrency, decoding speed is locked by memory bandwidth and memory access efficiency, and compute utilization stays low over the long term.
- As concurrency rises, batching improves total throughput, but per-request latency degrades further and the interactive experience suffers.
As a result, what engineering actually needs is not a single-point optimization, but a mechanism that can deliver gains in both “low concurrency with low latency” and “high concurrency with high throughput” at the same time.
2. The Basic Mechanism of Speculative Decoding: Candidate Generation and Parallel Verification
The core idea of Speculative Decoding is to rewrite serial verification as parallel verification. It introduces a lightweight draft model that continuously generates several candidate tokens, then hands all of these candidates to the target model at once for a parallel forward pass, determining through a single check “up to which position to accept.”
Its correctness relies on a key property: the parallel forward pass during verification is mathematically equivalent to token-by-token autoregressive forward passes. It simply merges multiple serial calls into one batched call. Therefore, as long as the acceptance rule is designed properly, the output distribution can stay consistent with native autoregression. The speedup comes from “reducing the number of serial steps,” not from “lowering quality.”
A minimal flow illustration is shown below (it expresses control flow only, not a specific API):
# Pseudocode: main loop of speculative decodingdraft_tokens = draft_model.propose(prefix, k=4) # draft model guesses k tokens in a rowlogits = target_model.forward(prefix + draft_tokens) # target model verifies in parallel in one passaccepted = accept_by_rule(draft_tokens, logits) # acceptance decisionprefix = prefix + draft_tokens[:accepted] + [sample(logits[accepted])]
There are three design points that determine the actual gains:
- Draft length k. If k is too small, the verification overhead cannot be amortized; if k is too large, the draft hit rate drops and wasted verification compute rises. A reasonable approach is to adjust k dynamically based on the entropy of the context.
- Acceptance strategy. It must guarantee an unbiased distribution while avoiding being overly conservative, which would lead to a too-low acceptance rate.
- The draft model and
