Skip to content

Trust Region Policy Optimization (TRPO)

optionalcorefundamentalpaperrubric 12/122015 · ICML 2015 · ~75 min

John Schulman, Sergey Levine, Philipp Moritz, Michael I. Jordan, Pieter Abbeel

Read first: Actor–critic methods and the advantage function

Status

TL;DR. A policy-gradient step tells you a direction, not how far to go. Too small and learning crawls; too large and the policy collapses, after which the data it collects is bad too. TRPO measures the step in terms of how much the action distributions change, the KL divergence between the old and new policy, and maximises a surrogate objective built from the old policy’s advantages subject to “average KL ≤ δ”. The theory behind it guarantees monotone improvement for an idealised penalised version. The practical algorithm uses conjugate gradient plus a line search and works with large neural-network policies.

Why it matters now. PPO, the default RLHF optimiser, is a first-order simplification of TRPO, and its ratio and clip only make sense once you have seen TRPO’s surrogate. The idea that the old policy, πold\pi_{\text{old}}, defines a region you should not leave in one update also underlies the “missing old logits” problems in asynchronous LLM-RL systems.

Step 1: an exact identity (Eq. 1, due to Kakade and Langford). For any two policies,

η(π~)=η(π)+Eτ∼π~[∑tγtAπ(st,at)].\eta(\tilde\pi) = \eta(\pi) + \mathbb{E}_{\tau \sim \tilde\pi}\left[\sum_{t} \gamma^t A_\pi(s_t, a_t)\right].

In words: the new policy’s return equals the old return plus the old policy’s advantages, summed along trajectories of the new policy. If the new policy picks actions with positive old advantage in the states it visits, it is better.

Step 2: a local approximation (Eq. 3). We cannot sample the new policy’s trajectories before choosing it, so replace its state distribution with the old one, ρπ\rho_\pi:

Lπ(π~)=η(π)+∑sρπ(s)∑aπ~(a∣s) Aπ(s,a).L_\pi(\tilde\pi) = \eta(\pi) + \sum_s \rho_\pi(s) \sum_a \tilde\pi(a \mid s)\, A_\pi(s,a).

LπL_\pi matches η\eta and its gradient at π~=π\tilde\pi = \pi, so a small enough step that improves LL improves η\eta. The question is how small.

Step 3: a lower bound (Theorem 1 and Eq. 9). With ϵ=max⁡s,a∣Aπ(s,a)∣\epsilon = \max_{s,a} |A_\pi(s,a)|,

η(π~)≥Lπ(π~)−C DKLmax⁡(π,π~),C=4ϵγ(1−γ)2.\eta(\tilde\pi) \ge L_\pi(\tilde\pi) - C\, D_{\mathrm{KL}}^{\max}(\pi, \tilde\pi), \qquad C = \frac{4 \epsilon \gamma}{(1-\gamma)^2}.

The right-hand side equals η(π)\eta(\pi) at π~=π\tilde\pi = \pi and lies below η\eta everywhere. Maximising it at each iteration can therefore never make η\eta worse (Algorithm 1, a minorise–maximise scheme).

Step 4: the practical problem (Eqs. 12–14). The theoretical CC forces tiny steps, so TRPO uses a constraint on the average KL instead, and estimates everything from old-policy samples with an importance ratio:

max⁡θ  Es,a∼πθold[πθ(a∣s)πθold(a∣s) A^(s,a)]s.t.Es[DKL(πθold(⋅∣s) ∥ πθ(⋅∣s))]≤δ.\max_\theta \; \mathbb{E}_{s, a \sim \pi_{\theta_{\text{old}}}}\left[\frac{\pi_\theta(a \mid s)}{\pi_{\theta_{\text{old}}}(a \mid s)}\, \hat A(s,a)\right] \quad \text{s.t.} \quad \mathbb{E}_{s}\left[D_{\mathrm{KL}}\big(\pi_{\theta_{\text{old}}}(\cdot \mid s) \,\|\, \pi_\theta(\cdot \mid s)\big)\right] \le \delta .

