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

Decouple Tuner from Trainer #16462

Merged
merged 40 commits into from
Jan 27, 2023
Merged

Decouple Tuner from Trainer #16462

merged 40 commits into from
Jan 27, 2023

Conversation

awaelchli
Copy link
Contributor

@awaelchli awaelchli commented Jan 21, 2023

What does this PR do?

Removes:

  • Trainer.tuner
  • Trainer.tune()
  • Trainer(auto_lr_find=..., auto_scale_batch_size=...)

New usage:

trainer = Trainer()
tuner = Tuner(trainer)
tuner.lr_find(...)
tuner.scale_batch_size(...)

Furthermore, the same tuner features are available through the LearningRateFinder and BatchSizeFinder callbacks.

Note: The tuning callbacks still rely on the Trainer handling the TunerExitException. Haven't yet found a way to decouple that. This can be discussed in a follow-up.

Fixes #5374
Fixes #9103

Does your PR introduce any breaking changes? If yes, please list them.

Yes, justified by the 2.0 initiative of making Trainer leaner.

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?

I made sure I had fun coding 🙃

cc @Borda @justusschock

@github-actions github-actions bot added the pl Generic label for PyTorch Lightning package label Jan 21, 2023
@awaelchli awaelchli added tuner breaking change Includes a breaking change and removed pl Generic label for PyTorch Lightning package labels Jan 21, 2023
@awaelchli awaelchli added this to the 2.0 milestone Jan 21, 2023
@awaelchli awaelchli self-assigned this Jan 21, 2023
@awaelchli awaelchli changed the title Remove Tuner from Trainer WIP: Remove Tuner from Trainer Jan 21, 2023
@github-actions github-actions bot added the pl Generic label for PyTorch Lightning package label Jan 21, 2023
@awaelchli awaelchli added the fun Staff contributions outside working hours - to differentiate from the "community" label label Jan 22, 2023
Copy link
Contributor

@carmocca carmocca left a comment

Choose a reason for hiding this comment

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

Phew! Nice work

src/pytorch_lightning/tuner/__init__.py Outdated Show resolved Hide resolved
src/pytorch_lightning/tuner/lr_finder.py Outdated Show resolved Hide resolved
@mergify mergify bot removed the has conflicts label Jan 27, 2023
@mergify mergify bot removed the has conflicts label Jan 27, 2023
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.

I love the simplification, just thinking about the new name...

Copy link
Member

@justusschock justusschock left a comment

Choose a reason for hiding this comment

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

Implementation looks good. Just a general question:
Do we really need a new tuner object or can these be callbacks only?

@awaelchli
Copy link
Contributor Author

awaelchli commented Jan 27, 2023

Do we really need a new tuner object or can these be callbacks only?

The tuner object is not new, it was always a public class (maybe it should not have been from the start). The callbacks were introduced recently yes, but there are features in the tuner that are a bit unclear how you would use them with just callbacks. For example, an interaction like this:

tuner = Tuner()
finder = tuner.lr_find(...)
finder.plot()
finder.suggestion()

etc.

The good thing is, after this PR, the development on the tuner code can happen without impacting anything on the Trainer side. So there is still the possibility to go in either direction.

@mergify mergify bot added ready PRs ready to be merged and removed has conflicts ready PRs ready to be merged labels Jan 27, 2023
@awaelchli awaelchli enabled auto-merge (squash) January 27, 2023 14:42
@awaelchli awaelchli merged commit b216a11 into master Jan 27, 2023
@awaelchli awaelchli deleted the removal/tuner branch January 27, 2023 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Includes a breaking change fun Staff contributions outside working hours - to differentiate from the "community" label pl Generic label for PyTorch Lightning package ready PRs ready to be merged tuner
Projects
None yet
4 participants