Maximum-Entropy RL & Soft Actor–Critic
Soft Bellman equations, soft policy iteration and automatic temperature tuning.
Adding the policy's entropy to the reward looks like a trick to keep exploring. It is more than that. It smooths the max of the Bellman equation into a log-sum-exp, makes the optimal policy a Boltzmann distribution over soft action values, admits a policy iteration with a short convergence proof, and provably buys robustness to some perturbations of the reward. This lesson develops that theory, follows it to soft actor–critic and its automatic temperature, and states what the entropy costs.
What you’ll learn
- Derive the soft Bellman optimality equations and the Boltzmann form of the optimal maximum-entropy policy from the Gibbs variational principle.
- Prove soft policy evaluation, soft policy improvement by information projection and the convergence of soft policy iteration, and relate soft policy iteration to entropy-regularized natural policy gradient.
- Derive SAC's losses, including the reparameterized policy gradient and the temperature as a dual variable, and place soft Q-learning and path consistency learning in the same family.
- Prove a one-step robustness guarantee for maximum-entropy policies, and quantify the bias the entropy introduces.
Soft values and the Boltzmann policy
Maximum-entropy RL scores a policy by its rewards plus times the entropy of its action distribution in every state it visits, with temperature . The soft value of a policy counts the entropy of the current state's action distribution, while the soft Q-function counts only the entropy of future states (the action at is already chosen):
Fix a state with action values and let , . Expanding gives, for every distribution ,
The KL divergence is nonnegative and zero only at , so the entropy-regularized maximum is a log-sum-exp, attained by a Boltzmann distribution:
A state has two actions with soft optimal values , and . What is ?
Show the answer
1.31
, and picks the first action with probability . The soft value exceeds the max because the policy also collects entropy. In general ; with here, , essentially the max.
Soft policy iteration
Haarnoja, Zhou, Abbeel and Levine (2018) built SAC on a policy iteration that works within a restricted class of policies , such as Gaussians. Their results assume a finite action set, so that entropies, and hence soft values, are bounded. Soft policy evaluation (Lemma 1): iterating converges to , because it is ordinary policy evaluation with the bounded reward .
is itself a candidate in the projection, so the minimizer does at least as well. The partition function depends only on and cancels from both sides:
So, in every state, acting once with and then following does at least as well, in soft value, as following :
Insert this bound into the soft Bellman equation of and repeat at every later step; the right side converges to the soft value of .
For the theorem, the soft values increase monotonically and are bounded, so they converge; at the limit the policy is its own projection, and the same unrolling shows its soft values dominate those of every other policy in . The guarantee is for exact evaluation and exact projection in the tabular case, and optimality is within .
When contains every policy, the projection is exact, , and soft policy iteration is entropy-regularized natural policy gradient with step size (The Natural Policy Gradient), which converges linearly, at rate (Cen, Cheng, Chen, Wei & Chi, 2022).
Soft policy improvement projects with , the new policy in the first argument. What does this direction buy in practice?
- It makes the new policy cover every mode of the Boltzmann distribution
- The objective becomes up to a constant: an expectation under the policy being optimized, estimable with its own samples, with the intractable dropping out
- It removes the need for a critic
- It guarantees that the projected policy is deterministic
Show the answer
B. The objective becomes up to a constant: an expectation under the policy being optimized, estimable with its own samples, with the intractable dropping out
In this direction the expectation is over , which we can sample and reparameterize, and is a constant per state. The reverse direction would need samples from , which is what soft Q-learning had to approximate with a separate sampler. The price is mode-seeking behavior: a unimodal Gaussian settles on one mode of a multimodal Boltzmann policy.
From soft policy iteration to SAC
SAC runs both steps of soft policy iteration approximately, one stochastic gradient step at a time, on minibatches from a replay buffer : twin soft critics with target copies , and a reparameterized actor , a tanh-squashed Gaussian with .
The sampled action depends on through , so the chain rule has a direct term (the log-density's own dependence on at fixed ) and a pathwise term through the action, which is where the critic's action gradient enters:
Automatic differentiation of the loss through computes exactly this. As and the policy becomes deterministic, only survives: the deterministic policy gradient of DDPG and TD3, which SAC contains as a limit.
The temperature as a dual variable. Haarnoja et al. (2018b) replace the fixed by a constraint: maximize the expected return subject to an average entropy of at least at every step. Over a finite horizon, solving backward in time gives a dual variable per step, the temperature, and strong duality holds because the objective is linear and the entropy concave in the policy. In practice SAC keeps one and takes one gradient step on per update, with by default. This truncated dual gradient descent has guarantees only under convexity, which neural networks do not provide; the authors found it works in practice.
The family. Soft Q-learning (Haarnoja, Tang, Abbeel & Levine, 2017), SAC's predecessor, learned the soft Q-function directly and sampled from the energy-based policy with a separate network trained by amortized Stein variational gradient descent; SAC's projection onto a tractable Gaussian replaced that sampler. Schulman, Chen and Abbeel (2017) showed that soft Q-learning is exactly equivalent to an entropy-regularized policy gradient method. And for deterministic transitions, the soft optimal values satisfy a consistency along any action sequence, , which path consistency learning (Nachum, Norouzi, Xu & Schuurmans, 2017) turns into one loss for the policy and values, usable on- and off-policy.
What entropy buys, and what it costs
Maximum-entropy policies are often reported to be robust: SAC's quadruped, trained on flat ground, walked over obstacles it had never seen. In one step the reason can be proved in a few lines. Write for a single decision with rewards , and let an adversary replace by any in the set . Since a log-sum-exp is at least its largest term, the adversary may lower each action's reward by at most , and by less when it lowers many at once.
For any full-support and any , write the log-sum-exp as an expectation under and apply Jensen's inequality to the concave logarithm:
Rearranged: every reward in gives the policy at least its entropy-regularized value, minus the budget. Equality holds for , which is in the set:
The set does not depend on , so the policy maximizing also maximizes the worst-case reward over . The worst case lowers the reward most on the actions the policy relies on, by , which is close to for likely actions; spreading probability out is what limits the damage.
Eysenbach and Levine (2022) proved sequential versions. The maximum-entropy objective of a full-support policy equals its worst-case return over a set of adversarially chosen reward functions, a set that now depends on the policy; and, for positive rewards, a related theorem bounds the worst case over a set of perturbed dynamics from below by a maximum-entropy objective with a transformed reward. They are careful to add that this does not make maximum-entropy RL the best robust RL method, only a simple one with guarantees.
That gap is the cost. The entropy-regularized optimum gives up at most of plain return (Global Convergence of Policy Gradients); here bounds the actual at . For continuous actions the bound is vacuous (a deterministic policy has differential entropy ). Choosing is also delicate, because its effect depends on the scale of the rewards, which differs across tasks and changes as the policy improves; that is why SAC's second version targets an average entropy instead of fixing a temperature. And entropy is undirected: it spreads probability over actions now, not toward states the agent knows little about, so it does not solve deep exploration, a point the next lesson's critique of control as inference sharpens.
Key takeaways
- By the Gibbs variational principle, , attained at : soft Bellman equations replace the max by a log-sum-exp, and the optimal policy is Boltzmann in the soft action values.
- Soft policy improvement projects onto the policy class with and never lowers soft values; soft policy iteration converges to the best policy in the class, and with an unrestricted class it is entropy-regularized natural policy gradient, linear at rate .
- SAC approximates both steps with twin soft critics, a reparameterized squashed-Gaussian actor whose loss is the information projection, and a temperature treated as the dual variable of an entropy constraint; as its actor gradient becomes the deterministic policy gradient.
- In one step, the maximum-entropy policy is exactly the robust policy for rewards an adversary may lower within an exponential budget; over many steps the equality holds with a policy-dependent set of rewards, and perturbed dynamics get a lower bound (Eysenbach & Levine, 2022).
- The price is bias, at most for finite actions, and entropy is undirected: it does not solve deep exploration.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
How does the soft optimal value compare with ?
- , because entropy is a penalty
- They are always equal
- is the average of the
Show the answer
C.
The sum contains the largest term, giving the lower bound, and at most copies of it, giving the upper bound. The gap is the entropy the soft-optimal policy collects in that state, at most .
The information projection onto a Gaussian class is usually not the Boltzmann policy itself. Why does soft policy improvement still never lower the soft values?
- Because Gaussian policies are always optimal for continuous actions
- Because the projection error is always zero for a large enough network
- Because the entropy bonus compensates exactly for any projection error
- Because the old policy belongs to the class, so the projected policy scores at least as well in the KL objective, which is exactly the one-step improvement inequality; unrolling the soft Bellman equation extends it to all steps
Show the answer
D. Because the old policy belongs to the class, so the projected policy scores at least as well in the KL objective, which is exactly the one-step improvement inequality; unrolling the soft Bellman equation extends it to all steps
The proof never compares the new policy with the Boltzmann policy, only with the old policy, which was a feasible choice. That gives in every state, and the rest is the usual policy-improvement argument.
With an unrestricted policy class, soft policy iteration updates . What is it?
- Entropy-regularized natural policy gradient with step size , which converges linearly at rate
- Ordinary policy iteration, since the exponential concentrates on the greedy action
- Plain softmax policy gradient with step size
- Value iteration on the hard Bellman equation
Show the answer
A. Entropy-regularized natural policy gradient with step size , which converges linearly at rate
Entropy-regularized NPG updates ; at the old policy's exponent vanishes, leaving soft policy iteration. Cen et al. (2022) prove the linear rate .
In the one-step robustness argument, which reward does the worst-case adversary choose from ?
- It lowers every action's reward by exactly
- , lowering the reward most on the actions the policy relies on, so a policy that spreads its probability loses less
- It lowers only the reward of the least likely action
- It leaves the reward unchanged, since the set is centered at
Show the answer
B. , lowering the reward most on the actions the policy relies on, so a policy that spreads its probability loses less
Equality in Jensen's inequality needs constant across actions, which with the budget gives . The policy then earns exactly : its entropy-regularized value is its guaranteed worst-case return, up to the constant budget.
Further reading
- T. Haarnoja, A. Zhou, P. Abbeel & S. Levine, "Soft actor-critic: Off-policy maximum entropy deep reinforcement learning with a stochastic actor," ICML (2018).
- T. Haarnoja, A. Zhou, K. Hartikainen, G. Tucker, S. Ha, J. Tan, V. Kumar, H. Zhu, A. Gupta, P. Abbeel & S. Levine, "Soft actor-critic algorithms and applications," arXiv:1812.05905 (2018).
- T. Haarnoja, H. Tang, P. Abbeel & S. Levine, "Reinforcement learning with deep energy-based policies," ICML (2017).
- B. Eysenbach & S. Levine, "Maximum entropy RL (provably) solves some robust RL problems," ICLR (2022).
- J. Schulman, X. Chen & P. Abbeel, "Equivalence between policy gradients and soft Q-learning," arXiv:1704.06440 (2017).