Repository navigation
Avoid per-microbatch D2H caused by isfinite - #3873
Merged
Merged
Conversation
[ghstack-poisoned]
tianyu-l
approved these changes
Jul 6, 2026
Collaborator
|
Hi @fegin, This looks like a good compromise to avoid the D2H overhead. I didn't realize it could have such a significant impact. Is the issue primarily that it interferes with kernel scheduling across successive microbatches, or is it mostly the overhead of transferring a single boolean to the host? One alternative that might be worth considering for the logging condition is to perform the torchtitan/torchtitan/trainer.py Lines 821 to 826 in d04f7b9 |
jemitche1
pushed a commit
to jemitche1/torchtitan
that referenced
this pull request
Jul 15, 2026
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.15.0) (oldest at bottom): * __->__ pytorch#3873 pytorch#3863 introduces a good feature to raise if loss is NaN but also introduces per-micro-batch D2H sync. This PR fixes the issue with the penalty that the actual batch that causes the NaN is unkown (within a certain range). pytorch#2728 is a potential solution to remove the penalty. Another mitigation from @mlazos: you could also copy N loss values on GPU to keep a record of which of the N steps had the NaN.
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.
Stack from ghstack (oldest at bottom):
#3863 introduces a good feature to raise if loss is NaN but also introduces per-micro-batch D2H sync. This PR fixes the issue with the penalty that the actual batch that causes the NaN is unkown (within a certain range).
#2728 is a potential solution to remove the penalty.
Another mitigation from @mlazos: you could also copy N loss values on GPU to keep a record of which of the N steps had the NaN.