Fix RNG reload in resume training from epoch checkpoint#17055
Merged
Conversation
|
The documentation is not available anymore as the PR was closed or merged. |
atreyasha
reviewed
May 3, 2022
tests/trainer/test_trainer.py
Outdated
| # For more than 1 GPUs, since the randomness is introduced in the model and with DataParallel (which is used | ||
| # in this test for more than 2 GPUs), the calls to the torch RNG will happen in a random order (sometimes | ||
| # GPU 0 will call first and sometimes GPU 1). | ||
| random_torch = torch.cuda.is_available() and torch.cuda.device_count() >= 1 |
There was a problem hiding this comment.
Sorry, just a question regarding this line. AFAICT random_torch would only be True if at least one GPU is available. But this would mean this test case will not cover torch randomness when using the CPU. The unit test before this commit however did test randomness on the CPU, or at least was able to if no GPU was available. Is this change intended?
Collaborator
Author
There was a problem hiding this comment.
Good catch! I'll fix this :-)
stevhliu
pushed a commit
to stevhliu/transformers
that referenced
this pull request
May 3, 2022
…17055) * Fix RNG reload in resume training from epoch checkpoint * Fix test
elusenji
pushed a commit
to elusenji/transformers
that referenced
this pull request
Jun 12, 2022
…17055) * Fix RNG reload in resume training from epoch checkpoint * Fix test
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?
This PR fixes the reproducibility in training when checkpoints are saved every epoch. The main reason it was failing (as pointed out in #17032) is that the RNG states were never reloaded. They need to be reloaded exactly before iterating through the new epoch, as the call to this will change the global PyTorch RNG (even if the dataloader uses its own generator...) The new test added makes sure this reproducibility is fully tested.
While debugging this, two issues occurred, which this PR also fixes.
DataParallel(an issue that wouldn't be the case withDistributedDataParallelbut we would need to execute the test via a launcher in that case). So in the test, we only do PyTorch randomness on one or zero GPU to fix this flakiness.Fixes #17032