Repository navigation
Fixing global_max_loss computation - #2314
Merged
Merged
Conversation
Shagun-G
requested review from
fegin,
tianyu-l,
wconstab and
wwwjn
as code owners
February 2, 2026 20:47
wwwjn
reviewed
Feb 2, 2026
| @@ -619,9 +619,14 @@ def train_step( | |||
| # loss = local_loss_sum / global_valid_tokens | |||
Contributor
There was a problem hiding this comment.
Suggested change
| # loss = local_loss_sum / global_valid_tokens | |
| # loss is define as local_loss_sum / global_valid_tokens |
Contributor
There was a problem hiding this comment.
Thanks! Let's make the calculation of global_avg_loss and global_avg_loss comment more clear. Can you help modify the comment about how to calculate global_avg_loss as well?
And please change the definition here as well:
torchtitan/torchtitan/components/metrics.py
Lines 411 to 412 in fdd3a37
Summary: As per the fix to handle token imbalance D91432940 , the global_max_loss computed is below the global_avg_loss as shown in the test plan. This is because of the pre division of the loss to the global tokens. While the avg loss computation is correct, the global max loss in this case becomes the max of the loss contribution of each rank, no the max of the local loss of each rank. One fix is to recale the local loss to the average loss for each rank to get the local average loss and then perform the max operation. The result can be seen in the test plan. Differential Revision: D92079302
tianyu-l
approved these changes
Feb 3, 2026
tianyu-l
left a comment
Contributor
There was a problem hiding this comment.
sounds ok to me as long as it's explicitly defined.
TXacs
pushed a commit
to McmillanTAC/torchtitan
that referenced
this pull request
Apr 13, 2026
Differential Revision: D92079302 Pull Request resolved: pytorch#2314
ACharacterInASimulation
pushed a commit
to ACharacterInASimulation/torchtitan
that referenced
this pull request
Apr 21, 2026
Differential Revision: D92079302 Pull Request resolved: pytorch#2314
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:
As per the fix to handle token imbalance D91432940 , the global_max_loss computed is below the global_avg_loss as shown in the test plan. This is because of the pre division of the loss to the global tokens. While the avg loss computation is correct, the global max loss in this case becomes the max of the loss contribution of each rank, no the max of the local loss of each rank.
One fix is to recale the local loss to the average loss for each rank to get the local average loss and then perform the max operation. The result can be seen in the test plan.
Differential Revision: D92079302