Speculative Decoding for Local LLM Inference: Faster Generation Without a New GPU

    This article explains why local LLM inference is often limited by memory bandwidth during decoding, and how draft-model speculative decoding can improve generation speed without upgrading the GPU. It covers the target/draft model workflow, acceptance and resampling rules, average acceptance length and theoretical speedup, a simplified main-loop example, deployment trade-offs, and a practical validation sequence.

    Why Local Inference Is Slow: Moving Data

    LLM inference typically has two stages. In the prefill stage, the model processes the entire user prompt at once, computes attention, and writes to the KV cache. This stage has many tokens that can be processed in parallel and is mainly constrained by compute capacity. In the decoding stage, the model outputs only one token at a time.

    To generate the next token, the compute units must read all model weights and the existing KV cache, then write the new key-value entries back to the cache after computation. For a large model, weights may occupy tens of GB of GPU memory. Every generated token requires moving all of this data again, so decoding speed is often determined by memory bandwidth rather than peak compute. The compute units may spend much of their time waiting for data.

    This means that simply adding more compute has limited impact on single-request decoding speed. To speed things up, we need to break the premise that every token requires a full pass over the weights. Speculative decoding starts from this point.

    The Core Idea of Draft Models

    Speculative decoding introduces two roles:

    • Target model: large and responsible for final output quality; all results must ultimately be confirmed by it.
    • Draft model: small and fast, responsible for guessing several future tokens in advance.

    For example, given the input “The cat,” the draft model might propose four candidates at once: sat, on, my, and lap. The target model does not generate them one by one. Instead, it treats “The cat sat on my lap” as a single sequence, performs one forward pass to obtain the probability distribution at each position, and then checks the candidates position by position.

    The validation rules fall into two cases:

    1. Under greedy decoding, a candidate token is accepted directly if it matches the target model’s highest-probability token at that position.
    2. Under sampling decoding, acceptance is decided by the probability ratio. If a candidate is rejected, a token is resampled from the adjusted distribution so that the final output distribution remains the same as using only the target model.

    In either case, once the first rejected position is reached, that position and all following candidates are discarded, and the round ends. If all candidates are accepted, the target model can also provide one additional token at the last position. Therefore, each round confirms at least one token, and in good cases it can confirm multiple tokens.

    The “free” speedup only holds when draft quality is high enough. If the draft model makes frequent errors, most of the computation is discarded, and overall speed may even decrease.

    The Key Metric: Average Acceptance Length

    Average acceptance length refers to the average number of draft tokens accepted by the target model per round. It directly determines the speedup ratio and is the most important metric to watch during tuning.

    For a theoretical estimate, assume that the acceptance probability of each draft token is independent, denoted as α, and the draft length is k. The expected number of tokens produced per round is:

    E = (1 − α^(k+1)) / (1 − α)

    The draft model itself also takes time. Assume that the per-step cost of the draft model is approximately c times that of the target model. The theoretical speedup ratio is approximately:

    Speedup ≈ E / (k × c + 1)

    The table below uses c = 0.05, meaning the draft model’s per-step cost is about 5% of the target model’s, and gives several estimates:

    Acceptance rate α Draft length k Expected tokens per round Theoretical speedup
    0.6 4 About 2.3 About 1.9
    0.8 4 About 3.4 About 2.8
    0.8 8 About 4.3 About 3.1

    Two points stand out from the table. First, acceptance rate has a larger impact than draft length. When acceptance rate rises from 0.6 to 0.8, the speedup increases noticeably. Second, increasing draft length has diminishing returns. When k increases from 4 to 8, the speedup improves by only about 10%, while the draft model overhead and discarded computation continue to increase.

    Note that these numbers are based on simplified assumptions about independence and cost ratios. In real scenarios, acceptance rate varies with context, and batch size, hardware, and inference-framework implementation overhead also affect results. Actual measurements should be the basis for decisions.

    Illustrative Code: The Main Speculative Decoding Loop

    The following code illustrates a single-round workflow. It omits KV cache reuse, boundary conditions, and performance optimization, and is not directly runnable.

    1. def speculative_step(target, draft, prefix, k):
    2. # 1. The draft model generates k candidate tokens consecutively
    3. candidates = []
    4. ctx = list(prefix)
    5. for _ in range(k):
    6. tok, q = draft.sample_with_prob(ctx) # q is the draft model's probability for this token
    7. candidates.append((tok, q))
    8. ctx.append(tok)
    9. # 2. The target model performs one forward pass and returns distributions for each position
    10. p_dists = target.forward_all_positions(prefix, [t for t, _ in candidates])
    11. # 3. Validate position by position
    12. accepted = []
    13. for i, (tok, q) in enumerate(candidates):
    14. p = p_dists[i][tok]
    15. if random() < min(1.0, p / q):
    16. accepted.append(tok)
    17. else:
    18. # Resample from the normalized distribution of max(0, p - q); end the round
    19. accepted.append(sample_residual(p_dists[i], draft.dist_at(i), ))
    20. return accepted
    21. # 4. If all candidates are accepted, the target model provides one extra token at the last position
    22. accepted.append(sample(p_dists[k]))
    23. return accepted

    This code reflects three key points: the draft stage has low overhead; the target model performs only one forward pass; and all candidates after a rejected position are discarded.

    Selection and Deployment Considerations

    For local deployment, consider the following factors when evaluating whether to introduce a draft model.

    • Vocabulary compatibility: standard speculative decoding requires the draft model and target model to use the same vocabulary; otherwise tokens cannot be aligned position by position. A common choice is a combination of models from the same family at different sizes.
    • Draft model size: a smaller draft model has lower per-step cost, but acceptance rate may decrease. Find a balance between the two.
    • Task type: acceptance rates are usually higher for code completion, structured output, and fixed-format text. Acceptance rates are usually lower for high-temperature sampling and creative writing, so the speedup benefit is smaller.
    • Memory budget: the draft model consumes additional GPU memory and reduces the space available for the KV cache. When memory is already tight, long-context or large-batch requests may become slower as a result.
    • Concurrency load: as concurrent requests increase, compute utilization rises, and the single-request speedup decreases. In some tests, a certain throughput improvement remains as concurrency increases, but the gain is usually smaller than in the single-request case.

    Practical Steps

    It is recommended to validate results in the following order.

    1. Collect real requests from the target workload and use them to measure average acceptance length for different draft models, rather than relying only on public benchmarks.
    2. Fix the target model and sweep the draft length k to find the balance between acceptance rate and draft cost.
    3. Measure throughput and time to first token under both single-request and target concurrency levels to confirm whether the benefit meets expectations.
    4. Record changes in memory usage and confirm that sufficient headroom remains at peak load.

    If acceptance rate in the first step is clearly low, it usually means the draft model differs significantly from the workload distribution. In that case, replace the draft model first, then adjust the draft length.