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

Smp grad accum #10488

Merged
merged 2 commits into from Mar 3, 2021
Merged

Smp grad accum #10488

merged 2 commits into from Mar 3, 2021

Conversation

sgugger
Copy link
Collaborator

@sgugger sgugger commented Mar 2, 2021

What does this PR do?

This PR adds support for gradient accumulation in SageMakerTrainer. It has been tested on the glue script with success (with and without gradient accumulation passed along).

@sgugger sgugger requested a review from LysandreJik March 2, 2021 21:25
@@ -108,7 +107,7 @@ def _wrap_model(self, model, training=True):
# Wrapping the base model twice in a DistributedModel will raise an error.
if isinstance(self.model_wrapped, smp.model.DistributedModel):
return self.model_wrapped
return smp.DistributedModel(model)
return smp.DistributedModel(model, backward_passes_per_step=self.args.gradient_accumulation_steps)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This does the equivalent of no_sync in regular DDP.

Comment on lines +741 to +745
def _no_sync_in_gradient_accumulation(self):
"""
Whether or not to use no_sync for the gradients when doing gradient accumulation.
"""
return not self.deepspeed
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is introduced to make it easy to skip the no_sync part in subclasses.

Copy link

@anirudh2290 anirudh2290 left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the fix! LGTM.

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.

Very nice! LGTM!

@sgugger sgugger merged commit b70f441 into master Mar 3, 2021
@sgugger sgugger deleted the smp_grad_accum branch March 3, 2021 17:13
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.

None yet

3 participants