In speculative decoding, a small draft model with next-token distribution q proposes a token x∼q, and the large target model with distribution p accepts it with probability min⁡(1,p(x)/q(x)). If it is rejected, a token is drawn from the residual ∝max⁡(0,p−q). Show that the output token is distributed exactly as p. For p=(0.5,0.3,0.2) and q=(0.2,0.5,0.3), find the acceptance probability and the expected number of tokens per target pass when k=4 tokens are drafted?

Sequence models and transformers, Inference
Level L5 Expert. Length Long. Nature Mat Mathematical.

What's being asked

Whether you can prove that rejection sampling with a residual correction gives samples from the target distribution, and turn the acceptance rate into a speed-up estimate.

Key idea

The probability of returning token x is q(x)min⁡(1,p(x)/q(x))+P(reject)⋅max⁡(0,p(x)−q(x))∑ymax⁡(0,p(y)−q(y)). The first term is min⁡(p(x),q(x)), and the residual term supplies exactly the missing mass p(x)−min⁡(p(x),q(x)).

Steps

  1. Accepted branch. Token x is proposed with probability q(x) and accepted with min⁡(1,p/q), so it is output this way with probability min⁡(p(x),q(x)).
  2. Total acceptance probability α=∑xmin⁡(p(x),q(x))=1−12∥p−q∥1, so P(reject)=1−α=∑xmax⁡(0,p(x)−q(x)). This is also the normaliser of the residual.
  3. Rejected branch. The residual density is max⁡(0,p(x)−q(x))/(1−α). Multiplying by P(reject)=1−α cancels the normaliser, leaving max⁡(0,p(x)−q(x)).
  4. Add both branches: min⁡(p,q)+max⁡(0,p−q)=p(x) for every x. So the output is distributed exactly as p.
  5. Numbers. min⁡(p,q)=(0.2,0.3,0.2), so α=0.7. The residual is max⁡(0,p−q)=(0.3,0,0), normalised to (1,0,0). Check token 1: 0.2+0.3×1=0.5. Token 2: 0.3+0=0.3. Token 3: 0.2+0=0.2. These match p.
  6. Tokens per pass. With acceptance probability α per drafted token (assumed independent), the target pass verifies k drafts and always yields at least one token (the first rejection's replacement, or a bonus token if all pass). The expected number is 1−αk+11−α=1−0.750.3=0.83190.3=2.77.
  7. Speed-up is therefore up to 2.77× in target passes, minus the cost of running the draft model k times.

Common mistakes

How long your answer should be

One page; 7–9 minutes.

Last checked on 4 December 2026.

Read this

Previous in Sequence models and transformers: Prove that a transformer encoder layer without positional encodings is permutation-equivariant: permuting the input tokens permutes the outputs in the same way. How do you show that a decoder with a causal mask and no positional encodings is not, and that it can still recover position information?
Next in Sequence models and transformers: none