Search

Search papers and lessons

Scaling LLM Test-Time Compute Optimally

Charlie Snell, Jaehoon Lee, Kelvin Xu et al. · 2024

Choosing how to spend a per-question inference budget, based on how hard the model finds the question, can beat best-of-N with up to 4x less compute and can rival a model 14x larger on easier questions.

On this page

  • Colour = topic mix
  • Probability
  • Neural network basics
  • Calculus
  • Linear algebra
  • Post-training
  • Discrete math
  • Sign in to see your progress

TL;DR

Snell and colleagues ask how much a language model improves on a hard problem if it may spend a fixed amount of extra compute at inference. Their answer is that the best way to spend that compute depends on how hard the question is for the model. Matched to difficulty, the budget beats best-of-N with up to 4x less compute. On easy and medium questions it can also beat a model 14x larger.

Where you'll see it: math and reasoning systems that sample several solutions and pick one with a verifier, and the choice of how many of those samples should be fresh attempts and how many should be revisions of earlier ones.

The problem

Scaling a model during pretraining is expensive, and the field had been doing it with little thought about inference. A model's answer to a question is usually one sample from its distribution. Two cheap ways to do better were known. One is best-of-N: draw N answers and keep the one a verifier scores highest. The other is to search over the reasoning steps with a process reward model (PRM), which scores each step.

Results on these methods were mixed. Some work showed that current models could use extra compute to improve, and other work found the gains on complex tasks such as math remained limited. The paper asks for a systematic analysis of the approaches, and whether the same budget should be spent the same way on every question.

Key idea

Test-time compute can change the model's distribution in two ways. It can change the proposal distribution, the process that generates candidate answers, for example by asking the model to revise its own earlier answer. Or it can change how a verifier selects among candidates, for example by searching over steps with a PRM. Each route has knobs: how many answers to generate, how many of them to generate in sequence instead of in parallel, and which search algorithm to run.

The paper defines a test-time compute-optimal scaling strategy: for a given question and budget, the setting of those knobs that maximizes accuracy. The exact optimum is unknown in deployment, because it needs the correct answer. The approximation the paper uses is to estimate the question's difficulty from the model's own pass rate, sort questions into five difficulty bins, and pick the best strategy for each bin on a validation set. Difficulty then serves as the one statistic that decides how to spend the budget.

The method

Setup

The experiments use the MATH benchmark, a set of high-school competition problems with 12,000 training and 500 test questions, following the split used in Lightman et al. The base model is PaLM 2-S*, a PaLM 2 variant that the authors judge to have non-trivial but unsaturated performance on MATH. Because the revision and verification abilities studied are not present in off-the-shelf models in the paper's experiments, the authors fine-tune the base model for them.

Difficulty bins

The paper estimates difficulty from the base model's pass@1 rate on each question, computed from 2,048 samples, and cuts the rates into five quantiles. The paper calls this oracle difficulty, since it uses the correct answers. For deployment it uses model-predicted difficulty, which bins questions by the average final-answer score of a learned verifier over the same 2,048 samples. The two bin assignments give nearly the same curves in the results, which is the paper's main evidence that the method works without ground truth. The estimate has a cost of its own, which the paper leaves as future work. It also uses two-fold cross-validation over the test set, so the strategy chosen on one fold is scored on the other.

Three search methods run against a PRM. Each sample is a full solution from a few-shot prompted base model.

  • Best-of-N weighted. Draw N solutions and pick the best by PRM score. Answers that reach the same final result have their scores summed, so the vote is weighted by verifier confidence.
  • Beam search. Draw N first steps, keep the best N/M by PRM score, expand each by M new steps, and repeat for up to 40 rounds. The final N candidates go to best-of-N weighted selection.
  • Lookahead search. At each beam step, roll out up to k more steps at temperature 0 and score the current step by the PRM value at the end of the rollout. Beam search is the case k = 0. A lookahead search of this kind costs N times (k + 1) samples.

