Fix Trainer with a parallel model#9578
Merged
LysandreJik merged 2 commits intomasterfrom Jan 14, 2021
Merged
Conversation
sgugger
commented
Jan 13, 2021
|
|
||
| if is_torch_available() and self.device.type != "cuda" and self.fp16: | ||
| raise ValueError("Mixed precision training with AMP or APEX (`--fp16`) can only be used on CUDA devices.") | ||
| self._n_gpu = torch.cuda.device_count() |
Collaborator
Author
There was a problem hiding this comment.
Removing from here, this is going to be completely setup in _setup_devices
sgugger
commented
Jan 13, 2021
| model.is_parallelizable = True | ||
| model.model_parallel = True | ||
| trainer = Trainer(model=model, train_dataset=RegressionDataset(), eval_dataset=RegressionDataset()) | ||
| args = TrainingArguments("./regression", per_device_train_batch_size=16, per_device_eval_batch_size=16) |
Collaborator
Author
There was a problem hiding this comment.
Make sure the test uses batch sizes of 16.
sgugger
commented
Jan 13, 2021
| trainer = Trainer(model, args, train_dataset=RegressionDataset(), eval_dataset=RegressionDataset()) | ||
| # Check the Trainer was fooled | ||
| self.assertTrue(trainer.is_model_parallel) | ||
| self.assertEqual(trainer.args.n_gpu, 1) |
Collaborator
Author
There was a problem hiding this comment.
This was still set to 2 before, so this checks it is indeed 1.
stas00
reviewed
Jan 13, 2021
LysandreJik
pushed a commit
that referenced
this pull request
Jan 14, 2021
* Fix Trainer with a parallel model * More clean up
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?
The test introduced in #9566 wasn't actually working as the default batch size is 8, not 16...
So the problem was still there, the reason because
_setup_devicesinTrainingArgumentsis acached_property, so its result is computed once and for all at init. Had to change the behavior slightly, but it should be okay since it's a private method.Fixes #9577 (model is getting wrapped into DataParallel because the value of
self.args.n_gpuis not updated.