Add SAPO policy loss objective#1864
Open
taivu1998 wants to merge 1 commit intoTHUDM:mainfrom
Open
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Implements SAPO as a new policy-loss objective for slime.
--policy-loss-type sapoalongside the existing clipped PPO objective.--sapo-tau-posand--sapo-tau-negto control the positive- and negative-advantage SAPO gates.Issue
Closes #954.
Implementation Details
The policy-loss helper now keeps the existing clipped PPO behavior as the default path and adds a SAPO path selected by
policy_loss_type. SAPO computes a clamped probability ratio from the policy KL term, applies sign-awaretauselection based on the advantage, and uses the soft-ratio gate from the issue design while keeping the result finite for extreme log-ratio inputs.The Megatron loss wrapper passes the configured loss type and SAPO tau values into the helper, then reduces and logs the SAPO auxiliary metric when applicable. Argument validation rejects non-positive SAPO tau values and limits SAPO to the GRPO/GSPO advantage estimators, matching the supported rollout objective surface.
Validation
uv run --isolated --python 3.10 --with pytest --with torch --with numpy --no-project python -m pytest tests/test_policy_loss.py -quv run --isolated --python 3.10 --with ruff --no-project ruff check slime/utils/ppo_utils.py slime/backends/megatron_utils/loss.py slime/utils/arguments.py tests/test_policy_loss.pyuv run --isolated --python 3.10 --no-project python -m py_compile slime/utils/ppo_utils.py slime/backends/megatron_utils/loss.py slime/utils/arguments.py tests/test_policy_loss.pygit diff --checkGPU integration smoke was not run in this local environment.