fix: weight PPO token-mean micro-batches by valid tokens - #292
Open
taking-lying-flat wants to merge 1 commit into
Open
taking-lying-flat wants to merge 1 commit into
taking-lying-flat wants to merge 1 commit into
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.
PR type
PR information
PPOLoss(loss_agg_mode='token-mean')averages valid tokens within a micro-batch but inherits sample-count weighting from GRPO. With response lengths 1 and 3 and advantages +1 and -1, changingmicro_batch_sizefrom 2 to 1 changes the loss from 0.5 to 0 and the same binary policy parameter's gradient from 0.25 to 0.Override PPO's micro-batch weight with the fraction of valid tokens in the logical input batch. Reuse
_resolve_loss_mask()so ignored labels andcompletion_maskmatch the loss's scoring mask. Keep sample-count weighting forseq-mean-token-meanand preserve the existing loss-return and accumulation contracts.Experiment results
tests/loss/test_ppo.py,tests/loss/test_grpo_gkd.py,tests/loss/test_bnpo_token_mean.pyandtests/model/test_micro_batch.py.pre-commit run --all-filesandgit diff --checkpassed.Only the production change in
src/twinkle/loss/grpo.pyis included (+10 lines).