Modern Deep Reinforcement Learning/Continuous Control: SAC and Beyond

Lesson 5.41,822 words

Continuous Control: SAC and Beyond

A companion to the DDPG and TD3 lesson. Where those actors are deterministic and explore with bolted-on noise, soft actor-critic (SAC) changes the objective itself: maximize return plus the entropy of the policy, so exploration becomes intrinsic and the agent stays robust.

╌╌╌╌

This builds on Continuous Control: DDPG and TD3, which built the off-policy actor-critic template — a Q-critic trained from a replay buffer and a deterministic actor trained to output the critic-maximizing action, sidestepping the intractable of continuous-action Q-learning. DDPG established the idea; TD3 made it reliable with twin critics, delayed policy updates, and target smoothing.

Both of those actors are deterministic, so exploration had to be added from outside as action noise. This lesson takes up the third member of the family, which rejects that design, and then the methods that build on the shared template.

SAC: the maximum-entropy objective

TD3 fights instability by tightening the value estimate. Soft actor-critic (SAC) takes a different route: it changes the objective itself, adding a term that rewards the policy for staying random.1 Standard RL maximizes expected return; SAC maximizes expected return plus the entropy of the policy at every visited state,

The entropy is largest when the policy spreads its probability mass widely and smallest when it collapses onto one action. The temperature sets the trade-off between the two terms: at the objective reverts to ordinary reward maximization, and as grows the entropy term weighs more heavily and the policy stays more random. Unlike A2C's entropy bonus — a term tacked onto the loss to discourage premature collapse — this entropy lives inside the value function, so it shapes not just the immediate action but the long-run bootstrap.

SAC learns a stochastic actor — typically a squashed Gaussian, with — and, borrowing from TD3, twin critics whose minimum forms the target. Exploration is now intrinsic: because the policy is genuinely stochastic and is rewarded for staying so, it explores on its own, and there is no external noise process to design. The actor is improved not by the deterministic policy gradient but by the reparameterized gradient of the soft objective, minimizing the KL between the policy and the exponentiated soft-Q:

where is the reparameterized sample, differentiable in .

The maximum-entropy objective. SAC maximizes reward plus times the policy entropy at every state; a high-entropy (spread-out) policy earns a bonus, so the actor keeps several actions plausible instead of collapsing onto one.

The reparameterization trick and the squashed Gaussian

The actor gradient above hides a subtlety: it is what keeps SAC's stochastic actor trainable. The naive way to differentiate with respect to is the score-function estimator — the same trick behind REINFORCE — but its variance is high, exactly the problem the deterministic policy gradient was introduced to escape. SAC keeps a stochastic policy and a low-variance gradient by reparameterizing the sample: instead of drawing directly, draw a fixed-distribution noise and compute

Now the randomness lives in , which does not depend on , so the whole expression is a deterministic differentiable function of for each fixed . The gradient flows straight through and by the chain rule — the same one backward pass that trained the DDPG actor — and the expectation over is estimated by sampling. This is why the SAC actor update reads like a deterministic gradient of despite the policy being genuinely random.

The outer is the squash: it maps the unbounded Gaussian sample into so the action respects the environment's bounded action range (torque limits, steering stops). It is not free — squashing changes the density, so the log-probability needs a change-of-variables correction. For the pre-squash sample with density and , the corrected log-density is

where the subtracted term is , the Jacobian of the . Without it the entropy term in every update would be wrong, and the temperature tuning below would chase a mismeasured entropy. The correction is a few lines of code, but it is essential.

The reparameterized squashed-Gaussian actor. Fixed noise xi enters, the network produces a mean and spread, their combination is squashed by tanh into the bounded action range; because the randomness (xi) is independent of theta, gradients pass straight through mu and sigma in one backward pass. A tanh Jacobian term corrects the log-probability.

Automatic temperature tuning

The one awkward hyperparameter is : too high and the agent acts near-randomly and never exploits; too low and it collapses to a deterministic policy and stops exploring. Worse, the right value drifts during training — early on more entropy helps, later less does. The refinement is to tune automatically by making it satisfy an entropy constraint. Fix a target entropy (a common default is , one nat of negative entropy per action dimension) and adjust by gradient descent on

When the policy's entropy sits below the target, this pushes up (more exploration); when it sits above, it pushes down (more weight on reward). The temperature becomes a learned control that holds the policy at a chosen level of randomness throughout training, removing the single most finicky knob.

