- Key idea
- Estimators: Monte Carlo averages, bias, variance, and mean squared error
- Real world
- A pollster can't ask every voter, so they ask 1,000 and report the average. A good method is right on average (unbiased) and doesn't swing wildly from poll to poll (low variance).
- In an LLM
- A model's pass@10 on a problem, the KL between policy and reference, the policy gradient itself: none can be computed exactly, because each is a sum over every possible answer. Each is estimated from a few sampled answers or tokens.
Monte Carlo estimation
Most quantities in LLM training are expectations: an average over every possible answer, weighted by how likely the model is to write it. There are astronomically many answers, so the sum can never be done. Instead:
- Sample a few answers from the model.
- Compute the quantity for each.
- Average.
This is Monte Carlo estimation, named after the casino. The law of large numbers (error bars) says the average approaches the true expectation as samples grow. The question this page answers is: how good is it with the few samples we can afford?
A player has a true free-throw rate of 70%. Watch 10 shots and count the makes: you might see 6, 7, 9 or 5. The method "makes ÷ shots" is right on average, but any single estimate from 10 shots is typically off by about 15 points.
A model solves a maths problem with probability 0.3. Sample 8 answers, check them, and report the fraction correct. Some runs give 1/8, others 4/8. RL methods like GRPO feed exactly this kind of noisy 8-sample estimate into every update.
Bias and variance
An estimator is a recipe that turns samples into a guess. Because the samples are random, the guess is random too. Two numbers describe it:
- Bias: how far the average guess is from the truth. Zero bias means "right on average": the estimator is unbiased.
- Variance: how much the guess jumps around from one batch of samples to the next. Its square root, the standard deviation, is the typical size of the error.
They combine into the mean squared error: bias² + variance. A slightly biased estimator with much lower variance often wins, which is the whole idea behind clipping and truncation in RL.
A scale that always reads 1 kg heavy is biased but consistent. A scale that is right on average but jumps ±3 kg each time is unbiased but has high variance. For tracking your weight week to week, the biased one is more useful: you can see the trend.
A trap: plugging an estimate into a formula
An unbiased estimate of does not give an unbiased estimate of a function of . The pass@k example: pass@k . You might estimate by and plug it in. But the formula is curved, so errors in don't cancel, and the result is systematically too low.
The fix, from the Codex paper, is an estimator built directly for pass@k: of the samples, are correct; choose of the at random; the chance that none of them is correct is . One minus that is unbiased.
Estimate a die’s chance of six by rolling 6 times and counting sixes, then plug that into "chance of at least one six in 6 rolls". See exactly one six and you get , the true value. But a run with no sixes gives 0, and a run with three gives 0.98. Because the curve flattens near 1, the highs don't make up for the lows. The average of the plug-in estimates is about 0.51, not 0.665.
20 samples, 2 correct. The plug-in gives . The unbiased estimator gives . Averaged over a benchmark, the plug-in version would understate pass@10 for every model.
Try it
Three KL estimators
The KL penalty needs , a sum over the whole vocabulary at every position. Trainers estimate it from the single sampled token, using the ratio :
| Estimator | Formula | Unbiased? | Notes |
|---|---|---|---|
| k1 | yes | Can be negative; high variance | |
| k2 | no | Low variance when close; biased as policies drift | |
| k3 | yes | Never negative; low variance when close; used by GRPO |
k3 works because has expected value zero under , so adding it changes nothing on average, but it cancels much of k1's noise. That's a control variate, the subject of the score function page.
Where this shows up
- pass@k in every reasoning paper uses the unbiased estimator: Does RL teach new skills?.
- The policy gradient is a Monte Carlo estimate; baselines are variance reduction: score function and baselines.
- Importance sampling reuses samples from the wrong distribution: importance sampling in depth.
- Evals are Monte Carlo estimates of a model's accuracy: error bars, comparing models.
Definitions
For a quantity and i.i.d. samples , the Monte Carlo estimator is
For any estimator of :
Why plug-in estimates are biased
If is convex, Jensen's inequality gives ; if concave, the reverse. is concave in , so plugging in underestimates pass@k. The same reasoning explains why of an average differs from the average of s, which shows up when papers estimate a sequence's log-likelihood from samples.
Unbiased pass@k
With samples and correct (Chen et al., 2021):
The product form avoids overflowing binomial coefficients. Pass@k training papers go further and derive unbiased, low-variance estimators of the gradient of pass@k, so RL can optimise it directly.
KL estimators
With and , using :
always, since . matches the KL only to second order. In papers you'll see these written per token, inside the GRPO objective, as
which is .
Papers
- Evaluating Large Language Models Trained on Code (Chen et al., 2021): the unbiased pass@k estimator
- Schulman, Approximating KL Divergence (blog, 2020): k1, k2, k3
- DeepSeekMath (Shao et al., 2024): GRPO, with k3 in the loss
- Pass@K Policy Optimization (Walder & Karkhanis, 2025): unbiased, low-variance pass@k gradient estimators
- On the Design of KL-Regularized Policy Gradient Algorithms for LLM Reasoning (Zhang et al., 2025) and Rethinking KL Regularization in RLHF (Liu et al., 2025): which estimator gives the right gradient
- A Comedy of Estimators: On KL Regularization in RL Training of LLMs (Shah et al., 2025): k1/k2/k3 in the reward versus the loss, compared empirically