What is GRPO?

Introduction

Project introduction

What is GRPO?

GRPO, group relative policy optimization, is a way to improve a language model with reinforcement learning. The model tries answers, each answer gets a reward, and training makes well-rewarded answers more likely. DeepSeek introduced it for math in DeepSeekMath and used it to train DeepSeek-R1.

For problems with a checkable answer, such as math or code with tests, the reward can come from a short program instead of a learned reward model. This is called reinforcement learning with verifiable rewards. The program pays 1 for a right answer and 0 for a wrong one.

Why groups?

A reward alone does not say whether an answer was good for that prompt, since a hard sum that the model gets right is worth more than an easy one. PPO, the classic method, trains a second network to predict the expected reward. GRPO skips it. It samples a group of answers to the same prompt and compares each answer with the group's average, so an answer is pushed up only if it beat its siblings.

The catch is that the program is the whole specification. If it accepts the right number anywhere in the text, the model learns to write several numbers. You will see this happen in about 20 seconds of training, and fix it.

One GRPO step

636+546=
1182,1182.1192,1193.1182,1193.1183.2183,1183.1182,1182.1182.1192.

Advantage of each answer

1182,1182.
1192,1193.
1182,1193.
1183.

3 of 8 are right, so the mean is 0.375, each right answer gets 1.21, and each wrong one gets -0.72

Sample a group8 answers per prompt
Check each onea program, no reward model
Compare in the groupreward minus the mean
Clipped updatestay near the start

What you will build

01

A strict checker

Score answers with a program that reads the format and pays for the final answer only.

02

Groups and the GRPO loss

Turn rewards into group-relative advantages and write the clipped loss with a KL penalty.

03

Reward hacking and measurement

See a lenient checker get gamed, compare length normalizations, and measure pass at k.

Start with the checker

Write the program that decides which answers earn a reward.

Continue to Problem 1