RL with verifiable rewards (GRPO)
Train on problems with automatically checkable answers by sampling a group of responses and using each one's reward, normalized by the group mean and std, as its advantage in a PPO-style clipped update. Explain why this needs no learned value model or reward model.
Builds on: PPO: clipped updates and a learned value baseline, Reward models from human comparisons
What the animation says
Two extra models
PPO trains a second network, the value model, often as big as the policy itself. Its job is to guess the expected reward from each prefix, giving updates a baseline. RLHF adds a third: a learned reward model that only approximates what people want. But for math with a known answer, or code with unit tests, a program can check correctness exactly. So a checker replaces the reward model. What could replace the value model's baseline?
Siblings as the baseline
The answer: ask the same prompt several times. Say G equals four, so four sampled responses. The checker scores each one: one if correct, zero if not. Their average reward estimates how well the policy does on this prompt. That's what the value model was trained to guess. Responses that beat their siblings get pushed up. Worse ones get pushed down. Here, one of four is correct. What happens to the three wrong ones?
Working the numbers
They fall below the average, so they're pushed down. Now let's find out how hard. The mean is zero point two five. Subtract it: the success is plus zero point seven five, each miss minus zero point two five. Then divide by the group's spread. Square the deviations, average over all four, and take the square root: about zero point four three three. Advantages: one point seven three for the success, minus zero point five eight for each miss. They sum to zero, and the rare success gets the big push.
When the group agrees
Now suppose all four answers are correct. Every reward equals the mean, so every deviation is zero, and so is the spread. The tiny delta prevents dividing by zero, and every advantage comes out zero. The same happens if all four fail. Prompts that are too easy or too hard teach nothing. Your turn: tap every group that gives no learning signal.
Plugging into PPO's clip
Everything else is PPO's clipped update. Each response gets one advantage, and every token in that response shares it. For each token, take the ratio of new to old probability, clip it near one, and keep the smaller term. Average over tokens and responses. Some recipes also add a KL penalty to stay near the SFT model. The price is G samples per prompt, and one advantage for all of a response's tokens. Tap the line that replaces the value model.
Let siblings be the baseline
GRPO's advantage and objective
One success out of four
Group advantages + clipped loss
import numpy as np
rng = np.random.default_rng(0)
r = np.array([1., 0., 0., 0.]) # checker rewards, G=4
A = (r - r.mean()) / (r.std() + 1e-6) # one advantage per response
logp_old = rng.normal(-1.5, 0.3, size=(4, 3)) # [G, T] token log-probs
logp_new = logp_old + rng.normal(0, 0.2, size=(4, 3))
ratio = np.exp(logp_new - logp_old) # pi_theta / pi_old per token
eps = 0.2
surr = np.minimum(ratio * A[:, None], np.clip(ratio, 1-eps, 1+eps) * A[:, None])
loss = -surr.mean() # minimizing = maximizing surrogate
print(A.round(2), loss)
Remember this
On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.
Bytewise
All courses