All courses

Explain reasoning models and test-time compute

Explain why longer chains of thought and more samples improve accuracy on hard problems. Explain how RL with verifiable rewards trains models to produce long reasoning, and how distillation spreads this ability to smaller models.

Builds on: Scaling test-time compute: parallel vs sequential, RL with verifiable rewards (GRPO), Distillation from a stronger model

▶ Watch this lesson Start the whole course

What the animation says

Fixed depth per token

A reasoning model writes thousands of tokens of scratch work before it answers. Yet its weights are the same size as the version that doesn't think. Here's the catch: every token gets exactly one forward pass, through the same fixed stack of layers. So the work per token is capped. Only the number of tokens can grow. Suppose a problem needs forty steps in a row, but one pass manages about ten. What can the model do?

Two ways to spend compute

Writing steps out works: each new token reads every earlier one, so serial work spreads across the chain. That's the sequential way. One answer of n tokens costs about two times the parameter count, times n, operations. In practice, each doubling of thinking tokens adds a similar gain, until it levels off. The parallel way: sample several independent tries and let a checker pick one. If one try is right twenty percent of the time, eight tries with a perfect checker succeed about eighty-three percent.

Scoring one group

How did training teach such long chains? With reinforcement learning from verifiable rewards. Sample a group of four attempts, and a checker marks each answer: one right, three wrong. The mean reward is a quarter, the spread about point four three. So the right chain gets plus one point seven three. Each wrong one gets minus point five eight. The right chain's tokens, including its 'wait, let me check,' become likelier. Length isn't rewarded; checking just wins more. Now suppose all four attempts are wrong. What are the advantages?

No contrast, no signal

All zero. Every reward equals the mean, so every advantage is zero. The spread is zero too; the tiny epsilon in this line makes the result zero, not zero over zero. With no contrast, no chain is pushed up or down. Nothing is learned. Same if all four are right: still no contrast. Here are four groups. Tap the ones that teach the model something.

Handing down the skill

So reinforcement learning only learns where the model sometimes succeeds. Smaller models have another route: distillation. A strong teacher solves problems; a checker keeps only the correct traces. The small student is fine-tuned to predict those traces token by token, with ordinary cross-entropy. It copies the strategy, checks and backtracks included, without having to discover it by trial and error. Recap: longer chains or more checked tries buy accuracy, and training rewards only correct answers.

Why does thinking longer make a model smarter?

A reasoning model writes thousands of tokens of scratch work before it answers. It solves competition math that its same-sized non-thinking version fails, yet no weights were added. This raises three questions: 1. Why do more tokens or more samples at inference buy accuracy? 2. How did training teach the model to write such long chains? 3. How can a much smaller model inherit the skill?

Compute per token is fixed; tokens are not

**Test-time compute:** each token costs one forward pass of fixed depth. A problem needing many serial steps must spread them over written tokens, and later tokens read the earlier results. More samples give more independent tries, and a verifier or majority vote picks one. **Training:** RLVR samples attempts, checks the answers and reinforces what worked. Re-checking and backtracking win more often, so chains lengthen. **Distillation:** small models imitate those winning traces.

What you pay and what gets reinforced

One answer of $n$ generated tokens costs about $2N\cdot n$ FLOPs. Empirically, accuracy grows roughly linearly in $\log n$: each doubling of thinking tokens adds a similar gain, until it saturates. If one sample is correct with probability $p$, then $k$ independent samples plus a perfect verifier succeed with $$\text{pass@}k = 1-(1-p)^k.$$ In GRPO, response $i$ in a group of $G$ gets advantage $A_i=(r_i-\bar r)/(\text{std}(r)+\epsilon)$. Here $r_i\in\{0,1\}$ comes from the checker, std is taken over the $G$ rewards (divide by $G$), and a tiny $\epsilon$ turns an all-equal group into $0$ rather than $0/0$. Length is never rewarded directly. Distillation is SFT of a small student on a teacher's verified traces with next-token cross-entropy. The student copies the strategy without having to discover it by RL.

One GRPO group, and one with no signal

Take $G=4$ samples. Suppose the rewards are $[1,0,0,0]$: - $\bar r=0.25$ and std $=\sqrt{0.25\cdot0.75}=0.433$. - The correct chain gets $A=+0.75/0.433=+1.73$. - Each wrong chain gets $-0.25/0.433=-0.58$. The correct chain's tokens, including its "wait, let me check", become likelier. Now suppose the rewards are $[0,0,0,0]$. Every $A_i=0$, so nothing is learned. A weak model that never succeeds first needs distilled traces or easier problems.

Both effects in a few lines

More samples raise the chance that at least one is right. A group with no correct answer gives zero advantage to every response.
import numpy as np
def pass_at_k(p, k):
    return 1 - (1 - p) ** k
def grpo_adv(r, eps=1e-6):
    r = np.asarray(r, float)
    return (r - r.mean()) / (r.std() + eps)  # np.std divides by G
print(pass_at_k(0.2, 1), pass_at_k(0.2, 8))  # 0.2, ~0.83
print(grpo_adv([1, 0, 0, 0]))  # ~[1.73 -0.58 -0.58 -0.58]
print(grpo_adv([0, 0, 0, 0]))  # all zeros: no signal

Remember this

Hard problems need more serial computation than one forward pass provides, so models buy accuracy with longer chains (sequential) or with more checked attempts (parallel). RLVR grows long, self-checking reasoning by rewarding only correct answers, but it learns only where the model sometimes succeeds. Distillation hands smaller models the winning traces directly.

On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.