Inference Systems

Speculative Decoding Without Hand-Waving

Jul 10, 202612 min readUpdated Jul 26, 2026

Hand-drawn pen-and-ink diagram of the mechanism explained in "Speculative Decoding Without Hand-Waving".
01 / 09

Trading cheap guesses for fewer target passes

Autoregressive generation normally invokes the full target model once per output token. Speculative decoding lets a smaller draft model propose several tokens, then evaluates those proposals in one target-model pass. When the target accepts a run of draft tokens, one expensive pass advances multiple positions. The method is lossless when the acceptance and correction procedure is implemented correctly: it samples from the same target distribution rather than merely approximating greedy output. Speedup comes from reducing sequential target invocations, not from eliminating target verification.

For sampling, each proposed token is accepted according to the relationship between target and draft probabilities. At the first rejection, a corrected token is drawn from the residual distribution, and later draft tokens are discarded. Greedy decoding has a simpler rule because proposals must match the target argmax. Implementations must preserve temperature, top-p, penalties, banned tokens, and grammar masks consistently across both models. A mismatch in logits processing can lower acceptance or, worse, violate the claim that output follows the target distribution.

The central metric is accepted tokens per target step, but it must be interpreted with draft and verification cost. Proposing eight tokens is harmful if the first is usually rejected, while proposing two may leave speedup unrealized on predictable text. Acceptance varies by language, domain, prompt style, temperature, and position in the response. Instrument proposal length, accepted prefix length, correction rate, and wall time for each stage. One global acceptance average hides the workload segments where speculation consumes extra compute without reducing latency.

02 / 09

Choosing and training the draft

A useful draft model is not simply the smallest available checkpoint. It must share the target tokenizer or provide an efficient token-alignment scheme, produce similar next-token rankings on the served workload, and run much faster than target verification. A generic draft may perform badly on proprietary code or a specialized language. Distill the target’s logits or continuations on representative prompts, including its current system template and tool syntax, then evaluate acceptance rather than relying only on draft perplexity.

Self-speculation avoids a separate model by exiting early from the target network and using intermediate layers to propose tokens. This shares weights and cache infrastructure, reducing deployment complexity and memory duplication. The draft head still needs training or calibration, and early layers may diverge on tasks requiring deeper reasoning. Another family uses lightweight heads to predict several future positions from one hidden state. These approaches change kernel and checkpoint requirements, so their operational simplicity depends on whether the serving runtime supports them natively.

The draft can become stale when the target changes. New fine-tunes, adapters, safety policies, or tokenizer templates alter the probability distribution and may collapse acceptance for specific tenants. Version the draft-target pair as one deployable unit and include adapter identity in routing. A canary should compare acceptance, quality invariants, and latency before full rollout. If a tenant’s adapter is rarely used, running an unadapted draft might still help, but that decision should be driven by measured accepted-token yield rather than assumed similarity.

03 / 09

Scheduling and cache mechanics

Speculation changes each sequence from a one-token decode step into a variable-length proposal and verification cycle. The scheduler now batches requests whose speculative lengths may differ, creating ragged verification tensors. Padding wastes compute, while grouping only identical lengths fragments batches. Practical runtimes bucket proposal sizes and adapt them based on recent acceptance. The target KV cache must append verified positions and roll back rejected speculative state safely; an off-by-one error can corrupt every subsequent token while appearing superficially fluent.

A separate draft model also needs its own KV cache. That memory reduces the target concurrency the server can host, especially for long contexts. The draft cache may use lower precision or reside on another device, but moving hidden state between devices can destroy the latency gain. Place the draft based on an end-to-end topology model. If it shares the target GPU, verify that draft kernels do not delay target batches enough to increase queueing for non-speculative traffic.

Continuous batching complicates fairness because a sequence accepting many tokens advances farther per scheduler turn. Charging one turn per target pass favors predictable requests and can starve sequences with low acceptance. Account for verified and drafted tokens separately, then enforce tenant quotas on actual resource time or weighted tokens. Cancellation must stop both draft and target work. Streaming should emit only accepted tokens, never optimistic proposals, unless the product explicitly supports visible correction and its UX can handle retracted text.

