Blockwise and Semi-Autoregressive Generation › Speculative Decoding: Exact Stochastic Verification
Language AI HandbookAll chapters The greedy verifier has one reference output for a given prompt and tie-breaking rule. For a sampling decoder, there is a reference distribution over outputs. Leviathan, Kalman, and Matias (2023) give an algorithm that preserves that distribution while still using multiple proposals per target pass.
Exactness means matching the output probability assigned by the baseline sampling policy to every sequence. Two implementations can consume random numbers in different orders. Their outputs with the same seed may differ even when the distributions agree.
The algorithm has four steps.
- Draft. Sample up to tokens autoregressively from the draft distribution within the remaining budget, stopping the draft on a proposed EOS. A latency gain depends on the draft's cost relative to target verification and on how many of its proposals pass.
- Score. Evaluate on the hypothetical prefixes using a batched target pass. For a block of proposals, the last committed position supplies and the logits at draft input supply . The last draft input can supply the distribution for an extra token if the entire block survives and generation can continue.
- Verify with rejection sampling. At each reached proposal , draw an independent . Accept the proposed token if . Both probabilities refer to the same reached prefix.
- Residual repair. If the first rejection happens at position , resample the output token from the residual distribution
Emit the replacement and discard the remaining draft. If every proposal is accepted and generation can continue, sample one extra token from . Apply the baseline's EOS and output-budget rules to the committed tokens.
The acceptance probability uses the actual probability of drawing the proposal from . For a token the draft overweights, the ratio accepts only enough proposals to match the smaller target mass. For a token the draft underweights, the residual supplies the missing probability. A draft with always passes at that position.
Why the Rule Is Exact
Consider a single position with target distribution and draft distribution . The sampler produces by accepting a proposal of or by drawing from the residual after a rejection. The first product below is zero whenever .
The first term simplifies to , because when , and when the term is .
For a concrete example, take target probabilities and proposal probabilities . The first and third proposals always pass. The second passes with probability . It carries proposal mass , so three quarters of that mass, , is already the required target mass. The remaining goes to the rejection branch. A replacement draw assigns it to the first token, the only token whose target mass exceeds its proposal mass.
The rejection probability in general is
Since both and sum to 1, , and that common value is the normalizer of the residual. When , the rejection branch has probability zero and every drawn proposal is accepted. For the two paths give
Rejection mass is also half the sum of the absolute differences . The positive differences and the negative differences have equal total magnitude because both distributions sum to one. This half-sum is total variation distance on the vocabulary. It gives a precise sense in which a better draft can pass more often at a fixed prefix. It also explains why keeping one phrase's top token unchanged can leave a sizable rejection probability when the rest of the distribution shifts.
This identity holds at each reached prefix . Reaching the next check depends on earlier draft tokens and their independent acceptance draws. Conditional on their prefix, the next token still comes from the actual proposal . After rejection, sample the replacement and restore both models to the committed prefix. Applying the resulting target conditional at every position gives the baseline sequence distribution. To compare to an exact top- baseline, must include the baseline's truncation and renormalization at the relevant prefix. The draft can use a different sampling rule. The verifier must use the distribution that actually generated the proposal, expressed over the same token events as .
Expected Tokens per Iteration
Take one speculative iteration that proposes tokens and can emit the extra target token after accepting all of them. Ignore EOS and length stops for this cost calculation. To emit at least tokens, the first proposals have to pass. With independent acceptance events of common probability , the probability for that event is . The expected committed count is the sum of these probabilities:
The first term counts the token guaranteed whenever an iteration can emit. In real decoding, acceptance probabilities can depend on the text and position. You can still sum the probabilities of reaching each accepted prefix length. Raising a single observed average acceptance rate to powers generally fails to estimate those probabilities exactly. For example, take two kinds of request that occur equally often. The first kind would pass both checks and the second kind would fail both checks if scored separately under their respective hypothetical draft prefixes. The chance of getting past both proposals is one half. Multiplying two unconditional per-position probabilities of one half would give one quarter under an independence assumption. The second check is reached only on the first kind of request, so its conditional acceptance rate is one. Pooling the first and reached second checks gives two successes for three checks per pair of requests. The exact expectation uses the probability of each whole accepted prefix, which is one half for lengths one and two in this example.
Each curve corresponds to a draft length. The horizontal axis is the assumed per-proposal acceptance probability. The vertical axis is the expected number of committed tokens from one target pass. At low acceptance, extra draft positions add small higher-power terms.
VisualizationOut [5]Expand

Let be the baseline time for one target token and the time for one draft token. The simulation uses the same cost for full-block verification and for the baseline single-token step, with the draft and verify stages run serially. With fixed costs and long outputs, its predicted speedup is
The numerator is the time the baseline would spend on the expected number of tokens committed by one speculative iteration. The denominator is the cost of that iteration in this simplified model. Real verification time can differ from , and cache rollback, scheduling and synchronization can add costs. Batch-level throughput and the latency seen by each request therefore need separate measurement.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!