For example, take a -dimensional action space, so the default target entropy is nats. Suppose at the current step the sampled action has log-probability , so the policy's per-sample entropy estimate is nats. The objective for is , and its gradient is

The gradient is positive, so a descent step decreases . That is the correct direction: the policy's entropy ( per sample) is above the target ( would correspond to a much more concentrated policy), so the constraint is satisfied with slack and the update shifts weight from entropy toward reward. With and learning rate , the new temperature is . Flip the scenario: if a mastered state gave (entropy , still above target) the gradient would be and would fall faster; and if the policy collapsed so that (entropy , now below the target in the sense that ), the gradient would be , pushing up to restore exploration. The temperature tracks the entropy constraint automatically, tightening when the policy over-explores and loosening when it collapses.

Automatic temperature control as a feedback loop. The policy entropy is measured against the target H-bar; if entropy is too high the update lowers alpha (spend slack on reward), if too low it raises alpha (buy exploration). The temperature settles where the policy holds the chosen entropy.
Algorithm:SAC\textsc{SAC} — soft (maximum-entropy) actor-critic
  1. 1
    input: stochastic actor πθ\pi_\theta, twin critics Qϕ1,Qϕ2Q_{\phi_1}, Q_{\phi_2}, target entropy Hˉ\bar{\mathcal{H}}
  2. 2
    initialize targets ϕ1,ϕ2\phi_1', \phi_2'; empty buffer D\mathcal{D}
  3. 3
    for each step do
  4. 4
    sample aπθ(s)a \sim \pi_\theta(\cdot \mid s), execute, store (s,a,r,s)(s,a,r,s') in D\mathcal{D}
  5. 5
    sample a minibatch from D\mathcal{D}
  6. 6
    aπθ(s)a' \sim \pi_\theta(\cdot \mid s')
  7. 7
    yr+γ[miniQϕi(s,a)αlnπθ(as)]y \gets r + \gamma\,[\min_{i} Q_{\phi_i'}(s', a') - \alpha \ln \pi_\theta(a' \mid s')]
    soft target
  8. 8
    for i=1,2i = 1, 2 do
  9. 9
    ϕiϕiηϕi(Qϕi(s,a)y)2\phi_i \gets \phi_i - \eta\,\nabla_{\phi_i}\,(Q_{\phi_i}(s,a) - y)^2
  10. 10
    θθηθ[αlnπθ(a^s)miniQϕi(s,a^)]\theta \gets \theta - \eta\,\nabla_\theta\,[\alpha \ln \pi_\theta(\hat a \mid s) - \min_i Q_{\phi_i}(s, \hat a)]
    reparam a^\hat a
  11. 11
    ααηα[α(lnπθ(a^s)+Hˉ)]\alpha \gets \alpha - \eta\,\nabla_\alpha\,[-\alpha (\ln \pi_\theta(\hat a \mid s) + \bar{\mathcal{H}})]
    tune temperature
  12. 12
    ϕiτϕi+(1τ)ϕi\phi_i' \gets \tau\phi_i + (1-\tau)\phi_i' for i=1,2i = 1, 2

The entropy term does more than sustain exploration. Because the agent is rewarded for keeping several actions viable, it does not commit to a single narrow solution that a small change in dynamics would break, which gives SAC its robustness — it transfers better across perturbations and tolerates imperfect models. Together with strong sample efficiency from the off-policy buffer, that is why SAC, alongside TD3, is a default choice for continuous control.

Beyond the three: distributional critics, ensembles, and pixels

DDPG, TD3, and SAC set the template, and the work after them mostly pushes on two levers the template exposes: make the critic better, and make the whole loop work from images.

Distributional critics. The critic in all three methods predicts a scalar . Replacing it with a distributional critic — the same return-distribution idea that powered Rainbow — sharpens the value signal. D4PG (Barth-Maron et al., 2018) is TD3-era DDPG with a C51-style categorical critic, -step returns, and distributed data collection; the distributional target measurably improved stability and final performance on hard continuous-control tasks.2 This carries the distributional lesson's point into continuous control: an agent that models the spread of returns, not just the mean, both learns a better mean and can act risk-sensitively when the spread matters.

Ensembled critics and high replay ratios. TD3's twin critics are the smallest possible ensemble. REDQ (Chen et al., 2021) scales that idea: keep an ensemble of critics (say ), form each target from a random subset of them (a random pair), and — the decisive move — perform many gradient updates per environment step (a high update-to-data ratio, e.g. ).3 The ensemble controls the overestimation that a high replay ratio would otherwise amplify, and the result matches the sample efficiency of model-based methods like PETS while staying fully model-free. It is a direct answer to the sample-efficiency case made in the model-based lesson: much of model-based sample efficiency can be had with a bigger critic ensemble and more updates, without ever learning a dynamics model.

Control from pixels. DDPG/TD3/SAC as stated assume a compact state vector. Running them from raw images was long thought to require a separate representation-learning stage, but two 2020–2021 results showed that plain image augmentation is enough. RAD (Laskin et al., 2020) and DrQ (Kostrikov et al., 2021) apply small random shifts and crops to the input frames and average the -target over a few augmented copies, and with nothing more than that, SAC from pixels reaches the sample efficiency of SAC from states on the DeepMind Control suite.4 The augmentation regularizes the critic — it encodes the prior that a two-pixel shift should not change the value — and that single inductive bias closed most of the pixels-to-states gap that had made image-based continuous control seem to need elaborate machinery.

Three post-SAC directions, each pushing one lever of the shared template. A distributional critic (D4PG) enriches what the critic predicts; a critic ensemble with many updates (REDQ) buys model-based-level sample efficiency; image augmentation (DrQ, RAD) makes the same agents learn from pixels.

Comparing the three

All three share the off-policy, replay-buffer, twin-or-single-critic skeleton and differ in the policy and the exploration mechanism.

MethodPolicyExplorationKey trickOverestimation cure
DDPGdeterministic external action noisedeterministic policy gradient, target netsnone
TD3deterministic external action noisedelayed updates, target smoothingclipped double-Q (twin min)
SACstochastic intrinsic (entropy reward)max-entropy objective, tuned clipped double-Q (twin min)
The lineage. DDPG establishes the off-policy deterministic actor-critic; TD3 adds twin critics, delayed updates, and target smoothing to fix overestimation; SAC swaps the deterministic actor for a stochastic one under a maximum-entropy objective.

The Q-critic gives off-policy sample efficiency; the learned actor replaces the intractable ; and the three methods disagree only on how to keep the coupled learning stable and how to explore. DDPG proves the idea works, TD3 makes it reliable by refusing to trust a single critic, and SAC makes it robust by rewarding entropy. When a modern robotics or MuJoCo agent learns continuous control off-policy, one of these three — most often TD3 or SAC — is almost certainly the algorithm underneath.

Footnotes

  1. Haarnoja et al. (2018), Soft Actor-Critic: Off-Policy Maximum Entropy Deep Reinforcement Learning with a Stochastic Actor, ICML, and the follow-up Soft Actor-Critic Algorithms and Applications (2018) — the maximum-entropy objective , the soft value functions and squashed-Gaussian stochastic actor, twin critics from TD3, and automatic temperature tuning against a target entropy ; Morales, Ch. 12, SAC: Maximizing the expected return and entropy.
  2. Barth-Maron et al. (2018), Distributed Distributional Deterministic Policy Gradients, ICLR — D4PG: DDPG with a C51-style categorical distributional critic, -step returns, prioritized replay, and distributed actors, improving stability and final performance on continuous-control tasks over scalar-critic DDPG.
  3. Chen, Wang, Zhou, Ross (2021), Randomized Ensembled Double Q-Learning: Learning Fast Without a Model, ICLR — REDQ: an ensemble of critics with targets formed from a random in-target subset, combined with a high update-to-data ratio, matching the sample efficiency of model-based methods (e.g. PETS) while remaining model-free.
  4. Laskin, Lee, Stooke, Pinto, Abbeel, Srinivas (2020), Reinforcement Learning with Augmented Data (RAD), NeurIPS; Kostrikov, Yarats, Fergus (2021), Image Augmentation Is All You Need: Regularizing Deep Reinforcement Learning from Pixels (DrQ), ICLR — random shift/crop augmentation of image observations, with the -target averaged over augmented copies, lets SAC learn from pixels at the sample efficiency of learning from states on the DeepMind Control suite.

╌╌ END ╌╌