Skip to content
LearnAI
PART 3 · TRAINING LLMS/ Reasoning & distillation

3.9Reasoning models: CoT, RLVR & test-time compute

Why letting a model "think" before answering helps, how reinforcement learning on checkable answers produced o1- and R1-style reasoners, and what more thinking buys you.

⏱ 13 minIntermediate

Thinking takes tokens

A transformer does a fixed amount of computation per token: one pass through all its layers. If you ask “What is 17 × 24?” and demand the answer as the very next token, the model gets exactly one forward pass to do the whole multiplication internally. For hard problems, that isn’t enough.

But a model that writes “17 × 24 = 17 × 20 + 17 × 4 = 340 + 68 = 408” gets a forward pass for every token of that working, and each step can read the results of the earlier ones. The written text is both extra compute and external memory. That is the core insight behind chain-of-thoughtChain-of-thought (CoT)Having a model write out intermediate reasoning steps before its final answer. (CoT) prompting, and, ultimately, behind today’s reasoning models.

ANALOGY· Mental arithmetic versus scratch paper

Ask someone to multiply 347 by 86 in their head and they’ll probably get it wrong. Give them scratch paper and they’ll get it right, not because they got smarter, but because they can break the problem into small steps and write down intermediate results. Give them time to double-check and they’ll catch their own slips.

The scratch paper is the chain of thought. Being trained to use the paper well (try an approach, notice an error, back up) is what RL with verifiable rewards teaches. Asking five people independently and going with the most common answer is self-consistency. And the time you’re willing to wait for the answer is your test-time compute budget.

From prompting trick to trained behavior

Chain-of-thought prompting (Wei et al., 2022) showed that including a few worked examples with step-by-step reasoning in the prompt dramatically improved large models on math word problems. With PaLM 540B and eight CoT examples, it reached state-of-the-art accuracy on the GSM8K grade-school math benchmark at the time. Notably, the benefit appeared mainly in very large models; small models produced fluent but wrong chains. A few months later, Kojima et al. showed that simply adding “Let’s think step by step” often worked too.

Self-consistency (Wang et al., 2022) added a second idea. A single chain of thought might take a wrong turn, but if you sample many chains at a nonzero temperatureTemperatureA sampling knob that divides logits before softmax. Low values make output more deterministic; high values make it more random. and take a majority vote over their final answers, the errors tend to scatter while correct reasoning converges. The paper reported large gains, for instance +17.9 percentage points on GSM8K. This is the simplest form of trading more inference compute for accuracy.

Both of these are prompting techniques: the model was never trained to reason well; you just coax it. The next step was to train for it directly.

RL with verifiable rewards

The previous lessons trained models against a learned reward model, and showed how policies learn to exploit it. For many reasoning tasks there is a better option: check the answer. A math problem has a known final answer. Code either passes its unit tests or it doesn’t. That is reinforcement learning with verifiable rewardsRL with verifiable rewards (RLVR)Reinforcement learning where the reward comes from an automatic checker, such as a correct math answer or passing unit tests. (RLVR): sample a chain of thought and an answer, give reward 1 if the answer checks out and 0 otherwise, and update with a policy-gradient method such as GRPO.

A verifiable reward is much harder to hack than a learned one: you can’t flatter a unit test. (Not impossible, though. Models have been observed exploiting weak tests or checkers, so verifier quality matters.) And crucially, the reward only judges the final answer. Nobody tells the model how to reason. Whatever reasoning style makes correct answers more likely gets reinforced: double-checking, trying alternatives, breaking problems apart.

DeepSeek-R1: reasoning from pure RL

In January 2025, DeepSeek published DeepSeek-R1 with open weights and a detailed paper, which made the recipe concrete. It contains two models.

DeepSeek-R1-Zero applied GRPO directly to the DeepSeek-V3 base model, with no SFT at all. The rewards were rule-based: an accuracy reward (is the final answer correct?) and a format reward (is the thinking enclosed in <think> tags?). The authors deliberately avoided neural reward models for this, citing the risk of reward hacking. Over thousands of RL steps:

  • AIME 2024 pass@1 rose from 15.6% to 71.0%, and to 86.7% with majority voting.
  • The average response length grew steadily on its own. Nobody asked for longer answers; longer thinking simply earned more reward.
  • Behaviors such as reflection (revisiting earlier steps) and exploring alternative approaches emerged. The paper highlights an “aha moment” in an intermediate checkpoint, where the model interrupts its own solution with “Wait, wait. Wait. That’s an aha moment I can flag here.” and re-evaluates.

