← Blog/blog/speculative-decoding-agreement-tax

The exact decoding shortcut that burns compute when guesses miss

Large language models generate one token, append it, then run again. That serial loop leaves modern accelerators waiting on memory traffic. Speculative decoding borrows branch prediction from processors: let a cheap draft model guess several tokens, then ask the expensive target model to verify the whole guess in one parallel pass.

A good guess turns one target-model call into several output tokens. A bad guess is discarded. The surprising part of Leviathan, Kalman, and Matias's method is that this shortcut does not approximate the target distribution—the correction step makes it exact.

01

Accept what the target can account for

Let q be the draft's next-token probabilities andp the target's. A proposed token is accepted with probability min(1, p/q). Where the draft assigns too much probability, some proposals are rejected. The replacement is sampled only from the target's leftover mass: max(0, p − q), normalized.

def correction_distribution(target, draft):
    excess = [max(0, p - q) for p, q in zip(target, draft)]
    rejected_mass = sum(excess)
    if rejected_mass <= 1e-15:
        return target[:]
    return [value / rejected_mass for value in excess]

The site runs the tested TypeScript implementation; Python and C++ are faithful translations of the same correction. For the tiny example below, the draft over-proposes token B, so rejected B proposals are corrected to A.

Hand-checkable two-token example. The draft proposes [20%, 80%], while the target is [60%, 40%]. After accept/reject correction, the speculative marginal returns exactly [60%, 40%].

The maximum numerical difference is 1.1e-16. More generally, the chance of accepting a draft token is the overlap Σ min(p, q)—one minus total-variation distance. Exactness holds even for a terrible draft; usefulness does not.

02

Agreement buys serial tokens

If the average acceptance rate is α and the draft proposesγ tokens, one target pass emits an expected1 + α + α² + … + αγ tokens. The paper's wall-time model divides that gain by 1 + γc, where c is one draft step's latency relative to one target step.

lookahead 3lookahead 5lookahead 7
Paper equation evaluated from the core module. Each curve assumes a draft step costs 5% of a target step. Longer lookahead wins only when guesses survive far enough to repay drafting them.
03

The speedup spends arithmetic

Here is the buried bill. Verification evaluates several target positions concurrently. When an early guess fails, later work is wasted. With five guesses and negligible draft arithmetic, low agreement can use almost five times the operations per emitted token even while reducing serial target calls.

Expected target-operation multiplier for lookahead 5, computed from the paper's equation with draft operations excluded. Lower acceptance wastes more parallel verification work.
04

What the paper measured

TaskSamplingDraft modelαWall time
English→GermanargmaxT5-small (77M)0.753.4×
English→Germantemperature 1T5-small (77M)0.622.6×
CNN/DailyMailargmaxT5-small (77M)0.653.1×
CNN/DailyMailtemperature 1T5-small (77M)0.532.3×
Paper-reported T5-XXL results at batch size 1 on one TPU-v4. Argmax is deterministic decoding; temperature 1 samples from the full adjusted distribution.

These are implementation- and hardware-specific measurements, not our analytical chart. The authors used existing checkpoints and found draft acceptance between 0.53 and 0.75 in the four highlighted T5-small runs. In our deliberately mismatched two-token example it is 60%.

05

What I would probe next

  • Choose lookahead per token instead of fixing it for a whole run.
  • Measure energy and throughput, not latency alone.
  • Stress acceptance after domain, language, and temperature shifts.

To inspect the autoregressive target and its key-value cache mechanics, poke at the interactive transformer page.

References

  1. Yaniv Leviathan, Matan Kalman, Yossi Matias (2023). Fast Inference from Transformers via Speculative Decoding. ICML 2023, PMLR 202
  2. Charlie Chen, Sebastian Borgeaud, Geoffrey Irving, Jean-Baptiste Lespiau, Laurent Sifre, John Jumper (2023). Accelerating Large Language Model Decoding with Speculative Sampling. arXiv:2302.01318