4.4.3 · D4Alignment, Prompting & RAG

Exercises — Proximal Policy Optimization for LLMs

2,345 words11 min readBack to topic

Before we start, one shared reminder so nothing is used unexplained.

The figure below is your reference picture for every clip question — keep it open.

Figure — Proximal Policy Optimization for LLMs

Level 1 — Recognition

Exercise 1.1

Match each symbol to its plain-English meaning: (a) , (b) , (c) , (d) .

Recall Solution
  • (a) = ratio of new-policy to old-policy probability for one token.
  • (b) = advantage — how much better than average that token was.
  • (c) = strength of the KL leash pulling the policy toward the reference.
  • (d) = half-width of the clip band; is allowed to roam in .

Exercise 1.2

True or false: "The clip caps how much the loss can grow when we push a good token () further." Explain in one sentence.

Recall Solution

True. For the surrogate is capped at ; once exceeds the term stops growing, so there is no reward for pushing that token's probability higher — the gradient there becomes zero.

Exercise 1.3

Which single term in the full LLM-RLHF objective is responsible for keeping the model "in-distribution" so the reward model stays trustworthy?

Recall Solution

The per-token KL penalty to the reference, . The reward model is only accurate near the Supervised Fine-Tuning (SFT) distribution; the KL leash keeps you there. This is the mitigation for Reward Hacking & Specification Gaming.


Level 2 — Application

Exercise 2.1

Given , , . Compute the unclipped surrogate, the clipped surrogate, and the value PPO actually uses.

Recall Solution
  • Unclipped: .
  • Clip : , so clipped surrogate .
  • PPO takes the min: . The min discards the over-optimistic : we refuse to reward pushing past .

Exercise 2.2

Given , , . Compute all three quantities.

Recall Solution
  • Unclipped: .
  • Clip: , clipped .
  • . For a bad token we take the more negative (pessimistic) value, so the policy is still permitted to keep lowering this token's probability. Clipping restrains over-optimism, never correction.

Exercise 2.3

A full response gets reward-model score . On one token the new policy assigns probability while the reference assigned , and . Compute the KL penalty and the effective end-of-sequence reward.

Recall Solution
  • Log-ratio: .
  • KL penalty: .
  • Effective reward: . The policy got greedy on a token the reference was unsure about, so PPO shaves reward to discourage drift. See Reward Modeling from Human Preferences.

Exercise 2.4

With and , at what value of does the clipped surrogate first stop increasing?

Recall Solution

At . For the clipped term is frozen at , and since there, the min stays at : gradient .


Level 3 — Analysis

Exercise 3.1

For a good token (), sketch/describe the surrogate as a function of over . Where is the gradient nonzero, and where is it zero? Reference the figure.

Recall Solution

Look at the left panel of the figure (magenta curve).

  • For (i.e. ): the min equals the unclipped line , which rises — gradient nonzero, so we keep encouraging the token.
  • For : the min equals the flat clipped value — gradient zero, no further push. So for good tokens PPO rewards improvement only up to the ceiling , then flatlines.

Exercise 3.2

Now the bad token (). Describe the same surrogate shape (right panel) and say where the gradient dies.

Recall Solution

Look at the right panel (violet curve). Because :

  • For (i.e. ): min equals the unclipped line , which falls as rises — gradient nonzero, so the model keeps lowering the probability of the bad token.
  • For : min equals the flat clipped value — gradient zero. Once we've already cut the probability far enough ( below the floor), PPO stops over-penalizing. Symmetric story: the flat region is on the opposite side of compared to the good-token case.

Exercise 3.3

A student claims: "Because is clipped to , one PPO update can change any token's probability by at most 20%." Refute this precisely.

Recall Solution

False. Clipping does not clamp itself — the actual new probability can move anywhere; clipping only clamps the value used inside the surrogate, which zeroes the gradient contribution of that token once leaves the band on the improving side. But:

  1. Other tokens in the sequence still contribute gradient.
  2. We take several gradient steps per batch (importance sampling, Step 4 of parent), so cumulative movement compounds. Hence the extra KL penalty is required as the true global leash. This is exactly Mistake A in the parent note.

Level 4 — Synthesis

Exercise 4.1

Combine both mechanisms. A token has , , . The same token has , , . Compute (i) the clipped surrogate contribution and (ii) the KL penalty, and state the net "shaped" signal .

Recall Solution

(i) Clipped surrogate: unclipped ; clipped ; min . (ii) KL penalty: . (iii) Net shaped signal . The clip capped the greedy over-reward at ; the KL further shaves a little because the policy over-committed relative to the reference.

Exercise 4.2

Contrast with Direct Preference Optimization (DPO): PPO needs a reward model + rollouts + clip + KL, DPO folds preference and KL into a single closed-form loss. In one sentence, which PPO ingredient does DPO's implicit-reward derivation replace, and what does DPO lose?

Recall Solution

DPO replaces the explicit reward model + PPO sampling loop by deriving the optimal KL-regularized policy in closed form, so it needs no rollouts or clip. What it loses: the ability to learn from fresh on-policy samples and from a separately reusable reward model, and it is more sensitive to the fixed preference dataset. (See Reinforcement Learning from Human Feedback (RLHF) for the pipeline both sit inside.)

Exercise 4.3

Explain why the baseline/critic can be subtracted "for free." Show the expectation argument in one line.

Recall Solution

The extra term is . Since does not depend on , pull it out: . So subtracting the baseline changes the expected gradient by zero, while slashing its variance. See Policy Gradient Methods & REINFORCE.


Level 5 — Mastery

Exercise 5.1

Design. You observe PPO training where reward keeps rising but human raters say outputs are getting worse (classic Reward Hacking & Specification Gaming). You have two knobs: (clip width) and (KL strength). Which do you change and why? What is the failure mode if you push it too far?

Recall Solution

Increase (tighten the KL leash). Rising RM reward with falling human quality means the policy has drifted out of the region where the reward model is calibrated and is now exploiting RM blind spots. The clip only affects per-token step size, not global drift, so it cannot fix distributional wandering. Too far: if is huge the policy is pinned to the reference and never improves — you get SFT behavior back with wasted compute. Tune so the running KL sits in a target band (adaptive-KL controllers do exactly this).

Exercise 5.2

Prove the clip is one-sided. Show that for the surrogate is bounded above by but is not bounded below by the clip (small still contributes), and state the symmetric fact for .

Recall Solution

Let . Define .

  • For : , and , so . Hence — an upper bound; pushing higher adds nothing.
  • For : , but , so (the smaller one), which keeps falling with — no clip protection on the low side. So for good tokens the clip caps over-optimism only. For everything mirrors: the clip caps at on the low- side, while large keeps producing the unclipped (more negative) value — the correction stays alive. This one-sidedness is the whole point of the .

Exercise 5.3

Synthesis under a degenerate case. What is when ? What does this say about tokens the model already rates as exactly average?

Recall Solution

for every . Its derivative in is everywhere, so such tokens produce no gradient. Interpretation: PPO only moves probability mass toward better-than-average or away from worse-than-average tokens; a token exactly at the baseline is left untouched — the advantage, not the raw reward, is the true learning signal.