IIntroduction to AI Systems Performance EngineeringTechnical textbook
Chapter 19: Quantization and Speculative Decoding
19.4

Speculative decoding

Explain acceptance and the latency trade

Before you begin

Follow a linked prerequisite when you cannot explain it from memory. Background skills without links are stated as abilities rather than hidden terminology.

  • Autoregressive decode
  • Probability distributions and sampling
  • Batch verification

Ordinary autoregressive generation uses one target-model pass for every new token. On the 7-billion-parameter service, suppose one decode pass takes 25 milliseconds at low load. Generating four tokens therefore needs about four serial target passes before sampling and other overhead. A much smaller draft model can propose four candidate tokens, after which one target pass scores the four proposed positions together.

Add one structured log row per speculative cycle: draft token identifiers, proposal length, draft milliseconds, target-verification milliseconds, number accepted before the first rejection, correction-sampling time, committed tokens, and key-value updates. A cycle that accepts all four candidates can advance several positions. A cycle that rejects the first candidate pays for drafting and verification while advancing only one corrected token. The observed acceptance-position distribution, not one average agreement percentage, determines progress.

Autoregressive decode is serial because token n+1 depends on token n. Speculative decoding does not remove that dependency semantically. The method uses a cheaper draft process to propose several tokens, then asks the target model to score the proposed sequence in a more parallel verification pass. An acceptance rule preserves the target distribution while allowing multiple tokens of progress when proposals agree.

The 2023 speculative-decoding and speculative-sampling papers showed how to preserve the target model distribution while using a cheaper approximation to propose tokens. The speedup comes from reshaping target work: one larger verification operation can use hardware more efficiently than several small serial decode steps. The method adds draft computation, rejected proposals, verification overhead, and cache-management work.

Acceptance rate alone does not determine speed. The required quantity is committed target-distribution tokens per unit wall time under the actual server schedule. Proposal length, draft location, target batch size, temperature, request domain, and cache commit cost all affect it.

Follow one proposal and verification cycle

A draft model or other proposal mechanism generates k candidate tokens autoregressively and records the proposal probabilities needed by the acceptance algorithm. The target model evaluates the candidate positions together. Because the full proposed prefix is known, target logits for several positions can be computed in a more parallel pass than k separate target decode calls.

The acceptance test proceeds from the first proposed position. In classical exact speculative sampling, a token can be accepted according to a probability ratio derived from target and draft distributions. At the first rejection, later draft tokens are not committed, and a correction token is sampled according to the method. If every proposal is accepted, the target can provide an additional token. Greedy variants use a corresponding equality or verification rule.

The previous progress rule is not universal. Tree-based proposals, multiple draft heads, relaxed verification, and other speculative algorithms can expose different numbers of candidate positions and use different commit rules. State the algorithm before defining accepted tokens, bonus tokens, or speedup. Distribution preservation applies only when the selected acceptance and correction rule provides it; an approximate rule requires a separate quality evaluation.

Only the accepted prefix and required target token become visible output. Target and draft KV state must commit the same accepted positions and discard or overwrite speculative suffix state. Cache commit and discard operations must be coordinated with paged blocks, batch membership, cancellation, and any prefix sharing.

Calculate progress and cycle cost

Let P be the number of committed tokens from a cycle. The no-speculation baseline requires approximately P serial target steps. The speculative cycle costs draft time D(k), target verification time V(k), and overhead H for acceptance, sampling, cache commit, and scheduling. An initial speed estimate is P / (D + V + H) when times are normalized to one target step.

For one simple model of classical speculative sampling, assume each draft position has the same conditional acceptance probability alpha and proposal length k. Progress is at least one token and at most k + 1 tokens. Its expectation is 1 + alpha + alpha^2 + ... + alpha^k, which equals (1 - alpha^(k + 1)) / (1 - alpha) when alpha is not one. Real acceptance events are position- and context-dependent, so measure the complete progress distribution instead of fitting every workload to one alpha.

Longer windows increase maximum progress but make more work depend on early proposals. If token two is rejected in an eight-token proposal, later draft generation and much verification work produce no committed progress. A shorter window gives up some maximum progress but can reduce waste and produce a more regular batch shape.

A more accurate draft raises acceptance but can raise D enough to erase the benefit. V(k) is not automatically the cost of one ordinary target decode step: verification has a longer query dimension, writes speculative KV, and can select different kernels or graph variants. Draft and target tokenizers or vocabularies can also complicate verification in some systems. Measure accepted-token count by proposal position, full cycle time, verification shape, draft cost, and commit or rollback bytes. Tune k by workload rather than by one mean acceptance number.

Integrate speculation with concurrent serving

Concurrent requests can have different accepted prefix lengths. After one verification batch, some requests advance one token while others advance several. Variable progress changes fairness, next-iteration membership, KV allocation, and the meaning of a sequence budget. A scheduler may need to budget speculative tokens separately from committed progress.

