liveBook · Manning

Chapter 7: Improving GRPO for reinforcement learning

What you will learn in chapter 7 of Build a Reasoning Model (From Scratch)

The chapter picks up from an implemented GRPO baseline and identifies training instability as a concern during longer runs.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter picks up from an implemented GRPO baseline and identifies training instability as a concern during longer runs.

Key terms: GRPO, training instability

7.1 Improving GRPO

This section introduces the chapter’s GRPO experiments and cautions against drawing strong conclusions from individual training runs.

Key terms: sampling, optimization, training runs, tradeoffs

7.2 Tracking GRPO performance metrics

This section introduces a discussion of GRPO training metrics for interpreting and debugging training behavior.

7.2.1 Executing a GRPO training run

This section shows how to obtain and run the chapter 6 GRPO training script, or use its saved logs instead of running a costly training job.

Key terms: GRPO, supplementary materials, rlvr_grpo_original_no_kl.py, uv run, log files, .txt, .csv

7.2.2 Inspecting the GRPO training run

The section uses plots of four GRPO training metrics to assess a run, identify signs of instability, and explain how to obtain evaluation accuracy.

Key terms: average response length, loss, sanity check, average reward, training signal, stopping early, evaluation accuracy, MATH-500, training instability, eval_acc

7.3 Tracking more advanced GRPO performance metrics

Introduces rollout advantages and generated-sequence entropy as additional metrics for examining GRPO training dynamics.

7.3.1 Advantage tracking

This subsection shows how the mean and standard deviation of GRPO advantages help diagnose training, especially when rewards provide no learning signal.

Key terms: advantages, sample mean, standard deviation, gradient signal, normalized advantages, policy gradient update, average reward

7.3.2 Entropy tracking

Explains how to calculate and track answer-token entropy as a diagnostic of uncertainty and exploration during GRPO training.

Key terms: entropy, exploration, training collapse, probs, logprobs, torch.softmax(), torch.log_softmax(), torch.exp(), step_entropy, entropy_all_steps

7.3.3 Plotting additional GRPO metrics

This section interprets plotted advantage statistics, entropy, and average reward together to assess a GRPO training run.

Key terms: average advantage, group mean, GRPO-style normalization, advantage standard deviation, rollouts, learning signal, entropy, next-token probabilities, average reward, collapse

7.4 Stabilizing sequence-level GRPO using clipped policy ratios

This section introduces clipped policy ratios as a way to stabilize GRPO training.

Key terms: clipped policy ratios, GRPO loss, model weight updates

7.4.1 Computing clipped policy ratios

This section compares old and updated sequence log probabilities, clips their policy ratios, and uses those ratios to limit the influence of rollouts on the GRPO loss.

Key terms: policy ratio, old logprobs, new logprobs, average policy ratio, clipped_ratio, clip_eps, advantage term, clipped policy gradient loss, clipped objective, policy ratios

7.4.2 Training with clipped policy ratios

This section applies clipped policy ratios in a GRPO training run, contrasts a large fixed-rollout approach with a smaller approximation, and reports improved stability in the resulting metrics.

Key terms: policy ratio, old_logps, new_logps, reference policy, current model, rollout pool, minibatches, reference model, eight rollouts, average reward

7.5 Controlling how much the model changes with a KL term

This section explains how a KL term constrains changes to a GRPO-trained model and how that differs from clipped policy ratios.

Key terms: KL, Kullback–Leibler divergence, current policy, reference policy, regularizer, clipped policy ratios, KL term, training trajectory

7.5.1 Implementing the KL loss term

This subsection explains how a KL loss term is computed and added to GRPO training to limit changes from a reference model.

Key terms: KL loss term, logprobs, reference logprobs, policy gradient loss, total loss, kl_coeff, reference model, clipped policy ratio

7.5.2 Training with a KL loss term

This section examines a GRPO run with a KL loss term, explains why its sampled surrogate can destabilize training, and discusses possible remedies.

Key terms: evaluation accuracy, average reward, loss, current trainable policy, reference policy, old rollout policy, sampled surrogate, new_logps, ref_logps, summed logprobs

7.6 Adding an explicit format reward

This section introduces format rewards as optional additions to the answer-correctness reward used in RLVR training.

Key terms: answer-correctness reward, auxiliary rewards, format reward, RLVR

7.6.1 Using <think> tokens

The section explains how <think> tags separate reasoning from a final answer, how to make a tokenizer recognize those tags, and how to reward their correct use during GRPO training.

Key terms: <think>, </think>, intermediate reasoning, final answer, base tokenizer, reasoning model variant, subword tokens, placeholder token IDs, vocabulary, reward_format

7.6.2 Training a model to emit <think> tokens

This section trains a reasoning-model variant with a <think> format reward and interprets a run in which reward stays high while accuracy declines.

Key terms: base model, reasoning variant, <think> and </think> tokens, instruction fine-tune, eval_acc, reward_avg, format_reward_avg, format_reward_weight, rlvr_reward, kl_loss

7.6.3 More GRPO modifications, tips, and tricks

This section surveys proposed GRPO modifications and briefly explains the training problems each aims to address.

Key terms: zero-gradient examples, active sampling, advantage signal, token-level loss, sequence-level loss, sequence-level importance sampling and clipping, standard-deviation normalization, group-based advantage normalization, reward component, KL loss term

7.7 Summary

The section summarizes how to diagnose GRPO training and how clipping, KL constraints, and format rewards affect stability and response structure.

Where this is used later

Concepts explained in this chapter

← Chapter 6: Training reasoning models with reinforcement learning Chapter 8: Distilling reasoning models for efficient reasoning →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.