Test-Time Compute › Multiple Sampling

Michael BrenndoerferMarch 27, 202613 min read
Language AI HandbookAll chapters
Part 66 of 67Frontier Methods of 2025
Chapter 502Test-Time Compute › Multiple Sampling
Reading section 3 of 10 · Multiple Sampling · 13 minSection 3 of 10 · 13 min

Book contents

Section 3 of 10 · 13 min read

Test-Time Compute › Multiple SamplingOne section · Sections in this chapter3 / 10 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Multiple sampling is the simplest test-time compute strategy. Given a prompt xx, you run the model NN times to produce a set of candidate responses. Formally, the candidate set is:

C={y1,y2,…,yN}\mathcal{C} = \{y_1, y_2, \ldots, y_N\}

where:

  • xx is the input prompt
  • yiy_i is the ii-th candidate response
  • NN is the number of independent samples drawn
  • Each yiy_i is sampled independently from the model's distribution: yi∼pθ(⋅∣x)y_i \sim p_\theta(\cdot \mid x)

The quality of this set depends on two factors. First, the coverage of the sample set: does it contain at least one good answer? Second, the selector's precision: can you reliably pick the best answer from the candidates? Both matter, and each is independently improvable. Coverage is primarily a function of the model's underlying accuracy and the sampling temperature. Selector precision is a function of the verification or scoring mechanism you apply.

It is worth emphasizing that even when coverage is high, a poor selector erases most of the benefit. If your selection rule cannot distinguish the correct answer from the wrong ones, having many correct candidates in the pool does not help. Conversely, even a mediocre selector can extract enormous value from a pool with high coverage. The two components interact multiplicatively: you need both to work.

Sampling Temperature and Coverage

When you sample with temperature T>0T > 0, the model's output distribution over the next token is reshaped. The model ordinarily outputs raw scores called logits, and the softmax function turns them into probabilities. Temperature scales the logits before the softmax, controlling how peaked or flat the resulting distribution is. For a single decoding step, the probability of token tt given the context is:

pθ(yt∣y<t,x)=exp⁡ ⁣(ztT)∑v∈Vexp⁡ ⁣(zvT)p_\theta(y_t \mid y_{<t}, x) = \frac{\exp\!\left(\dfrac{z_t}{T}\right)}{\displaystyle\sum_{v \in V} \exp\!\left(\dfrac{z_v}{T}\right)}

where:

  • ztz_t is the raw logit score for token tt from the model's output layer
  • T>0T > 0 is the temperature parameter
  • VV is the vocabulary (the set of all possible tokens)
  • y<t=(y1,…,yt−1)y_{<t} = (y_1, \ldots, y_{t-1}) is the sequence of tokens generated so far
  • The denominator is the partition function that ensures the distribution sums to 1

When T→0T \to 0, the formula reduces to argmax decoding: the token with the highest logit receives all the probability mass. When T=1T = 1, the distribution is unmodified. When T>1T > 1, the distribution is flattened toward uniform, increasing diversity at the cost of coherence.

For multiple sampling to work well, you need diversity: if all NN samples are nearly identical, you get NN copies of the same answer, and selecting among them gives no improvement over single-pass decoding. The choice of TT is a design decision that trades off coverage (higher TT) against quality per sample (lower TT).

This tradeoff is task-dependent. For math problems where the correct answer is a specific number or expression, high temperatures can improve coverage by exploring more distinct reasoning paths, even if individual chains become noisier. For code generation, moderate temperatures around 0.7 to 0.9 tend to work well, since you want diverse logic but not incoherent syntax. For factual question answering, lower temperatures often work better because the model's top-probability answers tend to be factually correct, and increasing temperature mostly adds noise. The right setting requires empirical calibration for your specific task and model.

Another dimension of diversity is top-p (nucleus) sampling and top-k sampling, which we covered in detail in the GPT Architecture chapter. These methods further shape the sampling distribution by truncating low-probability tokens before sampling. In the context of multiple sampling, they control whether the model explores rare but potentially correct reasoning paths or stays close to its high-confidence outputs.

The pass@k Metric

The probability that at least one of kk samples is correct can be computed exactly if you know how many of nn generated samples are correct. The pass@k formula, introduced for code generation evaluation, is:

pass@k=1−(n−ck)(nk)\text{pass@}k = 1 - \frac{\dbinom{n - c}{k}}{\dbinom{n}{k}}

where:

  • nn is the total number of generated samples for a single problem
  • cc is the number of correct samples among those nn (0≤c≤n0 \le c \le n)
  • kk is the number of samples you are allowed to submit (k≤nk \le n)
  • (ab)\binom{a}{b} denotes the binomial coefficient "a choose b"

The formula counts the fraction of size-kk subsets of the nn samples that contain no correct answer, and subtracts that from 1. If c=0c = 0 (none are correct), pass@k = 0. If c≥kc \ge k, the formula equals 1 because every subset contains at least one correct answer.

To understand why the formula takes this form, consider the complementary event: what is the probability that a randomly chosen subset of kk samples contains no correct answer? There are (n−ck)\binom{n - c}{k} ways to choose kk samples entirely from the n−cn - c incorrect ones, and (nk)\binom{n}{k} ways to choose any kk samples. The ratio of these two binomial coefficients gives the probability of failure, which subtracted from 1 gives the probability of success.

For independent samples each correct with probability pp, the expected pass@k simplifies to the approximation:

