Deep RL II: Policy Gradients, Actor-Critic, GAE and PPO
Policy optimization is the direct ancestor of modern language-model RL. This stage derives the estimator, proves what a baseline changes, implements actor-critic and GAE, and treats PPO clipping as a specific objective rather than a guarantee of safe updates.
Section 4 of 12 · 11 units · about 49 hours
By the end you can Derive REINFORCE and baseline unbiasedness, match actor-critic, GAE and PPO losses on fixed trajectories, and train a small policy across seeds while diagnosing two induced ratio, value, entropy or policy-version failures.
Units
- Trajectory objectives and the likelihood-ratio identity4h
- The policy-gradient theorem and REINFORCE4h
- Reward-to-go, baselines, unbiasedness and variance reduction4h
- Learned value baselines, critic targets and actor-critic dependencies4h
- n-step advantages, Generalized Advantage Estimation and the \(\gamma\)-\(\lambda\) trade-off5h
- Categorical, Gaussian and tanh-squashed policies and entropy regularization5h
- Old and new log probabilities, importance ratios and the PPO clipped surrogate5h
- Approximate KL, clip fraction and multiple-epoch off-policy drift4h
- Value loss, value clipping, loss coefficients and advantage normalization3h
- Vectorized rollouts, policy-version identity and fixed-trajectory tests5h
- Policy collapse, critic failure, stale log probabilities and multi-seed evaluation6h
Build it
Mini project · about 12 to 16 hours
Actor-critic and PPO with versioned rollouts
Build the policylab policy laboratory: exact gradient oracles, actor-critic with GAE, and PPO with immutable vector rollouts and full loss tests. Multi-seed CartPole evidence with induced failure postmortems closes the project before language-policy work begins.
- 1Build the exact-enumeration policy-gradient oracle in
deep/and a REINFORCE update whose expected gradient matches enumeration and finite differences, trained only on fresh trajectories. - 2Compare full-return, reward-to-go and baseline weightings on shared samples against exact expectations, and ablate the baseline on the short corridor.
- 3Add learned baselines and one-step actor-critic with frozen targets, separate termination from truncation bootstrapping, and prove actor gradients never flow through detached advantages or targets.
- 4Implement GAE by backward recursion with per-lane masks and endpoint oracles for termination, truncation and segment cuts, then test categorical and Gaussian densities with the squashing correction and entropy sign, and ablate trace decay at a matched budget.
- 5Pass Deep-ML 485, add sign-case and gradient regressions for the clipped surrogate, and test value clipping and normalization scope without letting normalized advantages mutate frozen return targets, with a matched normalization ablation.
- 6Collect immutable vector rollouts with behavior-policy identity and per-lane validity masks, verify unit ratios before the first update, and trace ratios with KL across epochs under a declared full-rollout stopping rule, plus a matched update-epoch ablation.
- 7Run multi-seed PPO evidence on CPU with independent checkpoint evaluation on separate streams, and write postmortems for two induced ratio, critic or entropy failures diagnosed from stored rollouts.
What you hand in
- Policy-gradient and GAE oracles with density, entropy and rollout identity tests.
- PPO losses with sign-case, clipping, normalization and stopping regressions.
- Multi-seed evidence with raw traces, two failure postmortems and the matched ablations.
How to check it
- Self-grade with the rubric below
- Deep-ML 485: PPO Clipped Surrogate Loss
Pass both public cases; add sign-case and gradient regressions.
How it's graded
Gradient oracles
Pass: Expected REINFORCE gradients match enumeration, and GAE advantages match their endpoint oracles with per-lane boundaries intact.
Great: A cross-lane leak is injected and caught by the lane oracle.
Loss honesty
Pass: Clipped, value and entropy losses pass sign-case and gradient tests with frozen targets.
Great: A normalization-scope defect is shown to flip a clipping branch and is pinned by regression.
Drift control
Pass: Per-epoch ratio and KL traces preserve one denominator under a declared stopping rule.
Great: Equal clipped objectives with different KL are exhibited on fixed batches.
Evaluation honesty
Pass: Multi-seed evidence uses separate streams with failures retained and no best-seed claim.
Great: Two induced failures are diagnosed from rollouts before code inspection.
Resources
- Berkeley CS 185/285 Deep Reinforcement Learning (Spring 2026) - Policy Gradients, Actor-Critic and Advanced Policy GradientsUC Berkeley
Slides are public at https://rail.eecs.berkeley.edu/deeprlcourse/static/slides/lec-N.pdf; current videos are not, and the public Fall 2023 playlist numbers lectures differently. Study Lectures 5 (policy gradients), 6 (actor-critic), 9 and 10 (advanced policy gradients). Work Homework 2 (
src/agents/pg_agent.py: return estimators, reward-to-go, a neural baseline and a GAE sweep); its runs take seconds to minutes on a laptop CPU. The homework pinsgym==0.25.2, which fails on NumPy 2, so port it to Gymnasium (terminatedandtruncated) or pinnumpy<2in its own environment, and turn off its forced WandB logging. - Reinforcement Learning: An Introduction (2nd ed.) - Chapter 13Richard Sutton and Andrew Barto
The authors post the full second edition free at incompleteideas.net; cite the printed page numbers. Study Sections 13.1 to 13.5 and 13.7: the policy-gradient theorem, REINFORCE, REINFORCE with baseline, actor-critic and Gaussian policies. Reproduce Example 13.1 (the short corridor) with and without a baseline, and derive the gradient and baseline result in the notation of the shared trajectory schema.
- Proximal Policy Optimization AlgorithmsOpenAI
Read the clipped objective, implementation variants and experiments. Build hand cases for positive and negative advantages, compare clipped and unclipped losses and show that clipping alone does not enforce a hard KL bound.
- High-Dimensional Continuous Control Using Generalized Advantage EstimationSchulman et al.
Derive GAE from TD residuals, implement backward recursion with terminal and truncation masks and sweep and on fixed trajectories before training.
- The 37 Implementation Details of Proximal Policy OptimizationHuang et al. (ICLR Blog Track 2022)
Use the core and continuous-action details as an audit checklist for your PPO: vectorized environments, advantage normalization, value clipping, entropy, global gradient clipping, learning-rate annealing and observation and reward normalization. For each detail you adopt, show its effect with an ablation on your own task.
- Reinforcement Learning Control Laboratory - Policy CoreRoadmap-Final
Complete REINFORCE with baseline, actor-critic, GAE and PPO requirements. Match hand-computed log probabilities, advantages, ratios and clipped losses and diagnose stale-policy, ratio, GAE and evaluation leakage defects.
- Stanford CS224R Spring 2026 - Policy Gradients and Actor-CriticStanford University
Use Lectures 03 (policy gradients) and 04 (actor-critic) as a second derivation, and the Homework 2 PPO handout for its exact GAE recursion and its note that several epochs on one batch is not strictly on-policy. Its runs need cloud GPUs, and its actor is a truncated normal, not a tanh-squashed Gaussian. Follow the Stanford honor code for course materials.
- Spinning Up - Intro to Policy Optimization and PPOOpenAI
Read Part 3 (Intro to Policy Optimization: the simplest policy gradient, reward-to-go, the expected grad-log-prob lemma, baselines) and the PPO page's background, which states that the clipped objective has no hard KL bound. Do not install its code: it needs TensorFlow 1, MPI and the retired Gym stack.
- CleanRL PPOCleanRL
Use the single-file implementation and implementation-details notes as a post-implementation audit. Trace rollout shapes, advantage calculation, minibatch epochs, ratios, clipping, value loss, entropy, seeding and environment semantics. Like the DQN script it reads
final_info, which Gymnasium 1.x next-step autoreset no longer provides; pingymnasium==0.29.1or patch the episode logging. - Hands-on Modern RL - REINFORCE, Actor-Critic and PPOWalking Labs
Use the REINFORCE page, the actor-critic chapter and the PPO and GAE pages for worked numbers: the three advantage-sign cases and the five-step GAE table.
code/chapter05_policy_gradient/reinforce_cartpole.pyandcode/chapter07_ppo/ppo_from_scratch.pyrun on CPU in minutes. Audit completion masks against the Gymnasium docs (its GAE helper cuts the bootstrap on truncation) and do not adopt its KL sketch as a reference. Pin commit 9231bab of walkinglabs/hands-on-modern-rl; itscode/chapterNNfolders do not follow the site chapter numbers. - Deep-ML - Policy-Gradient ProblemsDeep-ML
Use named problems as closed-book checks after your own implementation passes: 481 (REINFORCE with baseline), 482 (one-step actor-critic), 485 (PPO clipped surrogate with clip diagnostics) and 487 (GAE with episode boundaries). Read each problem's tests before trusting its statement.
- Soft Actor-Critic: action-bound density correctionHaarnoja et al.
Appendix C, Enforcing Action Bounds, Equations 20 and 21 in arXiv:1801.01290v2. Supplies the change-of-variables derivation missing from the pool's action-clipping checklist; do not study SAC training here.
- Gymnasium vector autoreset modesFarama Foundation
Read Next-Step Mode, Same-Step Mode and Disabled Mode in the official autoreset explainer, then SyncVectorEnv's reset and step API. Check against Gymnasium 1.4.0; pages read 2026-10-14. Supplies current rollout semantics missing from the older PPO examples.