Accept each proposed token with its actual probability ratio
Derive the retained proposal mass under min(1, p/q), handle zero support correctly, and distinguish exact acceptance from heuristic confidence thresholds.
On this page
The question for today
What you’ll understand
- Compute acceptance only for tokens the proposal distribution can generate.
- Explain why the retained mass is the overlap min(p, q).
- State the probability and numerical assumptions of the acceptance test.
The draft proposes a token more often than the target would. Accepting every such proposal would overrepresent that token, while always rejecting disagreements with the target argmax would implement another distribution. The exact stochastic rule retains a proposed token with probability min(1, p/q), using the target and actual proposal probabilities at the same history. This controls retained mass. A subsequent residual correction supplies what the retained proposals do not cover, which is why acceptance cannot be evaluated in isolation from the full algorithm.
Define the ratio only where a proposal can occur
Let p and q be normalized nonnegative distributions on one finite vocabulary at a fixed prefix. Draw X from q and an independent uniform random variable U for the test. For every possible proposal with q(X)>0, accept when U is below min(1, p(X)/q(X)), using a consistent endpoint convention. The continuous uniform ideal makes endpoint equality probability zero. If p(X)=0 while q(X)>0, acceptance is zero. If p(X) is at least q(X), acceptance is one. The proposal denominator is the probability actually used to draw X, not a raw logit or another temperature's softmax.
Tokens with q(x)=0 cannot be drawn by the ideal proposal sampler, so no division by zero is needed for them. They can still have positive target probability and must remain reachable through the full correction procedure. The algorithm does not require draft support to contain all target support when the residual is implemented correctly. If an implementation nevertheless presents a zero-q token as a sampled proposal, investigate inconsistent distributions, masking, or numerical behavior. Assigning an arbitrary acceptance value to a 0/0 expression is not part of the proof and can conceal that inconsistency.
The retained mass is exactly the overlap
The chance that token x is both proposed and accepted is q(x)a(x)=min(p(x), q(x)) when q(x)>0, and is zero for q(x)=0. Summing gives the overall one-position acceptance probability α. It equals one minus the total variation distance between the two finite distributions. This is distributional overlap, not the fraction of tokens whose argmax labels agree, a perplexity guarantee, or the number of semantically acceptable answers. A smaller draft can have useful overlap without predicting the target's most likely token at every history.
The overlap calculation must use the same conditioning state and declared decoding transforms on which the test relies. Sampling q after top-k truncation but dividing by an untruncated q changes the proposed-and-retained mass. Likewise, accepting any token whose target probability exceeds a fixed threshold is generally another law. Such heuristics can be deliberate approximate decoding choices, but they need their own quality and distributional evaluation and must not borrow the exact rule's proof. Keep proposal generation, probability collection, verification, and fallback paths versioned together.
Treat finite arithmetic and randomness as implementation conditions
A practical sampler uses finite precision and a pseudorandom generator, while the algebra describes exact probabilities and conditionally independent random draws. Compare log probabilities or otherwise use numerically appropriate arithmetic without silently modifying the mathematical rule. Underflow, inconsistent normalization, or a wrong mask can turn a positive probability into an apparent zero. Pin the target, draft, processors, dtype, and backend when validating behavior. Transformers 4.56.2 implements proposal-ratio checks in its speculative sampling path, but that concrete floating-point implementation still needs tests of its supported models and decoding configuration.
The probability lab shows one conditional acceptance event. Reset, set both the lab's success probability p=0.6 and n=1, predict the acceptance and rejection bars, then inspect. They carry masses 0.6 and 0.4 for a hypothetical already-proposed token whose target/proposal ratio is 0.6. This is not the entire vocabulary calculation and no random draws or language-model verification occur. Use the display to separate a conditional token acceptance probability from the total acceptance α, which additionally averages over which token q proposes.
Work it through
Compute conditional tests and total retained mass
At one fictional history, target probabilities for A, B, C are(0.5, 0.3, 0.2) and proposal probabilities are(0.2, 0.5, 0.3). Both vectors are normalized.
Conditional acceptance probabilities are 1 for A, 0.3/0.5=0.6 for B, and 0.2/0.3=2/3 for C.
Multiply by proposal probabilities to obtain accepted masses(0.2, 0.3, 0.2). Their sum gives overall acceptance α=0.7.
The remaining probability 0.3 requires the correct residual branch. Accepting every draft token or averaging the three acceptance numbers without q weights would not yield the target law.
The conditional tests differ by token, and their proposal-weighted acceptance is 70%. Retained masses alone are not the final target distribution.
The living notebook
Explore the model
Interactive lab · probability
Separate conditional acceptance from total overlap
Reset, set both lab success p=0.6 and n=1, predict, then inspect. The Bernoulli bars are 0.6 acceptance and 0.4 rejection for one stipulated proposed token. This exact probability display does not evaluate p/q, sample tokens, or model a whole speculative round.
- Mean · np
- 5
- Variance · np(1−p)
- 2.5
- Total probability
- 1
These are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forTotal acceptance averages conditional tests over the actual proposal distribution. The vocabulary probabilities and residual branch still need explicit calculation.
Pause & reason
Check your understanding
Your turn
Try it yourself
For target(0.4, 0.6) and proposal(0.8, 0.2), compute both conditional acceptance probabilities and their total proposal-weighted acceptance.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Apply min(1, p/q) and then multiply each result by its proposal mass.
Compare with the solution
The conditional acceptances are 0.5 and 1. Their retained masses are 0.8×0.5=0.4 and 0.2×1=0.2, totalingα=0.6. The remaining 0.4 is handled by correction; it is not permission to substitute any convenient fallback.
Keep the idea
Take it with you
- Use actual normalized proposal probabilities at the matching history.
- Retained proposal mass equals min(p, q), with support-zero cases handled explicitly.
- Exact arithmetic and conditional randomness assumptions do not validate arbitrary heuristic acceptance.
Read further
Original sources and deeper explanations to follow at your own pace.
- Leviathan et al.: Fast Inference from Transformers via Speculative Decoding, v 2
- Chen et al.: Accelerating Large Language Model Decoding with Speculative Sampling
- Transformers 4.56.2: Assisted Generation and Speculative Sampling Implementation
- Transformers 4.56.2: Generation Strategies and Assisted Decoding
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.