Skip to content

Maximum-entropy RL and Soft Actor-Critic (SAC)

optionalcorefundamentalpaperrubric 11/122018 · ICML 2018 · ~60 min

Tuomas Haarnoja, Aurick Zhou, Pieter Abbeel, Sergey Levine

Read first: Reinforcement Learning: An Introduction, Ch. 3–4 — Value Functions, Bellman Equations and Dynamic Programming · Playing Atari with Deep Reinforcement Learning (DQN) · Actor–critic methods and the advantage function

Status

TL;DR. Ordinary RL maximises reward. Maximum-entropy RL maximises reward plus a bonus for staying random, weighted by a temperature α\alpha. In the paper’s words, the agent should succeed “while acting as randomly as possible”. Three things follow. The Bellman max becomes a soft max (log-sum-exp). The best policy is a softmax over Q-values. And the method gets better exploration and more robust training. Soft Actor-Critic (SAC) turns this into a practical off-policy algorithm for continuous control (Haarnoja et al. 2018). A follow-up adds automatic tuning of α\alpha (Haarnoja et al. 2018b). The LLM payoff: the KL-regularised RLHF objective E[r]−β KL(π ∥ πref)\mathbb{E}[r] - \beta\,\mathrm{KL}(\pi\,\|\,\pi_{\text{ref}}) is the same objective, with the uniform distribution replaced by a reference model. Its optimum π∗∝πrefexp⁡(r/β)\pi^* \propto \pi_{\text{ref}} \exp(r/\beta) is the same softmax form, and that is where DPO begins. This transfers an objective and its optimal-policy algebra, not the SAC algorithm. Standard autoregressive RLHF/DPO does not become a Gaussian actor–critic with replay just because its objective is KL-regularised.

Why it matters for you. SAC itself is a robotics algorithm. Read this page for the objective. It explains why RLHF has a β, what “entropy collapse” means, and why LLM pipelines use a KL penalty or clipping tricks rather than SAC-style entropy bonuses. First read: the TL;DR, the key idea up to the worked example, then “The LLM connection” and the checklist. Skip on a first read: control as inference, SAC’s reparameterisation details, and the convergence proofs.

Notation.

  • ss is a state, aa an action, r(s,a)r(s,a) the reward, γ\gamma the discount factor, and π(a∣s)\pi(a \mid s) the policy (all as in MDPs and returns).
  • For the finite-action examples, H(π(⋅∣s))=−∑aπ(a∣s)log⁡π(a∣s)\mathcal{H}(\pi(\cdot \mid s)) = -\sum_a \pi(a \mid s)\log \pi(a \mid s) is discrete entropy. SAC’s continuous-action equations use differential entropy, replacing the sum with an integral over an action density; it can be negative and depends on the action coordinates. Discrete entropy is 0 for a deterministic policy, log⁡∣A∣\log|A| for uniform over ∣A∣|A| actions. Natural log throughout, so entropy is in nats.
  • α>0\alpha > 0 is the temperature.

Step 1: the objective. Add the entropy of the action distribution to each step’s reward (SAC Eq. 1):

J(π)=∑tE(st,at)∼ρπ[ r(st,at)+α H(π(⋅∣st)) ].J(\pi) = \sum_t \mathbb{E}_{(s_t,a_t)\sim\rho_\pi}\big[\, r(s_t,a_t) + \alpha\, \mathcal{H}(\pi(\cdot \mid s_t)) \,\big].

This display uses the finite-horizon form. For the discounted toy below, weight both reward and entropy at time t by γt\gamma^t. Here ρπ\rho_\pi is the distribution of states and actions the policy visits. As α→0\alpha \to 0 this is ordinary RL. The bonus is paid in every future state, so the agent also prefers to reach states where it can keep acting randomly. This differs from Boltzmann exploration bolted onto a greedy learner, which is only random now (Soft Q-learning, Haarnoja et al. 2017).

Step 2: the soft Bellman backup. In plain words, a state’s value is now “expected Q, plus the entropy you collect by acting randomly here”. For a fixed policy (SAC v2 Eqs. 2–3):

Q(s,a)=r(s,a)+γ Es′[V(s′)],V(s)=Ea∼π[Q(s,a)−αlog⁡π(a∣s)].Q(s,a) = r(s,a) + \gamma\, \mathbb{E}_{s'}\big[V(s')\big], \qquad V(s) = \mathbb{E}_{a\sim\pi}\big[Q(s,a) - \alpha \log \pi(a \mid s)\big].

Note that −α E[log⁡π]=αH-\alpha\,\mathbb{E}[\log\pi] = \alpha\mathcal{H}.

Step 3: the optimum is a softmax. Which π\pi maximises Eπ[Q]+αH(π)\mathbb{E}_\pi[Q] + \alpha\mathcal{H}(\pi) in one state? The answer is a softmax over Q with temperature α\alpha, and the value becomes a log-sum-exp. This is the “soft max” that gives the method its name (Soft Q-learning Theorem 1, Eqs. 5–6):

V∗(s)=αlog⁡∑aexp⁡ ⁣(Q∗(s,a)/α),π∗(a∣s)=exp⁡ ⁣((Q∗(s,a)−V∗(s))/α).V^*(s) = \alpha \log \sum_a \exp\!\big(Q^*(s,a)/\alpha\big), \qquad \pi^*(a \mid s) = \exp\!\big((Q^*(s,a) - V^*(s))/\alpha\big).

V∗/αV^*/\alpha is the log normaliser of the softmax, so the policy sums to 1. As α→0\alpha \to 0, log-sum-exp tends to max⁡aQ\max_a Q and the softmax to argmax, which recovers Q-learning. IR analogy: this is the ListNet / Plackett–Luce softmax over document scores. A high temperature shuffles the ranking; a low temperature makes it deterministic.

Worked example, by hand (one state, Q = (1, 0.5, 0)).

αexp(Q/α)ΣV = α log ΣπH(π)
12.718, 1.649, 15.3671.6800.507, 0.307, 0.1861.020
0.122026, 148.4, 1221751.00070.993, 0.007, 0.000050.041

Check at α = 1: Eπ[Q]=0.507+0.5×0.307=0.660\mathbb{E}_\pi[Q] = 0.507 + 0.5 \times 0.307 = 0.660, and 0.660+1×1.020=1.680=V0.660 + 1 \times 1.020 = 1.680 = V. The soft value is never below max Q.

Step 4: soft policy iteration. SAC alternates two steps. First, evaluate the current policy with the soft backup. Then improve it by moving it toward the softmax of the new Q: πnew=arg⁡min⁡π′KL(π′(⋅∣s) ∥ exp⁡(Q(s,⋅)/α)/Z(s))\pi_{\text{new}} = \arg\min_{\pi'} \mathrm{KL}\big(\pi'(\cdot\mid s)\,\|\,\exp(Q(s,\cdot)/\alpha)/Z(s)\big) (SAC Eq. 4; ZZ is the normaliser). In the tabular case this converges to the optimal policy within the chosen policy class (Theorem 1).

Running example: the search-or-answer MDP, softly

Section titled “Running example: the search-or-answer MDP, softly”

The site’s toy MDP has states Q (question only) and E (evidence retrieved). Answering ends the episode with expected reward 0.3 from Q or 0.8 from E. Searching costs −0.1 and moves to E (searching again in E stays in E). γ = 0.9. With hard Bellman, the optimum is to search, then answer, with v∗(Q)=0.62v^*(Q) = 0.62. Soft value iteration (Lab 1 below) gives:

αV(E)π(answer | E)V(Q)π(search | Q)
12.1170.2682.0060.818
0.10.8180.8380.6390.966
0.010.800≈1.00.620≈1.0

At α = 1 the agent mostly keeps searching in E. Each extra step keeps a two-way choice open, worth at most αlog⁡2\alpha\log 2 per future decision. At the α = 1 fixed point, the evidence-state policy is approximately (answer 0.268, search 0.732), whose entropy is about 0.581 nats. Searching keeps future entropy available, so its soft Q-value is −0.1 + 0.9 × 2.1174 ≈ 1.8057, greater than answering’s 0.8. Max-ent RL “farms” entropy when α is large relative to the reward scale. At α = 0.01 it reproduces the hard solution.

SAC learns three things from a replay buffer D\mathcal{D} of past transitions (s,a,r,s′)(s,a,r,s'), as in DQN. The equations below are from the follow-up paper (SAC v2), which dropped the 2018 paper’s separate V-network; the authors later “found it to be unnecessary”.

1. Twin soft Q-critics. Train two critics, Qθ1Q_{\theta_1} and Qθ2Q_{\theta_2}, toward the same soft target. Both critics regress on the smaller of two slowly updated target copies θˉi\bar\theta_i:

JQ(θi)=ED[12(Qθi(s,a)−y)2],y=r+γ(min⁡j=1,2Qθˉj(s′,a′)−αlog⁡πϕ(a′∣s′)), a′∼πϕ(⋅∣s′).J_Q(\theta_i) = \mathbb{E}_{\mathcal{D}}\Big[\tfrac12\big(Q_{\theta_i}(s,a) - y\big)^2\Big],\quad y = r + \gamma\Big(\min_{j=1,2} Q_{\bar\theta_j}(s',a') - \alpha\log\pi_\phi(a'\mid s')\Big),\ a' \sim \pi_\phi(\cdot\mid s').

For a genuine terminal transition, set the bootstrap to zero: use y=r+γ(1−d)[min⁡jQθˉj(s′,a′)−αlog⁡π(a′∣s′)]y=r+\gamma(1-d)\big[\min_jQ_{\bar\theta_j}(s',a')-\alpha\log\pi(a'\mid s')\big], where dd marks environment termination. A time-limit truncation is not automatically terminal.

Each critic’s own estimate is noisy, and maximising over noise biases values upward (the overestimation problem from the DQN page). The min is the TD3 fix for this; the paper reports that it significantly speeds up training on harder tasks. The targets track the critics slowly, θˉ←τθ+(1−τ)θˉ\bar\theta \leftarrow \tau\theta + (1-\tau)\bar\theta with τ = 0.005.

2. Policy via reparameterisation. The actor should put probability on high-Q actions while staying random (SAC v2 Eq. 7, with the reparameterisation of SAC Eq. 11):

Jπ(ϕ)=Es∼D, ϵ∼N[αlog⁡πϕ(a~∣s)−min⁡jQθj(s,a~)],a~=fϕ(ϵ;s).J_\pi(\phi) = \mathbb{E}_{s\sim\mathcal{D},\,\epsilon\sim\mathcal{N}}\big[\alpha\log\pi_\phi(\tilde a\mid s) - \min_j Q_{\theta_j}(s,\tilde a)\big], \qquad \tilde a = f_\phi(\epsilon; s).

Here fϕf_\phi maps Gaussian noise to an action (tanh⁡\tanh of mean plus standard deviation times noise). Because a~\tilde a is a differentiable function of ϕ\phi, the gradient flows through the critic into the action. That has much lower variance than the REINFORCE score-function gradient. It needs a continuous action, so it does not apply directly to discrete tokens. (Second-pass detail, SAC Appendix C.) For implementation, the tanh Jacobian is not optional: if a=tanh⁡ua=\tanh u, then log⁡π(a∣s)=log⁡p(u∣s)−∑ilog⁡(1−tanh⁡2ui)\log\pi(a\mid s)=\log p(u\mid s)-\sum_i\log(1-\tanh^2u_i). A library normally supplies a numerically stable version. Skipping this correction changes both actor learning and automatic temperature tuning.

3. Temperature tuned to a target entropy. A fixed α is brittle: the best value differs across tasks and across training. SAC v2 (§5) instead asks for maximal return subject to a minimum average entropy Hˉ\bar{\mathcal{H}}, with default Hˉ=−dim⁡(A)\bar{\mathcal{H}} = -\dim(A) (e.g. −6 for HalfCheetah). It treats α as the Lagrange multiplier of that constraint (Eq. 18):

J(α)=Ea∼π[−αlog⁡π(a∣s)−αHˉ],∂J∂α=E[−log⁡π]⏟current entropy−Hˉ.J(\alpha) = \mathbb{E}_{a\sim\pi}\big[-\alpha\log\pi(a\mid s) - \alpha\bar{\mathcal{H}}\big], \qquad \frac{\partial J}{\partial\alpha} = \underbrace{\mathbb{E}[-\log\pi]}_{\text{current entropy}} - \bar{\mathcal{H}}.

Gradient descent therefore lowers α when the policy is more random than the target and raises it when entropy falls below. Example: target −1, batch entropy estimate 0.5, gradient +1.5, so α goes down. (Continuous densities can have negative entropy, hence a negative target.) IR analogy: this is how a fairness-of-exposure constraint is often handled: fix the level you want and let a Lagrange multiplier find its price, instead of hand-tuning a penalty weight.

Why replay works without importance weights. Counterfactual LTR on click logs needs inverse propensity scoring (IPS), because it estimates a new ranker’s reward from actions chosen by the logging policy. SAC’s critic treats the logged action only as an input to Q(s,a)Q(s,a). The next action a′a' in the target is resampled from the current policy. So no action-probability ratio appears, and old data stays usable. The price is that SAC relies on Q generalising, which means bias rather than IPS variance. Nothing corrects for the buffer’s state distribution.

Control as inference (skip on a first read)

Section titled “Control as inference (skip on a first read)”

Levine (2018) explains where the softmax comes from. For nonpositive rewards, introduce a binary optimality variable with p(Ot=1∣st,at)=exp⁡(r(st,at))p(\mathcal{O}_t = 1 \mid s_t,a_t) = \exp(r(s_t,a_t)) (Eq. 3). For arbitrary rewards, treat exp⁡(r)\exp(r) as an unnormalised potential instead; otherwise positive rewards (like the toy’s) would produce probabilities greater than 1. The posterior over trajectories is then ∝p(τ)exp⁡(∑trt)\propto p(\tau)\exp(\sum_t r_t). Backward messages give V=log⁡∫exp⁡(Q) daV = \log\int\exp(Q)\,da, which is the soft value. With deterministic dynamics, fitting a policy to this posterior is exactly max⁡ E[∑trt+H(π)]\max\, \mathbb{E}[\sum_t r_t + \mathcal{H}(\pi)]. Two caveats from the tutorial:

  • Stochastic dynamics. With stochastic dynamics, exact inference gives an optimistic, risk-seeking backup, log⁡E[exp⁡V(s′)]\log\mathbb{E}[\exp V(s')]. Variational inference with the dynamics held fixed restores the ordinary E[V(s′)]\mathbb{E}[V(s')].
  • Non-uniform priors. The method assumes a uniform action prior. Any non-uniform prior “can be incorporated instead into p(Ot∣st,at)p(\mathcal{O}_t \mid s_t,a_t) via the reward function”. That sentence is the bridge to πref\pi_{\text{ref}}.

The LLM connection: KL-regularised RL is max-ent RL with a reference

Section titled “The LLM connection: KL-regularised RL is max-ent RL with a reference”

Same objective, different anchor. Entropy and KL to the uniform distribution UU are two views of one quantity: H(π)=log⁡∣A∣−KL(π ∥ U)\mathcal{H}(\pi) = \log|A| - \mathrm{KL}(\pi\,\|\,U). So max-ent RL is “maximise reward, stay close to uniform”. RLHF (InstructGPT) uses “maximise reward, stay close to the SFT (supervised fine-tuned) model πref\pi_{\text{ref}}”:

max⁡π Ey∼π[r(y)]−β KL(π ∥ πref)⟹π∗(y)=πref(y)exp⁡(r(y)/β)Z,Z=∑yπref(y)er(y)/β.\max_\pi\ \mathbb{E}_{y\sim\pi}[r(y)] - \beta\,\mathrm{KL}(\pi\,\|\,\pi_{\text{ref}}) \quad\Longrightarrow\quad \pi^*(y) = \frac{\pi_{\text{ref}}(y)\exp(r(y)/\beta)}{Z},\quad Z = \sum_y \pi_{\text{ref}}(y)e^{r(y)/\beta}.

Why that is the optimum (three lines).

  1. Write Eπ[r]−β KL=−β∑yπ(y)log⁡π(y)πref(y)er(y)/β\mathbb{E}_\pi[r] - \beta\,\mathrm{KL} = -\beta\sum_y\pi(y)\log\frac{\pi(y)}{\pi_{\text{ref}}(y)e^{r(y)/\beta}}.
  2. Divide and multiply by ZZ inside the log. This gives −β KL(π ∥ π∗)+βlog⁡Z-\beta\,\mathrm{KL}(\pi\,\|\,\pi^*) + \beta\log Z.
  3. The KL is ≥ 0 and equals 0 only at π=π∗\pi=\pi^*.

So the optimal objective is βlog⁡Z\beta\log Z, the soft value relative to πref\pi_{\text{ref}}. For a fixed finite set of MM complete responses and a uniform reference, the optimal policy is the same softmax as Step 3 (with β=α\beta = \alpha), but the optimal objective is βlog⁡∑yer(y)/β−βlog⁡M\beta\log\sum_y e^{r(y)/\beta}-\beta\log M. Thus the objectives agree up to a constant, not in their reported value. In a sequential problem, a per-step constant can affect preferences over episode lengths; do not silently drop it when termination is policy-dependent. Equivalently, KL-regularised RL is max-ent RL with the reward r+βlog⁡πrefr + \beta\log\pi_{\text{ref}}, which is Levine’s “put the prior into the reward”. DPO starts from this π∗\pi^* (its Steps 0–3), inverts it to r=βlog⁡(π∗/πref)+βlog⁡Zr = \beta\log(\pi^*/\pi_{\text{ref}}) + \beta\log Z, and cancels ZZ in a pairwise loss.

Worked example. Take three responses with πref=(0.6,0.3,0.1)\pi_{\text{ref}} = (0.6, 0.3, 0.1) and rewards r=(0,1,2)r = (0, 1, 2):

βweights πrefer/β\pi_{\text{ref}}e^{r/\beta}Zπ*E[r]KL(π*‖π_ref)β log Z
10.600, 0.815, 0.7392.1540.279, 0.379, 0.3431.0640.2970.768
0.250.6, 16.4, 2983150.002, 0.052, 0.9461.9442.021.438

Smaller β trusts the reward more and moves further from the reference. A response with πref=0\pi_{\text{ref}} = 0 keeps probability 0 at any β. The anchor limits the policy to what the reference model already supports.

Per token. For a language model, the state is the prompt plus the tokens so far, and the action is the next token. Transitions are deterministic (append the token), so Levine’s optimism problem does not arise for single-turn generation. It returns for agents, whose tool outputs are stochastic. The sequence log-ratio is the sum of the per-token log-ratios. InstructGPT therefore subtracts βlog⁡(π/πref)\beta\log(\pi/\pi_{\text{ref}}) from each token’s reward (β = 0.02). That is (r+βlog⁡πref)−βlog⁡π(r + \beta\log\pi_{\text{ref}}) - \beta\log\pi: an entropy bonus plus a reference-prior reward, exactly the form above.

Entropy bonus vs KL penalty in practice (claims from the linked site pages):

  • PPO’s generic loss adds c2×c_2 \times entropy, which is a pull toward uniform.
  • InstructGPT replaces it with a per-token KL to the SFT model. GRPO moves the KL into the loss (k3 estimator, coefficient 0.04).
  • DAPO removes the KL, arguing that long chain-of-thought training should move far from the start. It fights entropy collapse (the policy’s token entropy falling towards 0 so that it stops exploring) with clip-higher. DAPO warns that too much entropy brings gibberish, so entropy should stay in a range.
  • Entropy Mechanism shows that without KL or bonus, entropy collapses early and performance follows R=−aeH+bR = -a e^{\mathcal{H}} + b. A plain entropy bonus is fragile: coefficients 0.0001–0.001 do little, 0.01 makes entropy explode, and 0.005 holds it without beating the baseline. A reference-KL keeps entropy but lowers performance. The paper’s fix targets a tiny set of high-covariance tokens instead. The exponential relation and coefficient sweep are empirical findings for the paper’s training setups, not a universal entropy–accuracy law. A fluent KL anchor does not guarantee either accuracy or diversity.

Why the cited LLM reasoning recipes prefer other entropy controls (my synthesis of the above).

  • A uniform anchor over a vocabulary of tens of thousands of tokens pulls toward noise, and the right coefficient is very sensitive.
  • The pretrained model is a much better anchor than uniform.
  • What practitioners want is entropy kept in a band. SAC’s auto-α is the closest classical idea, but it sets a floor, not a band.

Optional checks — not part of the reading route

Section titled “Optional checks — not part of the reading route”

The toy calculation is enough to check the concepts. Skip Pendulum and the GRPO experiment unless you want implementation practice; neither is required to understand the LLM connection.

Lab 1 (laptop, any Python 3, under a minute). Soft value iteration on the toy MDP. It reproduces the table above. Then change α, γ or the search cost, and find the α at which “search again in E” overtakes “answer”.

import math
def soft_vi(alpha, gamma=0.9, iters=500):
VE = 0.0
for _ in range(iters): # E: answer -> 0.8 and stop; search -> -0.1, stay in E
qE = {'answer': 0.8, 'search': -0.1 + gamma * VE}
VE = alpha * math.log(sum(math.exp(q / alpha) for q in qE.values()))
qQ = {'answer': 0.3, 'search': -0.1 + gamma * VE}
VQ = alpha * math.log(sum(math.exp(q / alpha) for q in qQ.values()))
pi = lambda q, V: {a: round(math.exp((v - V) / alpha), 3) for a, v in q.items()}
print(f'alpha={alpha}: V(E)={VE:.4f} pi(E)={pi(qE, VE)} V(Q)={VQ:.4f} pi(Q)={pi(qQ, VQ)}')
for a in (1.0, 0.1, 0.01):
soft_vi(a)
Lab 2 (SAC on Pendulum, CPU) and Lab 3 (GRPO entropy logging): optional implementation practice

Lab 2 (CPU, about 5 minutes per run). SAC on Pendulum with Stable-Baselines3 (SB3). Its SAC uses two critics with the min, and by default auto-tunes α with target −dim⁡(A)-\dim(A). SB3 optimises a log-temperature surrogate, Jlog⁡α=−E[log⁡α stopgrad⁡(log⁡π+Hˉ)]J_{\log\alpha}=-\mathbb E[\log\alpha\,\operatorname{stopgrad}(\log\pi+\bar{\mathcal H})]. It has the same entropy-error sign and stationary condition as the paper’s temperature update, but differs from substituting α=eλ\alpha=e^\lambda into Eq. 18, whose λ-gradient carries an additional factor α. Verified with SB3 2.9.2, Gymnasium 1.4.0 and PyTorch 2.15 (CPU):

Terminal window
python3 -m venv sac-env && . sac-env/bin/activate
pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install stable-baselines3 gymnasium
cat > sac_pendulum.py <<'EOF'
import sys
from stable_baselines3 import SAC
ent = sys.argv[1] if len(sys.argv) > 1 else 'auto'
steps = int(sys.argv[2]) if len(sys.argv) > 2 else 20000
model = SAC('MlpPolicy', 'Pendulum-v1', ent_coef=ent if ent == 'auto' else float(ent),
learning_starts=1000, verbose=1, seed=0, device='cpu')
model.learn(total_timesteps=steps, log_interval=10)
EOF
OMP_NUM_THREADS=1 python sac_pendulum.py auto 20000 # then try 0.0, 1.0 and 20.0

Watch ep_rew_mean (closer to 0 is better) and ent_coef (the current α). ep_rew_mean is a mean over the last 100 episodes, so it lags behind the policy. Our runs used seed 0 and took about 4 minutes each on one CPU thread:

runep_rew_mean at 20k steps
auto α (decayed from 0.75 at 2k steps to 0.04 at 18k)−358
α = 0−378
α = 1−379
α = 20−1140 (barely learns)

Pendulum rewards are large (up to about −16 per step), so α = 1 is a small temperature here. Only α = 20 is enough to swamp the reward, the continuous version of the toy’s entropy farming. One seed on an easy task shows the scale effect, not that auto-α is better. To test that claim, use 5 seeds.

Lab 3 (optional, single GPU, no commands given). In a GRPO run you already have from the reasoning pages, log the mean per-token entropy and KL to π_ref of the policy’s own tokens every step. Check whether entropy collapses in the first few hundred steps, as the Entropy Mechanism paper reports.

SAC 2018 (1801.01290): MuJoCo and rllab locomotion, 5 seeds.

  • Baselines. DDPG made no progress on Ant, Humanoid-v1 or rllab Humanoid. Soft Q-learning (SQL) learned every task but more slowly and to a lower final return. SAC learned considerably faster than PPO, which needs large batches to be stable on hard tasks.
  • Ablations. A deterministic, DDPG-like variant (two Q-functions, no entropy, fixed exploration noise) varied much more across seeds on rllab Humanoid. Evaluating with the mean action beat sampling. Reward scale was the only hyperparameter tuned: 5 for most tasks, 20 for Humanoid-v1 and 10 for rllab Humanoid. Too small a scale gave a near-uniform policy; too large gave a near-deterministic one stuck in poor local minima.
  • Settings. Adam with learning rate 3·10⁻⁴, batch 256, a buffer of 10⁶ transitions, γ = 0.99, τ = 0.005.

SAC v2 (1812.05905):

  • Auto-α on benchmarks. It worked across all benchmark environments, comparable to per-task tuned α.
  • Minitaur. The quadruped learned to walk in the real world in 160k steps (about 2 hours) and without further training walked on a slope, through a block obstacle and down stairs.
  • Valve rotation. A dexterous hand learned to rotate a valve from raw images in 300k steps (about 20 hours), and from state in 3 hours, against a reported 7.4 hours for PPO.

Soft Q-learning (1702.08165): an energy-based policy keeps several routes open. In a maze with two identical-looking passages, one of them blocked, all soft Q-learning policies found the open route, against 60% for DDPG. A max-ent policy pretrained to run in any direction learned hallway tasks faster than DDPG from scratch (10 seeds).

  • The temperature is a reward scale. Without auto-tuning, α must be re-tuned whenever reward magnitudes change. Too large an α farms entropy, as in the toy loop.
  • Auto-α constrains average entropy, and only from below. v2 argues that the constraint is usually tight because the return-maximising policy is deterministic. For LLMs, too high entropy is also a failure, so you need a band.
  • Entropy ≠ useful diversity. Token entropy can rise while the model tries the same strategies; measure pass@k and strategy diversity (Evaluating reasoning RL). In IR terms it is like measuring answer diversity by lexical variance instead of nugget coverage.
  • Optimism under stochastic dynamics. The naive inference view is risk-seeking. SAC’s backup uses E[V(s′)]\mathbb{E}[V(s')] and avoids it. Watch for it in agent settings with stochastic tool outputs.
  • Continuous ≠ discrete. Reparameterisation and the −dim⁡(A)-\dim(A) target are tied to continuous actions. Token-level variants need other estimators.
  • compute a soft value and a Boltzmann policy by hand, and say what happens as α → 0 or ∞;
  • write SAC’s Q, policy and α losses and explain the min, the reparameterisation and the sign of the α update;
  • derive π* ∝ π_ref·exp(r/β) and explain why it is max-ent RL with a non-uniform reference;
  • explain why LLM RL uses a KL to π_ref, no anchor plus clip-higher, or targeted covariance methods, rather than a plain entropy bonus.

Questions to think through

These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.

  1. Derive / compute

    One state, three actions with soft Q-values 1, 0.5 and 0. Compute the soft value V = α·log Σ exp(Q/α) and the Boltzmann policy π = exp((Q − V)/α) at α = 1 and at α = 0.1. Check that V equals E_π[Q] + α·H(π) at α = 1, and explain what V and π become as α → 0 and as α → ∞.

    What a strong answer covers
    • α = 1: exp values 2.718, 1.649 and 1, sum 5.367, so V = ln 5.367 ≈ 1.680; π ≈ (0.507, 0.307, 0.186).
    • Check at α = 1: E_π[Q] ≈ 0.660 and H(π) ≈ 1.020 nats, and 0.660 + 1.020 ≈ 1.680 = V. The soft value is expected Q plus the entropy bonus of acting with π.
    • α = 0.1: V ≈ 1.0007, just above max Q = 1; π ≈ (0.993, 0.007, 0.00005), entropy ≈ 0.04 nats.
    • α → 0: V → max Q and π → greedy (ordinary Bellman optimality, Q-learning). α → ∞: π → uniform and V grows like α·log 3 (α times the maximum entropy), so the reward stops mattering.
  2. Derive / compute

    Starting from the KL-regularised objective max over π of E_π[r] − β·KL(π ‖ π_ref), derive π* ∝ π_ref·exp(r/β) and the optimal objective value β·log Z. Then evaluate it for π_ref = (0.6, 0.3, 0.1) and r = (0, 1, 2) at β = 1 and β = 0.25, and show that with a uniform π_ref the objective is max-entropy RL.

    What a strong answer covers
    • Rewrite E_π[r] − β·KL = −β·Σ π·log(π / (π_ref·exp(r/β)/Z)) + β·log Z = −β·KL(π ‖ π_ref·exp(r/β)/Z) + β·log Z with Z = Σ π_ref·exp(r/β). The KL is ≥ 0 and 0 only at π* = π_ref·exp(r/β)/Z, so the optimum value is β·log Z.
    • β = 1: weights 0.6, 0.3e ≈ 0.815, 0.1e² ≈ 0.739, Z ≈ 2.154, π* ≈ (0.279, 0.379, 0.343), E[r] ≈ 1.064, KL ≈ 0.297, objective ≈ 0.768 = ln 2.154.
    • β = 0.25: Z ≈ 315, π* ≈ (0.002, 0.052, 0.946), E[r] ≈ 1.944, KL ≈ 2.02, objective ≈ 1.438 = 0.25·ln 315. Smaller β trusts the reward more and moves further from π_ref.
    • Uniform π_ref = U over |A| actions: KL(π ‖ U) = log|A| − H(π), so the objective is E[r] + β·H(π) − β·log|A|: max-entropy RL with α = β, with the same optimal policy but a value lower by the constant β·log|A|. In sequential problems a per-step constant can change preferences over episode length, so do not drop it when termination depends on the policy. Equivalently, KL-regularised RL is max-ent RL with reward r + β·log π_ref.
    • π* is zero wherever π_ref is zero, and this is exactly DPO's starting point.
  3. Mechanism

    Write SAC's three losses (the twin soft-Q loss, the reparameterised policy loss and the temperature loss of the 2018 follow-up) and explain what each piece is for: why the minimum of two Q-networks, why reparameterise the action instead of using a REINFORCE-style score-function gradient, and which way α moves when the policy's entropy is above the target −dim(A).

    What a strong answer covers
    • Q loss: ½(Q_θi(s,a) − y)², with y = r + γ·(1 − d)·(min over i of Q_θ̄i(s′,a′) − α·log π(a′|s′)), d marking true termination, a′ sampled fresh from the current π, and no gradient through the target. The min counters the upward bias of maximising over noisy Q estimates (as in TD3).
    • Policy loss: E[α·log π(ã|s) − min Q(s, ã)], with ã = f_φ(ε; s) (e.g. tanh of mean + std·noise). The gradient flows through Q into the action, a low-variance pathwise gradient for differentiable continuous actions. A score-function estimator could also use the learned soft Q instead of Monte Carlo returns, so the contrast is pathwise versus likelihood-ratio, not critic versus returns.
    • Temperature loss: J(α) = E_{a∼π}[−α·log π(a|s) − α·H̄]. With gradients stopped through log π when optimising α, its gradient is (current entropy − H̄), so gradient descent lowers α when entropy is above target and raises it when entropy falls below.
    • Off-policy: (s, a, r, s′) come from a replay buffer of older policies; the logged action only enters as Q's input, and the next action a′ is resampled from the current policy, so no importance weights are needed (unlike IPS on click logs).
  4. What if…

    The 2018 SAC paper reports that reward scale is the only hyperparameter that needed tuning, and that a deterministic variant is much less stable. Explain why reward scale is really the temperature, what too-small and too-large scales do, how the search-or-answer MDP at α = 1 versus α = 0.1 illustrates the failure, and what the automatic temperature of the follow-up paper changes.

    What a strong answer covers
    • With J = E[Σ r + α·H], multiplying r by c is the same as using temperature α/c; the 2018 paper fixes α and tunes reward scale (5 for most tasks, 20 for Humanoid-v1, 10 for rllab Humanoid).
    • Too small a scale (high temperature) gives a near-uniform policy that ignores reward; too large (low temperature) gives a near-deterministic policy that explores poorly and gets stuck in poor local minima (Fig. 3b).
    • Toy MDP: at α = 1, searching again in E is worth more than answering (π(search | E) ≈ 0.73), because searching keeps a two-way choice (at most α·log 2 ≈ 0.69 nats per decision; the actual E policy (0.268, 0.732) has entropy ≈ 0.581) open, so Q(search | E) = −0.1 + 0.9 × 2.117 ≈ 1.806 > 0.8 = Q(answer | E); at α = 0.1, π(answer | E) ≈ 0.84 and V(Q) ≈ 0.64, near the hard optimum 0.62.
    • Deterministic variant (DDPG-like, two Q-functions, no entropy, fixed exploration noise): much higher variability across seeds on Humanoid (rllab), so the entropy term itself stabilises learning, not just the off-policy machinery.
    • The follow-up treats α as a Lagrange multiplier for a minimum-entropy constraint (target −dim(A)) and learns it; across its benchmarks this matched per-task tuned fixed α and removed the tuning.
  5. Critique

    Using the entropy/KL identity and the cited InstructGPT, DAPO and Entropy Mechanism results, explain why a uniform entropy bonus, a KL anchor to an SFT model, and clipping relative to the rollout policy are different controls. Which trade-offs are mathematical consequences, which are empirical findings of those experiments, and what would you measure before concluding that one is best for a new search agent?

    What a strong answer covers
    • H(π) = log|V| − KL(π ‖ uniform): an entropy bonus pulls every token distribution toward uniform over the whole vocabulary, a reference that knows nothing about language; a KL to π_ref pulls toward a model that is already fluent.
    • Entropy Mechanism (§4.1): bonus coefficients 0.0001 and 0.001 barely change entropy, 0.01 makes it explode, 0.005 holds it but does not beat the baseline. DAPO notes too-high entropy goes with gibberish and repetition; entropy should stay in a range.
    • The KL to π_ref costs performance as well: the Entropy Mechanism paper finds it keeps entropy up but lowers accuracy, and DAPO removes it because long-CoT training should move far from the start; RL-boundary finds even a small KL changes pass@k behaviour.
    • Separate a fixed SFT reference from the rollout policy used by clipping or KL-Cov. A reference-KL constrains drift, whereas targeted rollout-policy controls limit particular updates; neither is generally equivalent to targeting entropy.
    • Evaluate held-out task success, calibration or reward exploitation, pass@k and strategy/query diversity as well as entropy. The cited coefficient sweeps do not establish that plain entropy bonuses fail in every LLM setting.
  6. Design

    A GRPO search agent's token entropy collapses early. Design a controller that keeps the average entropy of policy-generated tokens between H_min and H_max. Derive which multiplier increases at each violated boundary, explain why replacing that multiplier with a reference-KL coefficient is not automatically valid, and propose a falsifiable comparison with DAPO-style clip-higher under a matched rollout and compute budget.

    What a strong answer covers
    • Measure entropy only on policy-generated query, reasoning and answer tokens, excluding retrieved text; use a fixed prompt distribution for monitoring and inspect per-stage entropy so a global average cannot hide query collapse.
    • For constraints H ≥ H_min and H ≤ H_max, add α_low·(H − H_min) + α_high·(H_max − H) to the reward-maximisation Lagrangian, with nonnegative multipliers. Projected dual descent increases α_low when entropy is too low and increases α_high when entropy is too high; the net entropy coefficient is α_low − α_high.
    • Do not assume increasing reference-KL weight increases entropy: it pulls toward the reference, which may have lower entropy than the current policy. If controlling KL or a clip bound instead, derive the corresponding constraint or empirically identify its response and add stability safeguards.
    • Compare no control, a tuned fixed entropy bonus, clip-higher with ε_high = 0.28, and the proposed controller across several seeds with matched generation, update and tuning budgets.
    • Measure task success, pass@1/pass@k, strategy/query diversity, answer coverage and length. Falsify the claimed benefit if the entropy band is maintained but success and useful diversity do not improve over clip-higher.

Done with this page?

Status