VerifiedarXiv:1801.0129031 min
RL & alignment · Continuous control

Soft Actor-Critic (SAC): Off-Policy Maximum Entropy Deep Reinforcement Learning with a Stochastic Actor

Reward an agent for succeeding and for staying random.

Soft Actor-Critic (SAC) trains a controller that samples each action from a learned probability distribution. It is scored on reward plus the spread of that distribution, learns from a buffer of past experience, and ends up in nearly the same place on every random seed.

Explaining the paperSoft Actor-Critic: Off-Policy Maximum Entropy Deep Reinforcement Learning with a Stochastic ActorHaarnoja, Zhou, Abbeel, Levine · UC Berkeley · ICML 2018 · arXiv:1801.01290 ↗

A January 2018 paper from Berkeley: four small networks, one hyperparameter tuned per task, and a simulated humanoid with 21 action dimensions that DDPG made no progress on.

In continuous control an agent picks a vector of real numbers every step (joint torques for a simulated robot, for example) and receives a reward. Deep reinforcement learning for this setting had two practical problems in 2017. The stable methods, TRPO and PPO, learn only from experience the current policy collected, so they need millions of environment steps. The method that reused old experience, DDPG, needed far fewer steps, but the SAC paper describes it as notoriously challenging to use because of its extreme brittleness and hyperparameter sensitivity.

SAC keeps DDPG's reuse of old experience and changes the objective: the agent maximizes reward plus the entropy of its own action distribution. The page follows the paper's order: the maximum-entropy objective and its temperature; soft value functions, and why the reward scale is the temperature; the policy-improvement step, a KL projection onto Gaussians; the four networks and their three losses; the reparameterized actor gradient and the tanh squashing of actions; then the experiments, and how this 2018 paper differs from the SAC in today's libraries.

Why off-policy control was hard before SAC

Reinforcement learning methods split by which data they can learn from. An on-policy method such as TRPO or PPO computes each update from experience collected by the current policy. PPO reuses a batch for several epochs of minibatch updates, but once the policy has moved, the batch describes a different policy, so it is discarded and new rollouts are collected. The SAC paper reports that it learns considerably faster than PPO and attributes the gap to the large batches PPO needs to learn stably on the harder tasks.

An off-policy method stores every transition (state, action, reward, next state) in a replay buffer and trains on random minibatches drawn from it, so one real step can feed many gradient updates. DQN did this for discrete actions, and its 2015 Nature version (Mnih et al.) added a slowly updated target network. For continuous actions the standard off-policy method was DDPG (Lillicrap et al., 2015): a deterministic actor that outputs one action per state, trained to climb the gradient of a learned Q-function, with fixed noise added to its actions for exploration.

Off-policy value learning is fragile for a mechanical reason. The Q-network is trained toward a target computed from its own current estimates (bootstrapping); it is a neural network, so an update at one state changes its outputs at nearby states (function approximation); and its data comes from older policies (off-policy). With all three, an error in one estimate can raise the targets of others and grow instead of shrinking. The paper names the combination of off-policy learning and nonlinear function approximation, citing Bhatnagar et al. (2009); Sutton and Barto's textbook calls the three together the deadly triad. A deterministic actor adds to it, because it moves toward whichever action the critic currently rates highest, including actions the critic overrates.

The maximum-entropy objective

Standard reinforcement learning maximizes the expected sum of rewards. The maximum-entropy framework (Ziebart, 2010) adds the entropy of the policy's action distribution at every state the policy visits:

J(π)=∑t=0TE(st,at)∼ρπ[ r(st,at)+α H(π(⋅∣st)) ]J(\pi) = \sum_{t=0}^{T} \mathbb{E}_{(\mathbf{s}_t,\mathbf{a}_t)\sim\rho_\pi}\Big[\, r(\mathbf{s}_t,\mathbf{a}_t) + \alpha\,\mathcal{H}\big(\pi(\cdot\mid\mathbf{s}_t)\big) \,\Big]J(π)=∑t=0TE(st,at)∼ρπ[ r(st,at)+α H(π(⋅∣st)) ]\begin{aligned} J(\pi) &= \sum_{t=0}^{T} \mathbb{E}_{(\mathbf{s}_t,\mathbf{a}_t)\sim\rho_\pi}\Big[\, r(\mathbf{s}_t,\mathbf{a}_t) \\ &\qquad + \alpha\,\mathcal{H}\big(\pi(\cdot\mid\mathbf{s}_t)\big) \,\Big] \end{aligned}
(1)

The expectation runs over the states and actions the policy visits, written ρπ\rho_\pi. The entropy H(π)=E[−log⁡π]\mathcal{H}(\pi) = \mathbb{E}[-\log\pi] measures how spread out the action distribution is. Over four actions it ranges from 0 nats (always the same action) to log⁡4≈1.39\log 4 \approx 1.39 nats (uniform). For a continuous action it is the differential entropy, which can be negative: a one-dimensional Gaussian with standard deviation σ\sigma has entropy 12log⁡(2πeσ2)\tfrac12\log(2\pi e\sigma^2), which is −0.88 nats at σ=0.1\sigma = 0.1 and 1.42 nats at σ=1\sigma = 1.

The temperature α\alpha converts entropy into units of reward. As α→0\alpha \to 0 the entropy term vanishes and (1) becomes the conventional objective; a large α\alpha makes the agent value randomness over reward. Equation (1) is a finite sum from t=0t = 0 to TT with no discount factor. The discount γ=0.99\gamma = 0.99 enters in the soft Bellman backup (2) below; the paper defers the discounted, infinite-horizon form of the objective to its Appendix A because writing it down is more involved (Thomas, 2014).

The paper gives three reasons to want the entropy term, and all three come from the policy keeping probability on more than one action. A policy that collapses onto one action loses entropy, so the objective pushes it to keep trying others, which is exploration. When two actions are nearly equally good, the maximum-entropy policy keeps probability on both instead of breaking the tie. And the paper cites earlier work showing that such policies hold up better under errors in the model or in the value estimates.

For one state with return R(a)R(a) over a one-dimensional action, the policy that maximizes E[R]+αH\mathbb{E}[R] + \alpha\mathcal{H} is π∗(a)∝exp⁡(R(a)/α)\pi^*(a) \propto \exp(R(a)/\alpha), derived in the next section. Figure 1 plots it for a return with two peaks, the left one higher. Below about α=0.12\alpha = 0.12 the policy is a spike on the higher peak, the choice a greedy method makes; at the default it has a second, smaller bump on the right peak; above about 1.2 it is close to uniform and the reward barely moves it.

Figure 1 · the maximum-entropy policy
1/α = 4.6
A return over one action with two good choices and the optimal soft policy π* ∝ exp(R/α). Slide the temperature α: near 0 the policy spikes on the best action (greedy), at moderate α it keeps mass on both peaks, and at large α it flattens toward uniform. The readout on the right of the slider is 1/α, the equivalent reward scale.

