← All questions
Inference & ServingHard· Speculative Decoding· Sampling· Probability Theory

How do you guarantee the output is drawn from the targe...

To ensure the final output is statistically identical to the target model’s distribution, speculative decoding employs a rejection sampling scheme. When a token is proposed by the draft model (q) and evaluated by the target model (p), the acceptance probability is set to min(1, q/p). If a token is rejected, the system samples from a residual distribution defined by the normalized difference between the target and draft probabilities. This mathematical correction guarantees that the resulting samples are unbiased.

Code playground (Python)