Step 5: solving it. Approximate the objective linearly (its gradient gg is the policy gradient) and the KL quadratically, 12Δθ⊤FΔθ\tfrac12 \Delta\theta^\top F \Delta\theta, where FF is the Fisher information matrix. The solution direction is F−1gF^{-1} g, the natural gradient, found with conjugate gradient using Fisher–vector products (no explicit matrix). Scale it to the boundary with β=2δ/s⊤Fs\beta = \sqrt{2\delta / s^\top F s}, then backtrack until the real surrogate improves and the real KL is within δ\delta. The paper notes that without the line search the algorithm occasionally takes large steps that cause catastrophic degradation. The natural policy gradient is the special case with a fixed step or penalty instead of a KL constraint.

TRPO step on the search-or-answer MDP Two panels sharing a horizontal axis p, the new probability of searching in the question state, from 0.48 to 0.62. Top: the expected return rises linearly from 0.46 at p = 0.5; here the surrogate equals the true return. Bottom: the KL divergence from the old policy is U-shaped with minimum zero at p = 0.5. The constraint KL at most 0.01 stops the step at p about 0.570, where the return is about 0.4825. The theoretical penalty would stop at p about 0.501. Return J = 0.3 + 0.32 p old policy: 0.46 TRPO step: 0.4825 surrogate = true J here KL(π_old ‖ π_new) δ = 0.01 penalty C·KL: p ≈ 0.501 0.50 0.57 0.60 p = π_new(search | Q) Ratio after the step: 0.570 / 0.5 = 1.14, inside PPO's clip range [0.8, 1.2].
Original sketch. TRPO on the search-or-answer MDP: the surrogate rises linearly with p = π(search | Q); the KL ≤ 0.01 constraint stops at p ≈ 0.570, while the theoretical penalty would stop at p ≈ 0.501.

Old policy: search in Q with probability 0.5, always answer in E. Advantages (actor–critic page): A(Q,search)=+0.16A(Q,\text{search}) = +0.16, A(Q,answer)=−0.16A(Q,\text{answer}) = -0.16. We only change p=πnew(search∣Q)p = \pi_{\text{new}}(\text{search} \mid Q).

  • Surrogate: L(p)−ηold=0.16 p−0.16 (1−p)=0.16 (2p−1)L(p) - \eta_{\text{old}} = 0.16\,p - 0.16\,(1-p) = 0.16\,(2p - 1). Because only the start state’s policy changes and Q is always the first state, the surrogate is exact here: the true return is 0.3+0.32 p0.3 + 0.32\,p, the same line.
  • KL to the old policy: DKL=0.5ln⁡0.5p+0.5ln⁡0.51−p=−12ln⁡(4p(1−p))D_{\mathrm{KL}} = 0.5 \ln\frac{0.5}{p} + 0.5 \ln\frac{0.5}{1-p} = -\tfrac12 \ln\big(4p(1-p)\big).
  • Constraint δ = 0.01: 4p(1−p)=e−0.024p(1-p) = e^{-0.02} gives p≈0.570p \approx 0.570. The quadratic approximation agrees: the Fisher information of a Bernoulli at 0.5 is 4, so Δp≈2×0.01/4≈0.071\Delta p \approx \sqrt{2 \times 0.01 / 4} \approx 0.071. Return rises from 0.46 to about 0.4825.
  • Theoretical penalty: ϵ=max⁡∣A∣=0.18\epsilon = \max|A| = 0.18 (searching again in E), so C=4×0.18×0.9/0.01=64.8C = 4 \times 0.18 \times 0.9 / 0.01 = 64.8. Maximising 0.32 Δp−64.8×2 Δp20.32\,\Delta p - 64.8 \times 2\,\Delta p^2 gives Δp≈0.0012\Delta p \approx 0.0012, about 57 times smaller than the constrained step. This is the gap that motivated the constraint.
  • Probability ratios after the step: search 0.570/0.5=1.140.570/0.5 = 1.14, answer 0.430/0.5=0.860.430/0.5 = 0.86. PPO with ϵ=0.2\epsilon = 0.2 would not clip this step.

