Paper
Proximal Policy Optimization Algorithms
PPO stabilizes policy gradient training by clipping the objective to prevent destructively large policy updates, becoming the dominant algorithm for RLHF.
John Schulman, Filip Wolski, Prafulla Dhariwal, Alec Radford, Oleg Klimov — OpenAI2017arXiv ↗Views: –
The step-size problem
A policy gradient method improves a stochastic policy by raising the probability of actions that beat expectation, following the estimator . The trouble is that this gradient is a direction, not a distance: it tells you where to move in parameter space but says nothing about how far is safe.
A step that is too small wastes samples and learning crawls; a step that is too large pushes the policy into a region the collected trajectories no longer describe, and performance collapses with no data on hand to undo the damage. TRPO addresses this by maximizing the surrogate subject to a hard constraint , which keeps each update inside a trust region. That works, but it requires solving a constrained second-order problem every step — a conjugate-gradient inner loop against the Fisher-vector product — which is awkward to implement and incompatible with architectures that share parameters or add noise. PPO keeps the trust-region intuition but throws out the machinery, using only first-order updates.
The surrogate objective
PPO is built around the probability ratio between the new and old policies, which is exactly before any gradient step is taken because the two policies are identical at that moment.
The "conservative policy iteration" surrogate weights each advantage by this ratio, giving . Maximizing it directly is the naive move and it fails for the same reason vanilla gradients do: nothing stops the optimizer from driving to enormous values when , sending far outside the region where the old samples — and the advantage estimates computed from them — remain valid.
Clipping the ratio
PPO's central trick is to clip the ratio into and take the minimum of the clipped and unclipped terms, so the objective becomes a pessimistic lower bound on .
The behaves differently depending on the sign of the advantage, and it is worth tracing both cases. When the action was better than expected and we want to rise; the term caps the reward at , so once the ratio crosses that ceiling the objective flattens and its gradient vanishes — there is no incentive to make an already-favored action drastically more likely. When the action was worse than expected and we want to fall; here the clip floors the contribution at , so pushing the probability down past that point stops helping. In both cases the ensures the bound only ever removes incentive to move far from ; it never lets a favorable clip make the objective look better than the honest unclipped term. One asymmetry to keep in mind: when and the ratio has already blown up past (the policy moved the wrong way), the unclipped term is the smaller one, so the gradient is not cut off and the update can still pull the mistake back.
The full loss
In practice the policy and value function share a network, and exploration needs encouragement, so the quantity actually optimized combines three terms.
The first term is the clipped surrogate that drives policy improvement. The second is a value-function regression loss, , which trains the critic whose predictions feed the advantage estimates; trades policy against value learning when they share weights. The third is an entropy bonus that keeps the action distribution from collapsing prematurely, with controlling how much exploration is rewarded.
Token-level PPO for language models
The reason PPO matters far outside robotics is that RLHF casts text generation as exactly this MDP. The state is the prompt plus everything generated so far, the action is the next token, and the policy is the language model itself: is the softmax probability the model assigns to token given the context. The ratio is therefore computed per token, comparing the model being trained against a frozen snapshot taken at the start of the current PPO iteration.
The efficiency that makes this tractable comes from teacher forcing: a single forward pass over the full completion, with the realized tokens as labels, yields at every position at once, so all ratios for an -token response fall out of one pass rather than sequential decodes. RLHF then adds a per-token penalty for drifting away from a separate reference policy — the frozen SFT model — pulling the effective per-token reward toward
where is nonzero only at the final token (the scalar reward-model score). This KL term, distinct from PPO's own clipping, is what stops reward hacking: without it the policy would chase whatever degenerate text maximizes the imperfect reward model, and the -weighted anchor to keeps generations fluent and on-distribution.
Advantages via GAE
The advantage that scales every ratio is itself estimated, and PPO almost always uses generalized advantage estimation. The one-step TD residual measures how much better a transition turned out than the critic predicted.
GAE forms an exponentially weighted sum of these residuals, where interpolates between the low-variance, high-bias one-step estimate (, just ) and the high-variance, low-bias Monte Carlo return ().
In the language-model setting is typically set near since the sequence is short and the reward is terminal, and the value head — predicting expected return from each partial generation — is the critic trained by the term above.
PPO training loop
Push the new policy toward the advantaged action (a₃). PPO clips the update so the policy can't move too far in one step.
Old policy πθ_old
New policy πθ
Probability ratio r(θ) = πθ(a₃) / πθ_old(a₃) = 2.160
Shaded band = clip window [1−ε, 1+ε] = [0.80, 1.20]. r is outside the window → the objective is clipped.
Unclipped r·A
2.160
PPO objective (clipped)
1.200
KL(old ‖ new)
0.2668
With a positive advantage the PPO objective is min(r·A, clip(r)·A). Once r exceeds 1+ε the clipped term wins, so the gradient flattens — large updates earn no extra reward, which keeps the new policy close to the old one (small KL).