Overview

7 Improving GRPO for reinforcement learning

This chapter revisits the GRPO reinforcement-learning setup from the previous chapter and shifts from a short proof-of-concept run to a longer, more realistic training analysis. It emphasizes that even when the code is technically correct, training can still become unstable over time, so careful monitoring is essential. The discussion is grounded in actual experiments, but the results are treated as illustrative rather than definitive because RL runs can vary noticeably from one seed to another.

A major theme is learning how to interpret training behavior through metrics beyond raw reward and accuracy. The chapter explains how to track loss, average reward, response length, and external evaluation accuracy, then extends that toolkit with advantage statistics and entropy. Advantage mean is mostly a sanity check because it should stay near zero by construction, while advantage standard deviation reveals whether there is still a usable learning signal. Entropy adds another useful diagnostic: low values can indicate collapse or overconfidence, moderate values suggest healthy exploration, and sudden changes can warn of instability.

The chapter then improves the basic GRPO algorithm itself by adding clipped policy ratios and, separately, a KL regularization term. Clipping limits how far the policy can move in one update, which helps prevent large destructive jumps and makes longer training runs more stable. The KL term constrains the model relative to a reference policy, but the chapter also shows that it can sometimes contribute to collapse, especially when rewards vanish and the KL penalty becomes the main gradient signal. Finally, the chapter introduces an auxiliary format reward based on tags, showing how extra reward shaping can encourage structured reasoning output, while also warning that such rewards must be balanced carefully so they do not distract the model from correctness.

A mental model of the topics covered in this book. This chapter provides a deeper coverage of the GRPO algorithm for reinforcement learning with verifiable rewards.
A chapter overview showing the different topics being covered in this chapter.
Output from a GRPO training run using GRPO in a terminal with several training statistics, such as the loss, average reward, tokens/sec throughput, and average response length.
The four metrics tracked during the GRPO training run (loss, average reward, average response length, and evaluation accuracy). The orange centerline represents a moving average over the last 25% of values, which helps reveal overall trends in the otherwise noisy training signals. The evaluation accuracy is shown as a bar plot since it is computed only every 50 steps rather than at each step.
After analyzing basic GRPO training metrics, we now add more advanced metrics to analyze the training run.
GRPO overview figure from chapter 6. The advantages are shown in step 3.
Log-probability (logprob) computation of a single token ("this") in the LLM's generated answer. The LLM returns the logits of the token, which are then converted to softmax probability values via torch.softmax() or logprob values via torch.log_softmax().
The entropy term is calculated by multiplying the token probabilities with the token logprobs.
Visualizing advantage statistics and entropy tracked during the GRPO training run (next to the average reward, which we tracked previously).
After plotting basic and advanced GRPO training metrics, we now modify the GRPO algorithm and add clipped policy ratios.
GRPO overview figure from chapter 6. We now use the sequence logprobs from step 4 to compute policy ratios and clipped policy ratios.
Calculating the policy ratio (ratio) and clipped policy ratio (clipped ratio) added to the GRPO from "new" and "old" logprobs.
Selected metrics from a GRPO training run using clipped policy ratios.
Implementing a KL loss term, which is a part of the original GRPO algorithm.
Overview of the GRPO algorithm with the KL loss term calculation added to the right.
Selected metrics from a GRPO training run after adding a KL loss term. ​​Here, loss (in the upper left) refers to the total GRPO loss, that is, the sum of the policy-gradient loss and the KL loss term.
Implementing a format reward that encourages the model to generate <think>...</think> tokens
Using the previous correctness reward (left) and a correctness plus format reward (right).
Basic metrics from a GRPO training run with a format reward.
Additional metrics from a GRPO training run with a format reward.
This last section in this chapter outlines some additional GRPO modifications that emerged in recent months.

Summary

  • Training reasoning models with GRPO can become unstable over longer runs, even when the implementation is correct and rewards initially improve.
  • Interpreting GRPO training requires tracking multiple metrics jointly (average rewards, response length, evaluation accuracy, advantage statistics, and entropy)
    • Basic metrics such as loss mainly serve as sanity checks in GRPO and should not be over-interpreted in isolation.
    • Advantage statistics provide useful diagnostics: the mean should remain near zero by design, while the standard deviation reflects the strength and stability of the learning signal.
    • Entropy measures how uncertain the model is during generation. Very low entropy can signal collapse, and very large entropy can indicate unstable updates and randomness in the model responses.
  • Clipped policy ratios limit how much the policy can change between updates and can substantially improve training stability over longer runs.
  • Adding a KL divergence term constrains long-term drift from a reference model but can destabilize training when rewards collapse.
  • For math reasoning tasks, several recent systems report better stability and performance by omitting the KL term altogether.
  • Auxiliary format rewards can improve the response structure, such as encouraging the use of <think> and </think> tokens.
  • Beyond the original GRPO algorithm, many recent extensions modify advantage normalization, importance sampling, clipping strategies, and KL handling to improve stability and efficiency.

FAQ

What is the main goal of chapter 7, “Improving GRPO for reinforcement learning”?The chapter focuses on analyzing GRPO training more deeply and improving it for longer runs. It covers how to interpret training curves, detect instability early, prevent reward exploitation, and add practical enhancements such as clipped policy ratios, KL regularization, and format rewards.
Which metrics are most useful to track during GRPO training?Besides reward and accuracy, the chapter recommends tracking loss, average response length, evaluation accuracy, advantage statistics, entropy, and policy ratio. These metrics together give a clearer picture of whether training is stable, improving, or collapsing.
Why is average reward alone not enough to judge GRPO training?Average reward can rise even when the model is becoming unstable or overfitting to the reward signal. The chapter emphasizes looking at it alongside evaluation accuracy, response length, entropy, and advantage standard deviation to understand whether the model is truly improving.
What does it mean when the average reward reaches 1.0?An average reward of 1.0 means all sampled responses are correct, which sounds ideal, but it also means the training signal has disappeared. At that point, further training is usually not useful, and stopping early may save time and compute.
Why are advantage statistics useful in GRPO?Advantages help reveal the quality spread of sampled rollouts. Their mean should stay near zero by design, so the mean is mostly a sanity check, while the standard deviation is more informative because it shows whether training still has a usable learning signal.
What does a very small or zero advantage standard deviation indicate?A very small or zero advantage standard deviation means the rewards have collapsed to nearly identical values, so the policy gradient becomes zero or nearly zero. In practice, this means the model is no longer learning from that batch.
Why is entropy tracked during GRPO training?Entropy measures how uncertain the model is when choosing the next token. High entropy means the model is exploring widely, low entropy means it is becoming deterministic, and a sudden collapse to very low entropy can be a sign of training failure.
How do clipped policy ratios improve GRPO stability?Clipped policy ratios limit how much the new policy can move away from the old one in a single update. This prevents overly large gradient steps, reducing the chance of reward crashes, entropy collapse, and other unstable training behavior.
What is the role of the KL loss term in GRPO?The KL term penalizes the current model for drifting too far from a reference policy. It acts as a regularizer that helps control long-term deviation, but if it is too strong it can also dominate training and cause undesirable behavior such as overly random outputs.
Why add a format reward with ... tokens?A format reward encourages the model to structure its reasoning explicitly using and tags. This can help shape the output format, but if the format reward is too strong it may distract the model from answer correctness, so it often needs careful weighting or conditional application.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Build a Reasoning Model (From Scratch) ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Build a Reasoning Model (From Scratch) ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Build a Reasoning Model (From Scratch) ebook for free