Surrogate objective and trust regions
Suppose a batch was collected with the policy . For a new policy , importance sampling rewrites the expected advantage-weighted objective with samples from the old policy: Here is an advantage estimate computed with the old policy, usually by generalized advantage estimation. At the gradient of equals the policy gradient. Away from , is only a local approximation, because the states in the batch were visited by the old policy, and maximizing it without limit overshoots. Trust region policy optimization (TRPO) (Schulman et al., 2015) maximizes subject to a bound on the average KL divergence between the old and the new policy, . TRPO comes with a monotonic improvement guarantee for an idealized version of the problem, but each update needs a second-order solve (conjugate gradient with Fisher-vector products and a line search), which is complex to implement and does not combine easily with networks that share parameters between actor and critic.The clipped objective
PPO keeps the idea of a trust region and replaces the constraint by a change in the objective: with around 0.2. The minimum makes a pessimistic bound on . Its effect depends on the sign of the advantage:
Once a good action has become times more likely, or a bad action times as likely, its sample stops contributing. On the other side of the window the unclipped term stays active, so a step that made a good action less likely is still corrected. Clipping does not bound the size of a step; it decides, before each step, which samples still pull. The minimal examples show both effects on a policy with one parameter.
The PPO paper also proposes a variant with a KL penalty instead of clipping, , where is doubled or halved after each update depending on whether the measured KL was above or below a target. In the paper’s experiments the clipped objective performed better, and it is the version most implementations use.
The full loss
With a shared network, or with separate actor and critic networks trained together, PPO maximizes The second term trains the critic toward return targets , usually . The third term is an entropy bonus that keeps the policy from becoming deterministic too early. The coefficients and weight the three parts.The algorithm
PPO talk
PPO talk
Analytical derivations
Analytical derivations
PPO for language models
PPO is the algorithm of the original RLHF pipeline for language models (Ouyang et al., 2022). The state is the prompt together with the tokens generated so far, an action is the next token, and an episode is one complete response. A reward model trained on human preference comparisons scores the finished response. Two changes adapt PPO to this setting:- A frozen copy of the model before RL, the reference model, stays loaded. A penalty on the per-token KL divergence between the policy and the reference is subtracted from the reward, which keeps the policy from drifting into text that fools the reward model.
- The critic is a separate value model, usually initialized from the reward model and as large as the policy.
Further reading
- Huang et al. (2022), The 37 Implementation Details of Proximal Policy Optimization: every engineering choice needed to reproduce PPO results in practice.
References
- Ouyang, L., Wu, J., Jiang, X., Almeida, D., Wainwright, C., et al. (2022). Training language models to follow instructions with human feedback. arXiv [cs.CL]. Link
- Schulman, J., Wolski, F., Dhariwal, P., Radford, A., Klimov, O. (2017). Proximal Policy Optimization Algorithms. arXiv [cs.LG]. Link
- Schulman, J., Levine, S., Moritz, P., Jordan, M., Abbeel, P. (2015). Trust Region Policy Optimization. arXiv [cs.LG]. Link
Found an error on this page? Report an issue.

