research29 min studyLesson 646 in Engineering

On-policy batches: freeze behavior identity across PPO reuse

Define rollout and update phases, preserve old probabilities, and distinguish PPO’s clipped surrogate from a hard policy-distance guarantee.

On this page

What you’ll understand

  • Define one behavior-policy batch and its permitted reuse.
  • Calculate positive- and negative-advantage clipped surrogate terms.
  • Explain why clipping does not make arbitrary stale replay on-policy.

An on-policy collector needs more than a queue of recent experiences. It needs a defined behavior snapshot and an algorithm specifying when those experiences are collected, reused, and retired. The original PPO actor-critic schedule collects fixed-length fragments using an old policy, computes advantages, and performs several optimization epochs on that batch before refreshing the behavior policy. During those epochs the current policy changes, so the fixed old probabilities remain essential. This is a particular surrogate-update protocol, not a license to treat unlimited historical replay as fresh on-policy data.

Make the rollout batch an immutable provenance boundary

Assign a batch identifier and freeze the behavior snapshot, action-distribution settings, preprocessing state, and old action log probabilities that define it. In the scoped pipeline here, advantages are computed under the chosen old critic and boundary rules, then held fixed for the batch’s surrogate updates. Another algorithm may recompute them, but that difference must be explicit. A fixed-length fragment can end before the task episode ends and use an appropriate bootstrap value; on-policy batching does not require inventing a task termination whenever the collector reaches its target length.

Actors that have not adopted the requested snapshot can produce a mixture of behavior versions. Decide whether to wait, reject, or use a different justified algorithm, and retain the resulting task and actor coverage. Dropping every slow actor can bias the batch toward easier or faster environments. Count valid transitions rather than reset-only vector outputs, and preserve recurrent sequence boundaries when shuffling minibatches. A uniform array of old log probabilities is not enough if its entries were computed using the wrong masks or a different behavior distribution.

rt(θ)=exp⁡ ⁣(log⁡πθ(at∣ht)−log⁡πold(at∣ht))r_t(\theta)=\exp\!\left(\log\pi_\theta(a_t\mid h_t)-\log\pi_{\rm old}(a_t\mid h_t)\right)
The dimensionless ratio uses the same stored action and defined history, with positive old probability or compatible density. Old probabilities remain tied to the fixed batch behavior. Support, transformations, masks, and recurrent context must match the action-distribution contract.↔ Scroll wide equations horizontally.

Clipping changes the incentive, not every resulting ratio

The clipped PPO term takes the minimum of an ordinary ratio-weighted advantage and a clipped-ratio version. For positive advantage it stops rewarding some further increases beyond the upper clip. For negative advantage, the relevant pessimistic branch can differ. This is not equivalent to replacing every ratio in every expression by its clipped value. Work through both signs before implementing the objective, since a sign error can reward exactly the policy changes the surrogate was intended to discourage.

The objective does not enforce that all actual action ratios stay inside the clip interval, nor does it provide a universal hard bound on KL divergence or monotonic improvement. Shared parameters couple actions and states, minibatch steps interact, and the critic and entropy terms add further forces. Monitor the relevant diagnostics and define any early-stop rule as part of the implementation. Multiple PPO epochs reuse the same old-policy batch under this surrogate; they do not erase behavior provenance or automatically justify arbitrary older off-policy trajectories.

ℓt=min⁡ ⁣(rtA^t,clip⁡(rt,1−ϵ,1+ϵ)A^t)\ell_t=\min\!\left(r_t\widehat A_t,\operatorname{clip}(r_t,1-\epsilon,1+\epsilon)\widehat A_t\right)
Here 0<ε<1 and the advantage is fixed for the scoped batch. This is one scalar clipped-surrogate term to maximize, in advantage units. It omits the separately specified value and entropy terms and does not impose a hard constraint on the learned policy.↔ Scroll wide equations horizontally.

Enforce batch retirement and compare algorithmic invariants

Log the rollout batch, behavior digest, learner update, epoch number, and valid-item count at every update. Verify that old log probabilities do not silently change when the current model changes. A ratio of one after every epoch may indicate that old probabilities were recomputed from the current policy, making the intended reference disappear. Test positive and negative advantages, masks, recurrent sequences, and partial minibatches with a hand-derived fixture. Compare objective components before looking for an improved episode-return curve.

The network lab illustrates one changing binary-action probability. Reset, explicitly set input one and weight one, predict the sigmoid output, then Play or Step. Compare a fresh Reset with input one and weight zero explicitly set. Its fixed bias minus 0.5 gives outputs about 0.62246 and 0.37754. This single unit can stand for a hypothetical Bernoulli action probability, but the instrument does not preserve an old policy, calculate a PPO objective, collect trajectories, or update parameters. The clipped-surrogate arithmetic must be checked separately.

The negative-advantage branch is not a blanket ratio clip

At one sampled action, old probability is 0.4 and current probability 0.6, giving ratio 1.5. Use epsilon 0.2. Compute the clipped-surrogate term once with advantage two and once with advantage minus two.

  1. The clipped ratio is 1.2. For positive advantage two, the ordinary term is 1.5×2=3 and the clipped term 1.2×2=2.4. The minimum is 2.4.

  2. For negative advantage minus two, the ordinary term is −3 and the clipped term −2.4. The minimum is −3. Simply using the clipped ratio everywhere would incorrectly replace this result with −2.4.

  3. The actual current ratio remains 1.5 in this fixture, outside the clip interval. The objective’s selected term changes an incentive; it does not project the policy ratio back to 1.2 or prove a KL-distance bound.

The result

The terms are 2.4 and −3 for the two advantage signs. Correct clipping depends on the minimum and the sign, not only a bounded numerical ratio.

Explore the model

Interactive lab

Interactive lab · network

A changed probability needs a stored reference to form a policy ratio

Use separate Reset → explicitly set BOTH input and weight → predict → Play/Step runs for (1,1) and (1,0). The unit computes σ(wx−.5), giving approximately .62246 and .37754. There is no PPO training, old-policy storage, clipping, or trajectory distribution in the model.

A changed probability needs a stored reference to form a policy ratioOne inspectable sigmoid unit, σ(wx − 0.5). Playback traces the computation graph. There is no training, attention mechanism or hidden deep network. Current readings: Product · wx: 1.2; Logit · wx − 0.5: 0.7; Sigmoid output: 0.6682. All parameters are adjustable with the labeled controls below.One input. One weight. One sigmoid.x1.20× w1.20+ b0.70σ0.668output0.668w = 1.00b = −0.50σ(z) = 1 / (1 + exp(−z))
Computation graphSignal trace
Product · wx
1.2
Logit · wx − 0.5
0.7
Sigmoid output
0.6682
t = 0 s

One inspectable sigmoid unit, σ(wx − 0.5). Playback traces the computation graph. There is no training, attention mechanism or hidden deep network. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forA current probability is interpretable only against the behavior reference and action contract that generated the batch.

Check your understanding

Why must old action log probabilities remain attached to a PPO rollout batch?

Try it yourself

Old probability is 0.5, current probability 0.3, epsilon 0.2, and advantage minus one. Calculate the ordinary term, clipped term, and selected surrogate. Does the selected term certify an improved policy?

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

The ratio is below the lower clip, and multiplying by a negative advantage changes which term is smaller.

Compare with the solution

The ratio is 0.6 and clips to 0.8. The ordinary term is −0.6, the clipped term −0.8, and the minimum is −0.8. This one contribution does not certify improved return, bounded KL, or correct batch provenance. Check the full objective, update schedule, value and entropy terms, and evaluation evidence. Keep the old probabilities and scoped advantage estimator fixed as required by this batch protocol, and do not interpret multiple epochs as permission for unlimited stale replay.

Take it with you

  • Freeze behavior provenance and the intended estimator within each batch protocol.
  • Calculate both signs of the PPO minimum correctly.
  • Clipping a surrogate is not a universal policy-distance or reward guarantee.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.