- Key idea
- Importance weights, effective sample size, self-normalisation, truncation, and per-token vs per-sequence ratios
- Real world
- A survey reached twice as many over-60s as the population has. Count each over-60's answer at half weight and each younger person's at a bit more, and the survey speaks for everyone. But if only 3 people under 30 replied, their huge weights make the result fragile.
- In an LLM
- Answers generated by a slightly older copy of the model, or by a fast inference engine, train the current model. Each answer is reweighted by how much more or less likely the current model makes it. For a 10,000-token answer, that weight can be astronomically large or tiny.
Importance sampling in the RL course introduces the idea. This page covers the probability behind it: when it works, how to measure how badly it's failing, and the corrections you'll meet in papers.
The identity
You want an average under a target distribution , but your samples come from a proposal (or behaviour) distribution . Multiply each sample by its importance weight :
It's exact, with one condition: must give some chance to everything can produce. If where , those outcomes are never sampled, and no reweighting can recover them.
The population is 25% over-60s; the survey got 50%. Weight each over-60 by and each younger person by . The reweighted average matches the population, without surveying anyone new.
A token was sampled when the model gave it probability 0.20; after one gradient step the model gives it 0.24. Its weight is : this sample counts 20% more when estimating what the current model would get. That ratio is exactly PPO's .
When it fails: effective sample size
The estimate stays unbiased however different and are. What breaks is the variance. If puts weight where rarely samples, a few samples get enormous weights and dominate the average. Your 1,000 samples behave like 5.
The effective sample size (ESS) puts a number on this:
If all weights are equal, ESS equals the number of samples. If one weight dwarfs the rest, ESS is close to 1. It's the standard diagnostic in statistics, and the thing to look at when an off-policy method misbehaves.
If 3 of 1,000 respondents are under 30 but the population is 20% under 30, each of those three gets weight about 67, while everyone else gets about 0.8. The ESS is about 70, not 1,000, and the "young people" part of the result is the opinion of three individuals.
In asynchronous RL, a batch was sampled four model versions ago. Most token weights are near 1, but a few tokens the model has since learned to avoid now have weights near 0, and a few it has come to favour have weights of 3 or more. Logging the ESS of a batch shows how much its staleness actually costs.
Three ways to tame the weights
| Method | What it does | Cost |
|---|---|---|
| Self-normalised IS | Divide by the sum of the weights instead of by n | Slightly biased; can't blow up past the largest |
| Truncated IS (TIS) | Cap each weight at C | Biased toward the proposal; bounded variance |
| Masking (IcePop, MIS) | Drop samples whose weight is outside a trusted range | Throws data away; ignores those samples entirely |
Try it
Long answers: per-token and per-sequence weights
An answer's probability is the product of its tokens' probabilities (chain rule), so the exact weight for a whole answer is the product of its token weights:
Take logs and it's a sum of small random terms. Sums of many random terms spread out like (the central limit theorem), so the log-weight spreads like and the weight itself spreads exponentially. For thousand-token answers the exact correction is unusable.
What methods do instead:
- Per-token weights (PPO, GRPO): weight each token's gradient by its own ratio. Bounded, but it ignores that earlier tokens changed what later tokens see. It's an approximation that's fine while the two policies stay close, which clipping enforces.
- Geometric mean (GSPO): one weight per answer, . The spread now shrinks like . Stable, at the price of no longer being an exact correction.
- Truncate or mask per token (TIS, IcePop): for the sampler–trainer mismatch, cap or drop tokens whose ratio between engines is extreme.
A 1% monthly difference in interest rate doesn't sound like much. Over 30 years, it's a factor of . Small per-step ratios multiplied over many steps stop being small.
The trainer and inference engine disagree by about ±0.01 in log-probability per token. Over 10,000 tokens, the sequence log-weight is off by about , a factor of either way, purely from rounding differences.
Where this shows up
- PPO and GRPO ratios: PPO, GRPO.
- GSPO, CISPO, TIS and other ratio fixes: GRPO fixes, sampler–trainer mismatch.
- Off-policy and asynchronous RL: async rollouts.
- Speculative decoding uses the same ratio to accept or reject: rejection sampling.
Estimators
With and :
Self-normalised IS also works when is only known up to a constant, , because the constant cancels. That matters for tilted distributions and sequential Monte Carlo, where the target is never normalised.
Variance and the χ² divergence
If each token's log-ratio is roughly under the sampler (so each token weight has mean 1), the sequence log-weight is and : exponential decay in length. The widget's "long answers" mode plots exactly this.
As written in papers
The PPO/GRPO token ratio and the GSPO sequence ratio:
For the sampler–trainer mismatch, is split in two: (what the inference engine computed) and (what the trainer computes). The TIS weight multiplies the usual loss.
Papers
- Owen, Monte Carlo theory, methods and examples, chapter 9 (book): importance sampling and ESS
- Group Sequence Policy Optimization (Zheng et al., 2025): length-normalised sequence ratio
- Defeating the Training-Inference Mismatch via FP16 (Qi et al., 2025)
- Every Step Evolves (Ling Team, 2025): IcePop masking
- Yao et al., Your Efficient RL Framework Secretly Brings You Off-Policy RL Training (blog, 2025): TIS