Trust Region Policy Optimization (TRPO)
Read first: Actor–critic methods and the advantage function
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, , defines a region you should not leave in one update also underlies the “missing old logits” problems in asynchronous LLM-RL systems.
Key idea
Section titled “Key idea”Step 1: an exact identity (Eq. 1, due to Kakade and Langford). For any two policies,
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, :
matches and its gradient at , so a small enough step that improves improves . The question is how small.
Step 3: a lower bound (Theorem 1 and Eq. 9). With ,
The right-hand side equals at and lies below everywhere. Maximising it at each iteration can therefore never make worse (Algorithm 1, a minorise–maximise scheme).
Step 4: the practical problem (Eqs. 12–14). The theoretical forces tiny steps, so TRPO uses a constraint on the average KL instead, and estimates everything from old-policy samples with an importance ratio:
Step 5: solving it. Approximate the objective linearly (its gradient is the policy gradient) and the KL quadratically, , where is the Fisher information matrix. The solution direction is , the natural gradient, found with conjugate gradient using Fisher–vector products (no explicit matrix). Scale it to the boundary with , then backtrack until the real surrogate improves and the real KL is within . 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.
Running example, solved exactly
Section titled “Running example, solved exactly”Old policy: search in Q with probability 0.5, always answer in E. Advantages (actor–critic page): , . We only change .
- Surrogate: . Because only the start state’s policy changes and Q is always the first state, the surrogate is exact here: the true return is , the same line.
- KL to the old policy: .
- Constraint δ = 0.01: gives . The quadratic approximation agrees: the Fisher information of a Bernoulli at 0.5 is 4, so . Return rises from 0.46 to about 0.4825.
- Theoretical penalty: (searching again in E), so . Maximising gives , about 57 times smaller than the constrained step. This is the gap that motivated the constraint.
- Probability ratios after the step: search , answer . PPO with would not clip this step.
Translating TRPO
Section titled “Translating TRPO”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 is the same ratio PPO clips. Two different KLs appear in RLHF and are easy to confuse: the trust-region KL to (the policy that generated this batch, refreshed every iteration) and the regularising KL to (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.
Key results
Section titled “Key results”- 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.
Limitations and open questions
Section titled “Limitations and open questions”- 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.
Connections
Section titled “Connections”- Previous: Actor–critic and the advantage. Read with: GAE (same authors; how to estimate ).
- Next: PPO keeps TRPO’s surrogate and replaces the KL constraint with a clipped ratio.
- KL to π_old vs π_ref in LLM RL: InstructGPT · Missing old logits · Asynchronous RLHF.
- Courses: Spinning Up TRPO · CS285.
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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.