Part 6 of 6 · What interviewers ask nextLearn and do
Speculative decoding: a small model guesses, the big one checks
Decoding is serial: one pass of the big model per token. Speculative decoding has a small draft model guess the next few tokens, then runs the big model once over all of them.
Predict
The draft guesses 4 tokens, and the big model rejects the 3rd. How many tokens does the round add?
One round of speculative decodingInteractive
→
→
→
→
draft q = x1 x2 x3 x4. The small draft model guesses 4 tokens, one at a time. Each guess is cheap.
Each guess x is accepted with probability min(1,p(x)/q(x)). Here p is the big model's distribution and q the draft's.
The output is distributed exactly as if the big model had sampled alone. Leviathan et al. report 2X to 3X speedups on T5-XXL, with identical outputs.
The tie to the sampler: p and q have to be the distributions you actually sample from, after temperature, top-k and top-p. Leviathan et al. show that argmax, top-k, nucleus and temperature all become plain sampling from an adjusted distribution, and they run the acceptance test on those adjusted distributions. Test acceptance against raw softmaxes while sampling with filters, and the output is no longer the big model's filtered distribution.
In the editor, guesses holds the draft's 4 guesses as (p, q) pairs: the big model's probability of the token, then the draft's. Write accept_prob(p_x, q_x): the chance that the big model accepts one guess. Set rates: that chance for each guess, in order. Set all_kept: the chance that all four are accepted.
Pick an answer above to see the rest
Instructions
1
Write accept_prob(p_x, q_x): the chance that the big model accepts a draft token.
2
Set rates: the chance for each of the draft's 4 guesses, in order.
3
Set all_kept: the chance that all four are accepted.