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

FSDP with full state dict #7487

Merged
merged 79 commits into from
May 24, 2021
Merged

Conversation

shuyingsunshine21
Copy link
Contributor

@shuyingsunshine21 shuyingsunshine21 commented May 11, 2021

What does this PR do?

Co-authored-by: @SeanNaren and @shuyingsunshine21

Integrates FSDP, #6152

Discussed with @SeanNaren , for V1, we only support usage where user will configure the wrap strategy in configure_sharded_model. And we currently do not support sharded checkpointing.

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 🙃

Shuying Sun and others added 30 commits March 23, 2021 12:06
Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:
…oint_consolidate

Update test_all_gather_grad.py
…1-checkpoint_consolidate"

This reverts commit c5053da, reversing
changes made to 0d23d75.
This reverts commit 70fe5da.
This reverts commit a9aae99.
@SeanNaren SeanNaren enabled auto-merge (squash) May 21, 2021 15:13
@SeanNaren SeanNaren added the ready PRs ready to be merged label May 21, 2021
"""

model = TestFSDPModel()
ck = ModelCheckpoint(save_last=True)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks @SeanNaren for the fix!!! I tried with ModelCheckpoint before, but use ModelCheckpoint(dirpath=tmpdir, save_last=True), wonder why removing dirpath works

Copy link
Contributor

@ananthsub ananthsub left a comment

Choose a reason for hiding this comment

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

awesome work @shuyingsunshine21 and @SeanNaren !

Comment on lines +118 to +119
if not self.on_gpu:
raise MisconfigurationException(
Copy link
Contributor

Choose a reason for hiding this comment

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

this could be easily unit tested

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds great, adding unit test for it.

Comment on lines +498 to 503
# as precision_plugin is dependent on training_type_plugin, make sure
# that we first select training_type_plugin, then precision_plugin
return acc_cls(
precision_plugin=self.precision_plugin,
training_type_plugin=self.training_type_plugin,
precision_plugin=self.precision_plugin,
)
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 try to move the precision inside before we add the next major plugin.

Comment on lines 25 to 31
trainer = Trainer(
default_root_dir=tmpdir,
fast_dev_run=True,
plugins="fsdp",
)
assert isinstance(trainer.accelerator.training_type_plugin, DDPFullyShardedPlugin)

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought it's not supported on CPU?
Can't we evaluate compatibility in the accelerator connector?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice catch here, it passed as our assertion for GPU happens in setup_distributed, not when initialize Trainer. I think we could do it in accelerator connector, but personal feeling is that file is becoming too giant and pretty complex, try to avoid additional logic there, feel it is specific plugin/accelerator strategy's responsibility to check when environment is setup.

Copy link
Contributor

@awaelchli awaelchli left a comment

Choose a reason for hiding this comment

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

interesting plugin
great effort from everybody

@awaelchli awaelchli disabled auto-merge May 21, 2021 21:23
@awaelchli
Copy link
Contributor

disabled auto merge in case you want to address some of the comments before merge but IMO this is unblocked and rdy to go. thx

@ethanwharris ethanwharris merged commit 299f2c4 into Lightning-AI:master May 24, 2021
@SeanNaren SeanNaren mentioned this pull request Jun 1, 2021
11 tasks
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.

7 participants