R1-Zero had problems, though: poor readability and language mixing (switching between languages mid-thought). DeepSeek-R1 fixed these with a multi-stage pipeline: a small cold-start SFT on thousands of long, readable chain-of-thought examples; reasoning-focused RL (with an added language-consistency reward); a new round of SFT on data produced by rejection sampling from that RL model plus general-purpose data; and a final RL stage covering all kinds of prompts. The result performed comparably to OpenAI’s o1-1217 on reasoning benchmarks, and its distilled smaller models are the subject of the next lesson.

Test-time compute: the new scaling axis

Reasoning models made test-time computeTest-time computeSpending more computation at inference, through longer reasoning or more samples, to get better answers. a design dimension in its own right. You can spend inference compute in two broad ways:

  • Sequentially: let one chain of thought run longer, so the model can explore, check and revise.
  • In parallel: sample many independent answers and aggregate them, by majority vote, or by a verifier or reward model that picks the best.

The demo below lets you explore the parallel side with exact probability, and then a cartoon of the sequential side. Two metrics matter. Majority@k is what you get by voting over k samples. pass@kpass@kThe probability that at least one of k sampled answers is correct. It measures what a model can reach with a perfect verifier, not what it answers by default. is the probability that at least one of k samples is correct, which you can only cash in if something can recognize the right one (a verifier, unit tests, or a human).

INTERACTIVETest-time compute simulator
0%25%50%75%100%1248163264number of samples k (log scale)
majority vote (self-consistency) pass@k (any of k correct; needs a verifier) one sample
k samples
8
one sample
40.0%
majority@8
90.5%
pass@8
98.3%

Exact multinomial math, no simulation. Voting helps when the right answer is the most common single answer. Push the distractor slider up with p below 50% and voting makes things worse: it confidently amplifies the popular mistake.

Thinking budget (illustrative curve, not measured data)
Overthinking
0%50%100%1285122k8k32kreasoning tokens per problem (log scale)
budget
2,048 tok
accuracy
66.6%
gain if doubled
+4.9 pts

Each doubling of the budget buys less than the last: on a log axis the curve flattens. With “overthinking” on, very long budgets slightly hurt, a pattern some studies report on easy problems.

Set the per-sample accuracy p and how much the wrong answers agree with each other. The chart shows exact majority-vote accuracy and pass@k as the number of samples k grows. Below, an illustrative thinking-budget curve.

Things to try:

  1. p = 40%, distractor 0%. Wrong answers are all different, so even a 40% model wins most votes once k is moderate: the correct answer is the most common single answer. Voting helps a lot.
  2. p = 40%, distractor 100%. Now every wrong sample gives the same wrong answer, which appears 60% of the time. Voting converges on the mistake and majority@k falls below 40%. Self-consistency only helps when the right answer is the mode.
  3. Compare pass@k with majority@k. pass@k climbs toward 100% quickly; it measures what is reachable, not what is chosen. The gap between them is the value of a good verifier.
  4. The thinking-budget panel. Each doubling of tokens buys less. With “overthinking” on, very long budgets slightly hurt. The curve is a cartoon, but the saturating shape matches what many papers and product docs describe.

Thinking budgets expose this trade-off to users. Several model APIs and open models let you cap the number of reasoning tokens or switch thinking off entirely for simple queries. Snell et al. (2024) argued that allocating test-time compute adaptively, per problem difficulty, can beat simply using a much larger model in some regimes. And researchers have documented overthinking: reasoning models spending hundreds of tokens on “what is 2 + 3?”, re-verifying answers they already had. Shorter-is-better rewards and adaptive budgets are active areas of work.

MATH CORNER · optionalMajority voting and pass@k, exactly

