Skip to content

Generalized Advantage Estimation (GAE)

How do we estimate the advantage A^t\hat{A}_t? There are many options:

Monte Carlo (high variance, no bias):

A^tMC=GtV(st)=k=0Ttγkrt+kV(st)\hat{A}_t^{MC} = G_t - V(s_t) = \sum_{k=0}^{T-t} \gamma^k r_{t+k} - V(s_t)

TD(0) (low variance, high bias):

A^tTD=rt+γV(st+1)V(st)=δt\hat{A}_t^{TD} = r_t + \gamma V(s_{t+1}) - V(s_t) = \delta_t

where δt=rt+γV(st+1)V(st)\delta_t = r_t + \gamma V(s_{t+1}) - V(s_t) is the TD residual.

Monte Carlo uses the actual return (accurate but noisy). TD uses the value estimate (smooth but biased by VV errors).

Generalized Advantage Estimation (Schulman et al., 2016) interpolates between these extremes with a parameter λ[0,1]\lambda \in [0, 1]:

A^tGAE(γ,λ)=k=0Tt(γλ)kδt+k\hat{A}_t^{GAE(\gamma, \lambda)} = \sum_{k=0}^{T-t} (\gamma \lambda)^k \delta_{t+k}

This can be written recursively:

A^tGAE=δt+γλA^t+1GAE\hat{A}_t^{GAE} = \delta_t + \gamma \lambda \hat{A}_{t+1}^{GAE}
λ\lambdaEquivalent toBiasVariance
λ=0\lambda = 0TD(0): A^t=δt\hat{A}_t = \delta_tHighLow
λ=1\lambda = 1Monte Carlo: A^t=GtV(st)\hat{A}_t = G_t - V(s_t)NoneHigh
0<λ<10 < \lambda < 1Weighted mix of n-step returnsMediumMedium

Worked Example: Computing GAE Across a 4-Step Episode

Section titled “Worked Example: Computing GAE Across a 4-Step Episode”

Concrete numbers. Rewards r=[1,0,0,2]r = [1, 0, 0, 2], value estimates V=[0.8,0.4,0.5,1.0,0]V = [0.8, 0.4, 0.5, 1.0, 0] (the last is V(sT)=0V(s_T) = 0 for terminal), γ=0.9\gamma = 0.9.

TD residuals δt=rt+γV(st+1)V(st)\delta_t = r_t + \gamma V(s_{t+1}) - V(s_t):

δ0=1+0.90.40.8=0.56δ1=0+0.90.50.4=0.05\delta_0 = 1 + 0.9 \cdot 0.4 - 0.8 = 0.56 \qquad \delta_1 = 0 + 0.9 \cdot 0.5 - 0.4 = 0.05 δ2=0+0.91.00.5=0.40δ3=2+0.901.0=1.00\delta_2 = 0 + 0.9 \cdot 1.0 - 0.5 = 0.40 \qquad \delta_3 = 2 + 0.9 \cdot 0 - 1.0 = 1.00

GAE recursion A^t=δt+γλA^t+1\hat{A}_t = \delta_t + \gamma \lambda \hat{A}_{t+1}, with three different λ\lambda values:

tδt\delta_tA^t\hat A_t, λ=0 (TD(0))A^t\hat A_t, λ=0.5A^t\hat A_t, λ=1 (MC)
31.001.0001.0001.000
20.400.4000.400 + 0.45·1.000 = 0.8500.400 + 0.9·1.000 = 1.300
10.050.0500.050 + 0.45·0.850 = 0.4330.050 + 0.9·1.300 = 1.220
00.560.5600.560 + 0.45·0.433 = 0.7550.560 + 0.9·1.220 = 1.658

At λ=1\lambda = 1 the GAE value matches the Monte Carlo return-minus-baseline exactly (you can verify: G0=1+0.90+0.810+0.7292=2.458G_0 = 1 + 0.9 \cdot 0 + 0.81 \cdot 0 + 0.729 \cdot 2 = 2.458, and G0V0=2.4580.8=1.658G_0 - V_0 = 2.458 - 0.8 = 1.658 ✓). At λ=0\lambda = 0 each A^t\hat A_t depends only on the one-step bootstrap — if VV is mis-calibrated even a little, that bias appears everywhere. Intermediate λ\lambda mixes them: a longer-horizon estimate where you still trust VV enough to short-circuit far-future noise.

The full PPO training loop:

  1. Collect rollout data with current policy πθold\pi_{\theta_\text{old}}
  2. Compute TD residuals: δt=rt+γVϕ(st+1)Vϕ(st)\delta_t = r_t + \gamma V_\phi(s_{t+1}) - V_\phi(s_t)
  3. Compute GAE advantages: A^t=k(γλ)kδt+k\hat{A}_t = \sum_k (\gamma\lambda)^k \delta_{t+k}
  4. Compute targets for the value function: Gt=A^t+Vϕ(st)G_t = \hat{A}_t + V_\phi(s_t)
  5. Run multiple epochs of mini-batch updates on LCLIPL^{CLIP} and the value loss

Edit the rewards or value estimates and slide λ\lambda to watch A^t\hat A_t morph between pure TD(0) (red) and pure Monte Carlo (green). With a perfectly-calibrated VV, all three curves coincide; introduce bias into VV and watch them diverge.

In LLM training (RLHF), episodes can be long (hundreds of tokens). Monte Carlo returns have very high variance because each token’s reward signal is buried under the noise of all future tokens.

GAE with λ<1\lambda < 1 exponentially downweights distant TD residuals, giving a much cleaner signal for credit assignment — which token actually contributed to the reward?

  • Schulman, Moritz, Levine, Jordan, Abbeel. High-Dimensional Continuous Control Using Generalized Advantage Estimation. ICLR 2016. arXiv:1506.02438