Unit 9 of 11 · about 3 hours · implement

Value loss, value clipping, loss coefficients and advantage normalization

Two agents with the same PPO surrogate can take different updates because of value clipping, normalization and loss coefficients. These choices need explicit tests and ablations, not a claim that defaults are optimal.

You'll be able to

  • Implement squared and pessimistically clipped value losses using frozen rollout targets and old values.
  • State the sign, scale and parameter ownership of policy, value and entropy losses.
  • Test how advantage centering and scaling depend on minibatch composition and standard-deviation convention.

Covers

Value loss, value clipping and loss coefficientsAdvantage centering, scaling and minibatch leakage
1

Read

In this order, only the parts listed

0 of 3 done

  1. PPO combined actor, value and entropy objectiveProximal Policy Optimization Algorithms

    arXiv:1707.06347v2, Section 5, Equation 9 and the squared-error value-loss definition

    Do not attribute value clipping or advantage normalization to Equation 9; those are implementation choices in the companion code.

  2. CleanRL: loss assembly and normalizationCleanRL PPO

    ppo.py, lines 260 to 290: minibatch normalization, clipped value loss, entropy, loss coefficients and optimizer step

  3. PPO normalization and value-loss auditThe 37 Implementation Details of Proximal Policy Optimization

    13 core implementation details: Normalization of Advantages, Value Function Loss Clipping, Overall Loss and Entropy Bonus, and Global Gradient Clipping

    Use Schedules, gradient accumulation and clipping for the earlier global-norm result; focus here on which losses feed that norm.

2

Focus on

  • The rollout return target is frozen, often . Normalize actor advantages separately; do not substitute normalized advantages into the critic's target.
  • Value clipping compares the raw squared error with the squared error at , taking the maximum. It is not clipping the target or enforcing a hard bound on value changes.
  • Centering can change an advantage's sign and therefore its PPO clipping branch. Per-minibatch centering gives a sample different weights in different shuffles; this finite-sample coupling is not evidence of new experience.
  • Record the normalization scope, standard-deviation correction and small-denominator handling. CleanRL uses std() with the default sample correction; singleton minibatches require an explicit policy rather than a silent nonfinite weight.
Common mistakes · 3
  • Using a minimum for value clipping because the policy surrogate uses a minimum. The pessimistic squared-error loss uses a maximum.
  • Allowing gradients into old values or return targets. That lets the target move to accommodate the current prediction.
  • Comparing loss coefficients without recording sum, mean and half-squared-error conventions. Those change the effective gradient scale.
3

Try it yourself

Closed-book, before checking anything

On CPU in float64, use old value 0, new value 1, return target 2 and value-clip width 0.2. The half-scaled unclipped loss is 0.5; the maximum-based clipped loss is 1.62 and has zero derivative with respect to the new value at this point. Next center advantages : population-standard-deviation scaling gives , while sample-standard-deviation scaling gives . Implement both conventions and keep the critic target unchanged.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Why does the reproduced clipped value loss have zero gradient?Answer

    The larger error comes from the clamped value, which is constant in this region. The unclipped branch is smaller and therefore inactive.

  2. 2.Does centering preserve every sample's PPO clipping branch?Answer

    No. A small positive advantage can become negative after subtracting the batch mean, which reverses the favorable clipping direction.

  3. 3.Does multiplying advantages by a positive constant change their signs?Answer

    No. It scales the policy-surrogate gradient but not the value or entropy losses. It is not generally equivalent to scaling the whole optimizer's learning rate.

  4. 4.Should a normalized advantage be used to reconstruct the return target?Answer

    No. Normalization changes the actor weight's units and offset. Use the original advantage plus the frozen old value for that target.

You're done when

Your loss reproduces the flat value-clipping case and both normalization conventions, and changing normalization cannot mutate the frozen return target.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 10 more in the section
  • Proximal Policy Optimization AlgorithmsOpenAI · required

    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.

  • The 37 Implementation Details of Proximal Policy OptimizationHuang et al. (ICLR Blog Track 2022) · required

    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.

  • CleanRL PPOCleanRL · support

    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; pin gymnasium==0.29.1 or patch the episode logging.

Also in this section

  • Berkeley CS 185/285 Deep Reinforcement Learning (Spring 2026) - Policy Gradients, Actor-Critic and Advanced Policy GradientsUC Berkeley · primary

    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 pins gym==0.25.2, which fails on NumPy 2, so port it to Gymnasium (terminated and truncated) or pin numpy<2 in its own environment, and turn off its forced WandB logging.

  • Stanford CS224R Spring 2026 - Policy Gradients and Actor-CriticStanford University · support

    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.

  • Reinforcement Learning: An Introduction (2nd ed.) - Chapter 13Richard Sutton and Andrew Barto · required

    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.

  • High-Dimensional Continuous Control Using Generalized Advantage EstimationSchulman et al. · required

    Derive GAE from TD residuals, implement backward recursion with terminal and truncation masks and sweep and on fixed trajectories before training.

  • Spinning Up - Intro to Policy Optimization and PPOOpenAI · support

    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.

  • Hands-on Modern RL - REINFORCE, Actor-Critic and PPOWalking Labs · support

    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.py and code/chapter07_ppo/ppo_from_scratch.py run 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; its code/chapterNN folders do not follow the site chapter numbers.

  • Deep-ML - Policy-Gradient ProblemsDeep-ML · support

    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.

  • Reinforcement Learning Control Laboratory - Policy CoreRoadmap-Final · required

    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.

  • Soft Actor-Critic: action-bound density correctionHaarnoja et al. · reference

    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 · reference

    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.