← All questions
Training & Fine-tuningMedium· Reinforcement Learning· GRPO

Walk me through the GRPO training loop.

The process begins with sampling G responses per prompt to compute rewards. Next, advantages are normalized within the group by subtracting the mean and dividing by the standard deviation. The inner loop computes importance ratios, applies a clipped surrogate loss with an optional KL penalty, and performs a gradient step. This cycle repeats for K iterations before refreshing the rollouts.

Code playground (Python)