show me the GRPO algorithm formula
- User
show me the GRPO algorithm formula
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
show me the GRPO algorithm formula
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
The Group Relative Policy Optimization (GRPO) algorithm is a variant of Proximal Policy Optimization (PPO) introduced by DeepSeek to enhance mathematical reasoning capabilities in language models while optimizing memory usage. The formal GRPO objective function is defined as:
Where the clipped surrogate loss component is:
And the group-normalized advantage is calculated as:
This component encourages the model to improve responses that receive higher rewards while preventing excessive policy updates through clipping:
GRPO's key innovation is its approach to calculating advantage without requiring a value function model:
This term prevents the policy from deviating too far from the reference model:
A more detailed version of the GRPO formula can be written as:
\mathcal{J}_{GRPO}(\theta) &= \mathbb{E}\left[q \sim P(Q),\left\{o_i\right\}_{i=1}^G \sim \pi_{\theta_{old}}(O \mid q)\right] \\ &\frac{1}{G} \sum_{i=1}^G \frac{1}{\left|o_i\right|} \sum_{t=1}^{\left|o_i\right|}\left\{\min \left[\frac{\pi_\theta\left(o_{i, t} \mid q, o_{i,<t}\right)}{\pi_{\theta_{old}}\left(o_{i, $\hat{a}_{i,t}$="" $g$="" $i$<a="" $o_i$="" $q$="" $t$="" (typically="" -="" 1+\varepsilon\right)="" 1-\varepsilon,="" 8)="" \end{aligned}$$="" \hat{a}_{i,="" \mathbb{d}_{kl}\left[\pi_\theta||="" \mid="" \operatorname{clip}\left(\frac{\pi_\theta\left(o_{i,="" \pi_{ref}\right]\right\}="" advantage="" at="" corresponds="" each="" for="" generated="" generations="" href="https://swift.readthedocs.io/en/latest/BestPractices/GRPO.html" is="" number="" o_{i,<t}\right)}="" o_{i,<t}\right)},="" o_{i,<t}\right)}{\pi_{\theta_{old}}\left(o_{i,="" of="" per="" position="" prompt="" q,="" represents="" response="" set="" style="color: #007bff" the="" to="" token="" t}="" t},="" t}\right]-\beta="" where:="">[1] ## How GRPO Differs from PPO The key difference between GRPO and traditional PPO lies in how the advantage is calculated: 1. **No Value Function Model**: Unlike PPO which requires a separate critic network to estimate advantages, GRPO uses group normalization of rewards, eliminating the need for a value function model[2][4] 2. **Memory Efficiency**: By removing the critic network, GRPO reduces memory usage by up to 90% compared to standard PPO implementations, making it more practical for training large language models[6] 3. **Simplified Training Process**: The GRPO workflow follows a more streamlined approach: - Generate multiple responses for each prompt - Score each response using reward functions - Normalize scores within each group to calculate advantages - Update the policy to maximize the reward while staying close to the reference model[3][4] This efficient approach is what allowed DeepSeek to train powerful reasoning models like DeepSeek-R1 and DeepSeekMath with significantly reduced computational requirements compared to traditional RLHF methods[5].