โ† All posts

Speculative Decoding

Speculative Decoding

Speculative decoding speeds up LLM generation by exploiting a key asymmetry: ๐˜๐—ผ๐—ธ๐—ฒ๐—ป ๐—ด๐—ฒ๐—ป๐—ฒ๐—ฟ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ถ๐˜€ ๐˜€๐—ฒ๐—พ๐˜‚๐—ฒ๐—ป๐˜๐—ถ๐—ฎ๐—น, ๐—ฏ๐˜‚๐˜ ๐˜๐—ผ๐—ธ๐—ฒ๐—ป ๐˜ƒ๐—ฒ๐—ฟ๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ถ๐˜€ ๐—ฝ๐—ฎ๐—ฟ๐—ฎ๐—น๐—น๐—ฒ๐—น.

  • ๐— ๐—ฎ๐—ถ๐—ป ๐—ฏ๐—ผ๐˜๐˜๐—น๐—ฒ๐—ป๐—ฒ๐—ฐ๐—ธ: Standard autoregressive decoding is memory-bandwidth bound. Each new token requires another full pass over the model weights in HBM, so GPUs spend much of their time waiting on memory rather than doing math.
  • ๐—–๐—ผ๐—ฟ๐—ฒ ๐—ถ๐—ฑ๐—ฒ๐—ฎ: Use a cheap draft proposer to guess several future tokens, then have the large target model verify them all at once in a single parallel forward pass.
  • ๐—›๐—ผ๐˜„ ๐—ถ๐˜ ๐˜„๐—ผ๐—ฟ๐—ธ๐˜€: The draft model proposes K tokens; the target model checks them left-to-right, accepts matching tokens, and replaces any mismatch with a token sampled from the target distribution.
  • ๐—ช๐—ต๐˜† ๐—ถ๐˜โ€™๐˜€ ๐—น๐—ผ๐˜€๐˜€๐—น๐—ฒ๐˜€๐˜€: With modified rejection sampling, the final output distribution is identical to sampling from the target model alone, so quality is preserved exactly.
  • ๐——๐—ฟ๐—ฎ๐—ณ๐˜ ๐—บ๐—ฒ๐—ฐ๐—ต๐—ฎ๐—ป๐—ถ๐˜€๐—บ๐˜€:
  1. ๐—ฆ๐—บ๐—ฎ๐—น๐—น ๐—ฑ๐—ฟ๐—ฎ๐—ณ๐˜ ๐—บ๐—ผ๐—ฑ๐—ฒ๐—น + ๐—น๐—ฎ๐—ฟ๐—ด๐—ฒ ๐˜๐—ฎ๐—ฟ๐—ด๐—ฒ๐˜ ๐—บ๐—ผ๐—ฑ๐—ฒ๐—น โ€” good accuracy, but extra VRAM.
  2. ๐—ฃ๐—ฟ๐—ผ๐—บ๐—ฝ๐˜ ๐—น๐—ผ๐—ผ๐—ธ๐˜‚๐—ฝ / ๐—ป-๐—ด๐—ฟ๐—ฎ๐—บ ๐—บ๐—ฎ๐˜๐—ฐ๐—ต๐—ถ๐—ป๐—ด โ€” no extra model, very fast, best when output overlaps with context (๐—ฒ.๐—ด., ๐—ฅ๐—”๐—š).
  3. ๐—ฆ๐—ฒ๐—น๐—ณ-๐˜€๐—ฝ๐—ฒ๐—ฐ๐˜‚๐—น๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ต๐—ฒ๐—ฎ๐—ฑ๐˜€ โ€” extra heads on the target model predict future tokens without a separate draft model.
  • ๐—ฃ๐—ฟ๐—ผ๐—ฑ๐˜‚๐—ฐ๐˜๐—ถ๐—ผ๐—ป ๐˜๐—ฟ๐—ฎ๐—ฑ๐—ฒ-๐—ผ๐—ณ๐—ณ:
  • At ๐—น๐—ผ๐˜„ ๐—ค๐—ฃ๐—ฆ, speculative decoding usually helps a lot because GPUs have idle compute.
  • At ๐—ต๐—ถ๐—ด๐—ต ๐—ค๐—ฃ๐—ฆ, it can hurt latency because the system is already compute-saturated, so extra verification adds overhead.
  • ๐—ฃ๐—ฟ๐—ฎ๐—ฐ๐˜๐—ถ๐—ฐ๐—ฎ๐—น ๐˜๐—ฟ๐—ฒ๐—ป๐—ฑ: Modern systems use ๐—ฑ๐˜†๐—ป๐—ฎ๐—บ๐—ถ๐—ฐ ๐˜€๐—ฝ๐—ฒ๐—ฐ๐˜‚๐—น๐—ฎ๐˜๐—ถ๐—ผ๐—ป, adjusting speculative length based on current load.

Speculative decoding trades a little extra draft work for fewer expensive target-model passes, giving substantial latency gains when the GPU is memory-bound and underutilized.

Originally published on LinkedIn.

Turn your expertise into LinkedIn posts like this one.

Try Postars free โ†’
Speculative Decoding โ€” Postars