pytorch-lightning
pytorch-lightning copied to clipboard
Fix restoring trainer after `lr_find()`
What does this PR do?
Fixes #12670: After using the LR finder and then training the model with the same trainer instance (which is the standard use-case), an incorrect learning rate schedule is used, leading to immediate divergence.
This bug was introduced in Lightning version 1.6 by commit a6a28e08d22f59f2468ff1049c67507df7519e7c, which removed two lines responsible for resetting the init_optimizers
method of the trainer after it has been replaced with a wrapper changing the LR scheduler to one trying different learning rates.
This PR reintroduces these two lines and updates them to match the current codebase, where trainer.init_optimizers
has been renamed to trainer.strategy.setup_optimizers
.
Does your PR introduce any breaking changes? If yes, please list them.
No
Before submitting
- [x] Was this discussed/approved via a GitHub issue? (not for typos and docs)
- [x] Did you read the contributor guideline, Pull Request section?
- [x] Did you make sure your PR does only one thing, instead of bundling different changes together?
- [x] Did you make sure to update the documentation with your changes? (if necessary)
- [ ] Did you write any new necessary tests? (not for typos and docs)
- [x] Did you verify new and existing tests pass locally with your changes?
- [x] Did you list all the breaking changes introduced by this pull request?
- [x] Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors)
PR review
Anyone in the community is welcome to review the PR. Before you start reviewing, make sure you have read the review guidelines. In short, see the following bullet-list:
- [x] Is this pull request ready for review? (if not, please submit in draft mode)
- [ ] Check that all items from Before submitting are resolved
- [x] Make sure the title is self-explanatory and the description concisely explains the PR
- [ ] Add labels and milestones (and optionally projects) to the PR so it can be classified
Did you have fun?
Make sure you had fun coding 🙃