Speculative Sampling (Probabilistic)

hard
Unit 25 · Inference III0/0 to milestone

Greedy speculative decoding only works for argmax decoding. Speculative sampling keeps the exact output distribution of the big model when sampling. For each drafted token xx, with draft probability q(x)q(x) and target probability p(x)p(x):

Pro problem

Unlock this and every premium problem across all tracks — plus hidden-test grading, advanced AI engineering modules and new content every week.

Start 7-day free trial
How LLMs Work· 19 of 19
solution.py · Python 3.13
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Speculative Sampling (Probabilistic) · TechGradify