The greedy spike puts all its probability on one action, so if that action leads somewhere bad or the environment changes so that the right peak becomes better, the agent has no experience with the alternative. At a moderate temperature the agent keeps sampling the second option and keeps its value estimate for it up to date.

Soft value functions and the reward scale

Optimizing (1) needs value functions that count future entropy as well as future reward. These are called soft. The paper defines the soft Q-function through a soft Bellman backup operator:

TπQ(st,at)≜r(st,at)+γ Est+1∼p[ V(st+1) ]\mathcal{T}^\pi Q(\mathbf{s}_t,\mathbf{a}_t) \triangleq r(\mathbf{s}_t,\mathbf{a}_t) + \gamma\,\mathbb{E}_{\mathbf{s}_{t+1}\sim p}\big[\, V(\mathbf{s}_{t+1}) \,\big]TπQ(st,at)≜r(st,at)+γ Est+1∼p[ V(st+1) ]\begin{aligned} \mathcal{T}^\pi Q(\mathbf{s}_t,\mathbf{a}_t) &\triangleq r(\mathbf{s}_t,\mathbf{a}_t) \\ &\quad + \gamma\,\mathbb{E}_{\mathbf{s}_{t+1}\sim p}\big[\, V(\mathbf{s}_{t+1}) \,\big] \end{aligned}
(2)

with the soft state value

V(st)=Eat∼π[ Q(st,at)−log⁡π(at∣st) ]V(\mathbf{s}_t) = \mathbb{E}_{\mathbf{a}_t\sim\pi}\big[\, Q(\mathbf{s}_t,\mathbf{a}_t) - \log\pi(\mathbf{a}_t\mid\mathbf{s}_t) \,\big]V(st)=Eat∼π[ Q(st,at)−log⁡π(at∣st) ]\begin{aligned} V(\mathbf{s}_t) &= \mathbb{E}_{\mathbf{a}_t\sim\pi}\big[\, Q(\mathbf{s}_t,\mathbf{a}_t) \\ &\qquad - \log\pi(\mathbf{a}_t\mid\mathbf{s}_t) \,\big] \end{aligned}
(3)

Equation (2) has the shape of the ordinary Bellman equation: the value of taking action at\mathbf{a}_t in state st\mathbf{s}_t is the immediate reward plus the discounted value of the next state. The difference is in VV. Since H(π)=E[−log⁡π]\mathcal{H}(\pi) = \mathbb{E}[-\log\pi], equation (3) says the soft value is the expected Q under the policy plus the entropy at that state. QQ bootstraps from VV at the next state, which contains the entropy there and a QQ that bootstraps one step further, so a soft Q-value counts the discounted entropy the policy will collect along the rest of the trajectory as well as the reward. Equation (3) is the value of the current policy π\pi, not of the optimal one.

The temperature is missing from (2) and (3) because the paper folds it into the reward. The objective r+αHr + \alpha\mathcal{H} equals α (r/α+H)\alpha\,(r/\alpha + \mathcal{H}), and multiplying an objective by a positive constant does not change which policy maximizes it, so the paper divides every reward by α\alpha and writes every equation from (2) on with α=1\alpha = 1 and a bare −log⁡π-\log\pi.

That makes the temperature and the reward scale the same knob: multiplying every reward by a constant cc sets α=1/c\alpha = 1/c. A larger reward scale makes reward outweigh the fixed entropy bonus, so the optimal policy becomes narrower and more deterministic; a smaller one makes it wider. In standard RL, multiplying all rewards by a positive constant leaves the optimal policy unchanged. In maximum-entropy RL it changes the policy. The paper found the reward scale to be the only hyperparameter it had to tune per task: 5 for Hopper, Walker2d, HalfCheetah and Ant, 20 for Humanoid-v1 and 10 for the rllab Humanoid, which correspond to α\alpha = 0.2, 0.05 and 0.1.

The best policy for a fixed set of soft Q-values has a closed form. Take one state with four actions whose soft Q-values are 2.0, 1.5, 0.5 and −1.0, at reward scale c=1c = 1. The greedy policy always picks the first action: E[Q]=2.00\mathbb{E}[Q] = 2.00, H=0\mathcal{H} = 0, so V=2.00V = 2.00. The uniform policy has E[Q]=0.75\mathbb{E}[Q] = 0.75 and H=log⁡4=1.39\mathcal{H} = \log 4 = 1.39, so V=2.14V = 2.14. The policy proportional to exp⁡Q\exp Q puts probabilities 0.53, 0.32, 0.12 and 0.03 on the four actions, with E[Q]=1.58\mathbb{E}[Q] = 1.58 and H=1.05\mathcal{H} = 1.05, so V=2.63V = 2.63. No distribution over the four actions does better, because for any policy π\pi

Eπ[Q]+H(π)=log⁡Z−DKL ⁣(π ∥ exp⁡QZ),Z=∑aexp⁡Q(a)\mathbb{E}_{\pi}[Q] + \mathcal{H}(\pi) = \log Z - D_{\mathrm{KL}}\!\Big(\pi \,\Big\|\, \frac{\exp Q}{Z}\Big), \qquad Z = \sum_{a} \exp Q(a)Eπ[Q]+H(π)=log⁡Z−DKL ⁣(π ∥ exp⁡QZ),Z=∑aexp⁡Q(a)\begin{gathered} \mathbb{E}_{\pi}[Q] + \mathcal{H}(\pi) = \log Z - D_{\mathrm{KL}}\!\Big(\pi \,\Big\|\, \frac{\exp Q}{Z}\Big), \\ Z = \sum_{a} \exp Q(a) \end{gathered}

To see it, expand the KL:

DKL(π ∥ exp⁡QZ)=∑aπlog⁡π−∑aπ (Q−log⁡Z)=−H(π)−Eπ[Q]+log⁡ZD_{\mathrm{KL}}\Big(\pi \,\Big\|\, \frac{\exp Q}{Z}\Big) = \sum_a \pi\log\pi - \sum_a \pi\,(Q - \log Z) = -\mathcal{H}(\pi) - \mathbb{E}_\pi[Q] + \log ZDKL(π ∥ exp⁡QZ)=∑aπlog⁡π−∑aπ (Q−log⁡Z)=−H(π)−Eπ[Q]+log⁡Z\begin{aligned} D_{\mathrm{KL}}\Big(\pi \,\Big\|\, \frac{\exp Q}{Z}\Big) &= \sum_a \pi\log\pi - \sum_a \pi\,(Q - \log Z) \\ &= -\mathcal{H}(\pi) - \mathbb{E}_\pi[Q] + \log Z \end{aligned}

