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

Add and Remove ZeRO 3 Hooks #5658

Merged
merged 20 commits into from
Aug 16, 2024
Merged

Add and Remove ZeRO 3 Hooks #5658

merged 20 commits into from
Aug 16, 2024

Conversation

jomayeri
Copy link
Contributor

Gives the ability to add and remove the forward hooks in ZeRO 3 by using a context manager. These code changes were taken from a Huggingface PR and integrated for direct support in DeepSpeed.

This is useful in the inference case and the speedup can be observed here.

@tjruwase
Copy link
Contributor

@jomayeri, please add some unit tests

@tjruwase tjruwase requested review from tohtana and removed request for mrwyattii June 18, 2024 00:25
@jomayeri jomayeri requested review from awan-10 and arashb as code owners June 27, 2024 18:59
@jomayeri jomayeri requested a review from loadams as a code owner July 16, 2024 19:47
@@ -69,6 +70,39 @@ def move_to_cpu(tensor_list):
tensor.data = tensor.data.cpu()


@contextmanager
def unwrap_model_for_generation(model):
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems my comment here was missed?

Suggested change
def unwrap_model_for_generation(model):
def unshard_and_remove_hooks(model):

@tjruwase
Copy link
Contributor

@jomayeri, can you please add documentation of this new API somewhere below?

https://deepspeed.readthedocs.io/en/latest/zero3.html

@jomayeri jomayeri added this pull request to the merge queue Aug 16, 2024
Merged via the queue into master with commit c2e3a70 Aug 16, 2024
14 checks passed
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