Fix OneCycle step length when in multiprocess #385
Merged
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.
Fix improper number of times OneCycle scheduler is called
What does this add?
This PR fixes an issue where
torch.optim.lr_scheduler.OneCycle.step
expects to be called a particular number of times, and will raise an issue when called more than this. The typical scenario of when this happens is when the user did not specifydrop_last=True
in theirDataLoaders
. For now this is specific toOneCycle
, but the API will ideally be consistent if another scheduler is added to Pytorch that uses this same method of tracking maximum steps.Note: All other schedulers work, it's just OneCycle that does not
Why is it needed?
The cv_examples currently all break in multiproc settings, due to the incorrect number of times
.step()
is being calledWhat parts of the API does this impact?
User-facing:
Nothing
Internal structure:
Adds the following check if not
self.split_batches
:for _ in range(num_processes): + if getattr(self.scheduler, "total_steps", 0) < self.scheduler.last_epoch: self.scheduler.step(*args, **kwargs)