Proximal policy optimisation (PPO)
Stable, reusable policy updates with a clipped surrogate objective and generalised advantage estimation.
Animated explanation
The idea
Policy gradients have a nasty failure mode: one overly large update can wreck the policy, the next batch of data is then collected by the wrecked policy, and learning collapses. We want to take the biggest safe step.
PPO does this with a simple trick. It measures how much the new policy changes the probability of each sampled action (the ratio ) and clips the objective so that pushing beyond earns nothing. The policy can then be optimised for several epochs on the same batch without running away. Combined with GAE advantages, a value loss and an entropy bonus, PPO is robust, simple to implement and the default algorithm in much of modern RL, including the fine-tuning of language models from human feedback (RLHF).
Trust regions, simplified
TRPO enforced a hard limit on the KL divergence between old and new policies using second-order optimisation. PPO approximates the same "trust region" with first-order SGD and clipping, which is much simpler and usually works as well. Some variants use an adaptive KL penalty instead of clipping; monitoring the approximate KL each update is a good health check.
Implementation details that matter
Normalise advantages per mini-batch; clip the value function too (optionally); use GAE with λ ≈ 0.95 and γ ≈ 0.99; 3–10 epochs per batch; Adam with learning-rate annealing; orthogonal initialisation; observation normalisation. Many published differences between PPO implementations come from these details rather than the core objective.
The algorithm, step by step
- 1Collect T steps with (log-probabilities, values, rewards, done flags).
- 2Compute δ and GAE advantages backwards: ; value targets .
- 3For K epochs, over shuffled mini-batches: maximise .
- 4Set ; repeat.
The maths
Probability ratio
Clipped surrogate
GAE recursion
Strengths and weaknesses
Strengths
- Stable and robust across many tasks
- Multiple epochs per batch: better sample use than vanilla PG
- Simple first-order implementation; scales with parallel environments
Weaknesses
- Still on-policy: data is discarded after each iteration
- Many implementation details and hyperparameters
- Less sample-efficient than off-policy methods like SAC
Reach for it when…
Check your understanding
Lambdian Lab
The pieces of PPO
Implement and test PPO's core computations.
- gae(rewards, values, dones, gamma, lam): values has length T + 1 (the last one bootstraps); return (advantages, returns) with returns = advantages + values[:T].
- clipped_objective(logp_new, logp_old, adv, eps): the mean of the clipped surrogate.
- ppo_bandit(steps, epochs, eps, lr, seed): a 3-armed bandit with rewards [0.2, 1.0, 0.5] and a softmax policy over logits; each step samples 64 actions, advantages = reward − batch mean, then "epochs" gradient-ascent steps on the clipped objective (numerical gradient is fine). Return the final logits.