From Pieces to GRPO Training

Introduction

Project introduction

From Pieces to GRPO Training

You have now written the core pieces of GRPO. These are group-relative advantages, the k3 estimate of the KL divergence, the clipped GRPO loss, three ways to normalize by length, and pass at k. The notebook gives you these pieces already written, so its tasks are about wiring them together and reading the results.

In the notebook these pieces train a real model, a tiny language model of about 154,000 parameters that adds two 3-digit numbers one character at a time. It was pretrained ahead of time and stopped early, so its sampled answers are right only about 58 percent of the time.

What you will see

First you train with a quick checker that pays when the right number appears anywhere. In 50 steps the reward climbs from about 0.63 to 0.82, but held-out accuracy only moves from 0.58 to about 0.62, because the model has learned to write two numbers almost every time, so either can earn the reward.

Then you train the same model with a strict checker. Reward and accuracy now move together, and accuracy reaches about 0.69. The accuracy gap between the two runs is modest, 0.03 to 0.07 over three seeds, so the hack is clearest in what the model writes. Pass at k shows what changed. Pass at 1 rises from about 0.56 to 0.69, while pass at 16 was already 0.97, so training mostly sharpened answers the model could already find. These are small-scale results from a CPU run, not the papers' numbers.

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

How the notebook is organized

01

Build GRPO

Score sampled answers in groups, see your advantages, KL penalty and loss in place, and wire them into one update.

02

Catch the hack

Train with the quick checker and measure how often it pays a wrong final answer.

03

Fix and measure

Train with the strict checker, test the gap against the noise, measure the length weighting, and see which sums changed.

Train, hack, and fix with GRPO

Run the whole investigation in the browser, about 50 minutes.

Open the notebook project