Have you ever wondered how tools like Chat GPT or Gemini can start answering your question so quickly ?
There are clever tricks that speed up generation and one of them is speculative decoding.
Normally, a language model generates text one token at a time, with each step depending on the previous one.
Speculative decoding adds a smaller, faster draft model.
It proposes several tokens ahead.
Then the larger model checks those proposed tokens together in parallel.
When it guesses match, multiple tokens can be accepted in one verification step.
If a guess diverges, the verification process corrects it.
That can reduce sequential decoding steps and make generation faster depending on the models and hardware and when implemented correctly, it preserves the target model's output distribution.
Small model drafts, large model verifies. That's speculative decoding.