LLM token generation. States are prefixes and actions are tokens, so the KL in the constraint is a per-token KL between the old and new next-token distributions, averaged over the tokens of sampled completions. The importance ratio πθ(yt∣⋅)/πold(yt∣⋅)\pi_\theta(y_t \mid \cdot)/\pi_{\text{old}}(y_t \mid \cdot) is the same ratio PPO clips. Two different KLs appear in RLHF and are easy to confuse: the trust-region KL to πold\pi_{\text{old}} (the policy that generated this batch, refreshed every iteration) and the regularising KL to πref\pi_{\text{ref}} (the frozen SFT model). Full TRPO is rarely used for LLMs, because conjugate gradient with Fisher–vector products over billions of parameters is expensive.

A search agent. The trust region should cover only the agent’s own tokens (reasoning, queries, answer), not retrieved text. A per-token average keeps long tool-heavy episodes from dominating. When the retriever or corpus changes between iterations, the “old policy” data no longer reflects the current environment either, which the trust region does not protect against.

  • Locomotion (Figure 4, five runs per method): single-path and vine TRPO solved all of the simulated tasks (cart-pole plus swimmer, hopper and walker) and gave the best solutions. Natural gradient with a tuned fixed step did well on the two easier tasks but did not learn forward-moving hopping and walking gaits. Max-KL learned somewhat more slowly than mean-KL. δ = 0.01 was used for all experiments.
  • Atari (Table 1, one run per game, same architecture and parameters): the same method learned from raw images with a 33,500-parameter network; the authors note that performance varies substantially from run to run. Against the 2013 DQN numbers it was higher on Enduro (534.6 vs 470), Pong (20.9 vs 20.0), Q*bert (vine 7732.5 vs 1952) and Seaquest (single path 1908.6 vs 1705), and lower on Beam Rider, Breakout and Space Invaders.
  • Second-order machinery. Conjugate gradient, Fisher–vector products and line searches are complex to implement and costly at LLM scale; PPO’s popularity comes largely from avoiding them.
  • Theory–practice gap. The guarantee needs exact advantages and the max-KL penalty. The practical algorithm uses estimated advantages and an average-KL constraint, so monotone improvement is not guaranteed.
  • What δ means for language. A per-token KL budget suitable for 1,000-token completions may be too loose or too tight for 30k-token agent trajectories; how to set it is open.

Questions to think through

