Let a small model guess the next 7 tokens, and let the big model check all 7 in one pass. For T5-XXL (11B) with a 77M draft, each guess survives 75% of the time. So one check yields 3.60 tokens on average, and the text is exactly what the 11B alone would write. Measured: 3.4 times faster.
Pick a draft model and press Race. Then we build, piece by piece, what makes long chains of thought affordable. That means the draft-and-check rule, stale data in RL, on-policy distillation, longer windows, and when more thinking pays.
You need a little Python, what a probability is and what a language model does (Lectures 7 and 12). We build the rest from zero.
Lecture 13, "Reasoning 2", of Stanford CS224N, Natural Language Processing with Deep Learning (Winter 2026, Diyi Yang and Yejin Choi; this lecture’s slides are Yejin Choi’s). Its readings are Let’s Verify Step by Step (Lightman et al., 2023), speculative decoding (Leviathan et al., 2023), compute-optimal test-time scaling (Snell et al., 2024) and RoFormer (Su et al., 2021). Before: Lecture 12, Reasoning 1. Next: Lecture 14, Tokenization and Multilinguality.
Acceptance α and draft cost c are Table 4 of Leviathan et al. (2023): T5-XXL translating English to German with argmax decoding. The measured speedups, 3.4, 2.8 and 1.7 times, are their Table 2. The race draws each guess’s fate at random with chance α, so one run varies; the read-out gives the average. The German sentence is a stand-in.
Chapter 0
Price one long chain of thought in time and in context, and see the four bills this lecture pays
A reasoning model answers a hard maths question by writing first. It tries an approach, checks it and backtracks, often for thousands of tokens. Lecture 12 showed how reinforcement learning teaches a model to write such chains. This lecture is about paying for them.
The warm tape is the chain the model writes. Drag its length. The pink bar is the least time it takes; the grey ruler is a 4,096-token context window.
Illustrative lower bound. A 70B model in 16-bit numbers is 140 GB. An H100 SXM reads memory at 3.35 TB/s (NVIDIA’s datasheet). We count only reading the weights once per token at batch size 1, on one GPU’s bandwidth.
Why is each token so slow? To write one token, the model runs one forward pass: every weight takes part once. At batch size 1, the GPU spends that pass waiting for weights to arrive from memory. It does little arithmetic on each one. So decoding is memory-bound: the speed of memory, not of arithmetic, sets the pace.
With numbers: 70 billion weights at 2 bytes each are 140 GB. At 3.35 TB per second, reading them takes 140 / 3,350 = 0.0418 s. That is 41.8 ms per token at the least. A 10,000-token chain then takes 418 s, about 7 minutes.
The lecture pays four bills. Time: make one big pass write several tokens. Training: RL needs fresh samples, but long chains are slow to sample. Room: the chain and its documents must fit in the context window. Payoff: spend extra thinking only where it helps.
Symptom: a reasoning model takes minutes for one answer.
Measure: tokens per second at batch size 1, against the weight-reading bound of one token per 41.8 ms.
Fix: get more than one token out of each big pass (Chapter 1).
Chapter 1
Let a small model guess several tokens, check them all in one big pass, and keep each guess by a coin flip
Not every token is hard. After "dogs love chasing", a small model guesses "after" about as well as a big one. Two teams proposed the same trick independently: Leviathan et al. at Google Research (November 2022) and Chen et al. at DeepMind (February 2023). It is called speculative decoding.
A small draft model writes γ guesses, one by one. It is fast. The big target model then runs once over all γ positions in parallel. That pass costs about as much as a pass for one token, because the time goes into reading the weights. Now the target has a probability for every guess.
Walk the guesses left to right. For a guess x, call the draft’s probability of it q(x). Call the target’s probability of the same token, after the same prefix, p(x). Keep the guess with this chance:
The chance to accept x equals the minimum of one and p of x over q of x.
If the target likes x at least as much as the draft did, p(x) ≥ q(x), keep it. If the draft was overconfident, keep x only with chance p(x)/q(x). At the first rejection, stop and draw one token from the target instead.
The slides’ example: for "chasing" the draft gave q = 0.9 and the target p = 0.8. Keep it with chance 0.8 / 0.9 = 0.889. For "after", q = 0.8 and p = 0.3: keep it with chance 0.3 / 0.8 = 0.375.
Each warm word is a guess, with the draft’s q and the target’s p under it. The blue bar is its keep chance, min(1, p/q). The thin line is a random draw u: the guess stays if u lands inside the bar. Press Check all.
The five words and both rows of probabilities are the lecture slides’ example (a 1B draft, a 100B target). The replacement word and the bonus token are our stand-ins.
The target likes the first two guesses more than the draft did, so both always stay. The third survives with chance 0.889 and the fourth with 0.375. All four survive together with 0.889 × 0.375 = 0.333, and the fifth then always stays. On average 3.56 of the 5 guesses survive. With one token from the target at the end, one big pass writes 4.56 tokens.
Symptom: the target rejects almost every draft at its first token, and decoding gets slower.
Measure: the acceptance rate α, the average chance a guess survives.
Fix: a draft trained on similar data with the same tokenizer. The lecture notes newer methods that align different tokenizers.
Chapter 2
Draw the replacement from the target’s leftover probability, and the two paths add up to p
Speculative decoding is not an approximation. Every token comes out with exactly the target’s probability p. The trick is where the replacement comes from after a rejection.
A token x can come out by two paths. Path one: the draft proposes x and we keep it. That happens with chance q(x) × min(1, p(x)/q(x)) = min(p(x), q(x)). Add this up over all tokens and you get α, the chance that a guess survives. Path two: a rejection, with chance 1 − α, followed by a draw from a residual distribution. Call it p′(x):
p-prime of x equals the maximum of zero and p of x minus q of x, divided by the sum over all tokens x-prime of the same maximum.
For each token, see how much more the target likes it than the draft does, p(x) − q(x). Drop the tokens where the draft already gives too much. Scale the rest to add up to 1. That is p′(x): it refills exactly the probability the draft missed.
With made-up numbers on four tokens A, B, C, D: p = 0.45, 0.30, 0.15, 0.10 and q = 0.25, 0.20, 0.40, 0.15. The gaps are 0.20, 0.10, 0, 0, so p′ = 0.667, 0.333, 0, 0. Token A: kept 0.25, plus 0.30 × 0.667 = 0.20 from the residual: 0.45, its target value.
In general: min(p, q) + max(0, p − q) = p, for every token. Path one gives the first term. Path two gives (1 − α) × p′(x), which is the second term.
Filled blue bars are the target’s p, outlined bars the draft’s q. The pink ticks are how often each token came out of draft-and-check. Pick a draft, then add draws.
Illustrative toy with a four-token vocabulary; the probabilities are ours. The sampler runs the real rule: draft from q, keep with min(1, p/q), else draw from p′.
Symptom: text from the speculative path reads differently from the target’s own samples.
Measure: token frequencies of both paths on the same prompts.
Fix: apply the same temperature and top-p to p and to q before the keep test. A mismatch breaks the guarantee.
Chapter 3
Count the tokens one check yields, charge the draft’s cost, and find the best number of guesses
How many tokens does one big pass give? Assume each guess survives with the same chance α, independently. The pass yields the run of kept guesses plus one token from the target. With γ guesses, the run stops at the first rejection or after all γ.
The draft is not free. Call the time of one draft pass, measured in big passes, c. One cycle then takes γc + 1 big passes of time. Divide the tokens per cycle by that time:
The speedup equals one minus alpha to the gamma plus one, divided by one minus alpha, times gamma c plus one.
The top over 1 − α is the average number of tokens per cycle: 1 + α + α² + … up to α to the γ. The bottom charges γ draft passes at c each, plus one target pass. Tokens per unit of time is the speedup.
From Leviathan et al.’s Table 4, T5-small drafting for T5-XXL: α = 0.75, c = 0.02, γ = 7. Tokens per cycle: (1 − 0.758) / 0.25 = 3.60. Time per cycle: 7 × 0.02 + 1 = 1.14. Speedup: 3.60 / 1.14 = 3.16. They measured 3.4.
The pink curve is the speedup for each γ; the dot is your γ. Start from a row of the paper’s table, then move the sliders.
The chips load α, c and γ from Table 4 of Leviathan et al. (T5-XXL, English to German) and show their measured speedup from Table 2. The formula assumes every guess survives independently with the same α; real text is burstier.
A bigger draft agrees more but costs more. T5-large has α = 0.82 and 4.42 tokens per cycle, but c = 0.11 makes a cycle cost 1.77 passes: 2.50 in theory and 1.7 measured. The 77M T5-small wins. On a 70B model, Chen et al. report 2 to 2.5 times with a 4B draft.
The lecture lists newer drafters, all supported by vLLM or SGLang. Medusa adds extra heads to the target that guess tokens further ahead. EAGLE-3 drafts from the target’s own hidden features. SuffixDecoding uses no model: it matches the current text against a suffix tree of earlier text. That suits repetitive agent loops.
Symptom: decoding with a draft is slower than without.
Measure: α and c on your own traffic.
Fix: a smaller draft or fewer guesses. Each extra guess costs c but survives only with chance α to the k.
Chapter 4
See why fast RL systems train on samples from older weights, and measure how much those samples still count
RL for reasoning works in rounds. The model writes answers, called rollouts; a checker scores them; the trainer updates the weights. With chains of thousands of tokens, writing the rollouts takes most of the time. So fast systems run generation and training at the same time, often on separate GPUs.
The lecture names two splits. Online RL keeps interacting with the task during training; offline RL learns from a fixed log. On-policy RL trains only on rollouts from the current weights, as REINFORCE, PPO and GRPO assume. Off-policy RL trains on rollouts from any policy, such as older weights.
Asynchronous RL is online but off-policy. By the time a rollout reaches the trainer, the weights have moved a few steps. PipelineRL (Piché et al., 2025) even swaps in new weights halfway through a rollout. This gap is off-policy drift.
The repair weights each rollout. Call the current policy π and the older policy that wrote rollout i μ. The importance weight wi = π(yi) / μ(yi) says how much more likely the new weights make that answer. For a chain, it multiplies one ratio per token. How much do N weighted rollouts still count?
E-S-S equals the square of the sum over i of w-i, divided by N times the sum over i of w-i squared.
Add the weights wi and square the total. Divide by N times the sum of the squared weights. If all weights are equal, ESS is 1. If one weight dwarfs the rest, ESS falls to about 1/N: one rollout decides the update.
With made-up weights for N = 4 rollouts: 2.0, 0.5, 0.5 and 1.0. The sum is 4.0, squared 16. The squares add to 5.5. ESS = 16 / (4 × 5.5) = 0.727: the four rollouts count like 2.9.
Each teal bar is one rollout; its blue cap is its weight, on a log scale around 1. Make the rollouts staler or the chains longer, and watch a few weights take over.
Illustrative toy. Each token’s log ratio is random with a spread of 0.004 per step of staleness, independent across tokens. Real ratios move together, but the trend holds: products of thousands of ratios spread wide. ESS uses 2,000 rollouts; the chart shows 48.
PPO and GRPO weight each token by its own ratio and clip it to a band such as 0.8 to 1.2. That trades a little bias for far less noise. Asynchronous RLHF trained a LLaMA 3.1 8B chatbot about 40% faster with the same final score (Noukhovitch et al., 2025). PipelineRL reports about 2 times faster learning.
Symptom: reward climbs, then training blows up or the model starts to exploit the checker.
Measure: ESS of each batch, or the share of token ratios that hit the clip.
Fix: the lecture’s list: PPO clipping, a KL penalty to a reference model, fewer passes over each batch, and fresher weights through in-flight updates.
Chapter 5
Let the student write and the teacher grade every token, with a loss that rewards one good mode over a blur
To make a small model reason like a big one, distill: train the small student to match the big teacher. The old way trains on the teacher’s text. At test time the student reads its own text, mistakes included, and it never practised recovering. This gap is exposure bias.
On-policy distillation (Gu et al., 2023; Agarwal et al., 2023) flips it. The student writes, and the teacher scores every token. The student learns in the states it visits, with a signal at every token instead of RL’s one score per answer.
What loss? Call the student’s next-token distribution πθ and the teacher’s πT. The reverse KL weights each token by the student’s own probability:
The KL from pi-theta to pi-T equals the sum over x of pi-theta of x, times the log of pi-theta of x over pi-T of x.
For each token x, take the log of how much more the student likes it than the teacher does. Weight it by the student’s own probability πθ(x), and add. Tokens the student never says cost nothing. Tokens it says that the teacher dislikes cost a lot.
With made-up numbers on three tokens: student 0.90, 0.05, 0.05 and teacher 0.50, 0.45, 0.05. Reverse KL = 0.90 × log 1.8 + 0.05 × log(0.111) + 0 = 0.529 − 0.110 = 0.419. The forward KL, weighted by the teacher, is 0.695: it punishes the missed second token harder.
The blue curve is the teacher with two modes. The purple bump is the student, which can only make one. Pick a loss and press Fit.
Illustrative toy on a number line, not a vocabulary. The teacher is an even mix of two bumps with spread 0.6; the student is one bump. Fit searches the student’s centre and spread for the lowest KL.
Forward KL covers every mode: the student spreads out, even between the modes. Reverse KL is mode-seeking: the student settles on one mode and is sharp there. In text, it commits to one good way to say it.
The Qwen3 report (Table 21) starts two runs from the same distilled Qwen3-8B. RL reached 67.6% on AIME’24 in 17,920 GPU hours. On-policy distillation from a larger Qwen3 teacher reached 74.4% in 1,800 hours, about a tenth.
Symptom: the student copies teacher text well, then drifts once its own early tokens go wrong.
Measure: the per-token reverse KL on the student’s own samples.
Fix: on-policy distillation. A sampled token with student 0.40 and teacher 0.10 gets a penalty of log 4 = 1.39.
Chapter 6
Turn each query and key by an angle that grows with its position, so their dot product sees only the distance
Long reasoning needs long context: a whole repository, or a chain with many false starts. The lecture lists three walls. Few web documents are long, attention cost grows with the square of the length, and position encodings trained on short text do not carry over.
Attention alone ignores order. GPT-2 and BERT learned one position vector per slot. A slot never seen in training has no vector at all. RoPE, rotary position embedding (Su et al., 2021), adds no vectors. It rotates each query and key by an angle set by its position.
Take one pair of numbers from a query and a key, as a 2-D arrow. Call the query’s position m, the key’s n, and the angle per position θ. Call the rotation by an angle a R(a). Rotating both, and then taking the dot product, gives:
R of m theta times q, dot R of n theta times k, equals q dot R of n minus m, times theta, times k.
Turn the query by mθ and the key by nθ, then take their dot product. Only the gap n − m survives, because turning both by the same amount changes nothing between them.
With made-up vectors q = (0.8, 0.6), k = (1.0, 0.2) and θ = 0.5: at positions m = 10, n = 11 the dot product is 1.018. At m = 100, n = 101 it is again 1.018. At m = 10, n = 14 it is 0.017.
Purple arrows are the query and key after rotation; the blue number is their dot product. Move one position, or shift both together.
We made up the vectors. The angles are RoPE’s for a head of size d = 128: pair i turns 10000 to the power −2i/128 radians per position.
A head of size 128 has 64 pairs, each with its own angle θi = 10000−2i/128. Pair 0 turns 1 radian per token, a full turn every 6.3 tokens: it sees order inside a phrase. Pair 63 turns 0.000115 radians, a full turn every 54,410 tokens: it sees where in a long text you are. RoPE turns queries and keys only, never values, in every layer.
Symptom: a model trained on 4,096 tokens writes nonsense past token 4,096.
Measure: loss or perplexity by position: it climbs past the trained length.
Fix: rescale the angles and fine-tune briefly (Chapter 7).
Chapter 7
Find the slow pairs that never finished a turn in training, and squeeze new positions into angles the model knows
If RoPE only sees distance, why does a model fail past its trained length? Look at the slow pairs. With a trained length of 4,096 and a head of 128, pair 0 turns 652 times. Pairs 46 to 63, 18 of the 64, never finish one turn. Past 4,096 they show angles the model never saw.
Position Interpolation (PI; Chen et al., 2023, at Meta) squeezes positions back into the trained range. Call the trained length L, the new length L′, and a token’s position m:
m-prime equals m times L over L-prime.
Shrink every position m by the same factor L/L′. The last position lands at L, so no angle goes past what training saw. The price: neighbours now sit only L/L′ apart.
LLaMA trained with L = 2,048. To reach L′ = 8,192, position 8,000 becomes 8,000 × 2,048 / 8,192 = 2,000. Two neighbouring tokens are now 0.25 apart, so pair 0 turns 0.25 radians between them instead of 1.
One column per frequency pair, fast on the left. Purple height is each pair’s turn per token after the change, against the trained one. Red marks a pair that now shows unseen angles. Pick a method and a length.
The pair angles, the NTK-aware base b·sd/(d−2), YaRN’s ramp with α = 1 and β = 32, and its temperature are the formulas of Peng et al. (YaRN, 2023), for a trained length of 4,096 and d = 128. Which angles a model can use is our simplification.
PI took LLaMA 7B to 65B up to 32,768 tokens with at most 1,000 fine-tuning steps. But it blurs neighbours, and YaRN’s authors saw PI degrade past about s = 8. NTK-aware scaling raises RoPE’s base instead: at s = 8, 10,000 becomes 82,685. Fast pairs barely change; slow pairs stretch.
YaRN (Peng et al., 2023) treats pairs by how often they turn in L tokens. It leaves pairs with more than 32 turns alone, squeezes pairs with less than one turn like PI, and ramps between. It also sharpens attention: the logits grow by (0.1 ln s + 1)², a factor of 1.46 at s = 8.
The lecture’s recipe: change the position encoding, then keep pretraining on long documents at growing lengths, such as 8K, 32K, then 128K. Its rule of thumb is 0.1 to 1% of the original pretraining tokens.
Symptom: after a big PI stretch, the model gets worse on short texts it used to handle.
Measure: perplexity on short documents, before and after.
Fix: leave the fast pairs alone, as NTK-by-parts and YaRN do.
Chapter 8
Sample many answers, let a checker pick one, and see why the checker sets the ceiling
The cheapest way to think longer is to answer many times. Sample N solutions at a temperature above 0, then pick one. Picking needs a rule. Majority voting takes the most common final answer, as in self-consistency (Lecture 12). A verifier is a model trained to score solutions, and best-of-N keeps the top-scored one.
An outcome reward model (ORM) scores the whole solution: is the final answer right? A process reward model (PRM) scores every step. Lightman et al. (2023) paid people to label steps of GPT-4 solutions to MATH problems as right, wrong or neutral. That is PRM800K: 800,000 step labels on 75,000 solutions to 12,000 problems. The PRM scores a solution as the product of its steps’ chances of being right.
A picker can only pick a right answer if the model wrote one. Call one sample’s chance of being right p and the number of samples N. The chance that at least one is right is the coverage:
Coverage equals one minus, one minus p, to the N.
One sample is wrong with chance 1 − p. All N are wrong with that chance multiplied N times. Coverage is everything else.
With p = 0.1: one sample covers 0.10, ten cover 1 − 0.910 = 0.651, and a hundred cover 0.99997. With p = 0, coverage stays 0 for every N.
The grey line is coverage, what a perfect checker would get. The pink line is the picker you choose. Slide N to sample more.
Illustrative toy: 400 made-up problems with mixed difficulty, a tempting wrong answer on some, and scorers whose scores separate right from wrong solutions by 1.0 (ORM-like) or 2.0 (PRM-like) noise widths. The real gap is Lightman et al.’s: see below.
Lightman et al. scored 1,860 samples per problem on 500 MATH test problems. Picking with the PRM solved 78.2%, with the ORM 72.4%, and by majority vote 69.6%. Taking the minimum step score instead of the product gave 77.6%, so the choice barely matters. Step labels help because they say where a solution went wrong, not only that it did.
Symptom: accuracy stops rising, or falls, as N grows.
Measure: the gap between coverage and the picked accuracy.
Fix: a better verifier. Snell et al. saw search against a PRM hurt on easy questions, where it chases the PRM’s quirks.
Chapter 9
Give a small model the compute a 14 times bigger model would cost, spend it on samples, and see which questions it wins
Snell et al. (2024, UC Berkeley and Google DeepMind) asked the budget question. On MATH, with PaLM 2-S*, they chose the test-time method per question by its difficulty. That beat best-of-N while using about 4 times less test-time compute. Then they compared against a model with about 14 times more parameters, at equal FLOPs.
The exchange rate comes from two rules of thumb. Pretraining costs about 6 FLOPs per parameter per training token; generating costs about 2 per parameter per token. Call the size ratio of the big model M. Call the ratio of tokens served to tokens pretrained R. The small model may spend K times its usual inference compute:
K equals M plus three times M minus one, over R.
The big model costs M times more on every token it serves: that gives M. It also cost M − 1 extra in pretraining, at 3 times the per-token price of serving. Spread that extra over the R served tokens: that adds 3(M − 1)/R.
With M = 14, Snell et al.’s three loads: R = 0.16 gives K = 14 + 39 / 0.16 = 257.75. R = 0.79 gives 63.37. R = 22, heavy serving, gives only 15.77.
Five difficulty levels. Pink bars: the small model with K samples and a verifier. Purple rings: the bigger model answering once. Change the load, the size gap and the verifier.
Illustrative toy. The per-level accuracies and the bigger model’s growth with M are ours; only the exchange rate K and the three R values are Snell et al.’s. With the verifier off, the toy picks by majority vote. "Hard" means levels 4 and 5.
The toy reproduces the paper’s pattern. On easy and medium questions, which the small model sometimes solves, extra samples beat the bigger model. On the hardest questions it almost never writes a right answer, so no checker helps, and the bigger model wins. Heavy serving shrinks K and moves the line toward pretraining.
The lecture’s timeline: Let’s Verify Step by Step showed test-time gains in May 2023. Snell et al. followed in August 2024, and OpenAI’s o1 made the idea popular in September 2024. Its takeaways: do not default to the largest model, and invest in verification.
Symptom: a big sampling budget buys almost nothing on your hardest questions.
Measure: one-shot accuracy and coverage per difficulty level.
Fix: route by difficulty. Sample more where coverage is rising; send near-zero cases to a bigger model.
Chapter 10
Keep the four tools, the numbers and the code, and see where to go next
A reasoning model pays for its chains four ways. Draft-and-check makes each big pass write several tokens with exactly the big model’s distribution. RL on long chains runs asynchronously, so its rollouts go stale and need weights or clipping. On-policy distillation lets a teacher grade every token the student writes. RoPE scaling stretches the window. More samples help only where a checker can find a right answer, and the checker sets the ceiling.
| Tool | What it buys | Key idea | Watch for |
|---|---|---|---|
| Speculative decoding | several tokens per big pass, same distribution | keep with min(1, p/q); else draw from the residual | low α; costly drafts; mismatched sampling settings |
| Asynchronous RL | GPUs busy while long rollouts finish | importance weights, clipped per token | ESS falling as rollouts go stale |
| On-policy distillation | a small model that reasons like a big one, cheaply | student writes, teacher scores each token, reverse KL | a weak teacher; dropped modes you needed |
| RoPE scaling | longer context with brief fine-tuning | squeeze slow pairs, keep fast pairs | short-text regressions; unused middle of the window |
| Best-of-N and verifiers | accuracy from extra samples | coverage 1 − (1 − p)N, then a checker picks | p near 0; a checker the search can fool |
| Number | Value | Where |
|---|---|---|
| 70B model, least time per token at 3.35 TB/s; a 10,000-token chain | 41.8 ms; 418 s | Chapter 0 |
| Keep chances in the slides’ example; tokens per pass | 1, 1, 0.889, 0.375, 1; 4.56 | Chapter 1 |
| T5-small for T5-XXL: tokens per cycle, predicted and measured speedup | 3.60; 3.16×; 3.4× | Chapter 3 |
| T5-large draft: predicted and measured speedup | 2.50×; 1.7× | Chapter 3 |
| Weights 2.0, 0.5, 0.5, 1.0: ESS | 0.727 | Chapter 4 |
| Qwen3-8B on AIME’24: RL against on-policy distillation (GPU hours) | 67.6% (17,920); 74.4% (1,800) | Chapter 5 |
| RoPE, d = 128: full turn of pair 0, of pair 63 | 6.3; 54,410 tokens | Chapter 6 |
| Trained length 4,096: pairs that never finish a turn | 18 of 64 | Chapter 7 |
| YaRN logit factor at s = 8; NTK-aware base at s = 8 | 1.46; 82,685 | Chapter 7 |
| MATH, best-of-1,860: PRM, ORM, majority vote | 78.2%, 72.4%, 69.6% | Chapter 8 |
| Exchange rate K at M = 14 for R = 0.16, 0.79, 22 | 257.75, 63.37, 15.77 | Chapter 9 |
The core as code: one draft-and-check step, the effective sample size, the per-token reverse KL, RoPE with PI, and coverage.
python import numpy as np rng = np.random.default_rng(0) def spec_step(p_rows, q_rows, drafts): """p_rows[i], q_rows[i]: target and draft distributions at guess i (one more p row at the end).""" out = [] for i, x in enumerate(drafts): p, q = p_rows[i], q_rows[i] if rng.random() < min(1.0, p[x] / q[x]): # keep with min(1, p/q) out.append(x); continue r = np.maximum(0, p - q); r /= r.sum() # residual p'(x) out.append(rng.choice(len(p), p=r)); return out out.append(rng.choice(len(p_rows[-1]), p=p_rows[-1])) # all kept: one bonus token return out def ess(w): # (sum w)^2 / (N sum w^2) w = np.asarray(w, float); return w.sum()**2 / (len(w) * (w**2).sum()) print(round(ess([2.0, .5, .5, 1.0]), 3)) # 0.727 def token_penalty(logp_student, logp_teacher): # one sample of the reverse KL return logp_student - logp_teacher # advantage = minus this print(round(token_penalty(np.log(.4), np.log(.1)), 2)) # 1.39 def rope(x, pos, base=10000.0, L=None, L_new=None): d = x.shape[-1] if L and L_new: pos = pos * L / L_new # Position Interpolation theta = base ** (-np.arange(0, d, 2) / d) # one angle per pair a = pos[:, None] * theta[None, :] x1, x2 = x[..., 0::2], x[..., 1::2] return np.stack([x1*np.cos(a) - x2*np.sin(a), x1*np.sin(a) + x2*np.cos(a)], -1).reshape(x.shape) coverage = lambda p, N: 1 - (1 - p)**N print(round(coverage(.1, 10), 3)) # 0.651
The slides point to faster drafters such as EAGLE-3 and SuffixDecoding, and to RL systems that update weights mid-rollout. They also show on-policy distillation restoring chat skills after training on a company’s documents. Lecture 14 turns to tokenization, which decides how many tokens a chain costs.
Now teach it: press Present or Teach. Explain why draft-and-check gives the big model’s exact distribution, why stale rollouts lose weight, and why more samples cannot fix p = 0. Then go back to the hero, choose T5-large, and say why the better guesser loses the race.