Trust Regions: TRPO & PPO
Stable policy updates with constraints.
A policy-gradient step that is slightly too large can wreck an on-policy agent: the worse policy collects worse data, and training may never recover. TRPO proved that a KL penalty makes every step an improvement, then relaxed the proof into a trust region; PPO replaced the trust region with a clipped ratio and became the default, for reasons that turned out to lie partly in its implementation details.
What you’ll learn
- Prove the performance-difference lemma, and explain why the surrogate objective matches the true objective to first order.
- State and prove TRPO's monotonic-improvement bound, and derive the natural-gradient trust-region step.
- Analyze PPO's clipped objective case by case, and explain why it does not strictly enforce a trust region.
- Summarize what large ablation studies found about which implementation details matter.
Why the step size is the hard part
In supervised learning a bad gradient step is corrected by the next minibatch. In on-policy RL the next minibatch comes from the policy you just damaged. And the size that matters is measured in policy space, not parameter space: a small change to the logits of a nearly deterministic softmax can move a lot of probability, while a large change elsewhere moves almost none. To control steps, you need to know how a policy change affects the return.
Since , the discounted sum along a trajectory of telescopes, and :
The right side needs states visited by the new policy, which we have not run. Replace by to get the surrogate; an importance ratio on the action lets it be estimated from data of :
At the two objectives agree in value, because advantages average to zero under the policy, and in gradient, because differentiating the importance ratio at reproduces the policy-gradient theorem. A small enough step that improves improves ; the question is how small.
Kakade and Langford's conservative policy iteration answered for mixtures. Moving to guarantees , with . The gain in is linear in and the penalty quadratic, so a small enough mixture always improves. Mixtures of neural policies are awkward, though, which is where TRPO comes in.
TRPO: a lower bound you can climb
Let . Subtracting the surrogate from the lemma leaves only the difference between the two state distributions:
Couple the two policies so that in every state they pick the same action except with probability . Since , is the expected change in advantage when the coupled actions differ:
Run the coupled policies from the same start. Their states at time can differ only if their actions disagreed at some earlier step, which has probability at most :
Sum the geometric series:
The bound is a minorizer: lies below everywhere and touches it at . Maximizing it therefore guarantees improvement, : a minorize–maximize (MM) algorithm. Gradient descent on a smooth function is the simplest instance. If is -Lipschitz, , a quadratic upper bound whose best step is and which guarantees a decrease for every .
For the gradient is -Lipschitz (). Gradient descent with : how many steps does it need to reach the minimum from any start?
Show the answer
1
The update is : one step. On a quadratic the upper bound is exact, so its minimizer is the true minimizer. Try it in the widget, then try steps that the bound does not certify.
With , how large is TRPO's penalty coefficient relative to the largest advantage ?
- About
- About
- About
- About
Show the answer
C. About
. With so large a penalty the steps the theory certifies are tiny, so practical TRPO keeps the logic but replaces the penalty by a constraint on the average KL divergence, with a radius chosen by hand.
Practical TRPO solves subject to , with in the original experiments. Linearize the objective, , and expand the constraint to second order, with the Fisher information: the solution is a natural-gradient step, . Using the average rather than the maximum KL was later supported by a bound stated with expected divergences (Achiam, Held, Tamar & Abbeel, 2017).
g ← ∇_θ L(θ) at θ_old # policy gradient with advantage estimates
s ← conjugate_gradient(F, g) # s ≈ F⁻¹g from Fisher–vector products alone
β ← sqrt(2δ / (sᵀ F s)) # largest step with ½·ΔᵀFΔ = δ
for j = 0, 1, 2, …: # backtracking line search
θ ← θ_old + 0.5^j · β · s
if KL(θ_old, θ) ≤ δ and L(θ) > L(θ_old): breakOne TRPO update. Conjugate gradient needs only products , each about as costly as a gradient, so is never formed; the line search enforces the true constraint and an actual improvement of the surrogate.
PPO: clipping the probability ratio
TRPO's second-order machinery is complicated, and awkward with architectures that share parameters between policy and value function. PPO (Schulman et al., 2017) keeps a first-order optimizer and removes the incentive to move far instead. With the probability ratio and advantages from generalized advantage estimation, it maximizes
| Advantage | Ratio | Active term | Gradient of the sample |
|---|---|---|---|
| raises the action's probability | |||
| zero: no reward for raising a good action further | |||
| lowers the action's probability | |||
| zero: no reward for lowering a bad action further |
for iteration = 1, 2, …:
run π_θold for T steps in each of N environments
compute advantages Â_t by GAE(γ, λ) with the critic V_φ; returns R̂_t ← Â_t + V_φ(s_t)
for epoch = 1, …, K:
for each minibatch M of the N·T samples:
r ← π_θ(a | s) / π_θold(a | s)
L_clip ← mean over M of min(r·Â, clip(r, 1 − ε, 1 + ε)·Â)
L_V ← mean over M of (V_φ(s) − R̂)²
gradient step to increase L_clip − c₁·L_V + c₂·(mean entropy of π_θ)
θold ← θPPO reuses each batch for several epochs; the paper's MuJoCo runs used 2,048 steps per iteration, 10 epochs and minibatches of 64, with GAE (). A variant with an adaptive KL penalty instead doubles or halves the penalty coefficient when the measured KL drifts from a target; the clipped version did better in the paper's benchmarks.
What actually matters
Engstrom et al. (2020) dissected the reference implementations of PPO and TRPO. Beyond the clipped loss, the PPO code contained "code-level optimizations": value-function clipping, reward scaling by a running estimate of the return's standard deviation, orthogonal initialization with layer scaling, learning-rate annealing, observation normalization and clipping, tanh activations, and global gradient-norm clipping. They concluded that these optimizations account for most of PPO's gain in reward over TRPO, and that they change how the algorithms behave, including how well the trust region is maintained. Ilyas et al. (2020) added that at typical batch sizes the gradient estimates correlate poorly with the true gradient, and that the surrogate's landscape can differ markedly from the true reward landscape.
Andrychowicz et al. (2021) trained over 250,000 agents to measure more than fifty such choices in on-policy actor–critic methods. Among their recommendations: use the PPO clipped loss, always normalize observations, initialize the policy's last layer with small weights so that the initial policy barely depends on the observation, use GAE with , and tune the discount factor per environment. The lesson generalizes beyond PPO: in deep RL, details that papers relegate to appendices can matter as much as the headline objective.
PPO's most visible deployment is fine-tuning language models from human feedback, where the "environment" is a learned reward model and a KL penalty to a reference model adds a second leash. Fine-Tuning, RLHF & Prompting and RLHF & Preference Optimization cover it, together with critic-free REINFORCE-style variants (RLOO, GRPO) that replace the value network with the average reward of several samples per prompt.
Key takeaways
- Performance-difference lemma: ; the surrogate swaps in the old state visitation and matches to first order.
- TRPO's theorem, , is proved by coupling; maximizing this minorizer is an MM algorithm with monotone improvement.
- Practical TRPO constrains the average KL to and steps along the natural gradient (by conjugate gradient) with size , checked by a line search.
- PPO's clipped surrogate is a pessimistic bound on that zeroes the gradient only for moves that would improve the objective beyond the band; it does not strictly enforce a trust region.
- Implementation details (normalization, initialization, schedules, value clipping) matter as much as the objective, as large ablation studies showed.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
The surrogate differs from the exact expression only in:
- The advantages, which it estimates for instead of
- The state weighting, instead of
- The discount factor
- Nothing: the two are equal
Show the answer
B. The state weighting, instead of
Everything else is exact. Using the old policy's state visitation is what makes computable from old data, and the TRPO theorem bounds the price of that substitution by a quadratic in the policies' divergence.
In PPO with , a sample has and probability ratio . What does it contribute to the gradient of ?
- Nothing: its ratio is outside the clip range
- A push to raise further
- A push to lower , since the unclipped term is the minimum
- A push toward exactly, and then nothing
Show the answer
C. A push to lower , since the unclipped term is the minimum
because , so the unclipped branch is active and its gradient lowers the probability of this bad action. Clipping removes only the incentive to move further in the direction that improves the objective; it never blocks a correction.
What is the direction of a TRPO step, and how is it computed?
- The natural gradient , computed by conjugate gradient from Fisher–vector products
- The plain gradient , scaled to the trust-region radius
- The Newton direction of the true objective
- The clipped-ratio gradient of PPO
Show the answer
A. The natural gradient , computed by conjugate gradient from Fisher–vector products
Linearizing the surrogate and approximating the average KL by gives a quadratically constrained linear program whose solution is along . Conjugate gradient approximates it without forming , and a line search checks the true KL and the improvement.
What did Engstrom et al. (2020) find about PPO's advantage over TRPO?
- It comes entirely from the clipped objective
- It disappears with proper hyperparameter tuning of TRPO's KL radius alone
- It comes from PPO's use of more environment samples
- Much of it comes from code-level optimizations such as value-function clipping, reward scaling, orthogonal initialization and learning-rate annealing
Show the answer
D. Much of it comes from code-level optimizations such as value-function clipping, reward scaling, orthogonal initialization and learning-rate annealing
They concluded that these optimizations are responsible for most of PPO's gain in reward over TRPO and fundamentally change how the algorithms behave, including how well the trust region is actually maintained.
Further reading
- S. Kakade & J. Langford, "Approximately optimal approximate reinforcement learning," ICML (2002).
- J. Schulman, S. Levine, P. Abbeel, M. I. Jordan & P. Moritz, "Trust region policy optimization," ICML (2015).
- J. Schulman, F. Wolski, P. Dhariwal, A. Radford & O. Klimov, "Proximal policy optimization algorithms," arXiv:1707.06347 (2017).
- L. Engstrom, A. Ilyas, S. Santurkar, D. Tsipras, F. Janoos, L. Rudolph & A. Madry, "Implementation matters in deep RL: A case study on PPO and TRPO," ICLR (2020).
- A. Agarwal, N. Jiang, S. M. Kakade & W. Sun, Reinforcement Learning: Theory and Algorithms (monograph draft, 2019–2022).