Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
[Model Parallel] Add configure sharded model hook #6679
[Model Parallel] Add configure sharded model hook #6679
Changes from 23 commits
9f8864f
eac5344
32df0cb
282a133
7a94e72
8091481
633fc77
c99a36f
a68c8d7
9529a22
3c1c782
a49ec3b
4dd55d7
caad43c
a2574be
8c2bd6a
3240569
897bdbb
626fc7b
e94a7ae
6a38417
202ef1a
0709baa
9152d08
fbfe65f
bae858f
41e9c22
76c7376
2dcafd0
aa35583
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SeanNaren n00b q: why is this needed as a callback hook too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allows us to do this:
For FSDP:
https://github.com/PyTorchLightning/pytorch-lightning/blob/feat/fsdp/pytorch_lightning/plugins/training_type/fully_sharded.py#L128-L147
For DeepSpeed:
https://github.com/PyTorchLightning/pytorch-lightning/blob/feat/ds_update/pytorch_lightning/plugins/training_type/deepspeed.py#L284
So for those really large models that we'd like to shard instantly, this provides a context manager to instantiate your layers. In FSDP, you'll have to call auto_wrap/wrap yourself, in DeepSpeed this is done for you (each module is automatically sharded, in FSDP we have a policy in place).
Reason it's done like this is because we do not have a distributed environment set up till the
Trainer
is called. then upon fit, we can setup the environment! Let me know if you do have ideas though!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But those two snippets you shared don't use
on_model_parallel_setup
, they usemodel_parallel_context
.I think the question is more along the lines of "when would you override
on_model_parallel_setup
?"There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The short answer is when you'd like to shard your model instantly (to save initialization time or load a very large model).
Here is a hard case for DeepSpeed: https://github.com/SeanNaren/minGPT/blob/stage3/mingpt/model.py#L155-L161
We'll eventually write docs once the integrations are merged to explain the use cases in greater details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't a name like
configure_sharded_model
orconfigure_parallel_model
be more appropriate?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a check that the context manager is actually being yield.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, it made me see an Issue in implementation. Fixinggg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to check the hook is not called within the callbacks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can assume Users would be aware of the implications.