Speculative Decoding

Layer 2 · Mechanics

Speculative Decoding

The accept/reject mechanics that make speculative decoding exactly lossless.

8 min read70 XP

  1. Draft model samples k tokens

    fast, sequential, cheap

  2. Target model scores all k+1 positions

    one parallel forward pass

  3. Accept/reject each draft token

    using probability ratio

  4. Resample at first rejection

    from a corrected distribution

One speculative decoding round.

Let the draft model's distribution at position be and the target model's be . For each drafted token , accept it with probability . If accepted, move to the next drafted token. If rejected, discard the rest of the draft and sample a replacement token from a corrected 'leftover' distribution instead of from directly.

Go deeper: L3 Code