Unit 7 of 12 · about 5 hours · derive, implement

Draft and target roles, exact acceptance and the correction distribution

The acceptance rule is what makes speculation free performance instead of a quality trade. A wrong rule still produces plausible text, so only the proof protects you.

You'll be able to

  • State the draft and target roles and why verification parallelizes while drafting does not.
  • Derive the acceptance probability and the residual distribution, and prove the output matches the target.
  • Implement exact speculative sampling on tiny distributions and confirm the empirical distribution equals the target.

Covers

Draft and target model rolesExact speculative acceptance probabilityCorrection distribution after rejection
1

Read

In this order, only the parts listed

0 of 3 done

  1. Acceptance, correction and the exactness proofFast Inference from Transformers via Speculative Decoding

    Sections 2.1 to 2.3 (overview, standardized and speculative sampling), Algorithm 1 SpeculativeDecodingStep, and Sections 3.1 and 3.2 with Theorem 3.5 and Corollary 3.6 (acceptance rate as expected overlap)

    Work the proof yourself before reading the appendix. Skip the distributed and cluster sections.

  2. Module 08: the acceptance rule and its proofLLM Inference: From scratch, one token at a time - Module 08

    Concept 02 The acceptance rule, and the proof that nothing changes: the min(1, p/q) rule, the residual formula and the two-case P(emit z) = p(z) derivation, with the naive-rule bias note

    The Concept 02 caveat and the matching Checkpoint question say that sampling parameters applied to the target only lose exactness. They do not: the proof holds for any the draft actually sampled from, so the output follows the processed target and only acceptance drops. Test it in your simulator.

  3. Day 15: the three-step loop in code100 Days of LLM Inference - Days 13, 14 and 15

    Notebook day15/speculative-decoding.ipynb: Concept Overview with the accept formula, and the speculative_decode_step and simulate_acceptance_rate cells

2

Focus on

  • The draft proposes tokens autoregressively with distributions ; the target scores all of them in one causal forward pass, yielding at every position. Verification is parallel because causality makes one pass cover every prefix.
  • Accept draft token with probability . On rejection, sample from the residual normalized by its sum, which exactly equals the rejection probability.
  • The acceptance rate is , or one minus the total variation distance. It depends only on the two distributions, never on the draft implementation.
  • A bad draft costs speed only. The output distribution is the target either way; the naive agree-with-target rule instead biases output toward the draft and looks fine while doing it.
Common mistakes · 3
  • Sampling the replacement from instead of the residual. That double-counts agreed mass and biases output; the residual is the mass wanted that undersupplied.
  • Building the ratio from a the draft did not sample from, such as raw logits when the draft used temperature. Exactness needs the actual draft distribution; processing only the target stays exact but cuts acceptance.
  • Reading acceptance as a property of the draft model. It is a property of the pair on a workload: same draft, new domain or higher temperature, new .
3

Try it yourself

Closed-book, before checking anything

Closed-book, prove in both cases, then work the four-token pair , : accepted masses, rejection probability, residual, and .
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.For the Reproduce pair, what are the accepted masses, the rejection probability and the residual?Answer

    Accepted masses , rejection , residual , and .

  2. 2.Why does sampling the replacement from the residual, not from the target, preserve the distribution?Answer

    The normalizer of the residual equals the rejection probability, so accepted mass plus residual mass sums to in both the and cases.

  3. 3.A run accepts 80 percent of draft tokens. What does that number predict, and what does it not predict?Answer

    It estimates , hence expected yield per verification. It does not predict wall-clock speedup, which also needs draft cost, batch effects and rollback overhead.

  4. 4.The target applies top-p 0.9 and the draft samples its full distribution. Is the output still exact?Answer

    Yes, if the ratio uses the distribution the draft actually sampled from: the proof holds for any . Acceptance drops, since drafts outside the top-p set are always rejected.

5

Practice

  • 100 Days of LLM Inference Day 15: acceptance simulation

    Cells speculative_decode_step and simulate_acceptance_rate: reproduce the Perfect, Good, Medium, Poor and Random rows and confirm simulated yield matches the formula within sampling noise

    The rows are labeled by mixing weight, not , and the step returns no bonus token: compare with using each row's measured mean . Keep this simulation separate from engine evidence.

You're done when

You prove exactness without notes, work the four-token arithmetic by hand, and your simulator matches the target distribution to sampling noise on arbitrary pairs.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 10 more in the section

Also in this section