04 / 09

Finding the true break-even point

Begin with a no-speculation baseline at several concurrency levels. Speculation that improves a single request may reduce fleet throughput because it spends additional draft compute and expands cache footprint. Compare time to first token, inter-token latency, completed output tokens per second, energy, and cost per accepted token. Run open-loop traffic so queueing remains visible. Segment by temperature and task: deterministic code completion often accepts longer runs than creative writing with high sampling entropy.

Adaptive proposal length can use recent acceptance as a feedback signal. Increase depth when consecutive cycles accept full proposals; shorten it after early rejection. Add bounds to prevent oscillation and reset history when context changes sharply, such as after a tool result. More advanced policies predict acceptance from target confidence or draft-target divergence, but their overhead must be included. A tiny controller that avoids obviously bad eight-token proposals may outperform a sophisticated predictor that adds synchronization to every cycle.

Deploy speculation behind a request-level feature flag and preserve the exact ordinary decoding path as a fallback. Automatically disable it when acceptance falls below a sustained threshold, memory pressure rises, or the paired draft is unavailable. Log enough metadata to reproduce distribution settings without storing sensitive prompts. The strongest production result is not a maximum laboratory speedup; it is a bounded improvement that survives mixed traffic, model updates, adapters, and failure recovery without changing the target model’s output contract.

05 / 09

Research foundation and scope

Speculative decoding uses a cheaper model to propose several tokens and the target model to verify them in parallel. The original acceptance-and-correction algorithm preserves the target sampling distribution when logits processing is identical [SPEC]. These sources establish the mechanism, but they do not remove the need to measure the local implementation. A paper's result belongs to its checkpoint, dataset, hardware, traffic, and experimental protocol; a standard describes a contract or risk practice, not a guarantee that a particular product follows it. The useful engineering move is to convert each cited idea into a hypothesis that can be falsified with representative inputs and observable intermediate state.

Speedup is not guaranteed. Draft latency, target verification shape, draft KV memory, acceptance probability, temperature, tokenizer alignment, and fleet concurrency jointly determine whether speculation saves wall time. Write these conditions into the design review before selecting a library or provider. Specify the authoritative source of truth, the authenticated principal, the versions that influence behavior, the maximum consequence of an error, and what the system will do when required evidence is missing. This boundary statement makes later optimization honest: teams can compare speed, cost, or convenience only after candidates satisfy the same correctness, authorization, privacy, and recovery contract.

Read [SPEC], [VLLM], [FLASH] together rather than treating one source as a recipe. Fast Inference from Transformers via Speculative Decoding supplies one part of the foundation; Efficient Memory Management for Large Language Model Serving with PagedAttention supplies a second perspective; FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness helps connect the mechanism to evaluation, governance, or operations. The citations are deliberately primary papers, standards, or official documentation. Product-specific claims still require local evidence, and any dated behavior must be rechecked against the cited version before an article or architecture decision is refreshed.

06 / 09

A production implementation blueprint

Version draft and target as a pair, apply the same grammar and sampling transforms, append only accepted target state, and emit only verified tokens. Let the scheduler adapt proposal depth by recent accepted progress without starving difficult sequences. Begin with one thin vertical path that preserves all decision evidence. Give each run a stable identifier; capture normalized input, authenticated scope, relevant dependency versions, selected policy, timing, result status, and any external receipt. Keep large or sensitive payloads in a separately governed store and pass bounded references through the orchestration layer. This produces a debuggable system without making raw customer content the default telemetry substrate.

Make state transitions explicit and make every external boundary return a typed result. Distinguish validation failure, permission denial, missing evidence, rate limit, timeout, dependency outage, user cancellation, and internal defect. The distinction matters because each permits a different response: clarify, retry, fall back, defer, compensate, or stop. A generic exception handler that asks the model to try again turns uncertainty into repeated cost and can duplicate irreversible effects. Retries require an idempotency strategy and a stored receipt, not optimism.

