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

Better dispatch for submodules #392

Merged
merged 1 commit into from
May 25, 2022
Merged

Better dispatch for submodules #392

merged 1 commit into from
May 25, 2022

Conversation

sgugger
Copy link
Collaborator

@sgugger sgugger commented May 24, 2022

While testing the dispatch_model features in this PR I hit some edge case for model parallelism: when a submodule of a given model is never actually called in the forward pass (like the h of the GPT-2 model which is a module list which is iterated on in the forward but not directly called) the inputs aren't necessarily moved to the right device.

This PR adds a hook in all submodules to just move those inputs to the device, which fix this issue.

@sgugger sgugger requested review from muellerzr and LysandreJik May 24, 2022 17:51
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented May 24, 2022

The documentation is not available anymore as the PR was closed or merged.

Copy link
Collaborator

@muellerzr muellerzr left a comment

Choose a reason for hiding this comment

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

LG2M!

Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

Perfect, should be very robust this way! Have you benchmarked the time difference between this implementation and the current one?

@sgugger
Copy link
Collaborator Author

sgugger commented May 25, 2022

Not yet, will have a look before merging (though I don't expect much difference since there is not that many submodules).

@sgugger sgugger merged commit 18085fa into main May 25, 2022
@sgugger sgugger deleted the better_dispatch branch May 25, 2022 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants