High-Dimensional Continuous Control Using Generalized Advantage Estimation (GAE)
Read first: Actor–critic methods and the advantage function
TL;DR. Policy gradients need an advantage estimate for every step. The one-step TD error is low-variance but trusts the critic completely. The Monte Carlo advantage trusts only real rewards but is noisy. Generalized Advantage Estimation takes an exponentially weighted sum of TD errors, , so a single knob λ slides between the two. It is one backward pass over the trajectory, and it is the advantage estimator inside almost every PPO implementation, including those used for RLHF.
Why it matters now. In LLM RL with a critic, λ decides whether early tokens learn from the actual final reward or from the critic’s guesses. With long reasoning traces that choice is large, which is why methods such as VAPO change how λ is set. In agent RL, GAE is how a terminal answer reward gets spread back across tool calls.
Key idea
Section titled “Key idea”Many valid multipliers. The paper lists several choices of in : total return, reward-to-go, reward-to-go minus a baseline, , , and the TD residual. The advantage gives the lowest variance in principle, but it must be estimated.
TD error as a one-step advantage (Eq. 10). With , if is the true value function then (actor–critic page).
k-step estimators (Eqs. 11–14). Use real rewards, then the critic:
The second equality is a telescoping sum: each intermediate appears once with a plus sign and once with a minus sign. More steps means less reliance on (less bias) and more random rewards (more variance).
GAE (Eq. 16). Average all the -step estimators with weights , exactly like the λ-return of TD(λ) (S&B Ch. 12). Collecting terms, each gets total weight :
In plain words: start with “how surprising was this step”, then add the surprises of later steps, discounted by per step. In code it is one backward loop, .
γ and λ are not the same knob. γ defines what you optimise: γ < 1 biases the gradient relative to the undiscounted return no matter how good is. λ < 1 adds bias only if is inaccurate. The paper finds the best λ much lower than the best γ, likely because λ introduces far less bias than γ when the value function is reasonable.
Training the critic. The paper fits by regression on discounted Monte Carlo returns with a trust region on the value function (Eqs. 28–30), and updates the policy using the value function from before this refit. Trying TD(λ) value targets instead made no noticeable difference.
Running example, worked by hand
Section titled “Running example, worked by hand”Trajectory: Q –search→ E –answer→ correct, rewards −0.1 then 1, γ = 0.9.
Exact critic (, ): and (E’s successor is terminal, value 0). So .
Poor critic (, ): , and . So .
| λ | , exact critic | , poor critic |
|---|---|---|
| 0 | 0.160 | −0.050 |
| 0.5 | 0.250 | 0.175 |
| 0.95 | 0.331 | 0.378 |
| 1 | 0.340 | 0.400 |
Now average over what happens in E (correct with probability 0.8). With the exact critic, every λ gives the true advantage 0.16 in expectation; λ = 0 does it with zero variance here, while λ = 1 swings between 0.34 and −0.56. With the poor critic, , so : negative (wrong sign) for λ below about 0.19. Plugging into the policy gradient of the REINFORCE page (π(search | Q) = 0.5, answer advantage −0.1 under this critic), the expected gradient is : only 0.0125 at λ = 0 versus the true 0.08 at λ = 1. Larger λ dilutes the critic’s error with real rewards.
Translating GAE
Section titled “Translating GAE”LLM token generation. With γ = 1 and only a terminal reward , for every token except the last, where . (In RLHF a per-token KL penalty to adds a small reward at every token.) With λ = 1, : every token sees the real reward, offset by the critic’s guess. With λ = 0.95, the final reward’s weight in is : about 0.006 for a token 100 positions before the end and about at 1,000 positions. Early tokens in long traces then learn almost entirely from the critic. VAPO responds with a length-adaptive λ for the policy, and, following VC-PPO, computes value targets with λ = 1 (“decoupled GAE”).
A search agent. Compute δ at the agent’s own decision points (after each tool result, and at the answer), not over retrieved-text tokens. A query that turned up the right document raises and gets a positive δ even before the answer is checked. If the episode stopped at the tool-call limit, the last δ should bootstrap from of the cut-off transcript, unless your task defines running out of budget as failure.
Key results
Section titled “Key results”- Cart-pole (21 seeds): best with γ in [0.96, 0.99] and λ in [0.92, 0.99] (fastest progress for λ in [0.92, 0.98]).
- 3D biped locomotion (9 seeds): best with γ in [0.99, 0.995] and λ in [0.96, 0.99]. The resulting gait used about 5.8 days of simulated real time (1,000 iterations of 50,000 timesteps).
- Quadruped and standing up (5 seeds): with γ = 0.995, the quadruped did best with a value function and λ = 0.96; for standing, the value function always helped and λ = 0.96 and λ = 1 were roughly the same. “No VF” (a time-only baseline) was worse.
- Discussion: λ in [0.9, 0.99] usually gives the best performance; one-step TD (λ = 0) led to excessive bias and poor performance in these tasks.
Limitations and open questions
Section titled “Limitations and open questions”- λ depends on critic quality, which changes during training. A fixed λ is a compromise; adaptive schemes (per length, per training phase) are mostly heuristic.
- Exponential decay is a strong assumption for long sequences. For 10k-token traces or 30-step agent episodes, almost no reward signal reaches early steps at λ = 0.95.
- The paper’s evidence is from continuous control with dense rewards and short-horizon dynamics. LLM settings (sparse terminal reward, deterministic transitions, very long horizons) behave differently, and evidence there comes from later work.
Connections
Section titled “Connections”- Previous: Actor–critic and the advantage · TRPO (same authors; GAE’s experiments use TRPO for the policy update).
- Next: PPO combines a clipped surrogate with GAE advantages; it is the standard RLHF optimiser.
- Where λ is reconsidered for LLMs: VAPO · GRPO (no critic, so no GAE) · InstructGPT.
- Where the TD error comes from: Monte Carlo, TD and Q-learning.
- Courses: Spinning Up · CS285.
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.
- Derive / compute
On the search-or-answer trajectory "search, then correct" (rewards −0.1 then 1, γ = 0.9), compute the GAE advantage of the first action for λ = 0, 0.5, 0.95 and 1, first with the exact critic (V(Q) = 0.46, V(E) = 0.8) and then with a poor critic (V(Q) = 0.4, V(E) = 0.5). With the poor critic, find the smallest λ for which the expected advantage of searching becomes positive.
What a strong answer covers
- Exact critic: δ₀ = −0.1 + 0.9·0.8 − 0.46 = 0.16 and δ₁ = 1 − 0.8 = 0.2, so Â₀ = 0.16 + 0.9λ·0.2 = 0.16 + 0.18λ: 0.16, 0.25, 0.331, 0.34. λ = 1 gives G₀ − V(Q) = 0.8 − 0.46.
- Poor critic: δ₀ = −0.1 + 0.45 − 0.4 = −0.05 and δ₁ = 0.5, so Â₀ = −0.05 + 0.45λ: −0.05, 0.175, 0.3775, 0.4.
- Expected over E's outcome (correct 0.8, wrong 0.2), E[δ₁] = 0.8·0.5 + 0.2·(−0.5) = 0.3, so E[Â₀] = −0.05 + 0.27λ, positive for λ above about 0.19.
- With the exact critic every λ has the right expected sign, and λ = 0 has zero variance here; with the poor critic small λ inherits the critic's error. That is the bias–variance trade λ controls.
- Mechanism
Derive GAE from k-step advantage estimators: show that the k-step estimator is a discounted sum of k TD errors, that an exponentially weighted average of them gives Σ over l of (γλ)^l·δ_(t+l), and explain why γ and λ play different roles even though both appear as a product.
What a strong answer covers
- Â^(k)_t = r_t + γr_(t+1) + … + γ^(k−1)r_(t+k−1) + γ^k·V(s_(t+k)) − V(s_t). Intermediate V terms telescope, so it equals Σ over l < k of γ^l·δ_(t+l).
- Average the k-step estimators with weights (1 − λ)λ^(k−1). Each δ_(t+l) appears in every estimator with k > l, and the weights sum to λ^l, giving Σ (γλ)^l·δ_(t+l).
- λ = 0 gives δ_t (biased unless V is exact, low variance); λ = 1 gives Σ γ^l r_(t+l) − V(s_t) (unbiased for the γ-discounted gradient, high variance).
- γ defines the objective: γ < 1 biases the gradient relative to the undiscounted return no matter how good V is. λ < 1 adds bias only when V is inaccurate. The paper finds the best λ much lower than the best γ.
- What if…
In the paper's cart-pole and 3D locomotion experiments, what happens when λ = 0, when λ is near 1, when λ is intermediate, and when the state-value function is replaced by a time-only baseline ("No VF")? What does this suggest about tuning λ for a new task?
What a strong answer covers
- Cart-pole (21 seeds): best results with γ in [0.96, 0.99] and λ in [0.92, 0.99]. 3D biped (9 seeds): best with γ in [0.99, 0.995] and λ in [0.96, 0.99].
- Quadruped: best with a value function and λ = 0.96. Standing up: the value function always helped, and λ = 0.96 and λ = 1 were roughly the same.
- The authors report that λ = 0 (one-step TD) led to excessive bias and poor performance, and conclude that λ in [0.9, 0.99] usually works best.
- Suggestion: start around 0.95 and sweep a few values, but expect the best λ to depend on how accurate the critic is; λ is not a property of the task alone.
- Connect
In LLM PPO with γ = 1, a terminal-only reward and λ = 0.95, how much of the final reward reaches the advantage of a token 100 positions before the end, and 1,000 positions before? What does this imply for long reasoning traces, and how does VAPO respond?
What a strong answer covers
- The final reward enters δ at the last token; its weight in Â_t is (γλ)^(T−1−t). With λ = 0.95 that is about 0.0059 at 100 tokens and about 5 × 10⁻²³ at 1,000 tokens.
- Early tokens therefore get almost all of their advantage from the critic's TD errors, not from the actual reward; if the critic is poor, they get mostly noise or bias.
- With λ = 1 the reward reaches every token undiminished (Â_t = R − V(prefix_t)), at the cost of more variance.
- VAPO uses a length-adaptive λ for the policy, and (following VC-PPO) trains the value function with λ = 1 targets while the policy uses a different λ.
- Design
Write the GAE computation for a search-agent episode that ended because it hit the 20-tool-call limit, rather than by answering. Specify δ at each step, the backward recursion, the value targets, and the one line that differs from an episode that terminated normally.
What a strong answer covers
- For each policy step t: δ_t = r_t + γ·V(s_(t+1)) − V(s_t), where r_t is any tool cost (and the final reward on the answer step).
- Backward pass: Â_(T−1) = δ_(T−1), then Â_t = δ_t + γλ·Â_(t+1). Value targets: Â_t + V(s_t) (or Monte Carlo returns, as in the paper).
- Normal termination: V(s_T) = 0 in the last δ. Truncation at the call limit: the task did not end, so bootstrap with V(s_T) of the cut-off transcript, unless running out of budget is itself defined as failure.
- Compute advantages only at the agent's own decision steps; retrieved-text tokens are environment transitions and get no advantage or loss.
- Critique
The paper trains the value function by regression on Monte Carlo returns with a trust region, and updates the policy using the value function from before the latest refit. Why that order? What would happen if the critic were refit to the same batch first and fitted it perfectly?
What a strong answer covers
- If V is fitted to the batch's own returns before computing advantages, it can memorise them. In the extreme every δ on that batch is 0, so the advantages and the policy gradient vanish.
- Using the previous V keeps the advantages an honest comparison between what happened and what was predicted before seeing these outcomes.
- The trust region on the value fit (a bound on how far the predictions move) limits overfitting to the most recent batch.
- The paper also tried TD(λ)-style value targets and saw no difference from Monte Carlo returns, so the ordering matters more than the exact target here.