Recommended resources
The freely available resources this lesson will direct you to.
- DeepSeek's GRPO (Group Relative Policy Optimization) | Reinforcement Learning for LLMswww.youtube.com
- The ONLY DeepSeek GRPO/PPO video you'll EVER need (with examples and exercises) | RL Foundationswww.youtube.com
- [PDF] DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via ...arxiv.org
- Advanced Understanding of Group Relative Policy Optimization ...huggingface.co
In our last lesson, we explored the motivation for GRPO's critic-free design, contrasting it with PPO's more complex actor-critic framework. We established that GRPO achieves its efficiency by replacing the learned value function (the critic) with a simpler, empirical baseline.
Today, we will derive and dissect this very baseline: the group relative advantage estimator. This component is the heart of GRPO's innovation, enabling it to evaluate policy updates without needing a separate critic network. By the end of this lesson, you will understand exactly how the advantage for a given model generation is calculated from a batch of its peers.
From Learned Baselines to Empirical Baselines
Let's quickly recall the role of the advantage function in policy gradient methods. The advantage, often denoted as , quantifies how much better a particular action is compared to the average action one might take in state . A standard formulation is , where the value function serves as a variance-reducing baseline.
In PPO, is learned by a critic network. GRPO's central idea is to construct a baseline directly from the data sampled during a rollout. This process involves three key steps:
- Group Sampling: For a given input prompt , the current policy is used to generate a group of distinct output sequences, .
- Reward Evaluation: A reward function (e.g., a simple binary check for correctness, or a more complex reward model) assigns a scalar reward to each output . This gives us a set of rewards .
- Advantage Calculation: The advantage for each output is calculated based on its performance relative to the group.
Deriving the Group Relative Advantage
The "relative" aspect is key. Instead of comparing an action's outcome to a learned expectation , we compare it to the empirical average performance on the same task.
The baseline in GRPO is simply the mean reward of the group:
An initial, unnormalized advantage for output is then . A positive value means the output was better than the group average, while a negative value means it was worse.
However, policy gradient updates are sensitive to the scale of the advantage values. To create a more stable and robust estimator, GRPO normalizes this raw advantage. Given your background in statistics, you'll recognize this normalization as the computation of a standard score (z-score). We divide the raw advantage by the standard deviation of the group's rewards.
This gives us the final group relative advantage estimator, , for the -th output:

The official DeepSeek paper presents this formula concisely. Take a moment to see how it's formally defined.
DeepSeek-R1 Paper: Advantage Formula
This excerpt from the DeepSeek-R1 paper formally presents the GRPO objective and the equation for the advantage estimator.
Read the section "2.1. Group Relative Policy Optimization". Your focus should be on Equation (3), which defines the advantage A_i. Note how it directly corresponds to the z-score calculation we just discussed.
Building Intuition for the Estimator
Now that you've seen the formal definition, let's explore the intuition behind its components. The following video provides an excellent breakdown of what each part of the advantage formula accomplishes.
The ONLY DeepSeek GRPO/PPO video you'll EVER need (with examples and exercises) | RL Foundations
The presenter from the Depth First channel explains the rationale behind both the mean-centering and the standard deviation scaling in the advantage formula.
Watch the segment from the breakdown of the advantage formula. Pay close attention to: How subtracting the mean reward turns the raw reward into a relative "advantage". How dividing by the standard deviation acts as a confidence measure, amplifying the advantage for "impressive" correct answers on hard questions (low reward variance) and dampening it on ambiguous ones (high reward variance).
As the video explains, this normalization does more than just control the scale of the updates. By dividing by the standard deviation, the algorithm becomes more sensitive to outcomes on prompts where the policy's performance is consistent (low std. dev.) and more conservative on prompts where performance is mixed (high std. dev.).
For a quick visual recap of this entire process, watch the following clip.
DeepSeek's GRPO (Group Relative Policy Optimization) | Reinforcement Learning for LLMs
Julia Turc provides a concise visual walkthrough of how the baseline and advantage are computed from a group of sampled trajectories.
Watch the segment from how GRPO computes the baseline. This will reinforce the core steps: sample a group, collect rewards, and then calculate the normalized advantage.
A Worked Example
Let's make this concrete with a numerical example. The Hugging Face guide on GRPO provides a clear, step-by-step calculation.
This resource walks through a practical example of calculating advantage values for a simple arithmetic problem.
Read the section "Step 2: Advantage Calculation". Follow the example where a group of 8 responses is generated, with 4 being correct (reward=1) and 4 being incorrect (reward=0). Trace how the group mean, standard deviation, and the final advantage values for correct and incorrect responses are calculated. You can stop at the "Interpretation" sub-heading.
As you saw in the example:
- A group of 8 responses with rewards .
- Mean: .
- Standard Deviation: The example uses a value of 0.53. A more precise calculation (using population standard deviation, which is common in these implementations) is . Let's use 0.5 for simplicity.
- Advantage for a correct response (): .
- Advantage for an incorrect response (): .
The resulting positive and negative advantages will be used to respectively increase or decrease the probability of generating those responses in the future.
Self-Check
Let's test your understanding. Suppose for a given prompt, you sample a group of responses and obtain the following binary rewards: .
Calculate the group relative advantage for the correct response (). You can use the population standard deviation formula: .
Click to see the solution
- Calculate the mean reward:
- Calculate the standard deviation:
- Calculate the advantage for the correct response ():
Notice how this advantage is significantly greater than 1. This is because the correct response was an outlier in a group of mostly incorrect answers, so the normalization gives it a stronger positive signal.
Conclusion
In this lesson, we have formally derived the group relative advantage estimator, the cornerstone of GRPO's critic-free architecture.
Here are the key takeaways:
- Critic Replacement: GRPO replaces PPO's learned critic with a non-parametric, empirical baseline computed on-the-fly.
- Derivation Steps: The advantage is calculated by (1) sampling a group of responses, (2) collecting their rewards, (3) subtracting the group's mean reward, and (4) normalizing by the group's reward standard deviation.
- Statistical Intuition: The resulting estimator is effectively the z-score of a response's reward within its sample group. This provides a scaled, relative measure of performance.
- Benefit: This simple statistical calculation provides a powerful-enough signal for policy updates while completely sidestepping the cost and complexity of training a separate critic network.
We now have the advantage term . In our next lesson, we will see how this term is integrated into the full GRPO objective function, alongside the clipped policy ratio from PPO and a regularizing KL-divergence penalty.