Draft execution can share the target GPU, use another GPU, run on the CPU, or use an integrated draft head. Sharing one GPU adds competing work but avoids transfer and extra hardware. A separate device can overlap some work but adds communication and cost. The best topology depends on target utilization and batch scale.

Speculation can improve single-request latency but lower server throughput if draft work occupies resources that ordinary batching would use more efficiently. Run open-loop load tests with speculation on and off. Compare TTFT, TPOT distribution, output goodput, draft and target utilization, cache memory, and quality-equivalent outputs.

Worked example: Evaluating a proposal window

A draft proposes four tokens in 0.35 units of target-step time. Verification costs 1.3 target-step units and yields an average of 3.1 accepted-plus-target tokens.

  1. Without speculation, 3.1 tokens require 3.1 serial target steps. The speculative cycle costs about 1.65 units, suggesting an ideal speedup near 1.88× before system overhead.
  2. Include cache commit, sampling, scheduler, and any lost batching efficiency. Measure complete cycle time and progress distribution, not only mean acceptance.
  3. Compare k = 2, 4, and 8 across domains and temperatures. At k = 8, early rejection may make verification and draft waste dominate despite more potential progress.
  4. Under concurrent serving, measure goodput and TPOT tails. Variable acceptance can create uneven iteration work and fairness effects.

Conclusion: The idealized calculation gives 3.1 / 1.65 ≈ 1.88× progress per unit time. The estimate becomes a valid serving result only after cache, scheduler, and batching overhead are included and the same target distribution and service workload are verified.

Common errors

  • Multiplying acceptance rate by window size and calling it speedup. Draft, verification, rollback, and batch effects determine time.
  • Using a draft nearly as expensive as the target because it accepts well. Alignment must be valued against proposal cost.
  • Benchmarking one prompt domain. Acceptance is workload- and sampling-dependent.

Reference summary

A speculative cycle uses a cheaper process to propose several tokens and then evaluates their positions with the target model in a more parallel verification pass. The acceptance and correction rule must preserve the target distribution for the selected decoding algorithm.

Calculate committed progress and complete cycle cost. Draft time, target verification, rejected suffix work, sampling, KV commit, scheduling, and lost ordinary batching all contribute. Under concurrent load, different acceptance lengths also change fairness and cache allocation.

cycle progress P = tokens committed by the algorithm's acceptance and correction rule
For classical exact speculative sampling, P is the accepted draft-prefix length plus a correction or bonus target token, subject to end-of-sequence handling. Other speculative algorithms can use different progress rules.
  • A highly accurate but expensive draft can erase the gain.
  • Long proposal windows increase potential progress and wasted work on early rejection.
  • Batching verification changes kernel shapes and KV writes.
  • Acceptance varies by domain, temperature, prompt, and model pair.
  • Measure E2E latency and throughput under load, not accepted tokens per step alone.

Knowledge check

Why can speculative decoding reduce single-request latency yet reduce server throughput under some loads?

Show the answer guide
  • Speculative decoding lets a small draft model propose several tokens and lets the target model verify them in one pass. With high acceptance and an underloaded server, one target iteration can advance a request by several accepted tokens, reducing serial latency.
  • The server now performs draft-model work plus target verification over multiple proposed positions. Rejected proposals waste some of that work, and cache rollback or correction adds overhead.
  • On a saturated server, ordinary continuous batching can use target compute to advance many independent requests. Large speculative verification batches, draft compute, longer scheduler iterations, and extra KV state can displace those requests and reduce total accepted tokens per second.
  • The trade depends on acceptance length, draft cost, verification efficiency, batch opportunity, and load. Report accepted target tokens and goodput, not proposed tokens or single-request speed alone.
Practice

Find the load where speculation changes sign

Serve one target model with speculative decoding disabled and enabled using draft lengths 2, 4, and 8. Replay the same 1024-token-prompt, 256-token-output workload at isolated request, 50% capacity, and saturation. Record proposed, accepted, rejected, and correction tokens, draft time, verification time, target iterations, scheduler iteration duration, and KV use.

Evidence to keep: Submit the configuration and workload trace, correctness tests showing identical target-distribution semantics, a matrix of per-request latency, accepted tokens per second, goodput, acceptance rate, and GPU time by load and draft length, plus a plot of speedup versus offered load. State the measured mechanism that causes any throughput reversal.

Quantization and speculative decoding enter production only through service objectives, observability, capacity planning, and graceful behavior under overload.

References

Sources and further reading

The lesson explanations synthesize primary papers and official references. Follow the originals for proofs, exact APIs, architecture details, and version-sensitive behavior.

  1. Mixed Precision Training
  2. SmoothQuant
  3. GPTQ
  4. AWQ
  5. Nsight Compute Profiling Guide
  6. Fast Inference from Transformers via Speculative Decoding