The Natural Policy Gradient
Fisher information, covariant updates and the link to policy iteration.
Plain gradient ascent is steepest ascent under a ruler nobody chose on purpose: the Euclidean length of the parameter change. The natural gradient picks the ruler deliberately, the KL divergence between action distributions, and inherits its invariances. This lesson derives the Fisher metric from the KL divergence, proves that the natural gradient ignores how the policy is parameterized, shows that for tabular softmax policies it becomes multiplicative weights on advantages, a soft form of policy iteration, proves its dimension-free rate, and explains how it is computed for networks with millions of parameters.
What you’ll learn
- Show that the KL divergence between nearby policies is the quadratic form of the Fisher information, and derive the natural gradient as steepest ascent in that metric.
- Prove that natural-gradient flow is invariant under smooth reparameterization, and say what the invariance does not cover.
- Derive the tabular softmax update and relate it to mirror descent and to policy iteration.
- Prove the rate of natural policy gradient with a per-state regret argument.
- Compute natural-gradient steps at scale with Fisher–vector products and conjugate gradient, and explain the Kronecker-factored approximation behind ACKTR.
KL divergence as a ruler
Fix a positive definite matrix and ask for the step that raises most among steps of a given length in the metric . Maximizing subject to gives ; plain gradient ascent is the choice . Amari (1998) argued that for a family of probability distributions the right comes from the distributions themselves, and the KL divergence supplies it.
Expand to second order in :
The linear term vanishes because the score has mean zero. For the quadratic term, , and :
Hence the KL divergence to a nearby distribution is half the Fisher quadratic form. The reverse divergence has the same expansion; the two directions first differ at third order.
A policy is a family of distributions, one per state, so its metric averages the per-state Fisher matrices , with the score , over a state distribution: . Kakade (2001) used the stationary distribution of an average-reward problem, Agarwal et al. (2021) the discounted distribution , and TRPO simply the states in the batch. The natural policy gradient is , with the Moore–Penrose pseudoinverse because is often singular: adding a constant to every logit of a softmax changes nothing, and a policy that has become nearly deterministic has a nearly vanishing score. In his experiments Kakade added about to at every step for that reason.
The state weighting has a cleaner justification than it looks. Bagnell and Schneider (2003) built the metric from the distribution over whole trajectories, and for episodes the two agree: the trajectory's score is , the transition probabilities do not depend on , and the cross terms vanish because for :
For a Gaussian policy with mean and log standard deviation , the Fisher matrix in the coordinates is . A trust-region step with KL budget moves only the mean. How far can the mean move when ?
Show the answer
0.0071
The budget is , so . The natural step in the mean scales with : as the policy sharpens, its steps shrink automatically, exactly enough to keep the change in behavior fixed. The plain gradient does the opposite: , so its steps in grow as shrinks.
Invariance under reparameterization
By the chain rule the score and the gradient pick up the Jacobian, so the Fisher matrix picks it up twice:
Map the -velocity of the natural flow into -coordinates; the Jacobians cancel:
Both flows solve the same differential equation in , so from the same starting policy they produce the same policies at every time. The plain flow instead gives , which equals only when is orthogonal.
Kakade (2001) illustrated the point on a one-dimensional linear–quadratic regulator, rescaling the units of one parameter or the other by a factor of 10: the natural gradient reached a good controller about three orders of magnitude sooner than the plain gradient. Its curves under the different rescalings were not identical either, which Kakade attributed to the state weighting inside . A classical result explains why the Fisher matrix is the metric to use: by Chentsov's theorem for distributions over a finite set it is, up to scale, the only Riemannian metric that is invariant under sufficient statistics.
Three limits of the invariance matter in practice. It holds for the flow; a finite step is invariant only to first order, which is one reason TRPO checks its steps with a line search. It concerns coordinates within one family of policies, not the choice of the family. And the natural gradient is not Newton's method: is the curvature of the KL divergence, not of . Kakade noted that the Hessian of couples the curvature of to the action values and is generally indefinite away from a maximum, while is positive semidefinite everywhere.
Tabular softmax: multiplicative weights on advantages
Take the tabular softmax policy , exact gradients of , and the Fisher matrix weighted by . Global Convergence of Policy Gradients states the resulting update; here is where it comes from (Kakade, 2001; Agarwal, Kakade, Lee & Mahajan, 2021, Lemma 15).
The score is . By the policy gradient theorem, using :
The Fisher matrix has no blocks across states, and its block for state is times the covariance matrix of a one-hot draw from . Because , the gradient block has the same form:
For every state with , is solved by the advantages up to the null direction of . The visitation weight cancels, and a constant added to a state's logits does not change its policy:
Three readings of the same update:
- Multiplicative weights. Each state runs Hedge (exponential weights) with gains . No state's step is scaled down by how rarely it is visited, which is precisely what plain softmax policy gradient suffers from.
- Mirror descent. In each state, : a linear model of improvement, held close to the current policy by a KL proximity term. This is policy mirror descent, the template TRPO and PPO approximate.
- Soft policy iteration. As the update puts all mass on : policy iteration. Kakade (2001, Theorem 2) proved the general form for exponential-family policies, where the limit is greedy with respect to the compatible critic's estimate of the advantage (exact in the tabular case). With entropy regularization of weight , the step gives exactly soft policy iteration, (Cen et al., 2022).
Use the closed form in the caption. At which iteration does the natural gradient's suboptimality first fall below ? (Check your answer in the widget.)
Show the answer
173
For large the third arm is gone and the suboptimality is about . Setting gives , and the exact formula crosses at iteration 173 (below at 288). The plain gradient needs 16,869 iterations to reach from the same start.
A dimension-free rate, by a regret argument
Write , , and . Taking logs of the update turns advantages into log-ratios of consecutive policies:
Regret side. The performance difference lemma compares with under 's state distribution. Averaged under , the log-ratios telescope into KL divergences, exactly as in the analysis of Hedge:
Improvement side. Apply the lemma to against from any start distribution . Averaged under , the log-ratios give a nonnegative KL term, and by Jensen's inequality. Since :
Values never decrease, in any state (take a point mass), and with the terms are bounded by the increase of . Sum over : the KL terms telescope to at most , the increases add up to at most , and monotonicity puts the last iterate below the average.
In the adversarial analysis of Hedge, the terms are bounded by a variance term of order per round, which forces a step size of order and an average regret of order . Here they are charged instead to the guaranteed improvement of the policy's own values, a structural fact about MDPs, so every step size works and the rate is .
The bound is a worst case. From the uniform start in the widget's bandit it gives , about at , when the actual suboptimality is already below and falling like . Faster guarantees exist: linear convergence with entropy regularization (Cen, Cheng, Chen, Wei & Chi, 2022; stated in Global Convergence of Policy Gradients) and, with no regularization at all, with geometrically increasing step sizes, which move the update toward policy iteration (Xiao, 2022).
Natural gradients for networks
For a network with parameters, is an matrix: storing it, let alone inverting it, is out of the question when runs into the millions. Two routes avoid it.
Matrix-free: conjugate gradient. Conjugate gradient solves using only products . Because is the Hessian of the mean KL divergence at , is a Hessian–vector product: differentiate the KL's gradient along (double backpropagation), for a small multiple of the cost of one gradient. TRPO used this analytic Fisher, which averages over all actions in each visited state rather than using only the sampled one. In RL the sampled estimate is unbiased too, because the actions come from the policy itself, unlike the "empirical Fisher" of supervised learning, which uses the data's labels instead of the model's own samples.
import torch
from torch.distributions import Categorical, kl_divergence
def fvp(policy_net, states, v, damping=0.1):
"""(F + damping*I) v, with F the Hessian of the mean KL(pi_old || pi) at theta_old."""
params = list(policy_net.parameters())
logits = policy_net(states)
kl = kl_divergence(Categorical(logits=logits.detach()), Categorical(logits=logits)).mean()
grads = torch.autograd.grad(kl, params, create_graph=True) # zero at theta_old
g_dot_v = torch.cat([g.reshape(-1) for g in grads]) @ v
hv = torch.autograd.grad(g_dot_v, params) # differentiate again
return torch.cat([h.reshape(-1) for h in hv]) + damping * v
def conjugate_gradient(Av, b, iters=10, tol=1e-10):
x, r, p = torch.zeros_like(b), b.clone(), b.clone()
rr = r @ r
for _ in range(iters):
Ap = Av(p)
alpha = rr / (p @ Ap)
x, r = x + alpha * p, r - alpha * Ap
rr_new = r @ r
if rr_new < tol:
break
p, rr = r + (rr_new / rr) * p, rr_new
return x # natural direction: conjugate_gradient(lambda v: fvp(net, s, v), g)The detached copy of the logits plays , so the KL and its gradient vanish at the current parameters while the second derivative gives the Fisher matrix. Damping () guards against a singular or badly estimated . Ten iterations, TRPO's choice, are typical: an approximate solve suffices, since and are themselves estimated from one batch.
Structured: K-FAC. Martens and Grosse (2015) approximate by a block-diagonal matrix with one block per layer, each factored into two small matrices. For a layer with input activations and backpropagated derivatives , the gradient is , and the block's expectation is split as if the two were uncorrelated:
ACKTR (Wu, Mansimov, Liao, Grosse & Ba, 2017) applied K-FAC to both the actor and the critic (for a critic with a Gaussian output, the Gauss–Newton matrix is its Fisher matrix) and capped each step with a trust region, . The authors reported 2- to 3-fold gains in sample efficiency over earlier on-policy actor–critic methods on Atari and MuJoCo, at 10–25% more computation per update than first-order methods.
Key takeaways
- The KL divergence between nearby policies is in either direction, with the state-averaged covariance of the score; steepest ascent in this metric is the natural gradient .
- Natural-gradient flow traces the same policies in any smooth reparameterization; finite steps are invariant only to first order, and is the curvature of the KL divergence, not of .
- For tabular softmax policies the state weighting cancels and the update is multiplicative weights on advantages, : policy mirror descent, policy iteration as , and soft policy iteration with entropy at .
- Natural policy gradient reaches for every step size: Hedge's regret in each state, with the normalization terms paid for by monotone improvement.
- At scale, is computed without forming , by conjugate gradient on Fisher–vector products (TRPO), or through Kronecker-factored layer blocks (K-FAC, ACKTR).
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
For nearby parameters, how do and compare?
- They differ already at first order in , which is why TRPO must pick the direction carefully
- Both equal up to third-order terms, so the choice of direction does not affect the local metric
- The first is and the second
- They are equal for all , because the KL divergence is symmetric
Show the answer
B. Both equal up to third-order terms, so the choice of direction does not affect the local metric
Both vanish with zero gradient at , and both have Hessian there, so they agree to second order. They differ at third order, which matters for large steps but not for the natural-gradient direction.
Why is the tabular softmax natural policy gradient update independent of the state distribution , while the plain softmax gradient is not?
- Because natural policy gradient uses a uniform state distribution by definition
- Because the advantages already contain the factor
- Because the pseudoinverse discards every state's block except the most visited one
- Because the gradient for state and the Fisher block for state both carry the factor , so it cancels in
Show the answer
D. Because the gradient for state and the Fisher block for state both carry the factor , so it cancels in
The gradient block is and the Fisher block is . Solving block by block leaves plus a constant, for every visited state, so rarely visited states are updated as aggressively as common ones.
In tabular natural policy gradient, . What does the update become as ?
- Policy iteration: each state puts all its probability on its greedy actions
- Plain policy gradient with an infinite step, which diverges
- The uniform policy, since all exponentials blow up together
- Value iteration on
Show the answer
A. Policy iteration: each state puts all its probability on its greedy actions
The largest advantage dominates the exponentials, so the normalized policy concentrates on the greedy actions: exactly a policy-improvement step. Finite interpolates between a slow, smooth update and policy iteration, which is the sense in which trust-region methods are "soft" policy iteration.
What approximation lets K-FAC invert the Fisher block of a layer with weight matrix cheaply?
- It keeps only the diagonal of the Fisher matrix
- It replaces the Fisher matrix by the identity, as in plain gradient descent
- It assumes the layer's input activations and backpropagated output derivatives are uncorrelated at second order, so the block factors as and inverts through the two small factors
- It computes the exact inverse by conjugate gradient at every step
Show the answer
C. It assumes the layer's input activations and backpropagated output derivatives are uncorrelated at second order, so the block factors as and inverts through the two small factors
The exact block is . Factoring the expectation gives , whose inverse is , so the update is : two matrices of size and instead of one of size . Blocks for different layers are treated as independent.
Further reading
- S. Amari, "Natural gradient works efficiently in learning," Neural Computation 10(2), 251–276 (1998).
- S. M. Kakade, "A natural policy gradient," NIPS 14 (2001).
- A. Agarwal, S. M. Kakade, J. D. Lee & G. Mahajan, "On the theory of policy gradient methods: Optimality, approximation, and distribution shift," JMLR 22(98), 1–76 (2021).
- J. Martens & R. Grosse, "Optimizing neural networks with Kronecker-factored approximate curvature," ICML (2015).
- Y. Wu, E. Mansimov, S. Liao, R. Grosse & J. Ba, "Scalable trust-region method for deep reinforcement learning using Kronecker-factored approximation," NIPS (2017).