Reasoning and Test-Time Compute
local graph
Chapter 38 — Reasoning and Test-Time Compute
Section titled “Chapter 38 — Reasoning and Test-Time Compute”For most of deep learning’s history, a trained model’s quality was fixed at inference: you ran a forward pass and read off the answer. The reasoning models of Chapter 25 broke that assumption. They opened a second axis of improvement — spending more computation at inference time to solve harder problems — and the consequences are still being mapped. This chapter examines test-time compute as a research frontier: how it works, how far it scales, how to spend it efficiently, and where the boundary of what reinforcement learning can teach now lies.
38.1 A Second Scaling Axis
Section titled “38.1 A Second Scaling Axis”Chapter 2 introduced the scaling laws that govern training: loss falls predictably as parameters, data, and training compute grow. Test-time compute is a parallel axis. A model that “thinks” — generating a long chain of intermediate reasoning before answering — spends more inference compute and, on suitable problems, gets more right. Strikingly, this too appears to follow a scaling curve: accuracy on hard reasoning benchmarks rises smoothly with the length of the reasoning the model is allowed to produce. The implication is profound. Capability is no longer a fixed property of the weights; it is partly a resource you allocate at run time, dialing a model from fast-and-shallow to slow-and-deep by changing nothing but its token budget — exactly the reasoning_effort control GLM-5.2 exposes (Chapter 44).
38.2 The Simplest Form: Sampling and Voting
Section titled “38.2 The Simplest Form: Sampling and Voting”The crudest way to spend inference compute is to sample many answers and aggregate them. Best-of-N generates N candidates and keeps the one a verifier or reward model scores highest; self-consistency samples many chains of thought and takes the majority answer. Both trade compute for accuracy with no change to the model:
from collections import Counter
def self_consistency(model, prompt, n=16, temperature=0.7): answers = [] for _ in range(n): chain = model.generate(prompt, temperature=temperature) answers.append(extract_final_answer(chain)) return Counter(answers).most_common(1)[0] # majority vote
*Python — self-consistency: sample many chains, vote on the answer*
These methods reveal something important: models often canreach the right answer but do not do so reliably on the first try, sosampling surfaces a correct answer that greedy decoding wouldmiss. They also have limits — majority voting cannot help if themodel is confidently wrong most of the time, and best-of-N is onlyas good as its verifier. The frontier is to internalize this behaviorso that a single, longer generation does the work that manysamples did, which is exactly what reasoning-trained modelslearn.
## 38.3 Learning to Think: RL with Verifiable Rewards
Chapter 25 showed the mechanism: reinforcement learningagainst a *verifiable* reward — a rule that checks whether a mathanswer is correct or a test suite passes — teaches a model togenerate reasoning that leads to right answers, with no human-labeled reasoning traces required. DeepSeek-R1 demonstratedthat this single idea, applied at scale, produces emergent long-chain reasoning: the model spontaneously learns to backtrack,check its work, and explore alternatives, because those behaviorsraise its reward. The research frontier now pushes this in severaldirections at once. How far does the verifiable reward signalextend beyond math and code — into science, tool use, andeventually tasks judged by reliable models rather than rules? Cana model generate its own training problems, bootstrapping hardercurricula through self-play? And how should reasoning be *verified*step by step, rather than only at the final answer, so that validreasoning with an arithmetic slip is not punished identically tononsense?38.4 Spending the Budget Wisely
Section titled “38.4 Spending the Budget Wisely”If thinking costs compute, then how much to think becomes an optimization problem. Easy questions deserve a quick answer; only hard ones merit a long deliberation. Allocating a “thinking budget” per problem — through explicit effort levels, learned stopping, or a separate controller that decides when to think harder — is an active area, because uniform deep reasoning wastes enormous compute on questions that never needed it. Related work studies how to make reasoning chains shorter without losing accuracy (much generated reasoning is redundant), and how to compress a verified chain into the weights so the model needs fewer tokens next time. The economic stakes are real: a reasoning model that thinks for ten thousand tokens on every query is far more expensive to serve than one that thinks only when it must.
| Method | How it spends compute | Needs |
|---|---|---|
| Self-consistency | many parallel chains, vote | nothing extra |
| Best-of-N | many candidates, pick best | a verifier / reward model |
| Long chain-of-thought | one long reasoning trace | reasoning-trained model |
| Tree / search | explore and prune branches | a value or process reward |
Table 38.1 — Ways to spend test-time compute
38.5 The Boundary of What RL Can Teach
Section titled “38.5 The Boundary of What RL Can Teach”A deeper question underlies all of this: does reinforcement learning on a base model teach new capabilities, or only elicit and sharpen what pretraining already made latent? The evidence is mixed and genuinely contested. On verifiable domains, RL clearly amplifies reasoning the base model could only occasionally produce; whether it can push a model beyond the frontier of its pretraining — into genuinely novel problem-solving — is unresolved and among the most consequential open questions in the field, because it bears directly on whether scaling test-time compute has a ceiling. What is no longer in doubt is that inference compute is a lever as real as training compute, and that a model’s intelligence is better understood as something you can spend on than something fixed in its parameters.
Compute you can allocate The reasoning revolution reframed capability as a resource. A model no longer simply is as good as its weights; it is as good as its weights plus the compute you let it spend at inference, on this particular problem. Sampling-and-voting buys accuracy with raw parallelism; RL with verifiable rewards teaches a model to do that work in a single deliberate pass; and the open frontier is to allocate that thinking precisely — deeply where it pays, not at all where it does not. The reader who built GRPO in Chapter 25 has already implemented the engine of this entire frontier.
38.6 Worked Example: Allocating a Test-Time Compute Budget
Test-time compute is a budget, and how you spend it matters as much as how much you have. Given, say, eight forward passes to answer a hard math problem, you could spend them on one chain of thought eight times as long, or on eight independent shorter chains combined by majority vote — self-consistency. On problems where mistakes are independent, the second strategy usually wins, because independent errors scatter while the correct answer concentrates:
from collections import Counteranswers = [extract(model.generate(prompt, temperature=0.7)) for _ in range(8)] # 8 independent reasoning tracesfinal = Counter(answers).most_common(1)[0][0] # majority votePython — reasoning/self_consistency.py: vote over sampled chains
The intuition is the same as an ensemble’s. If each chain is, say, 60% likely to reach the right answer and its errors are roughly independent, the most common answer across eight chains is far more than 60% likely to be correct, because the wrong answers spread across many different mistakes while the right one keeps recurring. This is why a reasoning model evaluated with self-consistency scores well above its single- sample accuracy — and why the frontier increasingly treats “how many samples, how long each, searched how” as a first-class deployment decision rather than a fixed property of the model.
^ore thinking, spent wisely A test-time budget can buy a longer chain, more parallel chains, or a search tree. Which wins depends on the task — but for problems with verifiable answers and independent errors, voting over several chains is a remarkably strong and cheap default.
38.7 Process Reward versus Outcome Reward
Section titled “38.7 Process Reward versus Outcome Reward”A central design question in reasoning models is what to reward. Outcome reward (Section 25.7) scores only the final answer: did the math come out right, did the tests pass? Process reward scores each step of the reasoning itself, rewarding a sound chain and penalizing a flawed one even when it happens to reach the right answer. The two make opposite bets about where the signal should come from.
Process reward, supplied by a process reward model trained on step-level judgments, gives a far denser signal and can catch the insidious case of a correct answer reached by faulty reasoning — valuable precisely because such cases generalize badly. Its cost is the step-level labels, which are expensive to collect and themselves debatable. Outcome reward needs only a checkable final answer, which is cheap and unambiguous where it applies. The surprise of DeepSeek-R1 (Section 25.3) was how far outcome-only reward could go: with a verifiable answer and enough samples, a model learned sophisticated multi-step reasoning without ever being told which steps were good. The frontier continues to debate which approach scales better, and increasingly explores combining them — outcome reward for its cheapness, a dash of process reward to suppress lucky-but-wrong reasoning.
Dense signal versus cheap signal Process reward grades every step and catches flawed reasoning, but needs costly step labels. Outcome reward grades only the answer, and R1 showed it suffices for a great deal. The open question is how much process supervision is worth its price.
38.8 Inference-Time Search: Tree of Thought
Section titled “38.8 Inference-Time Search: Tree of Thought”Chain-of-thought reasoning (Section 38.2) follows a single path: the model thinks step by step, but it commits to each step as it goes, and a wrong early turn dooms the rest. Tree-of-thought generalizes this from a line to a search. At each decision point the model branches into several candidate continuations, evaluates how promising each partial path looks, and explores the tree — breadth-first, depth-first, or with a more sophisticated search — keeping the lines that look strong and pruning the rest.
The payoff is on problems where a single greedy chain reliably gets stuck: puzzles, planning, proofs — anything with many possible approaches where the first one tried is often wrong. By exploring alternatives and backtracking from dead ends, the search finds solutions a linear chain would miss, at the cost of substantially more inference compute (many paths instead of one). This is the same principle that let game-playing systems surpass a single policy rollout by searching the game tree, now applied to reasoning, and it sits at the far end of the test-time-compute spectrum of Section 38.6 — where the most expensive but most capable strategies trade large amounts of inference compute for the ability to solve problems that no single forward pass, however good, can reach. The open question the frontier debates is when this search is worth its cost versus simply sampling more independent chains and taking the best (Section 29.8).
Search the tree, do not walk one path Tree-of-thought branches at decisions, scores partial paths, and backtracks — finding solutions a single chain-of-thought gets stuck before. It is game-tree search applied to reasoning, at the costly, capable end of test-time compute.
38.9 Self-Consistency: Sampling and Voting
Section titled “38.9 Self-Consistency: Sampling and Voting”One of the simplest and most effective test-time techniques for reasoning needs no search tree and no special training. Instead of generating a single chain of thought (Section 38.2), generate several independent chains — sampling with some temperature so they differ — and then take the answer that appears most often cross them. This is self-consistency, and it is majority voting applied to reasoning.
The intuition for why it works is that a hard problem often admits several different correct routes to the same answer but many different wrong answers. When multiple independent chains converge on the same final answer, that consensus is strong evidence the answer is right; when a single chain goes astray, the others outvote it. Self-consistency thus turns a handful of cheap, independent samples into a markedly more reliable result than any one of them, and it does so without the coordination machinery of tree-of-thought search (Section 38.8) — just sample, then count. Its requirement is a well-defined final answer that votes can be tallied over, which makes it a natural fit for math and other problems with a checkable result (Section 25.7). Sitting on the test-time-compute spectrum (Section 38.6) between a single greedy chain and full search, self-consistency offers much of the accuracy gain of the expensive methods at a fraction of their complexity, which is why it has become a staple of strong reasoning performance.
Sample several chains, trust the consensus Self-consistency generates multiple independent reasoning chains and takes the majority answer. Correct routes converge while wrong ones scatter, so consensus signals correctness — much of search’s benefit with none of its machinery, wherever a final answer can be voted on.