The KL is never negative and is zero only when π=exp⁡(Q)/Z\pi = \exp(Q)/Z, so the maximum soft value is log⁡Z=2.63\log Z = 2.63, reached by that one policy. This is the Boltzmann, or energy-based, policy. With the temperature written back in it is π∝exp⁡(Q/α)\pi \propto \exp(Q/\alpha), and as α→0\alpha \to 0 it becomes the greedy argmax.

Figure 2 runs this example. The bars are a candidate policy π∝exp⁡(Q/T)\pi \propto \exp(Q/T), and the curve is its soft value as TT sweeps from greedy to uniform. At c=1c = 1 the peak sits at T=1T = 1. Set the reward scale to 5 and the peak moves to T=0.2T = 0.2, where the best policy is nearly greedy, with probabilities 0.92, 0.08, 0.00 and 0.00.

Figure 2 · the soft value of one state
T = 1.00
c = 1.0 · α = 1.00
One state, four actions with soft Q-values 2.0, 1.5, 0.5 and −1.0. The bars are a candidate policy π ∝ exp(Q/T); the curve is its soft value E[cQ] + H as T runs from greedy (left) to uniform (right), and the dot marks the current T. Drag the reward scale c and the peak (dashed) moves to T = 1/c, where V equals log Σ exp(cQ).

SAC trains its policy toward this Boltzmann distribution, exp⁡(Q(s,⋅))/Z(s)\exp(Q(\mathbf{s},\cdot))/Z(\mathbf{s}), at every state. For a continuous action the distribution can have any shape and ZZ is an integral over the action space, so the next step needs an approximation.

How SAC improves the policy: a KL projection

Policy iteration alternates two steps: evaluate the current policy (compute its Q-values), then improve it (make it greedy with respect to those Q-values). Soft policy iteration evaluates with the soft backup (2) and replaces arg⁡max⁡aQ\arg\max_a Q with the Boltzmann policy exp⁡(Q)/Z\exp(Q)/Z.

For a neural Q-function over a continuous action, the Boltzmann policy can have any number of peaks, and neither sampling from it nor computing Z(s)=∫exp⁡(Q(s,a)) daZ(\mathbf{s}) = \int \exp(Q(\mathbf{s},\mathbf{a}))\,d\mathbf{a} has a closed form. SAC restricts the policy to a tractable family Π\Pi, in practice Gaussians squashed by tanh⁡\tanh, and picks the member of Π\Pi closest to the Boltzmann target in KL divergence:

πnew=arg⁡min⁡π′∈Π  DKL ⁣(π′(⋅∣st)  ∥  exp⁡(Qπold(st,⋅))Zπold(st))\pi_{\text{new}} = \arg\min_{\pi'\in\Pi}\; D_{\mathrm{KL}}\!\left(\pi'(\cdot\mid\mathbf{s}_t)\;\Big\|\;\frac{\exp\big(Q^{\pi_{\text{old}}}(\mathbf{s}_t,\cdot)\big)}{Z^{\pi_{\text{old}}}(\mathbf{s}_t)}\right)πnew=arg⁡min⁡π′∈ΠDKL ⁣(π′(⋅∣st)  ∥  exp⁡(Qπold(st,⋅))Zπold(st))\begin{aligned} \pi_{\text{new}} &= \arg\min_{\pi'\in\Pi} \\ &D_{\mathrm{KL}}\!\left(\pi'(\cdot\mid\mathbf{s}_t)\;\Big\|\;\frac{\exp\big(Q^{\pi_{\text{old}}}(\mathbf{s}_t,\cdot)\big)}{Z^{\pi_{\text{old}}}(\mathbf{s}_t)}\right) \end{aligned}
(4)

