03 · Actor-Critic & GAE
What you're learning
How to turn the policy gradient of lessons 01–02 into a low-variance, online algorithm by learning a value function alongside the policy — and how Generalized Advantage Estimation gives you a single knob to trade bias against variance in the advantage estimate. By the end you should be able to derive from the TD error and compute it by hand for a short trajectory.
1. Learning map
graph TD A["Policy gradient<br/>∇J = E[∇log π · A]<br/>(lesson 02)"] --> B["Advantage A_t<br/>needs an estimate"] B --> C["Monte Carlo return<br/>unbiased, high variance"] B --> D["Bootstrapped / TD<br/>biased, low variance"] C --> E["Bias–variance tradeoff"] D --> E D --> F["Learn a critic V_φ<br/>= actor-critic"] F --> G["TD error δ_t<br/>= 1-step advantage"] G --> H["n-step returns<br/>interpolate MC ↔ TD"] H --> I["GAE(γ,λ)<br/>exponential avg of n-step"] E --> I F --> J["Critic loss<br/>regress V_φ → returns"] I --> K["Actor-critic update loop"] J --> K K --> L["RLHF-PPO<br/>value head + token-level GAE"] L --> M["Critic-free methods<br/>GRPO — lesson 09"] style F fill:#4a4,color:#fff style I fill:#44a,color:#fff style L fill:#a44,color:#fff
Path: advantage needs estimating → MC vs TD are the two extremes → learn a critic to bootstrap → TD error is the 1-step case → n-step interpolates → GAE is the right exponential interpolation → train the critic → assemble the loop → apply to LLMs.
2. Why this matters
Lesson 02 left us with the policy gradient in its advantage form:
The whole game is now the quality of your estimate of the true advantage . Everything else is fixed.
If you estimate with the Monte Carlo return minus a baseline (REINFORCE-with-baseline), the estimate is unbiased but its variance grows with the horizon: a single reward at perturbs the credit assigned to every earlier action. Gradients become noisy, learning is slow and sample-hungry.
The actor-critic insight: learn a value function and use it to bootstrap — replace far-future sampled rewards with the critic’s prediction. This slashes variance (you stop summing hundreds of noisy reward terms) at the cost of some bias (the critic is imperfect). GAE then makes the bias-variance tradeoff continuous and controllable with one hyperparameter.
The one-sentence version
Actor-critic = “use a learned to shorten the horizon you have to sample over”; GAE = “don’t commit to one horizon — take an exponentially-weighted average over all of them.”
3. The actor-critic idea
Two learned components, trained jointly1:
- Actor — the policy. Updated by policy gradient.
- Critic — a learned estimate of the state-value . Updated by regression.
The critic serves two jobs at once:
- Baseline — subtracting from the return reduces variance without introducing bias (any function of alone is a valid baseline, since ).
- Bootstrap — lets us truncate the sampled return and substitute a prediction for the tail, which is where the variance reduction beyond a plain baseline comes from.
Baseline vs bootstrap are different mechanisms
Using purely as a baseline () keeps the estimate unbiased but still has MC-level variance in . The extra variance reduction of actor-critic comes from bootstrapping — replacing the sampled tail with . That substitution is what introduces bias. Don’t conflate the two roles.
Why bootstrapping reduces variance
The MC return is a sum over many random rewards; each future reward’s stochasticity (from policy, transitions, reward noise) adds to . Bootstrapping after steps,
replaces the infinite noisy tail with a single (nearly) deterministic function evaluation. Fewer random terms → lower variance. But in general, so you inherit the critic’s approximation error as bias.
4. The bias-variance tradeoff in advantage estimation
Define the -step advantage estimator:
The two endpoints:
| Estimator | Bias | Variance | |
|---|---|---|---|
| 1-step TD | high (leans on immediately) | low | |
| -step | medium | medium | |
| Monte Carlo | zero (if episodic, term vanishes) | high |
Intuition: the more real rewards you sum before bootstrapping, the closer to unbiased (you trust the sampled signal, not the critic) but the noisier (more random terms).
Quiz: Why is the (Monte Carlo) estimator unbiased regardless of how bad is?
Answer
As in an episodic task, the bootstrap term (either or the episode terminates with ). The estimator collapses to . The subtracted is a pure baseline — a function of only — so it drops out of the expected gradient without adding bias. All the critic-dependence that could bias the estimate lives in the bootstrap term, which has vanished. Hence unbiased. The price is that retains full MC variance.
5. The TD error as a 1-step advantage
The temporal-difference error is:
This is exactly : the 1-step return minus the current-state value baseline .
Key fact: if (the true value function), then is an unbiased estimator of the advantage :
In practice , so is biased — this is the “TD is biased” statement made precise. It’s low-variance because it involves only one sampled reward.
is the atom
Everything in GAE is built out of TD errors. The -step advantage telescopes into a sum of discounted TD errors:
Check the case by hand: . The intermediate terms cancel — a telescoping sum.
6. Generalized Advantage Estimation (GAE)
We have a whole family trading bias for variance. Which do you pick? Schulman et al. (2015, arXiv:1506.02438) answer2: don’t pick — take an exponentially-weighted average over all , with decay .
Define GAE as the -weighted average of the -step estimators:
The normalizer makes the weights sum to 1. Now substitute the telescoped form and swap the order of summation. Each TD error appears in every with , so its total weight is . This collapses beautifully:
A discounted sum of future TD errors — with the same exponential form as the return itself, but discount instead of . It computes in one backward pass:
is the bias-variance knob
- : — pure 1-step TD. Low variance, high bias (fully trusts ).
- : (the full telescope) — pure Monte Carlo advantage. High variance, low bias.
- : smooth interpolation.
and play distinct roles: controls how far-sighted the objective is (and adds bias by downweighting distant true rewards); controls how much you trust the critic vs. sampled rewards for a fixed objective. Typical values: , .2
is not "just a smaller discount"
It’s tempting to see and think you’ve merely lowered the discount. But the summand is the TD error , not a reward . Each already contains a bootstrap . Lowering downweights distant TD corrections, i.e. leans harder on the earliest bootstrap — that’s a bias choice, not a myopia choice.
Quiz: What does control, and what happens to bias and variance at and ?
Answer
is the bias-variance tradeoff knob for the advantage estimate — it sets the exponential decay rate on how much weight future TD errors receive, i.e. how far you sample real rewards before leaning on the critic’s bootstrap.
- : , the 1-step TD estimate. Minimum variance, maximum bias (relies entirely on after one step).
- : , the Monte Carlo advantage. Maximum variance, minimum bias (only enters, as a pure baseline).
In between you interpolate. Note this bias is w.r.t. the -discounted objective; already introduces its own bias relative to the undiscounted return.
Quiz: Derive why GAE at equals the Monte Carlo advantage .
Answer
Set : . Expand and telescope:
Group the value terms: from term , and from term . They cancel pairwise for all , leaving only from the first term. The reward terms sum to . Result: . ∎
7. Training the critic
The actor uses ; the critic must be trained so those advantages are meaningful. Two common targets:
Target 1 — bootstrapped -return (consistent with GAE). The value target that pairs naturally with GAE is
so the critic regresses toward its own advantage-corrected estimate. Loss:
Target 2 — Monte Carlo returns. Simpler: regress directly onto the empirical return . Unbiased target but high-variance, so slower critic learning.
Stop-gradient on the value target
is computed from the old critic (and old GAE) and treated as a constant — you do not backprop through it. Otherwise you get a moving-target instability where the network chases its own bootstrap. In practice the targets (“returns”) are computed once per rollout batch and detached.
PPO's clipped value loss
8. Putting it together: the actor-critic loop
graph TD A["Rollout: run π_θ<br/>collect (s_t, a_t, r_t)"] --> B["Critic forward:<br/>V_φ(s_t) for all t"] B --> C["Compute TD errors<br/>δ_t = r_t + γV(s_{t+1}) − V(s_t)"] C --> D["GAE backward pass<br/>Â_t = δ_t + γλ·Â_{t+1}"] D --> E["Value targets<br/>V_t^targ = Â_t + V_φ(s_t)"] D --> F["Actor loss<br/>−E[log π_θ(a_t|s_t)·Â_t]<br/>(Â_t detached)"] E --> G["Critic loss<br/>½E[(V_φ(s_t) − V_t^targ)²]"] F --> H["Backprop → update θ (and φ)"] G --> H H --> A style D fill:#44a,color:#fff style F fill:#4a4,color:#fff style G fill:#a44,color:#fff
Per iteration:
- Collect a rollout with the current policy.
- Evaluate at every visited state.
- Compute , then by the backward recursion.
- Update the actor with (advantages detached — they’re targets, not differentiated through).
- Update the critic by regressing .
Advantages are usually normalized (subtract mean, divide by std over the batch) before the actor update — a variance-reduction trick that stabilizes the gradient scale.4
Shared vs separate networks
Actor and critic can share a trunk with two heads (common at LLM scale, where the trunk is the transformer) or be fully separate. Sharing saves compute but couples the two losses — you need a coefficient on the value loss to balance them: (the last term is an entropy bonus for exploration).
9. LLM connection: GAE in RLHF-PPO
This is where actor-critic hits frontier practice. In classic RLHF-PPO (InstructGPT-style)5:
- Actor = the LLM policy , generating tokens autoregressively. Each token is an action ; the state is the prompt + tokens generated so far.
- Critic = a value head — usually a linear layer on top of the (shared or separately-copied) transformer backbone — outputting a scalar per token position.
- Reward is sparse: the reward model scores the whole completion, giving a single scalar at the final token. To this, a per-token KL penalty against the reference policy is added at every position:
GAE then converts this token-level reward-plus-penalty stream into token-level advantages via the exact same backward recursion. This is what lets the sequence-level reward propagate credit back to individual tokens: the terminal RM reward flows backward through -discounted TD errors, while the dense KL penalty shapes every step.
Why the value head is expensive at LLM scale
The critic is (roughly) a second model the size of the policy. Even as a value head on a shared trunk, PPO typically keeps a separate frozen reference model and a reward model in memory too — up to four large networks (policy, critic, reward, reference) during training.5 The critic also needs its own warmup and can be hard to fit well (value estimation over long token sequences with sparse reward is noisy). This memory + tuning burden is a major practical pain point.
Teaser — critic-free methods (lesson 09)
The cost of the value network motivates critic-free RLHF. GRPO (Group Relative Policy Optimization) drops entirely: instead of a learned baseline, it samples a group of completions per prompt and uses the group’s mean reward as the baseline, with advantages . No critic, no value head, no GAE — just Monte Carlo returns with a batch-computed baseline.6 We’ll dissect the tradeoffs in 09-rl-for-reasoning.
10. Practice problems
Practice problem 1: Compute GAE for a 3-step trajectory
Problem: A trajectory has three transitions. Rewards . Critic values (terminal). Use , . Compute and then .
Worked solution:
TD errors (, so ):
Backward recursion with :
Check via the direct sum: . ✓
Sanity: at this would be (pure MC advantage); at it would be (pure TD). Our answer sits between — as it must.
Practice problem 2: Diagnose a variance blow-up
Problem: You’re training PPO on a 1000-token generation task with sparse terminal reward. You set . Training is unstable with huge gradient variance. Explain mechanistically why, and what single knob you’d turn first.
Worked solution:
At , — pure Monte Carlo. With a sparse terminal reward and a 1000-step horizon, every token’s advantage depends on the entire future reward stream (the single terminal RM score plus 1000 KL terms). The estimator is unbiased but its variance scales with the horizon: one noisy completion perturbs the credit assigned to all 1000 tokens identically. The critic is only being used as a per-token baseline, not to shorten the effective horizon — so you get none of actor-critic’s variance reduction.First knob: lower (e.g. to ). This reintroduces bootstrapping: distant TD errors get downweighted by , so each token’s advantage leans on the (lower-variance) critic prediction for the far future instead of summing 1000 noisy terms. You accept a little bias from the imperfect in exchange for a large variance reduction. (Secondary: normalize advantages, and consider .)
11. Reading order
Work through these in order:
- Primary source: High-Dimensional Continuous Control Using Generalized Advantage Estimation — Schulman et al. 2015 (arXiv:1506.02438) — the GAE paper. Read Sections 2–3 for the derivation; the collapse is Eq. (16).
- Textbook grounding: Sutton & Barto, Reinforcement Learning: An Introduction (2nd ed.), Ch. 13.5 (actor-critic methods) and Ch. 12 (eligibility traces / -returns — GAE is the policy-gradient analogue of TD()).
- Implementation view: OpenAI Spinning Up — Vanilla Policy Gradient & the GAE-Lambda advantage — read the pseudocode and the
compute_gae/ discounted-cumsum trick. - LLM application: the InstructGPT paper (Ouyang et al. 2022) and any modern PPO-RLHF codebase (e.g. TRL’s
PPOTrainer) — trace how the value head and token-level GAE are wired.
12. What’s next
- 04-ppo — GAE is the advantage estimator inside PPO; next we add the clipped surrogate objective and trust-region intuition that make the actor update stable.
- 02-policy-gradients — revisit if the advantage form of the gradient or the baseline-doesn’t-bias argument felt shaky; GAE only makes sense on that foundation.
- 09-rl-for-reasoning (teaser above) — how dropping the critic entirely and using a group baseline trades the GAE machinery for sampling cost.
References
Reference topic: rl-for-llms | Filed: 2026-09-02
Footnotes
-
Sutton & Barto, Reinforcement Learning: An Introduction (2nd ed., 2018). Ch. 13.5 (actor–critic methods) for the actor/critic decomposition and baseline argument; Ch. 12 (eligibility traces / TD() and -returns), of which GAE is the policy-gradient analogue. ↩
-
Schulman, Moritz, Levine, Jordan, Abbeel (2015). “High-Dimensional Continuous Control Using Generalized Advantage Estimation.” arXiv:1506.02438. GAE origin; the collapse is Eq. (16), and the reported experiments use , . ↩ ↩2
-
Schulman, Wolski, Dhariwal, Radford, Klimov (2017). “Proximal Policy Optimization Algorithms.” arXiv:1707.06347. ↩
-
Engstrom et al. (2020), “Implementation Matters in Deep Policy Gradients: A Case Study on PPO and TRPO,” arXiv:2005.12729; and Huang et al. (2022), “The 37 Implementation Details of Proximal Policy Optimization,” ICLR Blog Track (https://iclr-blog-track.github.io/2022/03/25/ppo-implementation-details/). Cover the value-loss clipping heuristic and per-minibatch advantage normalization as code-level details that materially affect PPO performance. ↩ ↩2
-
Ouyang et al. (2022). “Training language models to follow instructions with human feedback” (InstructGPT). arXiv:2203.02155. The canonical RLHF-PPO setup: LLM policy + value head, per-token KL-to-reference penalty, and the policy/critic/reward/reference model configuration. ↩ ↩2
-
Shao et al. (2024). “DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models.” arXiv:2402.03300. Introduces GRPO (Group Relative Policy Optimization): drops the value function and uses the standardized group mean reward as the baseline. [recent] ↩