-
Notifications
You must be signed in to change notification settings - Fork 230
New Algorithm: MAPO implementation #388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ZiyiTsang
wants to merge
19
commits into
inclusionAI:main
Choose a base branch
from
ZiyiTsang:MAPO
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5f74710
MAPO implementation
ZiyiTsang e8681a9
.
ZiyiTsang 05bf6b2
.
ZiyiTsang a9de698
.
ZiyiTsang 62e7cfc
.
ZiyiTsang e4cc054
merge
ZiyiTsang a92564b
.
ZiyiTsang e1bbe4b
Update docs/algorithms/mapo.md
ZiyiTsang b6d0228
thank you gemini..code change
ZiyiTsang fba252f
thank you gemini..code change
ZiyiTsang df71ffb
.
ZiyiTsang aeb3222
commit for review
ZiyiTsang 1b575e6
Merge branch 'main' into MAPO
ZiyiTsang ed51e5f
commit for review
ZiyiTsang ff69805
.
ZiyiTsang 488e652
.
ZiyiTsang 63cd9a3
.
ZiyiTsang 987044e
Merge branch 'main' into MAPO
ZiyiTsang 71f51de
.
ZiyiTsang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # Mixed Advantage Policy Optimization (MAPO) | ||
|
|
||
| Last updated: Sep 27, 2025 | ||
ZiyiTsang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Author: [Ziyi ZENG](https://github.com/ZiyiTsang) | ||
|
|
||
|  | ||
|
|
||
| This paper introduces Mixed Advantage Policy Optimization (MAPO), an improved Group Relative Policy Optimization (GRPO) strategy designed to enhance the reasoning performance of foundation models. While GRPO has been effective in post-training foundation models for reasoning tasks, it suffers from "advantage reversion" and "advantage mirror" problems, which lead to an unreasonable allocation of advantage across different query samples. MAPO addresses these limitations by introducing the concept of "trajectory certainty" and proposing an "Advantage Percent Deviation" (APD) for high-certainty trajectories. Furthermore, it dynamically reweights the advantage function based on trajectory certainty through "Trajectory Certainty Reweight" (TCR). This adaptive approach allows MAPO to configure the advantage function to account for sample-specific characteristics, thereby mitigating the shortcomings of prior advantage function formulations and producing more stable and accurate reasoning performance across diverse tasks. | ||
|
|
||
| The overall surrogate objective is: | ||
|
|
||
|
|
||
| $$\mathcal{J}_{\mathrm{GRPO}}(\theta)=\mathbb{E}_{q\sim\rho_{Q}}\mathbb{E}_{o\sim\pi_{old}(\cdot|q)}\left[\frac{1}{G}\sum_{i}^{G}f_{\epsilon}\left(\frac{\pi_{\theta}(o_{i}|q)}{\pi_{old}(o_{i}|q)},\hat{\Lambda}_{i}\right)\right]-\beta\mathbb{D}_{KL}[\pi_{\theta}||\pi_{ref}],$$ | ||
| where: | ||
| $$f_\epsilon(x,y)=\min(xy,\mathrm{clip}(x,1-\epsilon,1+\epsilon)y)$$ | ||
|
|
||
| $$\lambda(p)=1-4p(1-p)\in[0,1]\quad(p\in[0,1])$$ | ||
|
|
||
| $$\hat{A}_i^*=(1-\lambda(p))*\underbrace{\frac{r_i-\mu}{\sigma}}_{\text{Deviation-based}}+\lambda(p)*\underbrace{\frac{r_i-\mu}{\mu}}_{\text{Mean-based}}.$$ | ||
|
|
||
|
|
||
| For more details: | ||
|
|
||
| - AReal Detail: [Paper of AReal](https://arxiv.org/abs/2505.24298) | ||
|
|
||
| - MAPO Detail: [Paper of MAPO](https://arxiv.org/abs/2509.18849v3) | ||
|
|
||
| ## Algorithm Core Parameters | ||
|
|
||
| - `actor.adv_norm.aggregation_mode`: the implementation of adv_norm. 'native' is the z-score normalization used by GRPO, while 'mix' is the implementation for MAPO. | ||
ZiyiTsang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Notice | ||
| For MAPO implementation, following constraints should be met: | ||
|
|
||
| 1. 'reward_function' should return binary result of any value. High value represents the successful trajectory, while the lower value represent the fail trajectory. | ||
| 2. the 'overlong_reward_panelty' should be disable | ||
ZiyiTsang marked this conversation as resolved.
Show resolved
Hide resolved
ZiyiTsang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| ## Example Usage | ||
|
|
||
| We recommend to change the parameter within the configuration file | ||
| (i.e. gsm8k_mapo.yaml). | ||
|
|
||
| | Backend | CMD | | ||
| | --------- | -------------------------------------------------------------------------------------------------------------------------------- | | ||
| | **local** | `python3 -m areal.launcher.local examples/experimental/mapo/gsm8k_mapo.py --config examples/experimental/mapo/gsm8k_mapo.yaml --<other_args_to_overwrite>` | | ||
| | **ray** | `python3 -m areal.launcher.ray examples/experimental/mapo/gsm8k_mapo.py --config examples/experimental/mapo/gsm8k_mapo.yaml --<other_args_to_overwrite>` | | ||
| | **slurm** | `python3 -m areal.launcher.slurm examples/experimental/mapo/gsm8k_mapo.py --config examples/experimental/mapo/gsm8k_mapo.yaml --<other_args_to_overwrite>` | | ||
|
|
||
| ## Baselines | ||
|
|
||
| We still lack baseline, welcome to contribute! | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| experiment_name: gsm8k-grpo | ||
| experiment_name: gsm8k-drgrpo | ||
| trial_name: trial0 | ||
|
|
||
| seed: 1 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| experiment_name: gsm8k-grpo | ||
| experiment_name: gsm8k-liteppo | ||
| trial_name: trial0 | ||
|
|
||
| seed: 1 | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.