27 July 2026
PPO for LLM Alignment
While learning RLHF, I kept mixing up two things: RLHF is the training framework, and PPO is the optimization algorithm that does the actual update inside it. PPO is a general reinforcement learning algorithm, and you could swap it for something else. I also had a wrong picture of what PPO does: I thought the new model answers the old questions again and we compare the two rewards. It doesn't. Today I want to get the real picture down.
In one sentence: PPO takes a fixed batch of generated answers, uses the advantage to push the probability of each old token up or down, and clips the probability ratio so the same batch can be reused without the policy moving too far.
Mapping RL words to LLM words
| RL concept | In an LLM |
|---|---|
| Policy / Actor | the language model generating tokens |
| State | prompt + tokens generated so far |
| Action | the next token |
| Trajectory | the full response |
| Reward | score for the full answer, plus a per-token KL penalty |
| Critic | predicts the total future return from this prefix |
The models involved
| Model | Updated? | Job |
|---|---|---|
| Actor | yes | the model we want to improve |
| Critic | yes | estimates the return, gives a low-variance baseline |
| Reward model | no | scores a full response by human preference |
| Reference | no | stops the actor drifting too far from the SFT model |
| Actor_old | frozen within one batch | the policy that generated this batch |
Actor_old is not a fifth permanent model. Every time we collect a new batch, the current actor becomes Actor_old for that batch.
Reward, return, value, advantage
The way I remember it: reward is how many points you got, value is how many points the critic expected, and advantage is how much better you did than expected.
- : make the old action more likely.
- : make the old action less likely.
GAE
The reward belongs to the whole answer, so GAE spreads the credit backwards from the end:
Rewards per token
The reward model usually gives one score for the whole answer. The KL penalty against the reference model turns into a small reward on every token:
The reward model's score is added only on the last token.
How PPO updates
1. Reuse the batch
Generating answers, scoring them and running the reference and critic are all expensive. So PPO fixes one batch of trajectories and trains on it for several ppo_epochs. In each epoch, it does not generate new answers. It just runs the current actor over the same old tokens (teacher forcing) and recomputes their log-probs.
2. The probability ratio
- : the new and old actor give the old token the same probability.
- : the current actor made it about 10% more likely.
- : about 20% less likely.
3. The clipped objective
With :
- Positive advantage: pushing the probability up is right, but there is no extra reward for going past 1.2.
- Negative advantage: pushing it down is right, but no extra reward for going below 0.8.
- If the policy moves in the wrong direction, the objective still punishes it. Clipping does not switch off every gradient.
One round of training
Actor_oldgenerates answers for a batch of prompts.- The reward model scores them, the reference model gives log-probs, the critic gives values.
- Compute rewards, then GAE advantages and returns.
- Freeze this batch and train the actor and critic on it for several epochs.
- Collect a fresh batch with the updated actor and repeat.
Fixed inside one batch: prompts, response tokens, old log-probs, old values, rewards, advantages, returns. Changing in each epoch: the actor and critic weights, new log-probs, the ratio, new values, the loss.
The critic learns to predict the fixed target return:
Two kinds of "don't move too far"
| Compare | Purpose | How long |
|---|---|---|
| Actor_new vs Actor_old | reuse one batch safely | refreshed every batch |
| Actor vs Reference | limit long-term drift during RLHF | fixed the whole time |
The PPO ratio and clipping are not the same as the reference KL. The first keeps one batch's optimization stable, and the second keeps the model close to the SFT model overall.
Things I got wrong at first
- Inside a PPO epoch the model does not answer again, and there is no
reward_new. New answers and new rewards only come in the next batch. - PPO looks at the advantage, not whether the reward is positive. A positive reward that is lower than the critic expected still gives a negative advantage.
- Clipping only affects the tokens that were sampled. It is not a hard limit on the whole vocabulary distribution, so people still monitor approximate KL.
Why it works, and why it is hard
It works because:
- it turns a non-differentiable reward score into token probability updates
- one expensive batch can be reused for several epochs
- the ratio and clipping stop the old data from being overused
- the critic and GAE reduce the variance of the policy gradient
It is hard because:
- the reward model can be exploited, and spreading one score over a whole answer is only an approximation
- four models run at the same time, so memory and throughput are expensive
- the KL coefficient, reward scale, advantage normalisation, clip range and GAE settings all affect stability