In speculative decoding, a draft model proposes tokens and each is accepted independently with probability . How do you derive the expected number of tokens produced per target-model forward pass, what is its value for and , and what is the expected speedup if one draft forward pass costs of a target forward pass?
Sequence models and transformers, Inference
Level L3 Intermediate. Length Medium. Nature Mat Mathematical.
What's being asked
Whether you can derive the expected accepted-token formula for speculative decoding, fold in draft-model overhead to compute wall-clock speedup, and explain why the output distribution stays exact.
Key idea
A target forward pass verifies all drafted tokens in parallel and emits at least token (if the first draft token is rejected) up to tokens (if all are accepted, plus one bonus token). Summing the survival probabilities gives , and dividing by the relative iteration cost gives the expected speedup.
Steps
- Count tokens emitted per target forward pass: let be the number of tokens produced in one iteration. If the first drafted tokens are accepted and token is rejected, the target model replaces token and emits tokens; if all are accepted, the target model also emits one bonus token from its next-step distribution, giving .
- Derive : token (for ) is emitted if and only if the first drafted tokens were all accepted, which has probability . Summing the tail probabilities gives a finite geometric series:
- Compute for and :
- Include the draft cost : running sequential draft forward passes followed by parallel target verification pass costs target-equivalent forward passes (assuming memory-bandwidth-bound verification of tokens takes about the same time as target forward pass). Standard decoding produces token per target pass, so the expected speedup is For , and : , so
- Explain exactness and the -versus- trade-off: modified rejection sampling accepts a draft token with probability (where is target and is draft) and, upon rejection, resamples from the normalised positive residual , which preserves identically (proven in the existing acceptance-correctness question). Increasing pushes toward its ceiling while the cost grows linearly, so higher or smaller justifies a larger , whereas low wastes draft compute if is too large.
Common mistakes
- Forgetting the bonus/replacement token emitted by the target model, which shifts the upper limit from to (so even still produces token per target forward pass).
- Confusing with the wall-clock speedup; you must divide by to account for the time spent running the draft model.
- Assuming acceptance rates are truly independent across positions in practice; varies by token and domain, and at large batch sizes verifying tokens in parallel stops being free once the GPU becomes compute-bound.
How long your answer should be
3–4 minutes; derive the geometric sum, compute 3.36 tokens and 2.80× speedup, and briefly explain exactness and choosing k.
Read this
Previous in Sequence models and transformers: Why is autoregressive LLM decoding at batch size memory-bandwidth bound? For a -billion-parameter fp16 model () on a GPU with memory bandwidth and of fp16 compute, what is the upper bound on tokens/s at batch size , what is the arithmetic intensity, and near what batch size does decoding reach the compute ridge point?
Next in Sequence models and transformers: What is the sinusoidal positional encoding, and why is a linear function of ? How do rotary position embeddings (RoPE) make attention scores depend only on relative position?