Roll out the implementation as a versioned policy. Record which cohort receives it, what baseline it replaces, which metrics can stop the rollout, and how to reverse stateful artifacts such as indexes, caches, adapters, or workflow histories. Review privacy and retention alongside performance. If raw content is needed temporarily for diagnosis, state the purpose, access, sampling, encryption, and deletion window. Production readiness means the team can explain, contain, and reverse behavior under load—not merely demonstrate the happy path once.

07 / 09

Failure lab and evaluation plan

Compare ordinary decode against several proposal depths at low and high concurrency. Slice accepted tokens per target pass by task, language, temperature, adapter, and response position, and charge draft work and cache memory to the comparison. Keep the arrival pattern, data distribution, authorization, and dependency versions close to production. Use a paired baseline where possible and retain per-case results so averages cannot hide a severe slice. Offline evaluation should localize the failing stage; shadow evaluation should expose integration and traffic effects; a canary should confirm user-facing outcomes with a small blast radius. Each stage needs an exit criterion rather than a vague request to 'look good.'

Force an early rejection, target timeout, draft outage, cancellation between proposal and verification, adapter mismatch, and a grammar mask that eliminates a proposed token. Verify rollback of both token state and KV pages. Add adversarial boundary cases and partial failures, not only malformed inputs. Terminate a worker after an external system may have committed, revoke access after a cache was populated, change one dependency version, and delay one branch until its data is stale. Confirm that cancellation releases resources and that a fallback preserves semantics. The test passes only when the external outcome, audit evidence, and user-visible state agree; a fluent final message is not proof of completion.

Evaluation data needs lineage equal to production data. Record why each case exists, who reviewed the expected behavior, which source or policy supports it, and when it must be refreshed. Separate generated cases from production incidents and prevent test cases from leaking into training. When a metric changes, inspect changed examples before accepting an aggregate. A statistically small regression can still block release if it crosses an authorization, privacy, safety, or irreversible-action boundary.

08 / 09

Operating metrics and decision record

Report accepted-prefix length, full-proposal acceptance, correction rate, draft and verification time, target passes per emitted token, inter-token latency, memory per sequence, energy, and fleet output throughput. Define every metric with a numerator, denominator, unit, time window, exclusions, and responsible owner. Segment by workload and consequence so a dominant easy class cannot hide a rare costly failure. Pair service signals with product outcomes: latency without completion encourages fast useless answers, while answer quality without queue and cost data can produce an uneconomic service. Review percentiles and distributions rather than relying on a single average.

Enable speculation only for segments whose target passes and latency fall after all draft costs are included, with automatic fallback when acceptance or memory headroom deteriorates. Put that choice in a short architecture decision record containing context, alternatives, evidence, assumptions, selected policy, rollout, reversal trigger, and unresolved risk. Link the evaluation snapshot and source versions. This document prevents a benchmark from becoming folklore and tells the next engineer which evidence must be repeated when the model, provider, traffic, data, regulation, or product promise changes.

Monitor leading and lagging signals after release. Leading signals reveal pressure—queue age, cache allocation, disagreement, validation failure, policy denial, or retry growth—before users report harm. Lagging signals show whether the job was actually completed and trusted. Alert on a service objective tied to user consequence, and make the run identifier available to support without exposing private content. Every serious miss should become a reproducible regression case and, when relevant, a new threat or data-quality control.

09 / 09

Primary sources and further reading

  1. Fast Inference from Transformers via Speculative DecodingOriginal research paper · paper
  2. Efficient Memory Management for Large Language Model Serving with PagedAttentionOriginal research paper · paper
  3. FlashAttention: Fast and Memory-Efficient Exact Attention with IO-AwarenessOriginal research paper · paper

Written by

Vishal RajpurohitCo-founder & CTO, ViitorCloud

Co-founder & CTO of ViitorCloud · Founder of LaraCopilot · Organizer of Laracon India · Shipping production software since 2005

More about Vishal