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

[DeepSpeed] Remove partitioning of model in ZeRO 3 #10655

Merged
merged 11 commits into from
Dec 17, 2021
Merged

Conversation

SeanNaren
Copy link
Contributor

@SeanNaren SeanNaren commented Nov 20, 2021

What does this PR do?

Partially Fixes #10510

Also adds parametrization to a few tests since it's supported, and handles deprecated args with the latest DeepSpeed.

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 list all the breaking changes introduced by this pull request?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

PR review

Anyone in the community is welcome to review the PR.
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 🙃

cc @Borda @justusschock @awaelchli @akihironitta @SeanNaren

CHANGELOG.md Outdated Show resolved Hide resolved
@mergify mergify bot added the ready PRs ready to be merged label Nov 21, 2021
@SeanNaren
Copy link
Contributor Author

SeanNaren commented Nov 21, 2021

Seems this is not so simple. If you load the model in inference mode you cannot save (which makes sense as it's the optimizers responsibility to save the ZeRO sharded weights).

Do we think that the case where the user does not call fit before saving should be supported?

trianer = Trainer(...)
trainer.test(model)
trainer.save_checkpoint(...)

If so I think it's better we keep the optimizer code as is and use the configure_optimizers to define the optimizer again.

cc @carmocca @awaelchli @rohitgr7

@rohitgr7
Copy link
Contributor

Seems this is not so simple. If you load the model in inference mode you cannot save (which makes sense as it's the optimizers responsibility to save the ZeRO sharded weights).

Do we think that the case where the user does not call fit before saving should be supported?

trianer = Trainer(...)
trainer.test(model)
trainer.save_checkpoint(...)

If so I think it's better we keep the optimizer code as is and use the configure_optimizers to define the optimizer again.

cc @carmocca @awaelchli @rohitgr7

Even if we do that, we do not force users to define configure_optimizers during inference so possibility of not getting an optimizer still exists. So there are 2 cases now:

  1. User calls .fit and then calls .test, which will work right? Since optimizers will be attached during .fit call.
  2. User calls .test directly, then I don't think they will do a save_checkpoint because it it's a completely new randomly initialised model then checkpointing is not necessary and if they are using some pretrained model for testing then they will already have the saved checkpoint and calling another won't make sense.

Maybe you can add an error/warning for the case with no optimizer and saving under deepspeed config.

.azure-pipelines/gpu-tests.yml Show resolved Hide resolved
@SeanNaren SeanNaren changed the title Remove optimizer for DeepSpeed inference [DeepSpeed] Remove partitioning of model in ZeRO 3 Nov 22, 2021
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.

LGTM !

@SeanNaren SeanNaren added this to the 1.5.x milestone Nov 22, 2021
@SeanNaren
Copy link
Contributor Author

Pulled out the other issue, will make a separate PR for the deepspeed inference/optimizer fix.

@SeanNaren SeanNaren enabled auto-merge (squash) November 22, 2021 11:58
# Conflicts:
#	CHANGELOG.md
#	pytorch_lightning/plugins/training_type/deepspeed.py
#	tests/plugins/test_deepspeed_plugin.py
@SeanNaren
Copy link
Contributor Author

This PR will partially fix the related issue, but there is still the case of partially defined partitioned weights to tackle.

@mergify mergify bot removed the has conflicts label Dec 17, 2021
@SeanNaren SeanNaren merged commit c66cd12 into master Dec 17, 2021
@SeanNaren SeanNaren deleted the fix/update_deepspeed branch December 17, 2021 12:36
SeanNaren pushed a commit that referenced this pull request Dec 20, 2021
lexierule pushed a commit that referenced this pull request Dec 21, 2021
@rohitgr7 rohitgr7 mentioned this pull request Feb 7, 2022
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DeepSpeed stage 3 and mixed precision cause an error
7 participants