GRPO: group-relative advantages with the PPO clipped objective
GRPO, used to train DeepSeek-R1, samples a group of answers per prompt and scores each against its own group, so no value network is needed. It then uses PPO's clipped objective.
For one prompt with G sampled answers:
- advantage A_i = (r_i - mean(r)) / (std(r) + 1e-8), population std
- ratio_i = exp(logp_new_i - logp_old_i)
- per-answer objective = min(ratio_i * A_i, clip(ratio_i, 1 - eps, 1 + eps) * A_i)
- return the mean objective over the group (to be maximised)
Write grpo_objective(rewards, logp_new, logp_old, eps=0.2). Return (objective, advantages).
def grpo_objective(rewards, logp_new, logp_old, eps=0.2)Understand the idea
GRPO samples several answers to the same prompt and scores each against its own group, so it needs no value network. Advantage = (reward - group mean) / group std, meaning better or worse than the average answer for this prompt. Then it uses PPO's clipped objective: the probability ratio new / old is clipped to [1 - eps, 1 + eps], and you take the smaller of the clipped and unclipped terms, a cautious choice. Worked example: rewards [1, 0, 0, 1], mean 0.5, population std 0.5, so advantages [1, -1, -1, 1]. Say ratios are [1.5, 1.0, 0.7, 1.0], eps = 0.2. Answer 1: min(1.5 x 1, 1.2 x 1) = 1.2. Answer 2: -1. Answer 3: min(0.7 x -1, 0.8 x -1) = min(-0.7, -0.8) = -0.8. Answer 4: 1. Mean = (1.2 - 1 - 0.8 + 1) / 4 = 0.1. Rule: A_i = (r_i - mean) / (std + 1e-8); ratio = exp(new - old); objective = mean(min(ratio A, clip(ratio) A)). DeepSeek-R1 style reasoning training uses GRPO.