PPO Optimization
Given the KL-regularized objective, we want a policy that maximizes reward while staying close to the reference model:
We cannot enumerate every possible completion, and reward is only defined on sampled trajectories. So RLHF turns the objective into stochastic optimization: sample outputs, estimate reward minus KL, and take gradient steps.
Advantage equation
Turn a scored response into an update signal
PPO does not just ask whether a response has a high reward. It asks whether the response is better than expected after subtracting drift from the reference policy.
Sampled response
"KL control matters because reward optimization can otherwise move the policy toward brittle shortcuts."
reward
7.4
KL cost
-1.6
baseline
-5.2
advantage
+0.6
A simple policy-gradient view is:
where
This is the REINFORCE idea: increase the probability of sampled outputs with positive advantage and decrease the probability of outputs with negative advantage. But for large language models, large reward signals can cause massive policy shifts, KL explosion, reward hacking, or collapse.
Policy-gradient intuition
Advantage tells log probability which way to move
Reinforce sampled outputs that beat the baseline, and suppress sampled outputs that underperform.
Before update
Probability of this sampled answer
Push
up
After one small step
Illustrative next probability
PPO stabilizes that update by comparing the current policy to the policy that produced the sampled data:
Then it maximizes the clipped surrogate:
The ratio asks how much more likely the new policy makes the sampled action. The clip prevents one batch from pushing probabilities too far in a single update.
PPO
Walk through the clipped objective
PPO compares the new policy to the old policy using a probability ratio, then clips updates that move too far.
min(...)
PPO takes the more conservative of the unclipped and clipped terms. That is the safety catch in the equation.
Unclipped term
rtA = 1.18 × 1.2 = 1.42
Clipped term
clip(1.18, 0.80, 1.20)A = 1.18 × 1.2 = 1.42
clip range
0.80-1.20
clipped r_t
1.18
unclipped
1.42
PPO term
1.42
The policy-optimization loop has four conceptual steps:
- Sample responses from the current policy for a batch of prompts.
- Score each response with the reward model, plus any safety or KL penalties.
- Estimate which sampled actions were better than expected.
- Update the policy carefully so good samples become more likely without causing a large distribution shift.
This is still reinforcement learning. The "environment" is the prompt-and-response process, the action is the generated text, and the reward is learned from human or AI feedback.
GRPO, or Group Relative Policy Optimization, makes the baseline local to the prompt. Instead of asking whether one response has a high score in absolute terms, it samples a small group of responses to the same prompt and asks which ones beat the group's average.
This is useful for language models because reward scales can vary across prompts. A score of 7 might be excellent for a difficult safety prompt but mediocre for an easy summary prompt. The group baseline turns the update into a within-prompt comparison.
Grouped optimization
Sample a response group
GRPO-style updates compare several sampled responses to the same prompt, using the group as the baseline.
Sample 1
2.1
-2.47
Sample 2
8.6
+4.03
Sample 3
3.2
-1.37
Sample 4
4.4
-0.17
group mean
4.57
strongest update
Sample 2
A simple group-relative advantage can be written as
Each response is compared to the average reward for the sampled group. Responses above the group mean receive positive advantage; responses below it receive negative advantage. This makes the training signal prompt-local: the model asks which sampled answer was better for this prompt, not merely which answer had a high global score.
Why PPO Instead of Raw REINFORCE?
- Raw updates can produce massive policy shifts
- KL can explode when reward pressure dominates
- The policy may discover reward hacks or collapse into narrow behavior
- PPO clips overly large probability-ratio changes before they dominate training
What is the purpose of comparing multiple sampled responses to the same prompt in a group-relative update?