Overview

7 Improving GRPO for reinforcement learning

This chapter takes the basic GRPO-based reinforcement learning setup from the previous chapter and examines what happens when training is run for longer. It emphasizes that reward and accuracy alone are not enough to understand training behavior: loss, response length, evaluation accuracy, advantage statistics, entropy, and policy ratios all provide complementary signals. The chapter shows that early improvements can be followed by instability, such as declining benchmark accuracy, growing or shrinking response lengths, reward saturation, or loss spikes, even when the implementation is technically correct.

A major focus is stabilizing GRPO. The chapter introduces advantage tracking, where the average advantage should remain near zero and the standard deviation indicates whether a useful learning signal remains. It also adds entropy tracking to monitor whether the model is becoming too deterministic, too random, or still exploring productively. To reduce overly large updates, the chapter implements clipped policy ratios, which compare old and new sequence log-probabilities and limit how much a rollout can influence an update. This modification leads to more stable training in the demonstrated run. The chapter also revisits the KL loss term, explaining that it constrains the trained model to remain close to a reference model, but also showing that a naive KL implementation can destabilize training by encouraging long outputs or dominating the gradient when rewards collapse.

The chapter then extends the reward design by adding an explicit formatting reward, encouraging the model to produce reasoning inside <think> and </think> tags. It explains how tokenizers must support these tags, why a model should ideally be pre-trained or instruction-tuned on such tokens before RL training, and how a format reward can be combined with correctness rewards. The experiments show that auxiliary rewards can help shape output structure but may also be exploited if they are too strong or granted independently of correctness. The chapter closes by highlighting that GRPO and RLVR remain active research areas, with many recent modifications aimed at improving stability, sampling efficiency, normalization, clipping, KL handling, and reward aggregation.

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 revisits the baseline GRPO implementation from the previous chapter and focuses on what happens during longer reinforcement-learning runs. It explains how to interpret training curves, track useful metrics beyond reward and accuracy, identify instability, prevent reward exploitation, and extend GRPO with practical additions such as clipped policy ratios, KL regularization, and format rewards.
Which basic metrics should be tracked during GRPO training?The chapter tracks loss, average reward, average response length, and evaluation accuracy. Average reward should generally increase, response length often grows as the model learns to reason more, and external evaluation accuracy should improve on a fixed benchmark such as MATH-500. Loss is less informative than in pretraining, but it is still useful as a sanity check; large spikes can indicate instability.
Why can an average reward of 1.0 mean training should stop?An average reward of 1.0 means all sampled responses in the current group receive full reward. While this is desirable, it also means there is no remaining relative learning signal for GRPO because all rollouts look equally good. At that point, further training is unlikely to help unless the model is given harder examples, so early stopping can save compute.
What are advantage statistics, and why are they useful in GRPO?GRPO computes advantages by normalizing rewards relative to the group mean. The advantage mean should stay near zero by construction, so it mainly acts as a sanity check. The advantage standard deviation is more informative: values near 1 suggest a well-scaled signal, very small values indicate a vanishing learning signal, and very large values can indicate unstable, spiky updates.
What does entropy measure during GRPO training?Entropy measures how spread out the model’s next-token probability distribution is. High entropy means the model is uncertain and exploratory, while low entropy means the model is confident and more deterministic. During healthy training, entropy may gradually decrease as the model becomes more confident, but a sudden collapse to very low entropy can signal unstable training or repetitive output behavior.
What are clipped policy ratios, and how do they stabilize GRPO?Clipped policy ratios compare the probability of a rollout under the current model with its probability under an earlier version of the model. If the ratio becomes too large or too small, it can produce overly aggressive updates. Clipping limits how far the model can move in one update step, reducing the risk of reward crashes, entropy collapse, or sudden shifts in token probabilities.
How does the KL term differ from clipped policy ratios?Both mechanisms control how much the model changes, but they do so differently. Clipped policy ratios mainly limit the size of individual update steps by comparing old and new policy probabilities. The KL term penalizes divergence from a reference model, often the original model at the start of training, and is used to control longer-term drift across the training trajectory.
Why did the KL loss experiment become unstable in the chapter?The chapter shows that adding a KL term can cause instability when it is computed from summed sequence log-probabilities. Longer responses naturally produce larger KL values, which can unintentionally encourage long outputs. Once rewards collapse to zero, the policy-gradient signal disappears, leaving the KL term as the dominant gradient source. This can push the model toward high entropy, random token generation, and near-zero evaluation accuracy.
What is a format reward, and why is it added?A format reward is an auxiliary reward that encourages outputs to follow a desired structure. In this chapter, the format reward gives credit when the model emits <think> and </think> tokens in the correct order. This can help separate intermediate reasoning from the final answer, but it must be balanced carefully so the model does not optimize formatting at the expense of correctness.
What problem can occur when the format reward is too strong?If the format reward is too large, the model may learn to focus on producing the required <think>...</think> structure rather than solving the task correctly. In the chapter’s experiment, the average reward stayed roughly constant while evaluation accuracy declined, suggesting that the model was receiving too much reward from formatting alone. Possible fixes include lowering the format reward weight or giving the format reward only when the answer is also correct.

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