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

Support individual setup of model and optimizer in Lite #15185

Merged
merged 36 commits into from
Nov 11, 2022

Conversation

awaelchli
Copy link
Member

@awaelchli awaelchli commented Oct 19, 2022

What does this PR do?

This PR is providing new APIs for setting up model and optimizers to enable FSDP in #14967.
The design considerations were discussed here.

Before:

Model and optimizers had to be set up jointly.

model = ...
optimizer = Adam(model.parameters())
model, optimizer = self.setup(model, optimizer)

Now:

Jointly setting up model and optimizer is still possible.

model = ...
optimizer = Adam(model.parameters())
model, optimizer = self.setup(model, optimizer)

For some strategies, this is the only way possible (DeepSpeed).

However, there are strategies (FSDP) that require to set up the model first before the optimizer can be created:

model = ...
model = self.setup_model(model)

optimizer = Adam(model.parameters())
optimizer = self.setup_optimizers(optimizer)

This PR introduces these two new APIs setup_model and setup_optimizers and the error messaging for which strategies support which setup procedure.

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

No.

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 @awaelchli @carmocca

@awaelchli awaelchli added feature Is an improvement or enhancement refactor fabric lightning.fabric.Fabric labels Oct 19, 2022
@awaelchli awaelchli added this to the v1.9 milestone Oct 22, 2022
@github-actions github-actions bot added the pl Generic label for PyTorch Lightning package label Oct 23, 2022
src/lightning_lite/strategies/strategy.py Show resolved Hide resolved
src/lightning_lite/lite.py Outdated Show resolved Hide resolved
@awaelchli awaelchli added the community This PR is from the community label Oct 23, 2022
@awaelchli awaelchli self-assigned this Oct 23, 2022
@github-actions github-actions bot removed the pl Generic label for PyTorch Lightning package label Nov 2, 2022
@mergify mergify bot removed the has conflicts label Nov 2, 2022
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.

  1. The API looks good to me 🦦
  2. why are you updating _notebooks head?
  3. shall we add also docs update for this?

@awaelchli
Copy link
Member Author

This PR is a preparation for #14898. I think it will make most sense to add the docs there for full context.

src/lightning_lite/lite.py Outdated Show resolved Hide resolved
src/lightning_lite/lite.py Outdated Show resolved Hide resolved
src/lightning_lite/lite.py Show resolved Hide resolved
@mergify mergify bot added the ready PRs ready to be merged label Nov 9, 2022
@mergify mergify bot added has conflicts and removed ready PRs ready to be merged labels Nov 10, 2022
@mergify mergify bot added ready PRs ready to be merged and removed has conflicts ready PRs ready to be merged labels Nov 10, 2022
@awaelchli awaelchli requested review from carmocca and removed request for otaj, rohitgr7 and kaushikb11 November 10, 2022 12:08
@carmocca carmocca merged commit 0dfb3d2 into master Nov 11, 2022
@carmocca carmocca deleted the lite/individual-setup branch November 11, 2022 13:37
@awaelchli awaelchli added fun Staff contributions outside working hours - to differentiate from the "community" label and removed community This PR is from the community labels Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fabric lightning.fabric.Fabric feature Is an improvement or enhancement fun Staff contributions outside working hours - to differentiate from the "community" label ready PRs ready to be merged refactor
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants