Policy gradients and actor-critic: from REINFORCE to PPO and SAC

Optimising the policy directly: the policy gradient theorem derived, REINFORCE and baselines, actor-critic and GAE, A2C and A3C, natural gradients and TRPO, PPO and the implementation details that carry it, and DDPG, TD3 and SAC for continuous control. A child page of Topic: rl. Data as of October 2026. Reading: 45 min, plus 9 in closed details.

The idea in one screen

Push up the log-probability of each action in proportion to how good it turned out. Every method on this page uses that one gradient, ∇θ log πθ(a | s) × weight, and differs in only two places: what number the weight is (the return, the return minus a baseline, a critic's estimate) and how far one batch of data may move the policy (a step size, a KL limit, a clip, an entropy bonus).

Fig. 1 · one update of a softmax policy, step by step

  1. A policy over three actions. One state, three actions with rewards 1, 2 and 6, and a softmax with every logit at 0: each action has probability 1/3, so V = 3. This is section 4's worked example illustrative.
  2. Sample an action and take its score. Action 1 is drawn. Its score with respect to the logits is e1 − π = (+0.67, −0.33, −0.33): the direction that makes action 1 more likely.
  3. Weight it by the return. With no baseline the weight is the reward itself, 1, so the update is (+0.67, −0.33, −0.33): the worst action is pushed up, because every reward is positive.
  4. Dial 1: subtract a baseline. With b = V = 3 the weight is 1 − 3 = −2 and the update is (−1.33, +0.67, +0.67): the same sample now pushes action 1 down.
  5. On average, the same gradient. Over the three possible samples both rows average to the exact gradient (−0.67, −0.33, +1); the glass shows how far single samples scatter. The total variance falls from 7.56 to 1.56 derived.
  6. Dial 2: how far one step may move the policy. A step of η = 0.5 along that gradient gives (0.22, 0.26, 0.51) illustrative, so action 3's probability is 1.54 times its old value. A step size, a KL limit (TRPO) or PPO's clip at 1 ± ε (the two glass plates, ε = 0.2) decides how far one batch may go.

You need: TD errors, TD(λ) and importance sampling from Model-free prediction and control (the critics here learn those targets); replay buffers and target networks from Value-based deep RL (DDPG, TD3 and SAC borrow them). The one-state version of the policy gradient is the gradient bandit on Bandits and exploration.

Score function
∇θ log πθ(a | s): the direction in parameter space that makes the action taken more likely (Sutton and Barto: the eligibility vector).
Advantage A(s, a)
Q(s, a) − V(s): how much better than the policy's average the action was.
Baseline, critic
a baseline is subtracted from the return and fixed before the action; a critic is a learned value whose estimate of the next state judges the action.
GAE(γ, λ)
an advantage estimate that averages the 1-step to ∞-step estimates; λ is the bias-variance dial.
Importance ratio rt(θ)
πθ(at | st) / πθold(at | st): how much the new policy has moved on a stored action.
Trust region, clip
a KL limit on how far the action distribution may move per update (TRPO); PPO's clip removes the incentive to move the ratio past 1 ± ε.
Temperature α
the price of randomness in maximum-entropy RL: reward plus α × entropy is maximised.

Two dials define every method: what weights the score, and how far one batch may move the policy

First dial: from the first box to the last, the weight relies less on sampled rewards and more on a learned critic, so variance falls and the critic's bias enters. Second dial: on-policy methods limit the step on fresh data (step size, KL, clip); off-policy ones reuse a replay buffer and need target networks, and SAC adds entropy to the objective. Tap a box to jump to its section.

MethodWhat weights ∇ log π(a | s)How far a step may goDataActions
REINFORCE (1992)The sampled return GtStep size onlyOn-policy, whole episodesAny
REINFORCE with baseline; RLOO, GRPOGt − b(st): a learned V, or the other samples' mean rewardStep size (GRPO borrows PPO's clip)On-policyAny
Actor-critic (1983)The critic's TD error δt = r + γV(s′) − V(s)Step sizeOn-policy, every stepAny
GAE (2015)Σ (γλ)l δt+l: λ slides from TD error to return minus V(an estimator, used by the rows below)On-policyAny
A3C (2016), A2C (2017)n-step return minus VStep size; parallel actors decorrelate the dataOn-policyAny
Natural gradient (2001), TRPO (2015)The advantage, through an importance ratioA hard KL limit δ, solved with the Fisher matrixOn-policyAny
PPO (2017)GAE advantage times a clipped ratioThe clip removes the incentive beyond 1 ± εApproximately on-policy: a few epochs per batchAny
DPG (2014), DDPG (2015)No log-probability: the critic's slope ∇aQ(s, a) through a deterministic actorSoft target networksOff-policy, replayContinuous
TD3 (2018)As DDPG, with the smaller of two criticsDelayed actor updatesOff-policy, replayContinuous
SAC (2018)The soft Q, minus α log π, through a reparameterised stochastic actorThe entropy bonus keeps the policy wideOff-policy, replayContinuous

Rows jump to their section. Dates and first papers match the parent's Method atlas tab, which places these among the other 47 methods. Widgets are computed exactly in the page and checked against Python; numbers are published (source linked) unless marked derived or illustrative. PPO for RLHF with its four models, GRPO, RLOO and their corrections on language models are on RL for LLMs.

1Why optimise the policy directly

A value-based agent acts by arg maxa Q(s, a): a maximisation over actions at every step, awkward when the action is a vector of joint torques and expensive when it is one of 100,000 tokens, and it only yields a deterministic policy plus bolted-on exploration noise. A parameterised policy has four advantages (Sutton and Barto §13.1): continuous and huge action spaces are natural (a Gaussian over torques, a softmax over tokens); the optimal policy may be stochastic (card games with hidden information, or states the agent cannot tell apart: an ε-greedy action-value method cannot represent specific probabilities; a softmax policy can); smooth change, since probabilities move continuously with θ while an arbitrarily small change in estimated values can flip an ε-greedy choice ("Largely because of this, stronger convergence guarantees are available for policy-gradient methods than for action-value methods", §13.2); and prior knowledge goes into the form of the policy, "often the most important reason for using a policy-based learning method".

The short corridor (Example 13.1) is the smallest problem on which a policy-gradient method beats every action-value method that uses the same features, and it runs through sections 3 to 5. Three states, reward −1 per step, actions right and left, switched in the second state; every state has the same features, so a policy is one number, p = probability of right.

Where J(p) and the optimum come from (Exercise 13.1) 1 min

In the first and third states right moves right and left moves left (left in the first state bumps the wall). Write v1, v2, v3 for the three states under "right with probability p". The Bellman equations are v1 = −1 + p v2 + (1 − p) v1; v2 = −1 + p v1 + (1 − p) v3 (switched); v3 = −1 + (1 − p) v2. Solving gives J(p) = v1 = 2(2 − p) / (p(p − 1)). Setting dJ/dp = 0 gives p* = 2 − √2 ≈ 0.5858 and J* ≈ −11.657 derived. The ε-greedy policies with ε = 0.1 choose their greedy action with probability 1 − ε/2 = 0.95: J(0.95) = −44.21 and J(0.05) = −82.11, the book's "less than −44 and −82" derived.

No deterministic policy can do well here; the best one flips a biased coin

The value of the start state is J(p) = 2(2 − p) / (p(p − 1)), maximised at p* = 2 − √2 ≈ 0.586 with J* = −(6 + 4√2) ≈ −11.66 derived. The two policies an ε-greedy method can reach (ε = 0.1) choose right with probability 0.95 or 0.05 and score −44.2 and −82.1. The book: "The best probability is about 0.59, which achieves a value of about −11.6."

The two policy parameterisations and their score functions

Everything below needs only the score ∇θ log π(a | s, θ). Nearly every implementation uses one of two:

Softmax: π(a | s) = exp(θ⊤x(s, a)) / Σb exp(θ⊤x(s, b)),   ∇ log π(a | s) = x(s, a) − Σb π(b | s) x(s, b)
Gaussian: a ~ 𝒩(μθ(s), σθ(s)2),   ∂ log π / ∂μ = (a − μ) / σ2,   ∂ log π / ∂ log σ = (a − μ)2 / σ2 − 1
x(s, a)
a feature vector of the pair; with a network the logits play the role of θ⊤x, and the score with respect to the logits is the one-hot vector of a minus the probabilities
μ, σ
the mean and standard deviation the network outputs (§13.7); a sample above the mean pushes μ up if it turned out well, a sample far from the mean pushes σ up

The Gaussian score needs no environment: with σ fixed, reward times noise over σ, averaged over samples, estimates the gradient of the expected reward with respect to μ. Dust uses exactly this to train a transformer with no backward pass: it adds noise to each token's activations at a layer, scores each token by its own loss change against the mean over draws (the baseline), and the reward-weighted noise estimates the error at that layer's output (Dust).

2The policy gradient theorem, derived

The objective is the expected return of trajectories τ = (s0, a0, r1, s1, ...) sampled by running the policy, J(θ) = 𝔼τ~πθ[G(τ)]. The difficulty: θ changes which trajectories happen, through a state distribution that depends on unknown dynamics. Four steps remove it.

  1. The log-derivative trick. ∇θ 𝔼x~pθ[f(x)] = Σx f(x) ∇pθ(x) = 𝔼x~pθ[f(x) ∇ log pθ(x)], because ∇p = p ∇ log p. A gradient of an expectation becomes an expectation of something we can sample.
  2. The dynamics drop out. log pθ(τ) = log p(s0) + Σt [log πθ(at | st) + log p(st+1, rt+1 | st, at)]. Only the policy terms depend on θ, so ∇ log pθ(τ) = Σt ∇ log πθ(at | st): no model of the environment is ever needed, only samples and a differentiable policy.
  3. Causality. That gives ∇J = 𝔼[G(τ) Σt ∇ log π(at | st)]. A reward received before time t does not depend on at, and 𝔼a~π[∇ log π(a | s)] = ∇ Σa π(a | s) = ∇1 = 0, so those rewards contribute nothing in expectation: each score is weighted only by the reward-to-go Gt = Σk≥0 γk rt+k+1. Same expectation, less variance (Fig. 2).
  4. From returns to action values. 𝔼[Gt | st, at] = Qπ(st, at), which gives the theorem.

Fig. 2 · causality deletes the lower triangle

  1. One episode. Four actions a0 to a3, then the rewards that followed them, 1, 0, 2, −1 (γ = 1) illustrative; reward rk arrives after action ak−1.
  2. The whole return weights every action. Each row is one action's weight, made of all four rewards, so every action is weighted by G(τ) = 2.
  3. Causality deletes the lower triangle. The rewards earned before an action (the glass cells) do not depend on it, and its score averages to zero against them, so they add only noise.
  4. The reward-to-go. What is left weights the four actions 2, 1, 1, −1: the same expected gradient as the whole return, with less variance.
∇θ J(θ) = 𝔼πθ [ Σt ∇θ log πθ(at | st) · Qπ(st, at) ]   ∝   Σs μ(s) Σa qπ(s, a) ∇θ π(a | s, θ)
∇ log π(at | st)
the direction that makes the action actually taken more likely in that state
Qπ(st, at)
how good that action turned out to be, in expectation, if the policy is followed afterwards
μ(s)
the on-policy state distribution; in the episodic case the constant of proportionality is the average episode length, in the continuing case it is 1 (Sutton and Barto, Eq. 13.5)

The second form is the statement in Sutton et al. (1999) and in the book, which proves it by unrolling ∇vπ(s) = Σa [∇π(a | s) qπ(s, a) + π(a | s) ∇qπ(s, a)] through the Bellman equation (the box on p. 325). Its point: the gradient does not involve the derivative of the state distribution, which depends on the unknown environment.

Compatible function approximation: when a learned critic leaves the gradient exact 1 min

The same paper's Theorem 2 says when a learned fw(s, a) can replace Qπ without biasing the gradient: if fw is a local optimum of the squared error to Qπ under π, and its gradient in w equals the policy's score, ∂fw/∂w = ∇θ π(s, a) / π(s, a). Its Theorem 3 then shows that "a form of policy iteration with function approximation is convergent to a locally optimal policy" under standard step-size conditions. Practical critics are not compatible in this sense; the theorem is why "a critic that is exactly right gives the exact gradient" holds and an arbitrary one does not.

3REINFORCE: the Monte Carlo policy gradient

REINFORCE (Williams 1992) samples the theorem directly: run an episode, then use each step's return as the estimate of Qπ.

For t = 0, ..., T − 1:   G ← Σk=t+1T γk−t−1 Rk;   θ ← θ + α γt G ∇ log π(At | St, θ)
the episode
S0, A0, R1, ..., ST−1, AT−1, RT, generated by πθ (Sutton and Barto's boxed algorithm, p. 328)
γt
the factor the discounted objective (the value of the start state) requires; most deep-RL code drops it and weights every step equally, which optimises a slightly different objective
∇ log π = ∇π / π
the update is inversely proportional to the action's probability, "otherwise actions that are selected frequently are at an advantage ... and might win out even if they do not yield the highest return" (p. 327)

It is unbiased: the expected update is the gradient, which assures improvement for a small enough α and convergence to a local optimum with decreasing step sizes (§13.3). It has high variance: one episode's return carries the randomness of every later action and transition. It needs episodes that end and updates only afterwards. And when every reward is positive, every sampled action is pushed up, the good ones merely more than the bad; when every reward is negative (the short corridor), every sampled action is pushed down. The policy still improves on average, slowly. With θ started at p(right) = 0.05 and 100 runs averaged, REINFORCE with α = 2−13 climbs from −82 to within about one unit of J* over 1,000 episodes, and α = 2−14 more slowly (Figure 13.1, rerun in section 4).

The name under 1 min

REINFORCE is an acronym, "REward Increment = Nonnegative Factor times Offset Reinforcement times Characteristic Eligibility", which describes the update's form, Δw = α(r − b)e: a step size, a reward minus a baseline, and the score.

Same random numbers, two learners: without a baseline, a constant offset makes every sample push its own action up

No baseline (REINFORCE)
Baseline b = V (exact)

Learning rate 0.1, 60 updates of one sampled action each. Bars are the policy's probabilities; thin marks are this sample's update (purple) against the exact expected gradient (grey); variance is the exact total variance of the one-sample estimate at the current policy. With offset 10, 86 of 200 seeded runs without a baseline lock onto a worse action within 60 updates, against none with it derived.

4Baselines: same mean, less variance

Subtract from the return any baseline b(s) that may depend on the state but not on the action. The gradient is unchanged in expectation, because the subtracted term averages to zero:

𝔼a~π[ ∇ log π(a | s) b(s) ] = b(s) Σa ∇π(a | s) = b(s) ∇ Σa π(a | s) = b(s) ∇1 = 0
b(s)
"can be any function, even a random variable, as long as it does not vary with a" (Sutton and Barto §13.4); a baseline that depends on the action taken breaks the second equality and biases the gradient

The natural choice is b(s) = Vπ(s), which turns the weight into the advantage Aπ(s, a) = Qπ(s, a) − Vπ(s): better-than-average actions are pushed up, worse-than-average ones down. "In some states all actions have high values and we need a high baseline to differentiate the higher valued actions from the less highly valued ones; in other states all actions will have low values and a low baseline is appropriate" (§13.4).

The identity needs on-policy samples. 𝔼a~π[∇ log π] = 0 holds only when the action is drawn from π itself. When it is drawn from another policy q but scored through π (an LLM's rollout engine against its trainer), 𝔼a~q[∇ log π] is not zero, and every update gains a term, the mean reward times that vector, that pulls π toward q whatever the rewards say. Subtracting 𝔼a~q[∇ log π] from each sample's score (score centering) restores the zero mean; unlike a baseline it moves the mean of the estimate rather than its variance, a bias correction, not a variance reduction (RL for LLMs, section 8; Score Centering).

Worked example illustrative: one state, three actions with rewards 1, 2 and 6, a softmax with all logits 0, so each action has probability 1/3 and V = 3. The score with respect to the logits is ea − π, so the exact gradient is πk(Rk − V) = (−0.667, −0.333, 1).

  • Sample action 1 (reward 1) without a baseline: 1 × (2/3, −1/3, −1/3) = (0.667, −0.333, −0.333), which raises the worst action. With baseline 3: (1 − 3) × (2/3, −1/3, −1/3) = (−1.333, 0.667, 0.667), which lowers it.
  • Sample action 3 (reward 6): (−2, −2, 4) without a baseline, (−1, −1, 2) with it: the same direction, half the size.
  • Averaged over the three actions, both give exactly (−0.667, −0.333, 1), but the total variance (summed over components) falls from 7.56 to 1.56 derived.

Predict, then move the offset to 10: adding 10 to every reward changes nothing about which action is best. Does REINFORCE without a baseline still find action 3 within 60 updates?

The animation, in five stretches

  1. Before any update. Both learners start from the uniform policy (1/3 each) and draw the same random numbers.
  2. Update 1. Each samples one action. Without a baseline the sampled action's logit goes up whatever its reward; with b = V it goes up only if its reward beats V. Purple marks are this sample's update, grey the exact expected gradient.
  3. Updates 2 to 10. Each update is one sample's push. Without a baseline its size grows with the reward offset; with the baseline it does not. Expected reward now: .
  4. Updates 11 to 30. Expected reward: . The variance stats under the chart are exact at each learner's current policy.
  5. Updates 31 to 60, and 200 seeded runs. Expected reward: . The shading is the 10th to 90th percentile of 200 runs; the last stat counts the runs that ended on a worse action.

Which baseline minimises the variance? For a constant b, the variance of (Ra − b)∇ log π(a) is a parabola in b with its minimum at the score-weighted mean b* = 𝔼[‖∇ log π‖2 R] / 𝔼[‖∇ log π‖2], not at V = 𝔼[R] (Greensmith, Bartlett and Baxter 2004, who "show that the popular approach of using the average reward to define the baseline can be suboptimal"). When every action's score has the same length, as at the uniform policy above, the two coincide; otherwise V is close, and it is what practice uses because it can be learned.

The mean never moves with b; the variance is a parabola whose bottom b* leaves V when the policy is uneven

Exact, not sampled: mean and variance are sums over the three actions weighted by their probabilities. Try: raise the logit of action 3 to 2 and watch b* leave V.

A learned baseline. V is unknown, so it is learned alongside the policy: Sutton and Barto's "REINFORCE with baseline" fits v̂(s, w) to the returns by Monte Carlo and updates θ with Gt − v̂(St, w) (box on p. 330). On the short corridor a one-number baseline, v̂ = w, with αθ = 2−9 and αw = 2−6, reaches the optimum within about 100 episodes, where REINFORCE at its best step size needs most of 1,000 (Figure 13.2, rerun below). The baseline also allows a 16 times larger policy step without diverging.

What these defaults reproduce, and what they do not 2 min
  • Exactly, independently: the optimum p* ≈ 0.59 with value ≈ −11.6, and the ε-greedy values below −44 and −82 (Example 13.1), from the Bellman equations.
  • In shape: Figure 13.2's result that a learned baseline (here v̂(s, w) = w, one number, as in the book) makes REINFORCE learn much faster. Figure 13.1's 2−13 and 2−14 curves have the same shape as the book's (the smaller step is slower).
  • Not reproduced: in the book's Figure 13.1 the largest step, 2−12, levels off well below the others. Here, with the 0.05 floor, 2−12 learns fastest of the three; without the floor some of its runs drive p to 0 or 1, episodes become thousands of steps long and the average collapses. The book does not state its starting policy or whether probabilities were bounded, so this page uses the widely used reproduction by Zhang and Bondariev (short_corridor.py): θ starts at [−1.47, 1.47] (p = 0.05, near ε-greedy left) and the smaller probability is never allowed below 0.05. Two departures from that code: the book's step sizes (powers of two) instead of its 2e-4, 2e-5, 2e-3, and the book's order of updates in REINFORCE with baseline (δ computed before w moves).
  • Features: both actions have the same feature vector in every state, x(s, right) = [1, 0] and x(s, left) = [0, 1]; γ = 1.
A baseline does not make an actor-critic
"In REINFORCE with baseline, the learned state-value function estimates the value of the first state of each state transition. This estimate sets a baseline for the subsequent return, but is made prior to the transition's action and thus cannot be used to assess that action" (§13.5). So REINFORCE with a learned baseline, RLOO (each sample's reward minus the mean of the other samples for the same prompt; Kool, van Hoof and Welling 2019) and GRPO (the group's mean and standard deviation; Shao et al. 2024) are REINFORCE-family policy methods, not actor-critics, as the root's Method atlas records. Their use on language models is on RL for LLMs.

Figures 13.1 and 13.2, rerun: a one-number baseline reaches the optimum about ten times sooner

Total reward per episode, averaged over seeded runs computed in your browser when the card comes into view; dashed: v*(s0) = −11.66. With 100 runs the baseline curve is within about 0.5 of J* by episodes 100 to 200, while REINFORCE at 2−13 is still near −25 there and approaches −12.6 by the end.

Three learners on the same random numbers: the baseline finds the stochastic optimum, the state-blind critic overshoots it

The curve is J(p) from section 1; each dot is one learning run, one frame every 10 episodes: REINFORCE with α = 2−13, REINFORCE with a learned baseline (αθ = 2−9, αw = 2−6, the book's settings for Figure 13.2), and one-step actor-critic with the same step sizes (not in the book). The average over 100 runs is the actor-critic curve in the figure above (turn it on there).

5Actor-critic: a critic judges each action

An actor-critic learns an actor π(a | s, θ), updated by the policy gradient, and a critic v̂(s, w), trained by TD learning, whose estimate of the next state turns one real reward into an assessment of the action just taken. Barto, Sutton and Anderson (1983) balanced a pole with an "adaptive critic element" and an "associative search element"; the root's Method atlas dates the family there.

δt = Rt+1 + γ v̂(St+1, w) − v̂(St, w);   w ← w + αw δt ∇v̂(St, w);   θ ← θ + αθ I δt ∇ log π(At | St, θ);   I ← γI
δt
the TD error, with v̂ = 0 at a terminal state. If the critic were exact, 𝔼[δt | St, At] = Qπ − Vπ = Aπ(St, At): the TD error is an unbiased sample of the advantage
I
the running γt factor; this is the one-step actor-critic of Sutton and Barto, p. 332, fully online: each transition is used once, as it happens

The trade is Model-free prediction and control's Monte Carlo against TD trade, moved to policies: one real reward and the critic's estimate give low variance and an update every step, but when the critic is wrong the weight is biased. The book adds: "the bias in the gradient estimate is not due to bootstrapping as such; the actor would be biased even if the critic was learned by a Monte Carlo method." Between the two ends sit n-step and λ-returns, which section 6 turns into an advantage estimator.

When the critic is too poor. Give the one-step actor-critic the same one-number critic as the baseline, v̂(s, w) = w. Every state looks the same to it, so δ = −1 + w − w = −1 on every step except the last, where δ = −1 − w > 0 derived. The last action of every episode is right from the third state, so the critic keeps crediting right, and the policy drifts past the optimum to the 0.95 floor (−44 per episode) within a few hundred episodes, while REINFORCE with the same baseline settles at the optimum. With a critic this poor, the actor-critic's bias wins over its lower variance; a smaller actor step (2−12) delays the drift but does not stop it. A baseline only has to be a number; a critic has to tell states apart.

The animation, in eight stretches (seed 1; p(right) for REINFORCE, with baseline, actor-critic)

  1. Episode 0. All three start at p(right) = 0.05, near the ε-greedy-left policy (value −82.1), and see the same random numbers.
  2. Episodes 1 to 10. Long episodes near the left wall; every step costs −1, so every sampled action is pushed down.
  3. Episodes 11 to 50. The baselined learner and the actor-critic move first: their policy step, 2−9, is 16 times REINFORCE's 2−13.
  4. Episodes 51 to 100. The baselined learner approaches the optimum p* = 0.586 (Figure 13.2: within about 100 episodes on average over 100 runs); the actor-critic is already past it.
  5. Episodes 101 to 200. The actor-critic does not stop at the optimum: its state-blind critic credits right on every last step, so it keeps climbing.
  6. Episodes 201 to 400. The actor-critic sits on the 0.95 floor (value −44); a single baselined run wanders around the optimum, which the average over 100 runs smooths out.
  7. Episodes 401 to 700. REINFORCE at 2−13 is still climbing slowly from the left.
  8. Episodes 701 to 1,000. The end of the run:

GAE is one backward pass: each advantage is its TD error plus γλ times the next advantage

The first action's advantage Â₀ as λ moves (the dot is the current λ)

The second episode is a chain whose only reward, 1, arrives at the end, with exact values V(st) = γ7−t plus the critic error illustrative. The chain is deterministic, so every true advantage is 0 and anything else is the critic's bias: at λ = 0 the first advantage is −0.3(1 − γ) = −0.003, at λ = 1 it is −0.3 exactly (a wrong baseline shifts every advantage by the same amount without biasing the expected gradient; the λ = 0 estimate is biased through the wrong V(st+1) inside each TD error). Try: error 0 (every advantage is 0 at every λ), then 0.3, and slide λ.

6Generalised advantage estimation: λ is the bias-variance dial

Worked example (γ = 1): a three-step episode with rewards 0, 0, 1 and critic values V(s0) = 0.5, V(s1) = 0.6, V(s2) = 0.8. The TD errors are δ0 = 0.1, δ1 = 0.2, δ2 = 1 − 0.8 = 0.2. The first action's advantage is 0.1 if we trust the critic after one step (λ = 0); 0.5 if we use the whole return, 1 minus V(s0) = 0.5 (λ = 1); and 0.1 + 0.95 × 0.2 + 0.952 × 0.2 = 0.4705 at λ = 0.95 derived. Every implementation computes it backwards, one TD error at a time:

The animation, in four steps (numbers for the worked example at λ = 0.95)

  1. One TD error per step. δt = rt + γV(st+1) − V(st), with V = 0 after the last step: 0.1, 0.2 and 0.2 here. Each needs one real reward and the critic.
  2. The last step first. Nothing follows the last step, so its advantage is its own TD error, 0.2.
  3. Backwards, one step at a time. Ât = δt + γλ Ât+1: Â1 = 0.2 + 0.95 × 0.2 = 0.39. In the 8-step chain this stretch fills Â6 down to Â1.
  4. The first action's advantage. Â0 = 0.1 + 0.95 × 0.39 = 0.4705, the unrolled sum Σ (γλ)l δl. The green dashes are the λ = 1 values (return minus V); the lower chart shows Â0 at every λ.

Between the one-step TD error and the full return sits a family of k-step estimators, Â(k)t = Σl<k γl δt+l = rt + γrt+1 + ... + γk−1rt+k−1 + γkV(st+k) − V(st) (the sum telescopes). GAE (Schulman et al. 2015) averages them with weights (1 − λ)λk−1, exactly as TD(λ) averages n-step returns, and the average collapses to a discounted sum of TD errors:

ÂtGAE(γ, λ) = Σl≥0 (γλ)l δt+l   =   δt + γλ Ât+1
λ = 0
Ât = δt: one real reward, lowest variance, biased whenever V is wrong
λ = 1
Ât = Σ γl rt+l − V(st): the return minus the baseline, unbiased whatever V is, highest variance ("GAE(γ, 1) is γ-just regardless of the accuracy of V, but it has high variance")
the recursion
one backward pass over the rollout, resetting at episode ends; the critic's regression target is then Ât + V(st), the λ-return

The two parameters bias different things: "Taking γ < 1 introduces bias into the policy gradient estimate, regardless of the value function's accuracy. On the other hand, λ < 1 introduces bias only when the value function is inaccurate." The paper concludes that "choosing an appropriate intermediate value of λ in the range [0.9, 0.99] usually results in the best performance"; PPO's reference settings use λ = 0.95 with γ = 0.99 (PPO, Tables 3 and 5). The bias-variance dial itself (bias squared, variance and mean squared error against λ) is drawn on Model-free prediction and control, which owns TD(λ); this section owns its use as an advantage estimator.

The paper's best ranges, and what GAE plus TRPO learned under 1 min

Best results at intermediate values: γ ∈ [0.96, 0.99] and λ ∈ [0.92, 0.99] on cart-pole, γ ∈ [0.99, 0.995] and λ ∈ [0.96, 0.99] on the 3D biped. With it, TRPO learned 3D biped and quadruped locomotion from raw joint states, with simulated experience equal to "1-2 weeks of real time" for the bipeds (Schulman et al. 2015).

7A3C and A2C: parallel actors instead of replay

On-policy methods cannot use a replay buffer (old data comes from old policies), yet consecutive transitions of one trajectory are highly correlated, which is what made naive deep RL unstable. A3C, asynchronous advantage actor-critic (Mnih et al. 2016), decorrelates the data with many actor-learners, each with its own copy of the environment, exploring different states at the same moment and applying their gradients to shared weights asynchronously. Each uses an n-step return minus V as its advantage, plus an entropy bonus: "adding the entropy of the policy π to the objective function improved exploration by discouraging premature convergence to suboptimal deterministic policies" (weight β = 0.01 on Atari). It "surpasses the current state-of-the-art on the Atari domain while training for half the time on a single multi-core CPU instead of a GPU", with 16 actor-learner threads.

A2C is the synchronous version. OpenAI's Baselines release found "Our synchronous A2C implementation performs better than our asynchronous implementations; we have not seen any evidence that the noise introduced by asynchrony provides any performance benefit", and that it "is more cost-effective than A3C when using single-GPU machines, and is faster than a CPU-only A3C implementation when using larger policies" (OpenAI Baselines: ACKTR and A2C, 2017, Wayback copy). The parallel actors helped; the asynchrony did not (one of the root Method atlas's corrections). A batch of rollouts from parallel environments, then one update, is the shape of PPO and of every LLM RL loop since.

A3C applies each worker's gradient whenever it is ready; A2C waits for all of them and takes one batched step

Four workers, time to the right illustrative timings. Bars are n-step rollouts labelled with the version of the shared weights θ they were computed on; a tick is a gradient applied, making the version written beside it. In A3C, worker 3's second gradient was computed on θ version 4 but is applied as version 9: four other updates landed while it rolled out (stale). In A2C the faster workers idle (hatched) at the barrier, then one update averages all four.

8Natural gradients and TRPO: measure the step in policy space

Why the step size is dangerous. The policy gradient is only valid near the policy that collected the data. In supervised learning a too-large step costs one bad update; in RL the next batch is sampled from the broken policy, so the data itself degrades and training may never recover. Two goals follow: the largest step that is still safe, and several gradient steps on one expensive batch of rollouts.

The step is measured in the wrong units. Take two actions with logit difference z, so p = σ(z). From p = 0.5, a step Δz = 1 moves p to 0.731, a KL divergence of 0.120; from p = 0.99 the same step moves it to 0.996, a KL of 0.0037, 33 times less derived. Gradient ascent is not covariant: reparameterise the policy and its steps change. The fix is to measure distance by how much the action distribution changes. To second order, KL(πθ ‖ πθ+Δ) ≈ ½ Δ⊤FΔ, where F = 𝔼[∇ log π ∇ log π⊤] is the Fisher information matrix (for two actions, F = p(1 − p): 0.25 at p = 0.5, 0.0099 at p = 0.99).

Natural gradient step:   Δθ = √( 2δ / (g⊤F−1g) ) · F−1g
g
the ordinary policy gradient
F−1g
the steepest-ascent direction when distance is the KL (to second order) rather than Euclidean distance in θ
δ
the KL budget for the step; the square root scales the step so that ½ Δ⊤FΔ = δ

Kakade (2001) introduced this natural policy gradient (his words and caveat are below). In the example, a KL budget of 0.01 allows Δz = 0.283 at p = 0.5 (exact KL 0.00997) and Δz = 1.42 at p = 0.99 (exact KL 0.0066: the quadratic approximation is loose far from the centre, which is why TRPO checks the true KL with a line search) derived.

The same step in θ moves a confident policy 33 times less; a fixed KL budget rescales the step to match

Exact KL(πold ‖ πnew) of two-action policies. Defaults reproduce the text's numbers at p = 0.5; drag to 0.99 for the other pair.

TRPO, trust region policy optimisation (Schulman et al. 2015), turns this into an algorithm. With the importance ratio rt(θ) = πθ(at | st) / πθold(at | st), maximising the surrogate 𝔼t[rt(θ) Ât] has the same gradient as the policy gradient at θ = θold, and the ratio corrects for the drift as θ moves (the importance-sampling correction of Model-free prediction and control, applied to a slightly stale policy). Theory bounds how far the surrogate can mislead, but its penalty is far too conservative, so TRPO uses a hard constraint:

maxθ 𝔼t[ rt(θ) Ât ]   subject to   𝔼t[ KL(πθold(· | st) ‖ πθ(· | st)) ] ≤ δ
δ
the trust region: "We used δ = 0.01 for all experiments"
the solver
a natural-gradient direction by conjugate gradient using Fisher-vector products (no matrix is ever formed; "k = 10" iterations "to be quite effective"), then a line search that shrinks the step "until the objective improves. Without this line search, the algorithm occasionally computes large steps that cause a catastrophic degradation" (Appendix C)

It works, but the second-order machinery is heavy, and TRPO is "not compatible with architectures that include noise (such as dropout) or parameter sharing (between the policy and value function, or with auxiliary tasks)" (PPO, §1). PPO keeps the idea and drops the machinery.

Kakade's covariance argument, in his words under 1 min

"the standard gradient descent rule is non-covariant ... we present a covariant gradient by defining a metric based on the underlying structure of the policy"; and "the natural gradient is moving toward choosing a greedy optimal action rather than just a better action." He also notes that the averaged F is not fully invariant, because of the weighting by the state distribution.

TRPO's monotonic improvement bound, and its two sampling schemes 1 min

From its Theorem 1 (stated with total variation) the paper derives η(π̃) ≥ Lπ(π̃) − C · maxs KL(π ‖ π̃), with C = 4εγ / (1 − γ)2 and ε = max |Aπ(s, a)| (Eq. 9), so maximising the penalised surrogate improves the true return monotonically. The penalty coefficient that theory gives is far too conservative in practice, hence the constraint.

It tried two ways of collecting data, "single path" (ordinary rollouts) and "vine" (branching rollouts from states along a trunk, which needs a resettable simulator), and learned "simulated robotic swimming, hopping, and walking gaits; and playing Atari games using images of the screen as input".

9PPO: the trust region from a clipped first-order objective

PPO, proximal policy optimisation (Schulman et al. 2017), replaces TRPO's constraint with a pessimistic objective that plain stochastic gradient ascent can optimise. Four cases with ε = 0.2 show what it does:

Case (ε = 0.2)r Âclip(r) ÂObjective (the min)Gradient
 = +2, r = 1.53.01.2 × 2 = 2.42.4zero: already raised past 1 + ε
 = +2, r = 0.71.40.8 × 2 = 1.61.4active: a good action became less likely, so push it back up
 = −1, r = 0.7−0.70.8 × (−1) = −0.8−0.8zero: already lowered past 1 − ε
 = −1, r = 1.5−1.51.2 × (−1) = −1.2−1.5active: a bad action became more likely, so push it back down
LCLIP(θ) = 𝔼t[ min( rt(θ) Ât,  clip(rt(θ), 1 − ε, 1 + ε) Ât ) ]
clip(x, 1 − ε, 1 + ε)
forces the ratio into that interval
ε
the clip range; among 0.1, 0.2 and 0.3 on the continuous-control tasks 0.2 did best; the Atari runs used 0.1 × α with α annealed linearly from 1 to 0
min
takes the more pessimistic of the clipped and unclipped terms, so clipping can only remove an incentive, never add one

A ratio that moved the wrong way (down for a good action, up for a bad one) is never clipped: the unclipped term is the smaller one there, so the full gradient pulls it back. The clip removes the incentive to exploit further; it never stops the correction of a mistake.

The objective goes flat only on the side the advantage wants to push; a wrong-way move keeps its full gradient

 = +1 (a good action)
 = −1 (a bad action)
LCLIP (the min)unclipped r·Âclip(r)·Â1 ± ε

The dot is grey where the gradient is zero. Try r = 0.7 (the good action's objective still slopes, the bad action's is flat), then 1.5 (the reverse).

The same sample, ten epochs, with and without the clip: the clip stops the push, it does not cap the ratio

The objective against the ratio
The ratio, epoch by epoch

A softmax policy over three actions with starting logits (0, 0.5, −0.5), one sampled action (probability 0.307 under the old policy), its advantage, and plain gradient ascent on the surrogate for ten epochs illustrative. Raise η and the clipped run overshoots 1 + ε on its first step and then stops: the clip removes the incentive, it does not bound the ratio, which is why practitioners also watch the KL and the fraction of clipped samples.

What makes the min useful is reuse: several epochs of minibatch SGD on each batch of rollouts (10 epochs in the paper's MuJoCo runs, 3 on Atari). Before and after, on one sample:

Predict: raise the step size η to 0.6 with the clip on. Does the ratio stay inside 1 ± ε?

The animation, in four steps (numbers at ε = 0.2, η = 0.2)

  1. Epoch 0. Before any update the policy is the one that sampled, so the ratio is 1 and both objectives agree.
  2. Epoch 1. Both runs take the same first step (ratio 1.160 for  = +1, 0.852 for  = −1): inside the band the clipped objective has the unclipped one's gradient.
  3. Epoch 2. The ratio reaches 1.343 (or 0.730), past 1 ± ε: the clipped objective goes flat and the clip run stops, after a step that already overshot the band.
  4. Epochs 3 to 10. Without the clip the ratio keeps going (2.632, or 0.291, by epoch 10), pushing one sampled action's probability on the strength of a single advantage estimate.

The full loss. With a network shared between policy and value, PPO maximises LCLIP+VF+S = 𝔼t[LCLIP − c1(Vθ(st) − Vtargt)2 + c2 S[πθ](st)]: a value regression term and an entropy bonus S. The algorithm: N parallel actors each run the policy for T steps, compute truncated GAE advantages, optimise the loss for K epochs with minibatches, repeat. In the paper's ablation (7 MuJoCo tasks), no clipping or penalty scored −0.39 against 0.82 for the clip at ε = 0.2, with KL penalties in between (details below). Its practical success made it the default on-policy algorithm (in Stable-Baselines3, CleanRL and verl; OpenAI Five was trained with it) and the template that RLHF and GRPO adapt (RL for LLMs).

PPO is on-policy, approximately
It reuses each batch for several epochs, and the ratio corrects for the drift within those epochs; it cannot learn from data collected by much older policies, and the batch is thrown away afterwards. That is the "approximately on-policy" cell of the root's Method atlas, and the reason PPO needs far more environment steps than the off-policy methods below.
The KL-penalty variant and the paper's ablation (Table 1) 1 min

The paper also tried a soft version of TRPO's constraint, maximising 𝔼[rt Ât − β KL(πold ‖ πθ)] with β either fixed or adapted after each update toward a target KL dtarg: "If d < dtarg/1.5, β ← β/2; If d > dtarg × 1.5, β ← β × 2" ("chosen heuristically, but the algorithm is not very sensitive to them"). Table 1: 7 MuJoCo tasks, 3 seeds each, one million timesteps, scores normalised so a random policy is 0 and the best result 1.

VariantNormalised score
No clipping or penalty−0.39
Clipping, ε = 0.1 / 0.2 / 0.30.76 / 0.82 / 0.70
Adaptive KL, dtarg = 0.003 / 0.01 / 0.030.68 / 0.74 / 0.71
Fixed KL, β = 0.3 / 1 / 3 / 100.62 / 0.71 / 0.72 / 0.69

The unclipped score is negative "because for one environment (half cheetah) it leads to a very negative score" (PPO, §6.1, Table 1).

The paper's settings, and the Atari result 1 min
PPO paper settingsMuJoCo (Table 3)Atari (Table 5)
Horizon T2048128
Adam step size3 × 10−42.5 × 10−4 × α
Epochs K103
Minibatch6432 × 8
γ, λ0.99, 0.950.99, 0.95
Parallel actorsnot listed8
Clip ε0.20.1 × α
c1, c2separate networks, no entropy bonus1, 0.01

On 49 Atari games, PPO had the best average reward over all of training in 30 games (ACER 18, A2C 1), but the best over the last 100 episodes in only 19 (ACER 28, A2C 1, one tie) (Table 2): PPO learns fast and simply rather than reaching the highest final scores.

10What actually makes PPO work: the implementation

PPO's paper describes an objective; its results come from an implementation. Engstrom et al. (2020) isolated nine "code-level optimisations" in the reference code and found they "are responsible for most of PPO's gain in cumulative reward over TRPO": with them, TRPO ("TRPO+") matched or beat PPO. And the clip does not do what its name suggests: "all three algorithms fail to maintain a ratio-based trust region, despite PPO and PPO-M being trained directly with a ratio-clipping objective", although all keep a KL-based one. Their summary: "code-level optimizations contribute to algorithms' increased performance often significantly more than the choice of algorithm."

What to watch while PPO trains
Approximate KL between old and new policy per update (a sudden jump means the step is too large); clip fraction (the share of samples whose ratio left 1 ± ε; a steady rise means the policy is moving further per batch); policy entropy (a collapse to near zero means exploration has stopped); explained variance of the critic (near 0 or negative means the advantages are mostly noise). These are the "debug variables" of detail 12 below, and the same four are watched in LLM RL.

Seeds. Deep RL results vary so much across random seeds that one run misleads: Henderson et al. (2018) split ten TRPO runs on HalfCheetah into two groups of five seeds and got significantly different curves (t = −9.09, p = 0.0016): "the variance between runs is enough to create statistically different distributions just from varying random seeds." Report interquartile means with bootstrap intervals (below).

Engstrom et al.'s nine optimisations and their numbers under 1 min

Value function clipping, reward scaling, orthogonal initialisation and layer scaling, Adam learning-rate annealing, reward clipping, observation normalisation, observation clipping, tanh activations, global gradient clipping. On Hopper, PPO 2513, PPO without them ("PPO-M") 2142, TRPO 2043, TRPO+ 2466; on Humanoid TRPO+ 1030 against PPO's 806 (Engstrom et al. 2020).

The 13 core implementation details (Huang et al. 2022) 1 min

Huang et al., "The 37 Implementation Details of Proximal Policy Optimization" (ICLR blog track, 2022) reproduced the official code detail by detail: 13 core details, 9 for Atari, 9 for continuous actions, 5 for LSTMs and 1 for multi-discrete actions. The 13 core ones:

  1. Vectorised environments (many copies stepped together; the rollout is N × T)
  2. Orthogonal initialisation of weights, constant initialisation of biases (policy output layer scaled by 0.01, value output by 1)
  3. Adam's epsilon parameter (1e-5 in the reference code, not PyTorch's default 1e-8)
  4. Adam learning-rate annealing to 0
  5. Generalised advantage estimation, with correct handling of episode ends and of truncation at the rollout's end (bootstrap from V)
  6. Minibatch updates over shuffled indices
  7. Normalisation of advantages, per minibatch
  8. The clipped surrogate objective
  9. Value function loss clipping
  10. The overall loss and entropy bonus
  11. Global gradient clipping (norm 0.5)
  12. Debug variables: approximate KL, clip fraction, explained variance
  13. Shared or separate networks for policy and value
What 250,000 agents recommend (Andrychowicz et al. 2021), and how to report seeds 1 min

The largest study, Andrychowicz et al. (2021), trained "over 250'000 agents in five continuous control environments" across more than 50 choices. Its recommendations: "Use the PPO policy loss. Start with the clipping threshold set to 0.25"; "Initialize the last policy layer with 100× smaller weights" and use softplus for the standard deviation; "Always use observation normalization"; "Use GAE with λ = 0.9 but neither Huber loss nor PPO-style value loss clipping"; the discount γ "is one of the most important hyperparameters and should be tuned per environment (start with γ = 0.99)"; and Adam with 0.0003 as "a safe default".

Agarwal et al. (2021) recommend "interval estimates via stratified bootstrap confidence intervals, as opposed to point estimates", and the interquartile mean, which "discards the bottom and top 25% of the runs".

11Deterministic policy gradients and DDPG

For a robot arm the action is a vector of torques, and Q-learning's max over actions becomes an optimisation problem at every step. The off-policy actor-critics train an actor that performs the max. Their theory is the deterministic policy gradient (Silver et al. 2014): for a deterministic policy a = μθ(s),

∇θ J(μθ) = 𝔼s~ρμ[ ∇θ μθ(s) · ∇a Qμ(s, a) |a=μθ(s) ]
∇aQ
the critic's slope: which way to nudge the action to make it better
∇θμ
the chain rule through the actor: how to change θ to move the action that way

There is no log-probability and no integral over actions, only over states, so "the deterministic policy gradient can be estimated much more efficiently than the usual stochastic policy gradient", and it is "the limiting case, as policy variance tends to zero, of the stochastic policy gradient" (Theorem 2). Because the expectation is only over states, it can be learned from data gathered by any exploratory behaviour policy, without importance ratios on actions.

Fig. 11 · one loop serves DDPG, TD3 and SAC: replay feeds a critic, the critic's slope trains the actor, slow target copies make the critic's target

DDPG: the critic regresses onto y = r + γQ′(s′, μ′(s′)); the actor climbs the critic's slope ∇ₐQ through the chain rule; exploration is noise added to the action; the targets follow the learned networks slowly (τ = 0.001).

  1. Act. The actor turns the state into an action and exploration perturbs it: Ornstein-Uhlenbeck noise in DDPG, 𝒩(0, 0.1) in TD3's paper, a sample from the tanh Gaussian in SAC.
  2. Store. The environment returns r and s′; the transition (s, a, r, s′) goes into a replay buffer of 106, where it can be reused many times by any later policy.
  3. Sample a minibatch. Random transitions (64 in DDPG, 100 in TD3's paper, 256 in SAC) break the correlation of consecutive steps.
  4. Build the target from slow copies. DDPG: y = r + γQ′(s′, μ′(s′)). TD3: the smaller of two target critics, with clipped noise on the target action. SAC: the smaller of two, minus α log π(a′ | s′). The critics regress onto y.
  5. Train the actor through the critic. DDPG and TD3 climb the critic's slope ∇aQ(s, μ(s)) by the chain rule (TD3 only every d = 2 critic steps); SAC's gradient of α log π − Q flows through the reparameterised sample a = tanh(μ + σξ).
  6. Let the targets follow slowly. θ′ ← τθ + (1 − τ)θ′, with τ = 0.001 in DDPG and 0.005 in TD3 and SAC; SAC also moves α toward its target entropy.

DDPG, deep deterministic policy gradient (Lillicrap et al. 2015), put this on networks with DQN's two stabilisers: a replay buffer (106 transitions) and target networks, here updated softly, θ′ ← τθ + (1 − τ)θ′ with τ = 0.001. The critic regresses onto r + γQ′(s′, μ′(s′)); the actor climbs ∇aQ; exploration is noise added to the actor's output. It "robustly solves more than 20 simulated physics tasks", nearly all "within 2.5 million steps of experience (and usually far fewer), a factor of 20 fewer steps than DQN requires" for Atari. In practice it proved brittle and sensitive to its settings, which is what TD3 set out to fix. (Replay and target networks are explained on Value-based deep RL.)

DDPG's paper settings under 1 min

Exploration by an Ornstein-Uhlenbeck process with θ = 0.15, σ = 0.2; Adam with learning rates 10−4 (actor) and 10−3 (critic); L2 weight decay 10−2 on the critic; γ = 0.99; minibatch 64; batch normalisation.

12TD3: three fixes for overestimation

The maximisation bias of Q-learning (the max of noisy estimates is biased upwards) does not need an explicit max: an actor trained to climb a noisy critic finds and exploits the critic's overestimates just as well. Fujimoto, van Hoof and Meger (2018) showed "this problem persists in an actor-critic setting" and fixed DDPG with three changes (switch Fig. 11 to TD3):

  1. Clipped double Q-learning. Two critics; the target uses the smaller: y = r + γ mini=1,2 Qθ′i(s′, πφ′(s′) + ε). For two independent unbiased estimates with noise σ, 𝔼[min] = −σ/√π ≈ −0.56σ below the truth, where 𝔼[max] is +0.56σ above derived: deliberately pessimistic, because "underestimated actions will not be explicitly propagated" through the policy update; the actor moves away from them.
  2. Delayed policy updates. Update the actor (and the target networks) once every d = 2 critic updates, so the actor climbs a critic whose error has had time to fall.
  3. Target policy smoothing. Add clipped noise to the target action, ε ~ clip(𝒩(0, 0.2), −0.5, 0.5), so the target averages the critic over a small neighbourhood and a narrow spurious peak cannot be exploited.
TD3's paper settings against the authors' current code under 1 min

Paper: exploration noise 𝒩(0, 0.1), τ = 0.005, Adam 10−3, minibatch 100, and purely random actions for the first 10,000 steps (HalfCheetah, Ant) or 1,000 (the others). The authors' current code uses batch 256, learning rate 3 × 10−4 and 25,000 random steps, and its README warns it is "no longer exactly representative of the code used in the paper" (sfujim/TD3).

13SAC and maximum-entropy RL

SAC, soft actor-critic (Haarnoja et al. 2018a; 2018b), changes the objective: maximise reward and the policy's entropy. A policy split evenly between two actions has entropy ln 2 ≈ 0.693, worth 0.2 × 0.693 ≈ 0.139 reward per step at α = 0.2; a deterministic policy earns nothing derived.

J(π) = Σt 𝔼[ r(st, at) + α ℋ(π(· | st)) ],   ℋ(π(· | s)) = −𝔼a~π[ log π(a | s) ]
ℋ
the entropy of the action distribution (a sum for discrete actions, an integral for continuous ones)
α
the temperature: how much randomness is worth relative to reward

The entropy enters the Bellman equation too: the soft value is V(s) = 𝔼a~π[Q(s, a) − α log π(a | s)] and the critic's target is r + γ𝔼[V(s′)], with the minimum of two Q networks as in TD3. Policy improvement moves π toward the Boltzmann distribution of the critic, πnew = arg minπ′ KL(π′(· | s) ‖ exp(Q(s, ·)/α) / Z(s)); in practice the actor minimises 𝔼[α log π(a | s) − Q(s, a)] with actions drawn by the reparameterisation trick, a = tanh(μ(s) + σ(s) ⊙ ξ), ξ ~ 𝒩(0, I), so the gradient flows through the sampled action into the critic ("a lower variance estimator" than the score function). The tanh keeps actions bounded and changes the density: log π(a | s) = log μ(u | s) − Σi log(1 − tanh2(ui)) (Appendix C), a correction that implementations forget at their peril.

The temperature is learned. The 2018b version adjusts α so that the policy's entropy stays near a target ℋ̄, minimising J(α) = 𝔼[−α log π(a | s) − αℋ̄]; its gradient is ℋ(π) − ℋ̄, so α falls while the policy is more random than the target and rises when it is less. The default target is "−dim(A) (e.g., −6 for HalfCheetah-v1)". The widget shows what α does on a one-dimensional action illustrative reward, exact computation: a tall narrow reward peak at +0.6, a lower wide one at −0.5, and an effort cost 0.5a2. For each α it computes the soft-optimal policy exp(r/α)/Z and the best Gaussian actor (the maximiser of 𝔼[r] + αℋ over all Gaussians, SAC's projection onto its policy class).

Predict: as α rises from 0.005, does the best Gaussian widen smoothly on the tall peak, or jump?

The paper's claim is stability as much as sample efficiency: "in contrast to other off-policy algorithms, our approach is very stable, achieving very similar performance across different random seeds" (2018a). Entropy bonuses and KL penalties toward a reference policy play the role of α ℋ in LLM training, keeping the policy from collapsing onto one mode; a KL to a fixed reference pulls toward a particular distribution, not toward uniform, so it is not the same thing (RL for LLMs covers each there).

Real robots, and SAC's default settings under 1 min

A Minitaur quadruped "learns to walk from 160k environment steps, or approximately 400 episodes ... approximately 2 hours of real-world training time", and a 3-finger dexterous hand learned to turn a valve from camera images in about 300,000 steps, "the equivalent of 20 hours of training" (from the valve's position alone, 3 hours, against 7.4 hours for PPO) (2018b, §7). Its settings are the defaults most libraries copied: Adam 3 × 10−4, γ = 0.99, replay 106, minibatch 256, τ = 0.005, two hidden layers of 256 units.

Raise the temperature and the best Gaussian jumps from the tall narrow peak to the wide one

Below about 0.16 the best Gaussian sits narrowly on the tall peak; just above, it jumps to the wide peak, where it can be much wider for little lost reward; by α ≈ 0.3 it covers both. The soft-optimal policy (purple) changes smoothly and is bimodal in between: a single Gaussian cannot represent it, which is the price of SAC's policy class. Expected rewards and entropies are exact (closed form for the Gaussian, an 801-point grid for the soft-optimal policy); the Gaussian is found on a 481 × 241 grid of means and widths.

14Continuous control in practice

  • The Gaussian head. A network outputs the mean of each action dimension; dimensions are independent (the log-probability is the sum over dimensions). PPO's reference code keeps a state-independent log standard deviation, a learned vector initialised to 0; SAC outputs a state-dependent one. Andrychowicz et al. found the two "very close" (37 details, continuous section).
  • Bounded actions. PPO's reference code clips the sampled action when stepping the environment but stores and trains on the unclipped sample; SAC squashes with tanh and corrects the density. Andrychowicz et al. found tanh squashing better.
  • Normalise observations and scale rewards. Running mean and variance for observations, clipped to [−10, 10]; rewards divided by the standard deviation of a running discounted return, also clipped. Engstrom et al. found reward scaling "can significantly affect" results.
  • On-policy or off-policy. PPO is simple, robust to settings and parallelises over many simulators, but discards every batch after a few epochs. SAC and TD3 reuse every transition from replay many times and need far fewer environment steps, which matters when the environment is a real robot.
Stable-Baselines3 defaults for PPO and SAC under 1 min

PPO: 2,048 steps per rollout, 10 epochs of minibatch 64, γ 0.99, λ 0.95, clip 0.2, value coefficient 0.5, gradient norm 0.5, learning rate 3 × 10−4 and no entropy bonus. SAC: a 106 buffer, minibatch 256, τ 0.005, automatic α with target −dim(A), learning starts after 100 steps (SB3 PPO, SB3 SAC).

15Which method when

SituationStart withWhy, and what it costs
Any action space, cheap parallel simulation, stability firstPPOSimple, robust to settings, first-order; on-policy, so it spends many environment steps
Continuous control, samples expensive (a real robot)SAC, or TD3Off-policy replay buys sample efficiency; more moving parts (twin critics, target networks, a temperature)
A stochastic policy is required, or states are aliasedAny stochastic policy-gradient methodGreedy value methods cannot represent a specific probability (the short corridor)
Need a guaranteed small step, compute is not the constraintTRPO or a natural-gradient methodThe KL constraint is explicit; second-order machinery and no parameter sharing
A teaching or debugging baselineREINFORCE with a learned baseline, or A2CFew parts, unbiased (REINFORCE) or low-variance (A2C); slow
Discrete actions and replay matters mostThe DQN familySee Value-based deep RL
Post-training a language modelPPO with a value model, or GRPO, RLOO and their correctionsSee RL for LLMs

On language models, PPO with a learned reward and a value model is the RLHF recipe; GRPO and RLOO delete the critic and use a group baseline, and the clip, the KL and the ratio all return in token form (RL for LLMs owns that, including the 2025 to 2026 corrections to GRPO). Beyond this page: AlphaZero's network is an actor-critic (a policy head and a value head) trained by search rather than by a policy gradient (Model-based RL and planning); offline actor-critics (CQL, IQL) and behaviour cloning learn with no interaction (Offline RL and imitation).

Depth

Eleven misconceptions, each answered by a section above 2 min
  • "A baseline biases the gradient." Any baseline that depends only on the state leaves it unbiased (section 4); one that depends on the action taken would bias it.
  • "The value function is the best baseline." It is the natural one and close to the best, but the variance-minimising constant is the score-weighted mean of the returns, which differs from V whenever the score vectors differ in length (Greensmith et al. 2004).
  • "REINFORCE with a learned baseline, RLOO and GRPO are actor-critic methods." Their baseline is computed before the action and never bootstraps from the next state, so it cannot assess the action (Sutton and Barto §13.5).
  • "A critic is always an improvement." It trades variance for bias; a critic that cannot tell states apart turns the trade into failure (the short corridor's actor-critic drifts to −44 while baselined REINFORCE finds −11.7).
  • "PPO's clip bounds the ratio." It bounds only the incentive. The ratio can leave [1 − ε, 1 + ε] during several epochs (Engstrom et al. found PPO does not keep a ratio-based trust region), and the gradient that corrects a wrong-way move is never clipped.
  • "PPO is on-policy, so it cannot reuse data." It reuses each batch for several epochs; the ratio corrects for the drift. It cannot use data from much older policies.
  • "PPO beats TRPO because of the clipped objective." Engstrom et al. attribute most of the gap to code-level optimisations.
  • "A3C works because its actors are asynchronous." The synchronous A2C performed as well or better.
  • "Off-policy means offline." DDPG, TD3 and SAC interact with the environment online and learn off-policy from a replay buffer; learning from a fixed dataset with no interaction is offline RL (Offline RL and imitation).
  • "Entropy bonuses are a hack." In SAC the entropy is part of the objective, with a temperature learned toward a target entropy.
  • "The policy gradient needs a model of the environment." The dynamics drop out of ∇ log p(τ) (section 2).

Why can DQN or SAC use a replay buffer but A2C cannot without corrections? Their targets do not depend on which policy chose the stored action (Q-learning's max, SAC's soft value under the current policy). A policy gradient is an expectation under the current policy, so stale data needs importance ratios, which PPO uses for slightly stale data only.