Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable lr_scheduler.step() in manual optimization #6825

Merged
merged 24 commits into from
Apr 20, 2021

Conversation

akihironitta
Copy link
Contributor

@akihironitta akihironitta commented Apr 4, 2021

What does this PR do?

Fixes #6379. Once #6567 and this PR are merged, users can call lr_scheduler.step() at arbitrary intervals in manual optimization for ultimate flexibility.

Before submitting

  • Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • 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)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

PR review

Anyone in the community is free to review the PR once the tests have passed.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • 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 🙃

@akihironitta akihironitta added the feature Is an improvement or enhancement label Apr 4, 2021
@akihironitta akihironitta added this to the 1.3 milestone Apr 4, 2021
@codecov
Copy link

codecov bot commented Apr 4, 2021

Codecov Report

Merging #6825 (0ff4fea) into master (d1529c2) will decrease coverage by 1%.
The diff coverage is 100%.

@@           Coverage Diff           @@
##           master   #6825    +/-   ##
=======================================
- Coverage      92%     91%    -1%     
=======================================
  Files         197     197            
  Lines       12588   12821   +233     
=======================================
+ Hits        11610   11696    +86     
- Misses        978    1125   +147     

@akihironitta akihironitta changed the title Disable lr_scheduler.step() in manual optimization [WIP] Disable lr_scheduler.step() in manual optimization Apr 5, 2021
@akihironitta akihironitta marked this pull request as ready for review April 5, 2021 09:20
akihironitta and others added 2 commits April 5, 2021 19:16
Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
CHANGELOG.md Outdated Show resolved Hide resolved
@@ -32,7 +32,7 @@ def update_learning_rates(self, interval: str, monitor_metrics=None):
interval: either 'epoch' or 'step'.
monitor_metrics: dict of possible values to monitor
"""
if not self.trainer.lr_schedulers:
if not self.trainer.lr_schedulers or not self.trainer.train_loop.automatic_optimization:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's update the doc with this change + add a warning if we detect the scheduler was on step or epoch, but never triggered.

Copy link
Contributor Author

@akihironitta akihironitta Apr 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tchaton I updated the docs and added a warning when scheduler keys (e.g. "interval", "frequency", "monitor"), which are invalid in manual optimization, are provided. Would you mind having a look at the changes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Could we add in the doc how to use the scheduler for interval=epoch.

 def training_step(self, batch, batch_idx)

     # do optimization

      if self.trainer.is_last_batch: # is_last_batch doesn't exist for the trainer, could be added.
             self.lr_schedulers[0].step()

Copy link
Contributor Author

@akihironitta akihironitta Apr 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tchaton I added self.trainer.is_last_batch and updated the docs. Could you have a look again?

akihironitta and others added 2 commits April 7, 2021 04:10
Co-authored-by: thomas chaton <thomas@grid.ai>
@akihironitta akihironitta marked this pull request as draft April 7, 2021 15:34
@akihironitta akihironitta mentioned this pull request Apr 8, 2021
7 tasks
Copy link
Contributor

@tchaton tchaton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work there !

CHANGELOG.md Show resolved Hide resolved
docs/source/common/optimizers.rst Outdated Show resolved Hide resolved
pytorch_lightning/trainer/training_loop.py Show resolved Hide resolved
@tchaton
Copy link
Contributor

tchaton commented Apr 9, 2021

@akihironitta. There is a bug with Pipe.

Better to access trainer.train_loop.automatic_optimization

Screenshot 2021-04-09 at 10 28 58

@mergify mergify bot added the has conflicts label Apr 9, 2021
@mergify mergify bot removed the has conflicts label Apr 9, 2021
@akihironitta akihironitta marked this pull request as draft April 9, 2021 10:06
@akihironitta akihironitta marked this pull request as ready for review April 9, 2021 10:18
@akihironitta
Copy link
Contributor Author

I think the failing tests on Windows are not related to the changes here as they're also failing on master.

tests/trainer/test_data_loading.py::test_dataloader_warnings[0] FAILED   [ 63%]
tests/trainer/test_data_loading.py::test_dataloader_warnings[1] FAILED   [ 63%]

Borda
Borda previously requested changes Apr 9, 2021
Copy link
Member

@Borda Borda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like all Windows tests are failing

@carmocca
Copy link
Contributor

carmocca commented Apr 9, 2021

Windows errors are caused by #6762

@akihironitta
Copy link
Contributor Author

@Borda The failing windows tests should be fixed now by @carmocca in #6930, so would you mind having a look again?

@akihironitta akihironitta requested a review from Borda April 9, 2021 20:04
@edenlightning edenlightning modified the milestones: 1.3, 1.4 Apr 16, 2021
@tchaton tchaton modified the milestones: v1.4, v1.3 Apr 19, 2021
@carmocca carmocca enabled auto-merge (squash) April 19, 2021 15:57
@akihironitta
Copy link
Contributor Author

Just for the note, as #6907 has been merged already, there's no need to change any docs here, so I reverted the docs change.

@carmocca carmocca dismissed Borda’s stale review April 20, 2021 11:00

Windows tests are fixed

@carmocca carmocca merged commit 0302b8b into master Apr 20, 2021
@carmocca carmocca deleted the feat/disable-lrscheduler-in-manopt branch April 20, 2021 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Is an improvement or enhancement ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't lr_scheduler.step() in manual optimization
6 participants