These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.

  1. Derive / compute

    In the search-or-answer MDP, the old policy searches in Q with probability 0.5, A(Q, search) = +0.16 and A(Q, answer) = −0.16, and only the decision in Q is being changed. Write the surrogate L(p) and the KL from the old to the new policy as functions of p = π_new(search | Q). With δ = 0.01, find the largest allowed p and the improvement in expected return. Compare with the step the theoretical penalty C·KL would allow (ε = max |A| = 0.18, γ = 0.9).

    What a strong answer covers
    • L(p) − η(π_old) = p·0.16 + (1 − p)·(−0.16) = 0.16·(2p − 1). Here it is exact, because only the start state's policy changes and the start state is always visited.
    • KL(old ‖ new) = 0.5·ln(0.5/p) + 0.5·ln(0.5/(1 − p)) = −0.5·ln(4p(1 − p)). Setting it to 0.01 gives p ≈ 0.570; the quadratic approximation (Fisher information 4 at p = 0.5) gives Δp = √(2·0.01/4) ≈ 0.071.
    • Improvement ≈ 0.16·(2·0.570 − 1) ≈ 0.0225, so J rises from 0.46 to about 0.4825.
    • Penalty: C = 4·0.18·0.9/(1 − 0.9)² = 64.8. Maximising 0.32·Δp − C·2·Δp² gives Δp ≈ 0.0012, about 57 times smaller. That is why the paper replaces the penalty with a constraint.
  2. Mechanism

    The surrogate L_π(π̃) uses the old policy's state-visitation distribution, not the new one's. Explain why that makes it computable from old-policy data, why it is only trustworthy near the old policy, and how the bound η(π̃) ≥ L_π(π̃) − C·KL_max turns this into guaranteed improvement.

    What a strong answer covers
    • The exact identity says the new return equals the old return plus the old policy's advantages summed along the new policy's trajectories. Those trajectories are not available before you choose the new policy.
    • Replacing the new state distribution with the old one gives L, which can be estimated from old rollouts with an importance ratio π̃(a|s)/π_old(a|s) on actions. L matches η to first order at π̃ = π_old, so its gradient is the policy gradient.
    • Far from π_old the state distributions differ and L can be badly wrong.
    • The bound gives a lower bound that touches η at π_old. Maximising the lower bound each iteration (minorise–maximise) can never decrease η, which is Algorithm 1's monotone improvement guarantee for exact advantages.
  3. What if…

    The TRPO paper compares its KL-constrained update with a natural-gradient update that uses a fixed step size (or fixed penalty), with a max-KL variant, and with derivative-free methods. What did each comparison show, and what does the line search add?

    What a strong answer covers
    • Fixed-step natural gradient (step size tuned by sweeping) did well on the two easier locomotion tasks but failed to learn forward-moving hopping and walking gaits; single-path and vine TRPO solved all of them.
    • Max-KL (only tractable on cart-pole) learned somewhat more slowly than mean-KL, suggesting the average-KL approximation behaves like the theoretical constraint.
    • CEM and CMA scaled poorly with the number of parameters and did badly on the larger problems.
    • Without the line search, the paper notes, the algorithm occasionally takes large steps that cause catastrophic drops in performance; the line search checks the real surrogate and KL, not their approximations.
  4. Connect

    Relate TRPO's constraint to PPO's clip and to the KL penalty used in RLHF. In the toy example the TRPO step moves the probability ratio for "search" to 1.14: is that inside PPO's clip range with ε = 0.2? Which policy is each KL measured against, and why does the difference matter?

    What a strong answer covers
    • PPO replaces the hard KL constraint with a clipped ratio (or an adaptive KL penalty), which needs only first-order optimisation. 1.14 is inside [0.8, 1.2], so PPO's clip would not bind for this step.
    • The clip limits the incentive to move each sampled ratio beyond 1 ± ε; it does not guarantee that the true KL stays below a threshold.
    • TRPO's KL is to π_old, the policy that collected the current batch; it changes every iteration and controls the step size.
    • The RLHF KL is to π_ref, the fixed SFT model; it is part of the reward (keep outputs close to the reference model) and does not vanish as training proceeds.
  5. Design

    You are fine-tuning a search agent with long multi-turn episodes and want a trust region. Decide what the KL is averaged over (tokens, turns or episodes), whether retrieved-document tokens count, how you would pick δ, and what you would log to detect that the trust region is too loose or too tight.

    What a strong answer covers
    • Average KL over the policy's own tokens only; retrieved text is environment output, not policy action, so its tokens are excluded.
    • Per-token mean KL is comparable across episodes of different lengths; a per-episode sum grows with length and would make long episodes take tiny steps.
    • Start near the paper's δ = 0.01 per state as a scale reference, then tune on short runs: too small learns slowly, too large shows reward collapses after updates.
    • Log: measured KL after each update, fraction of line-search backtracks, surrogate gain versus realised return change, and entropy. A surrogate gain that does not translate into return means the local approximation is breaking.
  6. Critique

    TRPO's Table 1 reports Atari scores for single-path and vine TRPO next to DQN. What conclusions about TRPO versus DQN does this table support, and what would you need before claiming either is better?

    What a strong answer covers
    • Mixed results: TRPO is higher on Enduro, Pong, Q*bert (vine 7732.5 vs 1952) and Seaquest (single path 1908.6 vs 1705), but lower on Beam Rider, Breakout (10.8 / 34.2 vs 168) and Space Invaders.
    • The paper's claim is narrower: one general policy-search method, with the same hyperparameters, reaches reasonable scores on both robotics and Atari.
    • Each TRPO entry comes from a single run with no error bars, and the authors note that performance varies substantially between runs. Preprocessing followed the DQN protocol, but the networks and training budgets differ.
    • A fair comparison needs multiple seeds, matched frames and compute, and the same evaluation protocol.

Done with this page?

Status