- Key idea
- On-policy vs off-policy data, and the importance weight new ÷ old
- Real world
- A phone poll reaches too many retirees. Pollsters don't throw the answers away; they count each retiree's answer for less and everyone else's for more, so the result matches the real population.
- In an LLM
- Answers generated by last step's weights, or by a separate fast inference engine, are used to train the current weights. Each token is reweighted by how much more or less likely the current model makes it.
On-policy and off-policy
Policy gradient assumes the samples came from the policy you are updating. That data is on-policy. As soon as the policy changes, even by one gradient step, older samples become off-policy: they show what the old policy did, not the new one.
Throwing them away is wasteful, because generating answers is the expensive part of LLM training. Importance sampling lets you keep them. Weight each sample by
Samples the new policy likes more than the old one count for more. Samples it likes less count for less.
A poll asks whether people support a new park. 60% of the people reached are over 60, but they are only 30% of the town.
| Group | Share of poll | Share of town | Support | Weight |
|---|---|---|---|---|
| Over 60 | 60% | 30% | 70% | 0.3 ÷ 0.6 = 0.5 |
| Under 60 | 40% | 70% | 40% | 0.7 ÷ 0.4 = 1.75 |
Plain average of the poll. Wrong: it describes the people reached.
Weighted. That is exactly the town's support.
The model wrote an answer that got advantage +1. Since then, the weights have moved:
| Token | Probability when sampled | Probability now | Weight |
|---|---|---|---|
So | 0.60 | 0.60 | 1.0 |
Wait | 0.10 | 0.15 | 1.5 |
Alternatively | 0.02 | 0.12 | 6.0 |
Each token's gradient is multiplied by its weight. Alternatively is now six times likelier than when it was sampled, so this old sample says a lot about the current policy, perhaps too much. That is where capping comes in.
Try it
Why weights explode for long answers
The probability of a whole answer is the product of its token probabilities, so the weight of a whole answer is the product of the token weights. Tiny differences on each token multiply up:
- 1,000 tokens each 1% more likely: .
- 1,000 tokens each 1% less likely: .
That's why LLM methods almost never use the raw sequence weight. They use per-token weights (PPO), clip or cap them (CISPO, TIS), or average the log-weights over the tokens (GSPO).
Where it shows up
- PPO: the ratio ρ is an importance weight, so a batch can be reused for several gradient steps.
- Asynchronous training: answers written by an older copy of the model, a few updates behind.
- Sampler–trainer mismatch: the fast inference engine and the trainer disagree slightly about probabilities, even with identical weights.
The identity
For a target policy and a behaviour policy that generated the data:
The estimate is unbiased but its variance grows with , which explodes when puts weight where rarely samples.
Truncated importance sampling uses : biased, but with bounded variance. For sequences, the policy gradient is usually approximated per token,
which ignores how earlier tokens changed the states later tokens see. It's a good approximation while and stay close, which is what clipping enforces.