The PRM is trained without human step labels. The authors estimate per-step correctness with Monte Carlo rollouts from each step, following Wang et al. Their reason is that PRM800k, the human-labelled dataset of Lightman et al., transferred poorly to their PaLM 2 samples, and a PRM trained on it was easy to exploit even with best-of-N.

Each PRM scores a whole answer by its prediction at the last step, not by the product or minimum of step scores. The authors found this aggregation worked best among those they tried.

Revisions

The second route changes the proposal. The base model is fine-tuned to revise its own answers given earlier attempts in its context. The training data is built from 64 independent samples at a higher temperature. Each correct answer is paired with up to four incorrect answers as context, chosen by a character edit distance so that the incorrect answers are similar to the correct one. This follows the on-policy recipe of Qu et al., adapted because multi-turn rollouts were too costly on the authors' infrastructure.

At inference a revision chain can be longer than the four answers seen in training, by keeping only the most recent four. The paper also reports a distribution shift: about 38 percent of correct answers in context get turned into incorrect ones by the next revision under a naive approach. So the final answer is picked by majority vote or by a verifier over the chain.

Splitting the budget

With a budget of N samples, the paper considers allocating some to parallel answers and the rest to sequential revisions. Parallel samples act as a global search over approaches. Sequential revisions act as local refinement. The paper sweeps the ratio for each budget and difficulty bin.

Results

All numbers below are the paper's. Accuracy is on the MATH test questions.

Search. At small budgets, beam search beats best-of-N clearly. The gain shrinks as the budget grows, and beam search often falls below best-of-N at large budgets. Lookahead search generally does worse than the other two at the same generation budget. Binned by difficulty, the pattern splits. On the easiest two levels, beam search gets worse as the budget grows, which the paper reads as over-optimization of the PRM. On levels 3 and 4, beam search consistently beats best-of-N. On the hardest level, neither method makes much progress.

Compute-optimal search. Choosing the search method per difficulty bin, with predicted difficulty, tracks the oracle version closely and can nearly outperform best-of-N with 4x less compute, for example 16 generations where best-of-N uses 64.

Sequential versus parallel. With the revision model, sampling N answers in sequence beats sampling N in parallel, under both verifier and majority selection. The ideal sequential-to-parallel ratio at a fixed budget is interior, not all-or-nothing. Easy questions benefit more from sequential revisions. On difficult questions the best choice is a balance of sequential and parallel compute.

Compute-optimal revisions. Per-bin ratios with predicted difficulty outperform best-of-N with up to 4x less test-time compute, for example 64 samples where best-of-N uses 256. At high budgets parallel sampling plateaus, while the compute-optimal policy keeps improving.

Summary claim. Across the methods studied, the paper reports that compute-optimal allocation improves test-time scaling efficiency by a factor of 2 to 4.

Against a larger model. The paper matches a smaller model with extra test-time compute against a model with about 14 times more parameters. The comparison is FLOP-matched. It uses the approximations of 6ND for training and 2ND for inference, with N the parameter count and D the number of tokens. Inference is then scaled by a factor of M + 3 (D_pretrain / D_inference)(M - 1) for a parameter ratio M. The paper parameterizes the workload by R = D_inference / D_pretrain and tests R = 0.16, 0.79 and 22. Test-time compute wins on easy and intermediate questions, and on hard ones with a small R. Pretraining wins on the hardest questions and for large R, which means long deployment with many inference tokens.

Why it mattered

The paper's contribution is a way to measure and allocate test-time compute. It frames test-time methods as two axes, the proposal distribution and the verifier, and shows that they are complementary. It shows that the best allocation depends on the question and cannot be read off one fixed recipe. It also reports that test-time compute can substitute for pretraining in some regimes, and says when it cannot. The paper is explicit that these results are for math reasoning with PaLM 2-S* fine-tuned for revision and verification, and that gains on the hardest questions are small with these methods. It names future work on combining PRM search with revisions, faster difficulty estimation, and distilling test-time outputs back into the base model.

