Support token-level loss, make default#90
Merged
tyler-griggs merged 7 commits intomainfrom Jul 15, 2025
Merged
Conversation
a4e5745 to
2d70b1e
Compare
SumanthRH
approved these changes
Jul 15, 2025
| loss_mask = torch.tensor([[1.0, 1.0, 1.0], [1.0, 0.0, 0.0]], device=device) | ||
|
|
||
| # Test token_mean without mask | ||
| loss_fn_token = PolicyLoss(loss_type="regular", loss_reduction="token_mean") |
Member
There was a problem hiding this comment.
nit: you should explicitly pass in the eps low and eps high values here to make the test less brittle
Member
|
Would be nice to add a screenshot for convergence on gms8k (and how it changes from before) before merging |
Co-authored-by: Sumanth R Hegde <39546518+SumanthRH@users.noreply.github.com>
Member
Author
|
Added details form gsm8k run in initial PR description. |
fannie1208
pushed a commit
to vinid/SkyRL
that referenced
this pull request
Aug 19, 2025
## What does this PR do? Adds support for token-level loss (ie, `token_mean` loss reduction type) as introduced by DAPO. With `token_mean` loss reduction, all tokens in all sequences contribute equally to loss. The loss reduction type is configurable via `trainer.algorithm.loss_reduction`, but the default is updated to be `token_mean`, as opposed to our previous implementation (`sequence_mean`). This loss reduction is what the community is standardizing on as default (TRL's [default](huggingface/trl#2881), verl's [default](https://github.com/volcengine/verl/blob/517cc23c9dbb0da5c2cd2b012466790e29cb781a/verl/trainer/config/actor/actor.yaml#L63)) Wandb report of comparing `token_mean` vs `sequence_mean`: https://wandb.ai/sky-posttraining-uc-berkeley/gsm8k/reports/Token-level-loss-token_mean---VmlldzoxMzYwMDc4MQ The only plot with a notable difference is `policy_loss`, which is much larger for `token_mean` than it is for `sequence_mean`: <img width="312" height="274" alt="Screenshot 2025-07-15 at 9 52 57 AM" src="https://github.com/user-attachments/assets/40f94cb6-c5e5-47f6-9b09-a076811746a0" /> However, this `policy_loss` matches the same magnitude of `pg_loss` we observe in verl: <img width="980" height="611" alt="Screenshot 2025-07-15 at 9 54 39 AM" src="https://github.com/user-attachments/assets/53714573-2b21-4e67-b30a-dd3648279438" /> --------- Co-authored-by: Sumanth R Hegde <39546518+SumanthRH@users.noreply.github.com>
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.
What does this PR do?
Adds support for token-level loss (ie,
token_meanloss reduction type) as introduced by DAPO.With
token_meanloss reduction, all tokens in all sequences contribute equally to loss.The loss reduction type is configurable via
trainer.algorithm.loss_reduction, but the default is updated to betoken_mean, as opposed to our previous implementation (sequence_mean). This loss reduction is what the community is standardizing on as default (TRL's default, verl's default)Wandb report of comparing
token_meanvssequence_mean: https://wandb.ai/sky-posttraining-uc-berkeley/gsm8k/reports/Token-level-loss-token_mean---VmlldzoxMzYwMDc4MQThe only plot with a notable difference is

policy_loss, which is much larger fortoken_meanthan it is forsequence_mean:However, this

policy_lossmatches the same magnitude ofpg_losswe observe in verl: