-
Notifications
You must be signed in to change notification settings - Fork 302
[skyrl-train] feat: add native GMPO policy loss with validation and tests #1449
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
taivu1998
wants to merge
3
commits into
NovaSky-AI:main
Choose a base branch
from
taivu1998:tdv/issue-834-gmpo
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 all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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
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
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 |
|---|---|---|
|
|
@@ -293,12 +293,31 @@ def validate_cfg(cfg: SkyRLTrainConfig): | |
| cfg.trainer.algorithm.off_policy_correction.tis_ratio_type = "token" | ||
| cfg.trainer.algorithm.off_policy_correction.token_tis_ratio_clip_high = cfg.trainer.algorithm.tis_imp_ratio_cap | ||
|
|
||
| if cfg.trainer.algorithm.policy_loss_type == "gmpo": | ||
| assert ( | ||
| cfg.trainer.algorithm.loss_reduction == "sequence_mean" | ||
| ), "GMPO requires `trainer.algorithm.loss_reduction` to be `sequence_mean`." | ||
|
Comment on lines
+296
to
+299
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency with the check inside if cfg.trainer.algorithm.policy_loss_type == "gmpo" and cfg.trainer.algorithm.loss_reduction != "sequence_mean":
raise ValueError("GMPO requires `trainer.algorithm.loss_reduction` to be `sequence_mean`.") |
||
|
|
||
| # off_policy_correction config validation | ||
| off_policy_correction = cfg.trainer.algorithm.off_policy_correction | ||
| tis_ratio_type = off_policy_correction.tis_ratio_type | ||
| sequence_mask_metric = off_policy_correction.sequence_mask_metric | ||
|
|
||
| uses_off_policy_correction = tis_ratio_type is not None or sequence_mask_metric is not None | ||
| gmpo_uses_off_policy_correction = uses_off_policy_correction or any( | ||
| threshold is not None | ||
| for threshold in ( | ||
| off_policy_correction.outlier_token_is_threshold_low, | ||
| off_policy_correction.outlier_token_is_threshold_high, | ||
| off_policy_correction.token_mask_is_threshold_low, | ||
| off_policy_correction.token_mask_is_threshold_high, | ||
| ) | ||
| ) | ||
|
|
||
| if cfg.trainer.algorithm.policy_loss_type == "gmpo" and gmpo_uses_off_policy_correction: | ||
| raise NotImplementedError( | ||
| "GMPO does not support `trainer.algorithm.off_policy_correction`; use `sequence_mean` without rollout correction." | ||
| ) | ||
|
|
||
| if uses_off_policy_correction: | ||
| # Validate tis_ratio_type | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
clip_ratioandclip_ratio_lowermetrics are slightly inaccurate as currently implemented.clippedis defined as any log-ratio outside the[-eps_clip_low, eps_clip_high]range, but in PPO-style clipping (which GMPO follows here), a token is only considered "clipped" if the clipping actually modifies the objective. For example, ifadvantages > 0andlog_ratio < -eps_clip_low, the objective uses the originallog_ratio(via theminimumlogic), so it isn't actually clipped.A more accurate way to compute these metrics is to check where
effective_log_ratiodiffers from the originallog_ratio.