Skip to content
nonconvexcard

Inference-Time Search and Best-of-n

What sampling more candidates actually buys — exponentially decaying failure for linear cost, an unbiased pass@k estimator, and the exact KL price of best-of-n.

AgentsGraduate⏱ 1 hour11 min readbest-of-npass@kverifierkl divergencetest-time compute
4 problems →

With a perfect verifier

PropositionBest-of-n with a perfect verifier

Let each of nn independent samples be correct with probability pp, and suppose a verifier identifies a correct sample whenever one is present. Then

P(success)=1−(1−p)n,\P(\text{success}) = 1 - (1-p)^n,

and the number of samples needed to reach target TT is

n ≥ log⁡(1−T)log⁡(1−p).n \ \ge\ \frac{\log(1-T)}{\log(1-p)} .

Estimating pass@k honestly

Evaluating pass@k\mathrm{pass}@k by drawing exactly kk samples is high-variance. The standard estimator draws n≥kn \ge k and computes a combinatorial correction.

PropositionThe unbiased pass@k estimator

Draw nn i.i.d. samples of which cc are correct. Then

pass@k^=1−(n−ck)(nk)\widehat{\mathrm{pass}@k} = 1 - \frac{\binom{n-c}{k}}{\binom{n}{k}}

is an unbiased estimator of the probability that a uniformly random subset of kk of those nn samples contains at least one correct sample.

What best-of-n costs in distribution

Selecting the best of nn samples changes the distribution you are sampling from. That shift has an exact closed form, and it is the quantity that governs reward hacking.

TheoremThe KL divergence of best-of-n

Let π\pi be a base policy and rr a reward whose distribution under π\pi is continuous (so ties have probability zero). Let πn\pi_n be the distribution of the highest-reward sample among nn i.i.d. draws from π\pi. Then

KL(πn ∥ π)  =  log⁡n−n−1n.\mathrm{KL}\big(\pi_n \,\|\, \pi\big) \;=\; \log n - \frac{n-1}{n}.

Key idea

The divergence grows like log⁡n\log n — slowly, but without bound, and it depends on nothing about the reward except that it is continuous. So best-of-nn gives a principled exchange rate between compute and distribution shift, and lets you compare test-time selection against a KL-regularised fine-tune on the same axis: n=8n = 8 costs about 1.201.20 nats, n=64n = 64 about 3.173.17.

This matters because distribution shift away from the base policy is exactly the regime where a learned reward model stops being trustworthy — it was fit on samples from the base policy, and best-of-nn is deliberately sampling where those were rare.

Imperfect verifiers

PropositionAn imperfect verifier caps the gain

Suppose each sample is correct with probability pp, the verifier accepts a correct sample with probability 11, and accepts an incorrect sample with probability \varphi > 0. If the system returns a uniformly chosen accepted sample, then as n→∞n\to\infty the probability that the returned answer is correct tends to

\frac{p}{p + (1-p)\varphi} \;<\; 1 .

What this does not say

Independence across samples is assumed throughout. Samples from one model at one temperature are not independent in the relevant sense — they share the model's systematic errors — so (1−p)n(1-p)^n overstates the benefit exactly as it did for majority voting. And nothing here addresses which search to run: best-of-nn over complete solutions, beam search over steps, or tree search with backtracking all spend the same compute differently, and the comparison between them is empirical.

Results stated on this page

  • PropositionBest-of-n with a perfect verifierproof includedFailure probability falls as (1−p)ⁿ, so success improves exponentially in samples while cost grows linearly.
  • PropositionThe unbiased pass@k estimatorproof includedFrom n samples with c correct, 1 − C(n−c, k)/C(n, k) is an unbiased estimate of the probability that k draws contain a correct one.
  • TheoremThe KL divergence of best-of-nproof includedBest-of-n sampling against a continuous reward has KL divergence exactly log n − (n−1)/n from the base policy.
  • PropositionAn imperfect verifier caps the gainproof includedWith false-positive rate φ, selected-answer precision is bounded regardless of n, and for large n the verifier's errors dominate.

Problems (4)

All problems