Reading guide

Read the paper in this order. Each prerequisite is linked where it first matters.

  • Section 1, Introduction. Neural Scaling Laws and Training Compute-Optimal Large Language Models (Chinchilla) for the pretraining-scaling baseline the paper compares against.
  • Section 2, Unified perspective. Best-of-N Sampling for the simplest verifier-based method, and Process Reward Model for the per-step verifier used in search.
  • Section 3, Compute-optimal strategy. Compute-Optimal Training for the pretraining version of choosing the best allocation of a fixed compute budget, which the paper cites as the counterpart to its inference-side question.
  • Section 4, Setup. No new prerequisites. The base model and benchmark are described in the paper.
  • Section 5, Verifiers and search. Reward Model for what a learned verifier is, Beam Search for the search used in Section 5.2, and Tree Search for the wider family of search procedures.
  • Section 6, Revisions. Best-of-N Sampling again, for the parallel baseline that revisions are compared with.
  • Section 7, Pretraining versus test-time compute. Neural Scaling Laws for how parameter count and FLOPs trade off in the FLOP-matched comparison.
  • Section 8, Discussion. No new prerequisites.

Check yourself

QuestionIn one sentence, what is a test-time compute-optimal scaling strategy, and why can it not be computed exactly at deployment?Show answer

It is the setting of the test-time knobs, such as the number of samples, the search method and the parallel-to-sequential split, that maximizes accuracy for a given question and budget. Computing it exactly needs the correct answer, which is unknown at deployment. The paper therefore estimates it from a difficulty bin, using the model's own pass rate or a verifier's average score.

QuestionThe paper's compute-optimal search policy with predicted difficulty can nearly match best-of-N using 16 generations where best-of-N uses 64. What is the compute saving, and why is 'nearly' the right word?Show answer

The saving is 64 divided by 16, which is 4x fewer generations. The paper says the policy can nearly outperform best-of-N at that point, so the reading is roughly equal accuracy at a quarter of the samples. The word "nearly" is the paper's own: the 4x figure is stated for the low-budget regime, and with predicted difficulty some of the benefit diminishes at higher budgets.

QuestionThe paper's FLOP-matching formula gives a factor M + 3 (D_pretrain / D_inference)(M - 1) for a parameter ratio M. Take M = 14 and R = D_inference / D_pretrain = 0.79. What inference multiplier does the small model get, and why does a larger R shrink it?Show answer

D_pretrain / D_inference = 1 / 0.79, about 1.266. The factor is 14 + 3 times 1.266 times 13, which is 14 + 49.4 = about 63.4. The small model may use about 63 times its base inference compute and still match the 14x larger model's FLOPs. A larger R means more inference tokens per pretraining token, so the large model's inference cost, which scales with M, dominates. The allowance for the small model then shrinks toward M, which is 14 when R is very large.

QuestionWhy does beam search get worse on the easiest questions as the budget grows, when it beats best-of-N on medium ones?Show answer

The paper reads this as over-optimization of the PRM. Searching harder against the PRM pushes the solutions toward whatever the PRM scores highly, and on easy questions that costs accuracy. On levels 3 and 4 beam search consistently beats best-of-N, and on level 5 no method makes much progress. The per-bin results are in Figure 3 (right).

QuestionRevisions beat parallel sampling at equal budget, yet the paper says about 38 percent of correct answers in context get turned into incorrect ones. How can both be true, and what does the paper do about the flip?Show answer

The 38 percent figure is about a revision that starts from a correct answer in context, which is a distribution shift because training contexts held only incorrect answers. The paper does not use the last revision alone. It picks the final answer with sequential majority voting or verifier-based selection over the revision sequence, so a correct answer that a later revision overwrites can still be selected.

Sources

Read the full paper

Charlie Snell, Jaehoon Lee, Kelvin Xu et al., 2024. arXiv:2408.03314