Suppose each sample is independently correct with probability pp, and (the simplest case) every wrong sample gives the same wrong answer. With kk odd, the vote is correct when more than half the samples are correct. With X∼Binomial(k,p)X \sim \text{Binomial}(k, p):

maj@k=P ⁣(X>k2)=∑j=⌈k/2⌉k(kj)pj(1−p)k−j.\text{maj@}k = P\!\left(X > \tfrac{k}{2}\right) = \sum_{j = \lceil k/2 \rceil}^{k} \binom{k}{j} p^j (1-p)^{k-j}.

The probability that at least one of kk samples is correct is

pass@k=1−(1−p)k.\text{pass@}k = 1 - (1 - p)^k.

Worked example. With p=0.6p = 0.6:

kkmaj@kkpass@kk
10.6000.6000.6000.600
33(0.6)2(0.4)+0.63=0.432+0.216=0.6483(0.6)^2(0.4) + 0.6^3 = 0.432 + 0.216 = 0.6481−0.43=0.9361 - 0.4^3 = 0.936
50.3456+0.2592+0.0778=0.6830.3456 + 0.2592 + 0.0778 = 0.6831−0.45=0.9901 - 0.4^5 = 0.990

With p=0.4p = 0.4 instead, maj@3 =3(0.4)2(0.6)+0.43=0.352= 3(0.4)^2(0.6) + 0.4^3 = 0.352: worse than one sample. In the binary case voting amplifies whichever answer is more likely, right or wrong; as k→∞k \to \infty it tends to 1 if p>0.5p > 0.5 and to 0 if p<0.5p < 0.5 (the Condorcet jury theorem). When wrong answers are scattered across many values, as in the demo’s 0% distractor setting, the bar drops: the correct answer only needs to be the most common single answer.

Estimating pass@k in practice. Evaluations draw n≥kn \ge k samples per problem, count cc correct, and use the unbiased estimator popularized by OpenAI’s Codex paper: pass@k=1−(n−ck)/(nk)\text{pass@}k = 1 - \binom{n-c}{k} / \binom{n}{k}.

In code

Self-consistency and the pass@k estimator take a few lines:

from collections import Counter
from math import comb

def self_consistency(model, question, k=16, temperature=0.8):
    answers = [extract_final_answer(model.generate(question, temperature=temperature))
               for _ in range(k)]
    answer, votes = Counter(answers).most_common(1)[0]
    return answer, votes / k            # the vote share is a rough confidence signal

def pass_at_k(n, c, k):
    """Unbiased pass@k from n samples with c correct."""
    if n - c < k:
        return 1.0
    return 1.0 - comb(n - c, k) / comb(n, k)

print(pass_at_k(n=20, c=4, k=5))       # ≈ 0.718

Note extract_final_answer: voting only works when answers can be compared exactly, which is why it’s used mostly for math and short-answer tasks, not essays.

COMMON MISCONCEPTIONS
  • “The chain of thought is a faithful transcript of the model’s reasoning.” It’s generated text that helps produce the answer, but studies have found cases where models’ stated reasoning omits factors that actually influenced the answer. Treat it as a useful scratchpad, not a guaranteed explanation.
  • “More thinking is always better.” Returns diminish, costs grow linearly with tokens, and on easy questions extra thinking can even hurt. Good systems adapt the budget to difficulty.
  • “Majority voting always improves accuracy.” Only if the correct answer is the most common single answer. If the model has a systematic favorite mistake, voting makes it more confident in it.
  • “Reasoning models were trained on human-written reasoning.” R1-Zero shows long chains of thought can emerge from RL on final-answer correctness alone. Human-style examples (cold start) were added mainly for readability and stability.

Check your understanding

0/5 answered
  1. Q1.Why does writing out a chain of thought help a transformer solve harder problems?

  2. Q2.A model is right 40% of the time, and when wrong it almost always gives the same wrong answer. What happens to majority-vote accuracy as you sample more answers?

  3. Q3.What were DeepSeek-R1-Zero's rewards during RL?

  4. Q4.Why did DeepSeek add 'cold-start' SFT data before RL for DeepSeek-R1?

  5. Q5.What does pass@k measure?

Further reading

Progress is saved in this browser only.
Type to search across all lessons and glossary terms.