Purpose of this lecture#
Week 7's on-policy methods — TRPO and PPO — use every rollout transition for only a few gradient steps before discarding it. On a physical robot, where each transition costs real hardware time, that waste is disqualifying. This lecture completes the modern deep RL toolkit with the off-policy actor-critic family — DDPG, TD3, and SAC — which reuse past transitions from a replay buffer, trading on-policy stability for sample efficiency and dominating physical robotics applications. We develop the family as a progression: DDPG introduces the deterministic policy gradient theorem; TD3 fixes its three core pathologies; SAC replaces the deterministic policy with a maximum-entropy stochastic one and adds automatic entropy tuning. A closing synthesis maps the family onto deployment contexts, in particular the PPO vs SAC choice for legged locomotion vs real-robot manipulation.
On-policy recap: TRPO and PPO#
TRPO and PPO were derived in full in Week 7. The key results:
TRPO constrains each update to a trust region defined by KL divergence:
providing monotone improvement guarantees at the cost of second-order optimization.
PPO approximates the trust region with a clipped surrogate:
The ensures updates that push far from 1 in the direction of improvement are capped; degrading updates are never capped. The full PPO loss adds a critic regression term and entropy bonus (see Week 7 for the complete derivation and RLHF mapping).
Why on-policy methods are sample-inefficient: both TRPO and PPO use each rollout transition for only a few gradient steps before throwing it away. Off-policy methods reuse past transitions via a replay buffer, which is the only viable regime when data is scarce — the core motivation for SAC and TD3 on the robots of Course 2. On a Unitree Go1 or manipulation arm, each second of real interaction is expensive, and SAC reaches strong performance within 100K transitions on standard MuJoCo tasks, while Haarnoja et al. (2018, Fig. 1) find it learns considerably faster than PPO (as well as DDPG and TD3) — a decisive advantage when every transition must come from real hardware.
The off-policy actor-critic family: overview#
The three off-policy algorithms in this lecture form a clear progression:
| Algorithm | Policy type | Exploration | Key problem solved |
|---|---|---|---|
| DDPG | Deterministic | External noise | Continuous actions with DPG theorem |
| TD3 | Deterministic | Smoothed noise | Overestimation + instability in DDPG |
| SAC | Stochastic (MaxEnt) | Intrinsic entropy | Exploration + robustness + auto-tuning |
Each algorithm inherits from its predecessor and adds targeted fixes, exactly as the DQN → Double DQN → Dueling → Rainbow progression did in Week 6.
All three share the DQN engineering foundation from Week 6: a replay buffer , target networks updated via Polyak averaging , and separate actor and critic networks.
DDPG, TD3, and SAC are one skeleton with targeted fixes: a replay buffer, Polyak-averaged target networks, and separate actor and critic. Each successor inherits its predecessor and repairs one specific failure mode.
Deterministic policy gradient (DDPG)#
From stochastic to deterministic policies#
Recall the stochastic policy gradient theorem from Week 7:
This requires the policy to be stochastic — the score function is well-defined only when for all . For continuous action spaces, we may want to learn a deterministic policy that directly outputs an action. The stochastic policy gradient theorem does not apply.
The deterministic policy gradient theorem#
DPG theorem (Silver et al., 2014): For a deterministic policy , the gradient of the expected return is:
Derivation. The expected return under the deterministic policy:
where is the state visitation distribution induced by . Both factors in the integrand depend on : depends on directly through the action , but also depends on , since changing the policy changes which states get visited at all. Applying the product rule to differentiate under the integral sign therefore produces two terms — one from differentiating with held fixed, and one from differentiating itself with held fixed:
The first term is the one that survives and gives the boxed result above. The second term — differentiating the state-visitation distribution through the policy — is exactly the term the stochastic policy gradient theorem also has to dispose of, there via the log-derivative ("score function") trick that turns a derivative of a distribution into an expectation under that distribution. Here Silver et al. (2014) show, under regularity conditions on the MDP, that this second term integrates to zero: this is the nontrivial content of the DPG theorem, not a one-line consequence of the chain rule. The intuition is the same as in the stochastic case — small perturbations to shift where probability mass sits in , but they don't change the total mass (it still integrates to 1), so first-order changes in the visitation distribution alone cannot change ; only the change in -value at each visited state can. The full proof (Silver et al., 2014, Theorem 1) works this out formally via the Bellman equation for ; we omit it here and simply invoke the result.
Key difference from stochastic PG:
| Stochastic PG | Deterministic PG | |
|---|---|---|
| Gradient signal | Score function | Critic action-gradient |
| Exploration | Policy stochasticity | External noise added to |
| Critic type | or | — must be differentiable in |
| Data | On or off-policy | Off-policy (replay buffer) |
The gradient flows through the Q-function with respect to the action, then through the actor with respect to . This requires to be differentiable in — satisfied by neural network critics with continuous action inputs. (That is why DDPG is the default for continuous control in Course 2 robot learning: joint torques are continuous, so with respect to joint configurations is well-defined and cheap to evaluate.)
DDPG architecture and exploration#
DDPG (Lillicrap et al., 2015) combines the DPG theorem with DQN's engineering:
Initialize actor μ_θ, critic Q_φ, target networks μ_{θ⁻}, Q_{φ⁻}
Initialize replay buffer D
For each step t:
# Action selection with exploration noise
aₜ = μ_θ(sₜ) + εₜ, εₜ ~ N(0, σ²)
# Environment step, store transition
Execute aₜ, observe rₜ₊₁, sₜ₊₁
Store (sₜ, aₜ, rₜ₊₁, sₜ₊₁) in D
# Sample mini-batch
Sample {(sⱼ, aⱼ, rⱼ, s'ⱼ)} from D
# Critic update (DQN-style TD target)
yⱼ = rⱼ + γ Q_{φ⁻}(s'ⱼ, μ_{θ⁻}(s'ⱼ))
Minimize Σⱼ (yⱼ - Q_φ(sⱼ, aⱼ))² over φ
# Actor update (DPG theorem)
Maximize Σⱼ Q_φ(sⱼ, μ_θ(sⱼ)) over θ
(gradient: ∇_θ μ_θ(sⱼ) · ∇_a Q_φ(sⱼ, a)|_{a=μ_θ(sⱼ)})
# Soft target updates
θ⁻ ← τθ + (1-τ)θ⁻
φ⁻ ← τφ + (1-τ)φ⁻
- Action selection with noise (
aₜ = μ_θ(sₜ) + εₜ): the deterministic policy explores only through noise added to the output action. - TD target with target networks (
yⱼ = rⱼ + γ Q_{φ⁻}(s'ⱼ, μ_{θ⁻}(s'ⱼ))): both target networks are used — the target actor selects the next action, the target critic evaluates it. - Critic regression (
Minimize Σⱼ (yⱼ - Q_φ(sⱼ, aⱼ))²): minimizes the mean squared Bellman error, exactly as in DQN. - Actor gradient (
Maximize Σⱼ Q_φ(sⱼ, μ_θ(sⱼ))): the actor maximizes the critic's output, the gradient flowing backward from critic to actor via . - Polyak averaging (
θ⁻ ← τθ + (1-τ)θ⁻): soft target updates blend the current weights into the target weights each step — gentler and far more stable than DQN-style hard resets.
Exploration in DDPG is entirely external: the policy is deterministic, so exploration requires adding noise at action selection time. The original paper uses Ornstein-Uhlenbeck noise (temporally correlated, mean-reverting) to simulate momentum-like exploration in physical systems. In practice, uncorrelated Gaussian noise performs comparably and is simpler. The behavior policy differs from the target policy — DDPG is inherently off-policy, which is why the replay buffer's off-policy data is justified.
DDPG limitations#
Despite its elegance, DDPG has three pathologies in practice:
-
Overestimation bias: the critic target evaluates the target policy's action exactly. Like the single-network DQN target, this is susceptible to overestimation — the critic learns to overvalue actions the actor has been encouraged to take, creating a feedback loop.
-
Coupling between actor and critic errors: the actor gradient depends on the quality of the critic. An inaccurate critic provides misleading gradients that update the actor in the wrong direction, degrading the policy, which in turn produces worse training data for the critic. This coupled instability is severe in early training when both networks are randomly initialized.
-
Sensitivity to hyperparameters: the learning rates for the actor and critic must be carefully balanced. If the critic learns too slowly, actor gradients are noisy; if the actor updates too quickly relative to the critic, the policy diverges.
TD3 addresses all three.
Twin delayed deep deterministic policy gradient (TD3)#
TD3 (Fujimoto et al., 2018) introduces three targeted fixes to DDPG's pathologies. Each fix corresponds to a precisely identified failure mode.
Fix 1: clipped double Q-learning#
Maintain two independent critic networks and . Compute TD targets using the minimum of the two:
Why the minimum corrects overestimation. Each critic has independent random initialization and independent gradient noise, so their errors are partially decorrelated. The maximum of two estimates is biased upward (Jensen's inequality: in expectation when errors are symmetric). The minimum is biased downward — slightly underestimating is far less harmful than overestimating, because underestimation does not produce the positive feedback loop (overestimated values → actor selects overvalued actions → critic reinforces overvaluation).
This is the continuous-action analog of Double DQN from Week 6: decoupling the networks that select and evaluate actions to reduce the max-over-noise bias. (The mechanism matters in Course 2's offline robot learning, where the replay buffer holds demonstrations from suboptimal policies; overestimation would make the robot imitate the worst of them.)
Fix 2: delayed policy updates#
Update the actor less frequently than the critics — typically once every two critic gradient steps:
For each step t:
Update Q_φ₁ and Q_φ₂ (every step)
If t mod d == 0:
Update μ_θ using ∇_a Q_φ₁ (every d steps, d=2 typically)
Update all target networks
Why delayed updates stabilize training. The actor gradient is only meaningful when the critic is a reliable estimate. In early training, the critic is inaccurate, and updating the actor from a bad critic pushes the policy in the wrong direction. Delaying actor updates gives the critics more time to converge on each policy before the policy is updated.
Fix 3: target policy smoothing#
Add clipped noise to the target policy's action when computing the TD target:
Why this regularizes the critic. A deterministic policy evaluates the critic at exactly one action per state. If develops a sharp peak at (which the actor is incentivized to exploit), the critic will overfit to these exact actions and generalize poorly. Adding noise smooths the target: instead of fitting to the value at a single point, the critic must fit the value in a neighborhood of actions around . The clipping ensures the smoothed action stays near the target policy and does not drift to irrelevant regions of the action space.
TD3 pseudocode summary#
Initialize μ_θ, Q_φ₁, Q_φ₂ and target networks μ_{θ⁻}, Q_{φ₁⁻}, Q_{φ₂⁻}
Initialize replay buffer D
For each step t:
aₜ = μ_θ(sₜ) + ε, ε ~ N(0, σ²)
Store (sₜ, aₜ, rₜ₊₁, sₜ₊₁) in D
Sample mini-batch from D
# Smoothed target action
ã' = μ_{θ⁻}(s') + clip(N(0,σ̃²), -c, c)
# Critic targets (clipped double Q)
y = r + γ · min(Q_{φ₁⁻}(s', ã'), Q_{φ₂⁻}(s', ã'))
# Update both critics
Minimize (y - Q_φᵢ(s, a))² for i = 1, 2
# Delayed actor update
If t mod d == 0:
Maximize Q_φ₁(s, μ_θ(s)) over θ
Update target networks via Polyak averaging
- Target Policy Smoothing (
ã' = μ_{θ⁻}(s') + clip(N(0,σ̃²), -c, c)): clipped noise on the target action stops the critic overfitting to the deterministic actor output. - Clipped Double Q-Learning (
y = r + γ · min(Q_{φ₁⁻}(s', ã'), Q_{φ₂⁻}(s', ã'))): both target critics evaluate the smoothed action and the minimum is taken, removing the overestimation bias endemic to Q-learning. - Critic updates (
Minimize (y - Q_φᵢ(s, a))² for i = 1, 2): both critics regress to the same conservative target. - Delayed Policy Updates (
If t mod d == 0): the actor and target networks update only everydcritic steps, so the actor optimizes against a settled critic. - Actor update (
Maximize Q_φ₁(s, μ_θ(s))): maximizes ; only one critic is needed to supply the actor's gradient.
Soft actor–critic (SAC)#
SAC (Haarnoja et al., 2018) replaces the deterministic policy with a maximum entropy framework, changing the problem the actor-critic is solving at a fundamental level.
The maximum entropy objective#
Standard RL maximizes expected return:
Maximum entropy RL augments this with a policy entropy bonus at every timestep:
where and is the temperature parameter controlling the entropy-reward tradeoff. This is not just reward shaping — it changes the definition of optimality.
The soft Bellman equation#
The maximum entropy objective admits a modified Bellman equation. Define the soft Q-function as the solution to:
where the soft value function integrates over both reward and entropy:
The last equality (the log-sum-exp / soft maximum) follows from the closed-form optimal policy:
The optimal maximum entropy policy is a Boltzmann distribution over the Q-function, with temperature . As , this collapses to a deterministic policy selecting the greedy action. As , the policy approaches uniform — all actions are equally likely. At intermediate , the policy concentrates on high-value actions while maintaining uncertainty in lower-value regions.
This is a principled closed-form result, not a heuristic: maximum entropy RL has a well-defined optimal policy, and SAC approximates it.
The reparameterization trick#
PPO estimates policy gradient via the score function (Week 7):
This is high-variance because and are correlated through different paths. SAC uses the reparameterization trick: instead of sampling directly, write:
where (for diagonal Gaussian, typically with tanh squashing for bounded actions). Then:
The gradient now flows directly through with respect to , then through with respect to . This is lower-variance than the score function estimator because the backpropagation path is deterministic (noise is fixed when differentiating). The reparameterization trick is what enables SAC to use a stochastic policy while maintaining the low-variance gradient of the DPG theorem.
Automatic entropy tuning#
The temperature controls the exploration-exploitation tradeoff: high encourages diverse actions; low focuses the policy. Manually tuning as a hyperparameter requires task-specific knowledge. SAC automatically adjusts by formulating it as a constrained optimization: maintain a target entropy and find the that achieves it.
Applying dual gradient descent (Lagrangian duality) to the constraint :
In practice, is updated alongside the actor and critic via a separate gradient step:
If the current policy entropy is above , this decreases (reduce exploration penalty); if below, it increases (increase exploration). The system self-regulates. A common choice is (negative of action dimension), which works well across continuous control tasks without manual tuning.
This is the same Lagrangian dual ascent used for temperature optimization in Haarnoja et al. (2018); it is analogous to the automatic KL-coefficient tuning in some RLHF implementations.
SAC pseudocode#
Initialize actor π_θ (stochastic: outputs μ_θ(s), σ_θ(s))
Initialize critics Q_φ₁, Q_φ₂ and target networks Q_{φ₁⁻}, Q_{φ₂⁻}
Initialize temperature α (or α-network for auto-tuning)
Initialize replay buffer D
For each step t:
# Stochastic action via reparameterization
aₜ = μ_θ(sₜ) + σ_θ(sₜ) ⊙ ξ, ξ ~ N(0, I)
Store (sₜ, aₜ, rₜ₊₁, sₜ₊₁) in D
Sample mini-batch from D
Sample â' = μ_θ(s') + σ_θ(s') ⊙ ξ', ξ' ~ N(0, I)
# Critic targets (soft Bellman, clipped double Q)
y = r + γ · (min(Q_{φ₁⁻}(s', â'), Q_{φ₂⁻}(s', â')) - α log π_θ(â'|s'))
# Update both critics
Minimize (y - Q_φᵢ(s, a))² for i = 1, 2
# Actor update (reparameterization trick)
â = μ_θ(s) + σ_θ(s) ⊙ ξ
Maximize min(Q_φ₁(s, â), Q_φ₂(s, â)) - α log π_θ(â|s) over θ
# Temperature update (auto-tuning)
Minimize α(-log π_θ(â|s) - H_target) over α
# Soft target updates
φᵢ⁻ ← τφᵢ + (1-τ)φᵢ⁻ for i = 1, 2
Note three connections to prior lectures: the clipped double Q target (Week 6: Double DQN), the soft Bellman entropy term in the critic target (the maximum entropy modification), and the reparameterization gradient in the actor update (as opposed to the score function estimator in PPO).
Algorithm synthesis#
Expanded comparison table#
| Algorithm | Policy | Exploration | Critic | Target network | Sample efficiency |
|---|---|---|---|---|---|
| PPO | Stochastic | Policy entropy | None | Low (on-policy) | |
| DDPG | Deterministic | External noise | Polyak | High | |
| TD3 | Deterministic | Smoothed noise | Polyak | High | |
| SAC | Stochastic (MaxEnt) | Intrinsic entropy | Polyak | Highest |
PPO vs SAC: the robotics decision#
In practice, the choice between PPO and SAC depends on the data collection regime:
Choose PPO when:
- Fast parallel simulation is available (IsaacLab, MuJoCo with 4096 parallel envs). On-policy inefficiency is irrelevant when you can collect millions of transitions per second in simulation. PPO with GAE achieves excellent results in legged locomotion (ANYmal, Unitree, Spot) precisely because massive parallelism compensates for sample inefficiency.
- Reward shaping is complex. On-policy data always reflects the current policy, making reward shaping and curriculum learning easier to reason about. Off-policy replay buffers contain stale data from old policies, which can interact badly with changing reward functions.
- Implementation simplicity matters. PPO has fewer moving parts than SAC — no
automatic entropy tuning, no reparameterization, no double critics. RSL-RL's PPO
implementation for legged locomotion is 484 lines (
rsl_rl/algorithms/ppo.py; Rudin et al., 2022), whereas a full SAC implementation is substantially more complex.
Choose SAC when:
- Real-robot data collection is the bottleneck. SAC's replay buffer reuses every transition, so it needs far fewer interactions than on-policy PPO to reach the same performance (Haarnoja et al., 2018). For Franka arm manipulation or other real-hardware setups, this difference is decisive.
- Exploration quality matters more than speed. SAC's entropy-driven exploration produces smoother, more diverse trajectories than -greedy or additive noise, which is particularly valuable for contact-rich manipulation tasks where the agent must discover narrow-margin contact modes.
- Hyperparameter robustness is needed. Automatic entropy tuning makes SAC largely self-configuring on the temperature hyperparameter, reducing the tuning burden compared to PPO's entropy coefficient and GAE .
The hybrid regime: many modern systems train with PPO in simulation (fast, stable, handles complex reward shaping), then fine-tune on real hardware with SAC (sample efficient, smooth exploration).
GenAI context: PPO for RLHF and SAC for structured generation#
PPO in RLHF (recap from Week 7): the language model is the actor, the reward model provides the return signal, and the KL penalty against the SFT reference model prevents reward hacking. PPO's on-policy sampling is acceptable in this setting because the language model generates its own rollouts (completions), and on-policy data ensures the distribution of completions matches the current policy — important for RLHF where the reward model may be poorly calibrated outside the SFT distribution.
SAC-inspired ideas in GenAI: maximum entropy RL has influenced several GenAI directions:
- Temperature sampling in language model decoding is the inference-time analog of the Boltzmann optimal policy — high temperature encourages diverse completions; low temperature is greedy.
- Energy-based models for text generation model the distribution over sequences as , the same Boltzmann form as the SAC optimal policy.
- DPO and GRPO (next lecture) eliminate the critic and reformulate RLHF as a maximum-entropy optimization directly on preference data, removing the need for PPO entirely.
Browser lab: twin Q min (TD3) + soft max-ent policy (SAC)#
Two mechanisms from modern continuous-control actors, in 1-D discrete action form:
- TD3: cuts overestimation when one critic is optimistic.
- SAC: — temperature trades return vs entropy.
import numpy as np
rng = np.random.default_rng(0)
# 5 actions, true Q*; two noisy critics (one systematically high)
A = 5
Q_star = np.array([0.5, 1.0, 0.2, 1.4, 0.8])
Q1 = Q_star + rng.normal(0, 0.15, size=A) + 0.35 # optimistic bias
Q2 = Q_star + rng.normal(0, 0.15, size=A)
def greedy(Q):
return int(np.argmax(Q))
print("True best action:", greedy(Q_star), "Q*=", Q_star[greedy(Q_star)])
print("Q1 greedy: ", greedy(Q1), " (overest risk)")
print("min(Q1,Q2) greedy:", greedy(np.minimum(Q1, Q2)))
print(f" max Q1={Q1.max():.2f} max min={np.minimum(Q1,Q2).max():.2f} true max={Q_star.max():.2f}")
def soft_policy(Q, alpha):
z = Q / alpha
z = z - z.max()
p = np.exp(z)
return p / p.sum()
print("\nSAC-style soft policy π(a) ∝ exp(Q*/α):")
print(f"{'α':>6} {'entropy':>8} {'E[Q]':>8} {'p(best)':>8}")
best = greedy(Q_star)
for alpha in [0.1, 0.5, 1.0, 2.0, 5.0]:
p = soft_policy(Q_star, alpha)
H = -np.sum(p * np.log(p + 1e-12))
print(f"{alpha:6.1f} {H:8.3f} {p @ Q_star:8.3f} {p[best]:8.3f}")
print("Notice: twin min prefers safer targets; low α → near-greedy, high α → explore (max-ent).")
What to try: increase Q1 bias to +1.0 — single-critic greedy picks the wrong arm more often; min still tracks .
Key takeaways#
The lecture develops the off-policy actor-critic family as a principled progression. DDPG combines the deterministic policy gradient theorem — gradient flows through rather than — with DQN's replay buffer and target networks, but suffers from overestimation, coupled instability, and sensitivity to hyperparameters. TD3 applies three targeted fixes: clipped double Q-learning reduces overestimation via the minimum of two independent critics (continuous-action Double DQN); delayed policy updates decouple critic convergence from actor updates; target policy smoothing prevents the critic from overfitting to sharp peaks at deterministic actions. SAC replaces the deterministic policy with the maximum entropy framework, whose optimal policy is provably a Boltzmann distribution over the soft Q-function. The reparameterization trick provides lower-variance gradients than score function estimation. Automatic entropy tuning via dual gradient descent eliminates the temperature hyperparameter.
The PPO vs SAC choice maps cleanly onto deployment context: PPO with fast parallel simulation for legged locomotion, SAC for real-robot data-scarce settings, with hybrid workflows bridging the two.
Conceptual questions#
-
The deterministic policy gradient theorem gives . Compare this with the stochastic policy gradient theorem from Week 7. In the stochastic case, where does the gradient come from? In the deterministic case, what must be true about the critic for this gradient to be well-defined? Why does DDPG use a Q-critic rather than a V-critic?
-
TD3 uses the minimum of two Q-estimates as the critic target: . Using the minimum rather than the mean introduces a downward bias. Explain why downward bias is less harmful than upward bias in the actor-critic setting by tracing the feedback loop that upward bias (overestimation) creates between the actor and critic.
-
SAC's optimal policy is . Show what happens to this policy as and as . Then explain: if is too large during training, what behavior do you expect from the agent? If is too small, what problem arises? How does automatic entropy tuning resolve this without manual intervention?
-
Compare exploration mechanisms across the three off-policy algorithms: DDPG adds external Gaussian noise to the deterministic action; TD3 adds smoothed noise to the target policy (not the behavior policy); SAC's stochastic policy provides intrinsic exploration. For a manipulation task requiring precise contact (narrow-margin task), which exploration mechanism is most appropriate and why? What happens to DDPG-style exploration when the task reward requires very precise actions?
-
You are training a quadruped locomotion policy. You have two setups: (A) IsaacLab with 4096 parallel simulation environments, each running at 100 Hz; (B) a single physical Unitree Go1 robot collecting ~1 Hz data due to safety stops. For each setup, argue which algorithm — PPO or SAC — is more appropriate, citing sample efficiency, exploration quality, and implementation complexity. For setup B, what modifications to the standard SAC algorithm would you make to handle the safety constraints of real hardware?
Knowledge Check#
Check the off-policy continuous-control family from this week.
TD3 reduces overestimation bias by taking the ___ of two critics when forming the bootstrap target.
Soft Actor–Critic (SAC) differs from DDPG mainly by:
The deterministic policy gradient updates the actor using:
Implementation exercises#
Exercise 1: DDPG core loop#
Implement the DDPG training loop in Python using a deep learning framework of your choice. Start from the pseudocode above. Key implementation details:
- Critic architecture: The critic takes both state and action as input and outputs a scalar Q-value. Concatenate action after a hidden layer (not at the input) for numerical stability.
- Exploration noise: Start with simple Gaussian noise — it performs comparably to Ornstein-Uhlenbeck and is simpler to debug.
- Polyak averaging: Use for target network updates. Verify that
target_actor.parameters()trackactor.parameters()with a small lag. - Training ratio: One gradient step per environment step. Use a replay buffer of size and batch size 64.
Test on Pendulum-v1: The agent should solve it (average return > −200 over 100 episodes) within 100 episodes.
Exercise 2: Upgrade DDPG to TD3#
Starting from your DDPG implementation, add the three TD3 fixes one at a time, testing after each:
- Add a second critic network (). Use for target computation. Track the Q-value gap during training — it should shrink as both critics converge.
- Delay the actor update to every 2 critic steps (). Plot policy entropy over time — a stable TD3 policy should show less oscillation than DDPG.
- Add target policy smoothing with , . Compare critic gradient variance with and without smoothing.
Test on HalfCheetah-v4 (MuJoCo): TD3 should outperform DDPG by approximately 30% in final return (Fujimoto et al., 2018).
Exercise 3: SAC with automatic entropy tuning#
Implement SAC extending your TD3 codebase. Key additions:
- Stochastic actor: Outputs and for a diagonal Gaussian. Apply
tanhsquashing for bounded actions (add log-probability correction for the Jacobian of tanh). - Reparameterization trick: Sample with . The gradient flows through via autodiff — not through a score function estimator.
- Soft Bellman target: .
- Automatic entropy tuning: Initialize (not ) to ensure positivity. Target entropy . Update with a separate optimizer (learning rate ).
Test on Ant-v4 (MuJoCo): SAC should achieve approximately 6000 return in 1M steps — 3–5× better sample efficiency than TD3 (Haarnoja et al., 2018b).
Extension prompts#
-
Continuous-action Rainbow: Combine TD3's clipped double Q with SAC's maximum-entropy framework and automatic temperature tuning. How does this hybrid perform on
Humanoid-v4compared to either algorithm alone? What does the entropy curve reveal about the benefit of stochastic exploration in high-dimensional action spaces? -
Offline RL via CQL: Collect 1M transitions from a partially trained SAC agent. Train a new policy from this fixed dataset using Conservative Q-Learning (CQL), which penalizes overestimated Q-values for out-of-distribution actions. Compare with standard SAC trained on the same offline data. Which shows less extrapolation error?
-
Sim-to-real gap: Train a policy in MuJoCo, deploy it in a different physics engine (e.g., PyBullet or Isaac Sim), and measure the performance gap. Explore domain randomization (varying mass, friction, joint damping ranges) as a mitigation — how much randomization is needed before the policy transfers without fine-tuning?
Further reading#
- Silver, D., et al. (2014). Deterministic Policy Gradient Algorithms. ICML. (DPG Theorem).
- Lillicrap, T. P., et al. (2015). Continuous control with deep reinforcement learning. ICLR. (DDPG).
- Fujimoto, S., et al. (2018). Addressing Function Approximation Error in Actor-Critic Methods. ICML. (TD3).
- Haarnoja, T., et al. (2018). Soft Actor-Critic: Off-Policy Maximum Entropy Deep Reinforcement Learning with a Stochastic Actor. ICML. (SAC).
- Haarnoja, T., et al. (2018b). Soft Actor-Critic Algorithms and Applications. arXiv. (Automatic entropy tuning and practical SAC implementation details).
- Duan, Y., et al. (2016). Benchmarking Deep Reinforcement Learning for Continuous Control. ICML. (Standardized evaluation benchmarks for DDPG, TRPO, and other continuous-control algorithms).
- Rudin, N., Hoeller, D., Reist, P., & Hutter, M. (2022). Learning to Walk in Minutes Using Massively Parallel Deep Reinforcement Learning. CoRL. (The
rsl_rllibrary; the source of the 484-line PPO implementation used for legged locomotion — leggedrobotics/rsl_rl).
Reading is free. PDF and ePub unlock with the newsletter. Join once and every lesson opens in this browser.