4.4.3 · D3Alignment, Prompting & RAG

Worked examples — Proximal Policy Optimization for LLMs

2,641 words12 min readBack to topic

This is a Deep Dive child of Proximal Policy Optimization for LLMs. The parent built the clipped surrogate and the KL leash. Here we do only one thing: we grind through every case the PPO objective can throw at you — every sign of the advantage, both directions the probability ratio can move, the exact spot where the clip bites, the degenerate ratio-equals-one case, and a couple of real training-style word problems.

Before anything, let us re-anchor the two numbers that drive every single example on this page. Everything below is arithmetic on just these two things, so let us make sure they are pictures, not symbols.

Everything the clip does is decided by the sign of crossed with which way moved. That is a -something grid, so let us literally draw the grid first, then fill in each cell.


The scenario matrix

The clipped surrogate for one token is

Here = "pick the smaller of the two numbers", and = "if is below lo return lo, if above hi return hi, else return itself" — it drags a stray value back to the nearest edge of the safe band.

Every token you will ever feed PPO lands in exactly one row below:

# Cell (case class) Sign of Where is ? Does the clip bite? What the update does
1 Good token, eager but inside band no keeps pushing prob up
2 Good token, TOO eager yes (upper) gradient zeroed, stop pushing
3 Good token, policy backed OFF no (min keeps unclipped) correction still allowed
4 Bad token, policy already dropped it yes (lower, via min) keeps letting prob fall
5 Bad token, policy got MORE eager no (min keeps unclipped) strong corrective push down
6 Neutral / degenerate or anywhere / exactly irrelevant zero contribution
7 Real-world: KL leash shaving reward (any) reward reshaped before advantage
8 Exam twist: identical numbers, opposite conclusions both signs same depends on sign shows sign decides everything

The single most important picture on this page is the two curves of as a function of — one for good tokens, one for bad tokens. Study it; every example is just a dot on one of these curves.

Figure — Proximal Policy Optimization for LLMs

Read the figure: the flat plateaus are exactly where the clip has zeroed the gradient (no reward for moving further). The sloped part still active is where PPO still lets the policy move. Notice the flats are on opposite sides for good vs bad tokens — that asymmetry is the whole trick.


The six sign-and-ratio cases


Case #7 — Real-world word problem: the KL leash reshapes reward

Before any advantage is computed, the per-token reward already has the KL penalty baked in (see KL Divergence and Reinforcement Learning from Human Feedback (RLHF)). We must show how a raw reward-model score becomes the number PPO actually optimizes.

Figure — Proximal Policy Optimization for LLMs

Case #8 — Exam twist: same numbers, opposite verdicts


Recall Scenario matrix — cover and recall

Clip bites for a good token when ::: (ratio above the ceiling). Clip bites for a bad token when ::: (ratio below the floor), through the min picking the clipped-and-more-negative branch. If the surrogate contribution is ::: exactly , for any ratio. If the surrogate equals ::: itself — PPO reduces to plain advantage-weighted policy gradient. Same , vs give ::: (clipped) and (unclipped) — the sign of decides. The KL leash punishes a token when ::: (positive log-ratio, policy drifting away from reference).

Related deep tools you may want next: Direct Preference Optimization (DPO) (skips PPO's rollout loop entirely), Supervised Fine-Tuning (SFT) (the reference model), and Reward Hacking & Specification Gaming (why the KL leash exists at all).