E[pass@k]≈1−(1−p)k\mathbb{E}[\text{pass@}k] \approx 1 - (1 - p)^k

where pp is the per-sample probability of correctness. This approximation is tight when nn is large relative to kk.

The practical implication is stark. Even a model with p=0.05p = 0.05 on a hard coding problem achieves:

pass@50≈1−(1−0.05)50=1−0.9550≈0.923\text{pass@50} \approx 1 - (1 - 0.05)^{50} = 1 - 0.95^{50} \approx 0.923

Scaling kk from 1 to 50 converts a near-impossible task (5% success rate) into a highly likely success (92%). This is the mathematical core of why test-time compute works for verifiable tasks: you are not improving any single sample, but you are dramatically improving the probability that your sample set contains at least one correct answer.

Out[4]:
Visualization
Five line curves showing expected pass@k rising toward 1.0 as sample count increases, with faster saturation at higher per-sample accuracy.
Expected pass@k as a function of number of samples k for models with different per-sample accuracy rates. Even a model with only 5% per-sample accuracy reaches over 90% pass@k when given 50 attempts. Curves flatten as k grows, showing the sublinear returns of additional samples once common correct answers are already well-covered.
pass@k

A metric from competitive programming evaluation. Given a problem and kk generated solutions, pass@k is 1 if any of the kk solutions passes all test cases, 0 otherwise. The expected pass@k across problems measures how often the model solves a problem when given kk attempts. It directly quantifies the value of test-time compute by measuring whether the candidate pool contains a correct answer, independent of how well you can identify which candidate is correct.

Selection Strategies

Generating many candidates is useless unless you can pick the best one. The selection problem is harder than it looks, because you cannot in general know which candidate is correct without running the same computation that originally produced it. Several approaches exist for this problem, each with different assumptions, costs, and reliability properties.

Majority voting (self-consistency). If answers to the same question can be compared directly, such as numerical answers or classification labels, select the most frequently occurring answer across all candidates. This works remarkably well for math reasoning: if you generate 40 chain-of-thought solutions and 28 of them arrive at the same numerical answer, that answer is likely correct even if many of the individual reasoning chains contain errors. The underlying reason is that correct answers tend to be unique (there is typically one right answer), while wrong answers are diverse (different chains make different mistakes). This asymmetry means that correct answers accumulate plurality votes while wrong answers split votes among many alternatives.

Majority voting requires no additional model and adds almost no compute overhead, since you just count answer occurrences. Its main limitation is that it only works when answers can be directly compared. For open-ended prose, there is no natural notion of two responses being "the same answer."

Reward model scoring. Train a separate scoring model on human preferences or correctness labels, then select the candidate with the highest score. This is the reranking paradigm used in passage retrieval and code generation. The quality of selection is bounded by the accuracy of the scorer, which means that reward model quality is the binding constraint. A poorly calibrated reward model will select confidently wrong answers, producing no benefit or even net harm from the sampling.

Process reward model (PRM) scoring. Rather than scoring completed answers, a PRM scores each reasoning step and aggregates across the chain. PRMs are more robust to "correct-answer, wrong-reasoning" failure modes because they require the intermediate steps to be valid. When used for candidate selection, the total score for a candidate is typically the product or minimum of its step-level scores. The product penalizes chains with any weak step; the minimum is even stricter, selecting only chains where every step is confident. We covered the design and training of PRMs in detail in the Process Reward Models chapter.

Verifier-guided selection. For structured tasks such as code or formal proofs, you can execute or symbolically check the candidate answer directly. A program that passes all test cases is correct by definition; no learned verifier is needed. This is the gold standard when applicable, because the verification is guaranteed correct and requires no additional model training.

The choice of selection strategy has a large impact on overall accuracy. Majority voting is cheap and reliable when the answer is discrete. Reward model scoring generalizes to open-ended outputs but depends on the quality of the scorer, which may itself be brittle on out-of-distribution queries. PRM scoring sits between these extremes: it is more expensive than majority voting because it requires running the reward model over every step of every candidate chain, but it is more reliable than outcome-level reward models because it catches errors at the step where they first occur rather than only penalizing wrong final answers.

Verifier-guided selection is uniquely powerful for code and formal math because the verification is guaranteed correct. No amount of reward model training can match the reliability of a formal checker or a unit test suite. For this reason, the most impressive test-time compute results in the literature tend to appear on coding and math benchmarks, where this class of feedback is available.

Out[5]:
Visualization
Line chart with random accuracy flat at 0.25, majority-vote accuracy rising toward 1.0, and oracle accuracy forming an upper bound across sample sizes 1 to 64.
Simulated accuracy of three selection strategies (random, majority vote, oracle) as the number of samples N grows from 1 to 64 for a model with 25% per-sample accuracy. Diverse wrong answers let majority voting close most of the gap to the oracle upper bound by N=16, while random selection stays flat at the base accuracy.
Grouped bar chart showing majority-vote marginal gains across six sample-count doublings and zero gain for random selection.
Marginal accuracy gain from each doubling of samples for majority voting vs. random selection. Majority-vote gains concentrate in the early-to-middle doublings and diminish near saturation, while random selection provides zero marginal gain because it is uninformed.

The simulation reveals a consistent pattern: majority voting becomes increasingly valuable once repeated correct answers form a consensus. Its gains peak across the early-to-middle doublings and then diminish as accuracy approaches its ceiling. This is the behavior predicted by the pass@k formula: informed selection converts candidate coverage into accuracy, while random selection remains at the base rate.