The new policy π′\pi' is in the first slot. The paper calls this the information projection; it is the reverse KL, as opposed to the forward KL with the target first. Expanding it as in the four-action example gives −(Eπ′[Q]+H(π′))+log⁡Z-(\mathbb{E}_{\pi'}[Q] + \mathcal{H}(\pi')) + \log Z, so minimizing (4) over π′\pi' is maximizing the soft value within Π\Pi.

The direction of the KL decides what a single Gaussian does when the target has two peaks. The reverse KL averages log⁡π′−log⁡p∗\log\pi' - \log p^* over samples from π′\pi', where p∗p^* is the target. A Gaussian sitting in the valley between the peaks draws its samples where p∗p^* is small, so log⁡p∗\log p^* is very negative there and the divergence is large. A Gaussian sitting on one peak draws its samples where p∗p^* is large, and the other peak costs it nothing, because it draws no samples there. So the reverse KL is mode-seeking: the best narrow Gaussian sits on one peak. The forward KL averages over samples from the target instead, charges the Gaussian for every region of target mass it fails to cover, and at a fixed narrow width puts the mean between the peaks.

In Figure 3 the target is the Boltzmann policy, at α=0.3\alpha = 0.3, of a two-peak return like the one in Figure 1. With the default width σ=0.16\sigma = 0.16, the Gaussian starts in the valley at a reverse KL of 1.85 nats, and the best mean is −0.44, on the left peak, at 0.52 nats. Switch to the forward KL and the best mean moves to −0.06, in the valley, close to the target's overall mean. Widen σ\sigma past about 0.6 and both directions put the mean near the middle, because a Gaussian that wide covers both peaks.

Figure 3 · the policy update is a projection
σ = 0.16
The soft-greedy target exp(Q/α)/Z has two peaks; the policy is a single Gaussian. Drag on the plot to move its mean; the dashed line is the best mean for the current width and KL direction. Under the reverse KL that SAC uses, a narrow Gaussian fits one peak; under the forward KL it sits between them. Both divergences are computed on a grid over a ∈ [−1, 1].

Writing the improvement as (4) has two consequences. The normalizer Z(s)Z(\mathbf{s}) depends on the state and the Q-function but not on the policy's parameters, so its gradient with respect to them is exactly zero and SAC never computes it. And the paper proves (Lemma 2) that the projected policy has soft Q-values at least as high as the old policy's at every state-action pair, so alternating evaluation and projection improves the policy monotonically; Theorem 1 says the alternation converges to the best maximum-entropy policy within Π\Pi. Both results assume a finite action set with exact evaluation and exact projection, the tabular setting. The deep algorithm below replaces each exact step with one gradient step on a neural network and has no convergence proof.

The networks and the replay buffer

The deep algorithm approximates both halves of soft policy iteration with networks trained by stochastic gradient descent, interleaved with collecting data. This paper (SAC version one) trains four networks:

There is also exactly one target network, VψˉV_{\bar\psi}, an exponential moving average of the value network's weights that is never trained by gradient. Every network has two hidden layers of 256 ReLU units. The value network is redundant in principle, since (3) gives VV from QQ and π\pi; the paper keeps it because, it reports, a separate value approximator stabilizes training and is convenient to train alongside the others.

Figure 4 is the outer loop. The current policy samples an action, the environment returns a reward and a next state, and the transition (s,a,r,s′)(\mathbf{s}, \mathbf{a}, r, \mathbf{s}') goes into a buffer holding the last 10610^6 transitions. Then one gradient step updates every network on a minibatch of 256 transitions drawn at random from the buffer, most of them collected by older versions of the policy.

Figure 4 · the off-policy actor-critic loop
The policy acts, the transition is stored in the replay buffer, a past batch is sampled back out, and the networks learn from it. Tap a stage for detail; the LEARN stage holds the three losses and the target network.

Every loss below can be computed on transitions from an older policy. The Q-loss uses the stored state, action, reward and next state. The value and policy losses use the stored state but draw a fresh action from the current policy, so they never need the action the old policy took. The paper points to this property as the reason the stochastic actor can be trained entirely on replayed data.

How SAC trains the critics

The value network regresses onto the right-hand side of (3):

JV(ψ)=Est∼D[12(Vψ(st)−Eat∼πϕ[ Qθ(st,at)−log⁡πϕ(at∣st) ])2]J_V(\psi) = \mathbb{E}_{\mathbf{s}_t\sim\mathcal{D}}\Big[\tfrac{1}{2}\Big(V_\psi(\mathbf{s}_t) - \mathbb{E}_{\mathbf{a}_t\sim\pi_\phi}\big[\,Q_\theta(\mathbf{s}_t,\mathbf{a}_t) - \log\pi_\phi(\mathbf{a}_t\mid\mathbf{s}_t)\,\big]\Big)^2\Big]JV(ψ)=Est∼D[12(Vψ(st)−Eat∼πϕ[ Qθ(st,at)−log⁡πϕ(at∣st) ])2]\begin{aligned} J_V(\psi) = \mathbb{E}_{\mathbf{s}_t\sim\mathcal{D}}\Big[\tfrac{1}{2}\Big(&V_\psi(\mathbf{s}_t) - \mathbb{E}_{\mathbf{a}_t\sim\pi_\phi}\big[\,Q_\theta(\mathbf{s}_t,\mathbf{a}_t) \\ &- \log\pi_\phi(\mathbf{a}_t\mid\mathbf{s}_t)\,\big]\Big)^2\Big] \end{aligned}
(5)

The state st\mathbf{s}_t comes from the buffer D\mathcal{D}; the action inside the target is sampled from the current policy, because (3) is an expectation under the current policy. The paper estimates the gradient from one such action:

∇^ψJV(ψ)=∇ψVψ(st) (Vψ(st)−Qθ(st,at)+log⁡πϕ(at∣st))\hat\nabla_\psi J_V(\psi) = \nabla_\psi V_\psi(\mathbf{s}_t)\,\big(V_\psi(\mathbf{s}_t) - Q_\theta(\mathbf{s}_t,\mathbf{a}_t) + \log\pi_\phi(\mathbf{a}_t\mid\mathbf{s}_t)\big)∇^ψJV(ψ)=∇ψVψ(st) (Vψ(st)−Qθ(st,at)+log⁡πϕ(at∣st))\begin{aligned} \hat\nabla_\psi J_V(\psi) &= \nabla_\psi V_\psi(\mathbf{s}_t)\,\big(V_\psi(\mathbf{s}_t) \\ &\quad - Q_\theta(\mathbf{s}_t,\mathbf{a}_t) + \log\pi_\phi(\mathbf{a}_t\mid\mathbf{s}_t)\big) \end{aligned}
(6)

Both Q-networks regress onto one target built from the stored reward and the target value network at the stored next state:

JQ(θ)=E(st,at)∼D[12(Qθ(st,at)−Q^(st,at))2]J_Q(\theta) = \mathbb{E}_{(\mathbf{s}_t,\mathbf{a}_t)\sim\mathcal{D}}\Big[\tfrac{1}{2}\big(Q_\theta(\mathbf{s}_t,\mathbf{a}_t) - \hat{Q}(\mathbf{s}_t,\mathbf{a}_t)\big)^2\Big]JQ(θ)=E(st,at)∼D[12(Qθ(st,at)−Q^(st,at))2]\begin{aligned} J_Q(\theta) &= \mathbb{E}_{(\mathbf{s}_t,\mathbf{a}_t)\sim\mathcal{D}}\Big[\tfrac{1}{2}\big(Q_\theta(\mathbf{s}_t,\mathbf{a}_t) \\ &\qquad - \hat{Q}(\mathbf{s}_t,\mathbf{a}_t)\big)^2\Big] \end{aligned}
(7)
Q^(st,at)=r(st,at)+γ Est+1∼p[Vψˉ(st+1)]\hat{Q}(\mathbf{s}_t,\mathbf{a}_t) = r(\mathbf{s}_t,\mathbf{a}_t) + \gamma\,\mathbb{E}_{\mathbf{s}_{t+1}\sim p}\big[V_{\bar\psi}(\mathbf{s}_{t+1})\big]Q^(st,at)=r(st,at)+γ Est+1∼p[Vψˉ(st+1)]\begin{aligned} \hat{Q}(\mathbf{s}_t,\mathbf{a}_t) &= r(\mathbf{s}_t,\mathbf{a}_t) \\ &\quad + \gamma\,\mathbb{E}_{\mathbf{s}_{t+1}\sim p}\big[V_{\bar\psi}(\mathbf{s}_{t+1})\big] \end{aligned}
(8)

Here the state and the action both come from the buffer, so this loss is fully off-policy. Its one-sample gradient, the paper's (9), is ∇θQθ\nabla_\theta Q_\theta times the residual Qθ−r−γVψˉ(st+1)Q_\theta - r - \gamma V_{\bar\psi}(\mathbf{s}_{t+1}). (The paper prints the first Q in (9) with its arguments swapped, Qθ(at,st)Q_\theta(\mathbf{a}_t,\mathbf{s}_t); the meaning is the same.)

After every gradient step the target network moves by ψˉ←τψ+(1−τ)ψˉ\bar\psi \leftarrow \tau\psi + (1-\tau)\bar\psi with τ=0.005\tau = 0.005. The gap between ψˉ\bar\psi and ψ\psi shrinks by a factor of 0.995 per step, to 37% after 200 steps (a half-life of about 138 steps), so the Q-target drifts gradually even though VψV_\psi changes every step. The paper credits target networks to Mnih et al. (2015). Its Figure 3(c) sweeps τ\tau on Ant-v1 from 0.0001 to 0.1: large values are unstable, small values train slowly, the range of good values is wide, and 0.005 is used on every task. A separate variant copies the weights outright every 1,000 steps (τ=1\tau = 1, a hard update).

SAC trains two Q-networks with independent parameters θ1\theta_1 and θ2\theta_2 on the same loss (7), and uses the smaller of their two outputs in the value gradient (6) and in the policy gradient (13), to counter an upward bias. The actor moves toward actions with high Q, and the value target averages Q under that actor, so an action whose Q the critic overrates gets chosen more often and lifts the value target; through the bootstrap in (8), the inflated value then lifts other Q-targets. The paper cites van Hasselt (2010) for this positive bias and takes the minimum of two Q-functions from TD3 (Fujimoto et al., 2018), which was published concurrently.

Figure 5 isolates the statistics. When two estimates of the same true value q∗q^* carry independent Gaussian errors with standard deviation σ\sigma, their maximum averages q∗+σ/πq^* + \sigma/\sqrt{\pi} and their minimum q∗−σ/πq^* - \sigma/\sqrt{\pi}, about ±0.56 σ\pm 0.56\,\sigma. SAC takes the minimum and accepts a small underestimate in exchange for offsetting the overestimate that a max-seeking actor would otherwise feed into the bootstrap. Averaging the two critics would shrink the noise, but the actor would still select the actions whose average is overrated.

Figure 5 · why the minimum of two critics
σ = 1.00
Two independent noisy estimates of one true Q value. The distribution of their maximum sits σ/√π above the truth; the minimum sits the same distance below. Slide the noise σ and both offsets grow in proportion.

The minimum is not in the Q-target: (8) contains only VψˉV_{\bar\psi}, and both Q-networks bootstrap from it. And the second critic is a speedup, not a requirement: the paper reports that a single Q-function learns even the 21-dimensional rllab Humanoid, and that two Q-functions significantly speed up training, especially on the harder tasks. The authors' released code applies the minimum in the value target only; its reparameterized policy loss uses Qθ1Q_{\theta_1} alone.

How SAC trains the actor

The policy minimizes the expected KL (4) over states from the buffer:

Jπ(ϕ)=Est∼D[ DKL ⁣(πϕ(⋅∣st)  ∥  exp⁡(Qθ(st,⋅))Zθ(st))]J_\pi(\phi) = \mathbb{E}_{\mathbf{s}_t\sim\mathcal{D}}\Big[\,D_{\mathrm{KL}}\!\Big(\pi_\phi(\cdot\mid\mathbf{s}_t)\;\Big\|\;\frac{\exp(Q_\theta(\mathbf{s}_t,\cdot))}{Z_\theta(\mathbf{s}_t)}\Big)\Big]Jπ(ϕ)=Est∼D[ DKL(πϕ(⋅∣st)∥  exp⁡(Qθ(st,⋅))Zθ(st))]\begin{aligned} J_\pi(\phi) &= \mathbb{E}_{\mathbf{s}_t\sim\mathcal{D}}\Big[\,D_{\mathrm{KL}}\Big(\pi_\phi(\cdot\mid\mathbf{s}_t) \\ &\qquad \Big\|\;\frac{\exp(Q_\theta(\mathbf{s}_t,\cdot))}{Z_\theta(\mathbf{s}_t)}\Big)\Big] \end{aligned}
(10)

Expanding the KL and dropping log⁡Z\log Z, which does not depend on ϕ\phi, leaves an expectation of log⁡πϕ(a∣s)−Qθ(s,a)\log\pi_\phi(\mathbf{a}\mid\mathbf{s}) - Q_\theta(\mathbf{s},\mathbf{a}) over actions sampled from πϕ\pi_\phi. The sampling distribution itself depends on ϕ\phi, so the gradient cannot be moved inside the expectation.

One standard answer is the likelihood-ratio estimator (Williams, 1992), also called REINFORCE: ∇ϕE[f(a)]\nabla_\phi \mathbb{E}[f(\mathbf{a})] equals the expectation of f(a) ∇ϕlog⁡πϕ(a∣s)f(\mathbf{a})\,\nabla_\phi\log\pi_\phi(\mathbf{a}\mid\mathbf{s}). It needs only the value of ff at the sampled action, so it works even when ff cannot be differentiated. SAC's ff contains the critic, a neural network that can be differentiated with respect to its action input, and the paper uses the reparameterization trick instead, stating that it gives a lower-variance estimator. The action is written as a deterministic function of the state and an independent noise sample:

at=fϕ(ϵt; st)\mathbf{a}_t = f_\phi(\epsilon_t;\, \mathbf{s}_t)
(11)

where ϵt\epsilon_t comes from a fixed distribution, such as a spherical Gaussian, that does not depend on ϕ\phi. For SAC's policy the function is

fϕ(ϵ;s)=tanh⁡(μϕ(s)+σϕ(s)⊙ϵ)f_\phi(\epsilon;\mathbf{s}) = \tanh\big(\mu_\phi(\mathbf{s}) + \sigma_\phi(\mathbf{s})\odot\epsilon\big)

with ⊙\odot the elementwise product. The expectation over actions becomes an expectation over noise, and the gradient can move inside it:

Jπ(ϕ)=Est∼D, ϵt∼N[ log⁡πϕ(fϕ(ϵt;st)∣st)−Qθ(st,fϕ(ϵt;st)) ]J_\pi(\phi) = \mathbb{E}_{\mathbf{s}_t\sim\mathcal{D},\,\epsilon_t\sim\mathcal{N}}\big[\, \log\pi_\phi\big(f_\phi(\epsilon_t;\mathbf{s}_t)\mid\mathbf{s}_t\big) - Q_\theta\big(\mathbf{s}_t, f_\phi(\epsilon_t;\mathbf{s}_t)\big) \,\big]Jπ(ϕ)=Est∼D, ϵt∼N[ log⁡πϕ(fϕ(ϵt;st)∣st)−Qθ(st,fϕ(ϵt;st)) ]\begin{aligned} J_\pi(\phi) = \mathbb{E}_{\mathbf{s}_t\sim\mathcal{D},\,\epsilon_t\sim\mathcal{N}}\big[\, &\log\pi_\phi\big(f_\phi(\epsilon_t;\mathbf{s}_t)\mid\mathbf{s}_t\big) \\ &- Q_\theta\big(\mathbf{s}_t, f_\phi(\epsilon_t;\mathbf{s}_t)\big) \,\big] \end{aligned}
(12)

with the one-sample gradient, evaluated at at=fϕ(ϵt;st)\mathbf{a}_t = f_\phi(\epsilon_t;\mathbf{s}_t),

∇^ϕJπ(ϕ)=∇ϕlog⁡πϕ(at∣st)+(∇atlog⁡πϕ(at∣st)−∇atQ(st,at)) ∇ϕfϕ(ϵt;st)\hat\nabla_\phi J_\pi(\phi) = \nabla_\phi\log\pi_\phi(\mathbf{a}_t\mid\mathbf{s}_t) + \big(\nabla_{\mathbf{a}_t}\log\pi_\phi(\mathbf{a}_t\mid\mathbf{s}_t) - \nabla_{\mathbf{a}_t}Q(\mathbf{s}_t,\mathbf{a}_t)\big)\,\nabla_\phi f_\phi(\epsilon_t;\mathbf{s}_t)∇^ϕJπ(ϕ)=∇ϕlog⁡πϕ(at∣st)+(∇atlog⁡πϕ(at∣st)−∇atQ(st,at))∇ϕfϕ(ϵt;st)\begin{aligned} \hat\nabla_\phi J_\pi(\phi) &= \nabla_\phi\log\pi_\phi(\mathbf{a}_t\mid\mathbf{s}_t) \\ &+ \big(\nabla_{\mathbf{a}_t}\log\pi_\phi(\mathbf{a}_t\mid\mathbf{s}_t) - \nabla_{\mathbf{a}_t}Q(\mathbf{s}_t,\mathbf{a}_t)\big) \\ &\quad \nabla_\phi f_\phi(\epsilon_t;\mathbf{s}_t) \end{aligned}
(13)

Take (13) term by term. ∇aQ\nabla_{\mathbf{a}} Q is the critic's slope with respect to the action, and ∇ϕfϕ\nabla_\phi f_\phi says how the sampled action moves when the policy parameters move; their product, with the minus sign, moves the action uphill on the critic, the same gradient DDPG uses for its deterministic actor. The two log⁡π\log\pi terms are the derivative of the entropy part: the first differentiates the density with the action held fixed, the second accounts for the change in log⁡π\log\pi as the action moves. The paper calls (13) an unbiased estimator that extends DDPG-style policy gradients to any tractable stochastic policy. The gradient passes through only fϕf_\phi and QθQ_\theta, with no model of the environment.

JπJ_\pi is a loss that Algorithm 1 minimizes by gradient descent, while J(π)J(\pi) in (1) is an objective to maximize; the paper uses the same letter for both. Minimizing E[log⁡π−Q]\mathbb{E}[\log\pi - Q] raises E[Q]\mathbb{E}[Q] and raises the entropy E[−log⁡π]\mathbb{E}[-\log\pi], which is gradient ascent on the soft value.

Figure 6 compares the two estimators on a one-dimensional problem of our own: critic Q(a)=−a2Q(a) = -a^2, policy N(μ,σ2)\mathcal{N}(\mu, \sigma^2), and the quantity to estimate is the derivative of E[Q(a)]\mathbb{E}[Q(a)] with respect to μ\mu, which is −2μ-2\mu. From one noise sample ϵ\epsilon, the pathwise estimate is Q′(μ+σϵ)=−2(μ+σϵ)Q'(\mu + \sigma\epsilon) = -2(\mu + \sigma\epsilon), with standard deviation 2σ2\sigma. The likelihood-ratio estimate is Q(μ+σϵ) ϵ/σQ(\mu + \sigma\epsilon)\,\epsilon/\sigma. At μ=1\mu = 1 and σ=0.5\sigma = 0.5 the true gradient is −2, and the standard deviations are 1.00 for pathwise and 4.66 for likelihood ratio, or 3.24 with the usual baseline E[Q]\mathbb{E}[Q] subtracted. As σ→0\sigma \to 0 the pathwise spread goes to zero, leaving DDPG's deterministic gradient, while the likelihood-ratio spread without a baseline grows like 1/σ1/\sigma.

Figure 6 · two estimates of the same policy gradient
σ = 0.50
μ = 1.00
Histograms of 2,000 single-sample estimates of d/dμ E[Q] for Q(a) = −a² and policy N(μ, σ²). Likelihood ratio (REINFORCE), with an optional baseline, against pathwise, as in SAC. The dashed line is the true gradient −2μ, and the std readouts are exact. Drag σ toward 0.05 to watch the pathwise spread vanish.

The pathwise estimate is tighter because it uses the critic's slope at the sampled action, which says which direction in action space raises Q. The likelihood-ratio estimate uses only the critic's value at the sample and recovers the direction only through the correlation between those values and the noise, averaged over many samples.

Squashing actions into bounds

Real actuators are bounded, say a torque in [−1,1][-1, 1], and a Gaussian proposes values anywhere on the real line. SAC samples an unbounded u\mathbf{u} from the Gaussian and outputs a=tanh⁡(u)\mathbf{a} = \tanh(\mathbf{u}), applied to each coordinate, which maps every real number into (−1,1)(-1, 1). The density of a\mathbf{a} follows from the change-of-variables formula (the paper's Appendix C):

π(a∣s)=μ(u∣s) ∣det⁡dadu∣−1\pi(\mathbf{a}\mid\mathbf{s}) = \mu(\mathbf{u}\mid\mathbf{s})\,\left|\det\frac{d\mathbf{a}}{d\mathbf{u}}\right|^{-1}
(20)
log⁡π(a∣s)=log⁡μ(u∣s)−∑i=1Dlog⁡ ⁣(1−tanh⁡2(ui))\log\pi(\mathbf{a}\mid\mathbf{s}) = \log\mu(\mathbf{u}\mid\mathbf{s}) - \sum_{i=1}^{D}\log\!\big(1 - \tanh^2(u_i)\big)log⁡π(a∣s)=log⁡μ(u∣s)−∑i=1Dlog⁡ ⁣(1−tanh⁡2(ui))\begin{aligned} \log\pi(\mathbf{a}\mid\mathbf{s}) &= \log\mu(\mathbf{u}\mid\mathbf{s}) \\ &\quad - \sum_{i=1}^{D}\log\!\big(1 - \tanh^2(u_i)\big) \end{aligned}
(21)

In (20) and (21), μ(u∣s)\mu(\mathbf{u}\mid\mathbf{s}) denotes the Gaussian density, not its mean. Because tanh⁡\tanh acts on each coordinate separately, the Jacobian da/dud\mathbf{a}/d\mathbf{u} is diagonal with entries 1−tanh⁡2(ui)1 - \tanh^2(u_i), and its log-determinant is a sum over the DD action dimensions; this holds whether or not the Gaussian itself is diagonal. Each entry is at most 1, so each log is at most 0, and subtracting it raises the log-probability. At ui=0u_i = 0 the term is 0. At ui=2u_i = 2, tanh⁡(2)=0.964\tanh(2) = 0.964, 1−0.9642=0.0711 - 0.964^2 = 0.071, and the correction adds 2.65 nats in that dimension: tanh compresses a stretch of uu into a short stretch of aa near the bound, which raises the density there.

In Figure 7 the teal Gaussian along the bottom is the distribution of uu, and the amber density down the left side is the resulting distribution of the bounded action. Move the mean or widen the Gaussian until it reaches the flat tails of tanh, and the action density piles up against ±1\pm 1.

Figure 7 · reparameterize, then squash
μ = 0.70
σ = 0.90
A Gaussian over u (marginal along the bottom) is squashed by tanh into a bounded action density over a ∈ (−1, 1) (down the left). Drag μ and σ: as the Gaussian reaches tanh's flat tails, probability mass collects at the bounds ±1. The dots are fixed noise quantiles carried through the map.

Computing the correction as log(1 - tanh(u)**2) fails near the bounds. In 32-bit floats tanh⁡(10)\tanh(10) rounds to exactly 1.0, so the expression evaluates to log⁡0=−∞\log 0 = -\infty, while the true value is −18.61. An exact rewrite that stays finite:

log⁡ ⁣(1−tanh⁡2u)=2(log⁡2−u−softplus⁡(−2u))\log\!\big(1-\tanh^2 u\big) = 2\big(\log 2 - u - \operatorname{softplus}(-2u)\big)

which follows from 1−tanh⁡2u=4/(eu+e−u)21 - \tanh^2 u = 4/(e^{u} + e^{-u})^2. The authors' released code takes a different route and adds 10−610^{-6} inside the log, which caps each term at log⁡10−6≈−13.8\log 10^{-6} \approx -13.8.

A full SAC update in code

The listing is one gradient step in PyTorch-style pseudocode, following Algorithm 1: the value network first, then both Q-networks, then the policy, then the target network. The minimum of the two critics appears in the value target and the policy loss and not in the Q-target. The value target uses a plain sample, and the policy loss uses rsample, the reparameterized draw that keeps the gradient path from the action back to the policy's weights. The reward-scale multiply and the (1 - done) mask on terminal states are in the released code but not in the paper's equations.

# one SAC (v1) gradient step on a replayed minibatch; B = 256, D = action dims
def step(opt, loss):
    opt.zero_grad(); loss.backward(); opt.step()

s, a, r, s2, done = buffer.sample(B)   # s (B,obs)  a (B,D)  r (B,)  s2 (B,obs)
r = reward_scale * r                   # c = 1/alpha, e.g. 5 for Hopper

# value network, eq (5): target E_pi[min Q - log pi] with a FRESH action at s
a_new, logp = pi.sample(s)             # (B,D), (B,); no gradient needed here
q_min = torch.min(Q1(s, a_new), Q2(s, a_new))
step(opt_V, 0.5 * ((V(s) - (q_min - logp).detach()) ** 2).mean())

# both Q-networks, eqs (7)-(8): stored (s, a), target from Vbar, no min
q_hat = (r + gamma * (1 - done) * Vbar(s2)).detach()
step(opt_Q, 0.5 * ((Q1(s, a) - q_hat) ** 2).mean()
          + 0.5 * ((Q2(s, a) - q_hat) ** 2).mean())

# policy, eq (12): reparameterized sample, minimize E[log pi - Q]
a_rp, logp_rp = pi.rsample(s)          # a = tanh(mu + sigma * eps), keeps grad
q_rp = torch.min(Q1(s, a_rp), Q2(s, a_rp))   # paper; released code: Q1 only
step(opt_pi, (logp_rp - q_rp).mean())  # opt_pi steps the policy's weights only

# target value network: EMA, tau = 0.005
for p, p_bar in zip(V.parameters(), Vbar.parameters()):
    p_bar.data.mul_(1 - tau).add_(tau * p.data)

For HalfCheetah, with D=6D = 6 action dimensions, a minibatch holds 256 states. The policy network outputs a 256 × 6 mean and a 256 × 6 log standard deviation; the noise, the pre-squash u\mathbf{u} and the action are 256 × 6; the log-probability sums over the 6 dimensions into 256 numbers; each Q-network takes the state and the 6-dimensional action and returns 256 numbers, as does the value network from the state alone. The sampling step, with the tanh correction:

# tanh-squashed Gaussian policy: sample and log-prob, eqs (11) and (21)
mu, log_sigma = policy_net(s)                  # each (B,D)
u = mu + log_sigma.exp() * torch.randn_like(mu)  # reparameterized, (B,D)
a = torch.tanh(u)                              # every coordinate in (-1, 1)
logp = Normal(mu, log_sigma.exp()).log_prob(u).sum(-1)       # log mu(u|s), (B,)
logp -= (2 * (log(2) - u - F.softplus(-2 * u))).sum(-1)      # tanh correction

Every task in the paper uses the same settings: Adam with learning rate 3×10−43 \times 10^{-4}, discount γ=0.99\gamma = 0.99, a buffer of 10610^6 transitions, minibatches of 256, two hidden layers of 256 ReLU units in every network, τ=0.005\tau = 0.005, a target update every step, and one gradient step per environment step; the reward scale is set per task as listed above.

Results: sample efficiency and seed stability

The paper trains five seeds of each method on six benchmarks (Hopper-v1, Walker2d-v1, HalfCheetah-v1, Ant-v1, Humanoid-v1 and the rllab Humanoid), with one evaluation rollout every 1,000 environment steps. The baselines are DDPG, PPO, Soft Q-Learning (SQL, the authors' earlier maximum-entropy method) and TD3, with Trust-PCL in an appendix. SAC performs comparably to the baselines on the easier tasks and outperforms them by a large margin on the harder ones, in learning speed and in final return. DDPG fails to make any progress on Ant-v1, Humanoid-v1 and the rllab Humanoid. SQL learns every task, more slowly than SAC and to lower final returns.

The stability claim comes from one experiment, on the rllab Humanoid. Five seeds of SAC are compared with five seeds of a deterministic variant that drops the entropy term. Apart from that, the variant resembles DDPG, except that it keeps two Q-functions, uses hard target updates, has no separate target actor, and explores with fixed rather than learned noise. The SAC runs end close together and the deterministic runs vary widely across seeds. The paper concludes that stochasticity can stabilize training, which matters most on hard tasks where tuning hyperparameters is difficult. Figure 8 redraws the comparison schematically.

Figure 8 · stochastic keeps the seeds together
draw #1
Five seeds each, drawn schematically after the paper's Figure 2. Stochastic SAC climbs in a tight band; a deterministic variant without the entropy term spreads widely, some seeds learning and some stalling. Resample to draw a new set. (Illustrative curves, not the paper's returns.)

The paper gives two mechanisms. In the policy, the entropy term prevents the policy's variance from collapsing too early (the paper points to (10)). In the value function, it raises the value of states from which the agent can keep acting with high entropy, which encourages exploration (the paper points to (5)). The evidence is the one task and five seeds per arm, so it supports the claim on the rllab Humanoid rather than measuring it across the benchmark.

The ablations on Ant-v1 cover three more choices. Sweeping the reward scale over 1, 3, 10, 30 and 100 shows the temperature's two failure modes: at small scales the policy becomes nearly uniform and fails to exploit the reward, and at large scales it learns quickly at first, then becomes nearly deterministic and gets stuck in poor local optima. The τ\tau sweep is described above. And for evaluation the paper uses the mean action rather than a sample from the policy, which generally gives higher returns. All the curves plot the sum of rewards, not the entropy-augmented objective SAC optimizes.

This paper versus the SAC in libraries

The SAC implementations in Stable-Baselines3, CleanRL and Spinning Up follow a separate, later paper by the same group, Soft Actor-Critic Algorithms and Applications (Haarnoja et al., December 2018, arXiv:1812.05905). It drops the separate value network, bootstraps the Q-targets from target copies of the two Q-networks (taking the minimum of the two there), and learns α\alpha during training so that the policy's entropy stays near a target value, which replaces the per-task reward-scale tuning this paper needed. The maximum-entropy objective, the soft Bellman backup, the KL projection, the reparameterized tanh-Gaussian actor and the two critics are all already in this paper.

The paper's own claim of novelty is narrower than "the first off-policy actor-critic", a title DDPG already holds: to the authors' knowledge, SAC is the first off-policy actor-critic method in the maximum-entropy framework. Its predecessor in that framework, Soft Q-Learning, trains a Q-function for the optimal policy and a separate sampler that affects learning only through the data it collects; SAC's actor is the policy whose soft value the critics estimate.

Provenance Verified against primary literatureHow we verify
Maximum entropy RL (Ziebart, 2010)The reward-plus-entropy objective and the energy-based (Boltzmann) optimal policy.
Soft Q-Learning (Haarnoja et al., 2017)The maximum-entropy predecessor. Its Q-function estimates the optimal soft Q and its sampler is not a true actor; SAC replaces that approximate inference with an actor trained by the KL projection.
DDPG / SVG(0) (Lillicrap 2015; Heess 2015)The off-policy actor-critic and the pathwise policy gradient that SAC extends to stochastic policies. SVG(0) is close but optimizes the standard return and has no separate value network.
TD3 (Fujimoto et al., 2018)The minimum of two Q-functions that curbs overestimation bias. Concurrent with SAC; van Hasselt (2010) is cited for the bias, not for the minimum.
DQN (Mnih et al., 2015)Replay-based off-policy Q-learning and the target network. The target network is from the 2015 Nature paper; the 2013 Atari preprint had replay only.
Released code (github.com/haarnoja/sac @ 8258e33)sac/algos/sac.py 256-262: Q target = scale_reward * r + (1 - done) * gamma * Vbar(s'). Lines 306-313 and 327-331: min(Q1, Q2) in the value target, Q1 alone in the reparameterized policy loss. sac/policies/gaussian_policy.py 15, 131-133: tanh correction log(1 - tanh(u)^2 + 1e-6).
correctionThe reward scale is the inverse temperature, c = 1/alpha: a larger reward scale makes the policy more deterministic, not more random. Section 5.2 of the paper prints "Larger reward magnitudes correspond to lower entries", which should read lower entropies (the next sentences describe the large-scale policy as nearly deterministic). Second, the authors' released code applies min(Q1, Q2) only in the value target and uses Q1 alone in the policy loss, while Section 4.2 says the minimum also enters the policy gradient (13); this page follows the paper. Third, the SAC that most libraries implement is the follow-up paper (arXiv:1812.05905), which drops this paper's value network and learns the temperature.

Questions you might still have

?

Why does adding randomness make training more stable, not less?
The entropy term keeps the policy variance from collapsing early and raises the value of states from which the agent can keep acting randomly, so the agent keeps trying alternatives instead of locking onto whatever behavior its first lucky estimates favored. The paper's evidence is one task, the rllab Humanoid, where five SAC seeds end close together and five seeds of a deterministic variant spread widely (Figure 8 redraws it schematically).

?

Is this the SAC I would get from Stable-Baselines3?
Probably not. Libraries usually implement the follow-up paper (arXiv:1812.05905): no separate value network, Q-targets from target copies of the two Q-networks, and a temperature learned to hold a target entropy instead of a hand-set reward scale. The objective, the soft values, the reparameterized tanh-Gaussian actor and the two critics are shared.

?

Why keep a separate value network if it is redundant?
Equation (3) gives V from Q and the policy, so V is redundant in principle. The paper keeps a separate network because it reports that this stabilizes training and is convenient to train alongside the others. The follow-up paper found it unnecessary and removed it.

?

Why the minimum of two Q-functions, not the average?
The actor moves toward actions the critic rates highly, so wherever the critic overestimates, the error is selected and then fed back through the bootstrap. The minimum of two independently trained critics is a deliberate underestimate that offsets it; an average reduces noise but does not remove the bias. The minimum comes from TD3.

?

Is the reward scale the only thing to tune?
In this paper, yes: every other hyperparameter is shared across all six benchmarks, and the reward scale is 5 for Hopper, Walker2d, HalfCheetah and Ant, 20 for Humanoid-v1 and 10 for the rllab Humanoid. It has a best value per task rather than a "bigger is better" direction. The follow-up paper learns the temperature instead.

?

Why does SAC evaluate with the mean action instead of sampling?
The policy is trained on reward plus entropy, so its samples are deliberately spread out. For evaluation the paper uses the mean of the policy distribution as an approximation of the most likely action, and on Ant-v1 that generally scores higher than sampling. The paper adds that the mean action is not in general the optimal action for the reward-only objective.

?

If one Gaussian fits only one mode, where does the multimodal behavior go?
Within one state, a single tanh-Gaussian trained by the reverse KL covers one mode of the Boltzmann target. The entropy term still keeps that mode wide, and different states can favor different modes. The paper names more expressive policy classes as future work.

Footnotes & further reading

  1. The paper: Haarnoja, Zhou, Abbeel, Levine, Soft Actor-Critic: Off-Policy Maximum Entropy Deep Reinforcement Learning with a Stochastic Actor (UC Berkeley, ICML 2018). The authors' code: github.com/haarnoja/sac.
  2. The follow-up that most implementations track, with automatic temperature tuning and no value network: Haarnoja et al., Soft Actor-Critic Algorithms and Applications (2018).
  3. The maximum-entropy predecessor SAC builds on: Haarnoja et al., Reinforcement Learning with Deep Energy-Based Policies (Soft Q-Learning, 2017), and the framework's roots in Ziebart, Modeling Purposeful Adaptive Behavior with the Principle of Maximum Causal Entropy (2010).
  4. The clipped double-Q minimum: Fujimoto, van Hoof, Meger, Addressing Function Approximation Error in Actor-Critic Methods (TD3, 2018), building on the overestimation analysis of van Hasselt's Double Q-learning (2010).
  5. The reparameterized (pathwise) gradient: SAC attributes it to the DDPG line, Lillicrap et al., Continuous Control with Deep Reinforcement Learning (2015, our DDPG explainer), and Heess et al.'s stochastic value gradients (2015). The same trick trains the variational autoencoder (Kingma & Welling, 2014), which SAC does not cite.
  6. The off-policy value-learning recipe SAC reuses, replay buffer and target network: Mnih et al., Human-level control through deep reinforcement learning (DQN, Nature 2015). Our explainer of the earlier Atari DQN covers replay; the target network arrived in the 2015 version.