Skip to content

reduce memory usage for centered rmsprop #24170

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

Closed

Conversation

meijieru
Copy link
Contributor

Reduce gpu memory usage by using in-place operation

@pytorchbot pytorchbot added the module: optimizer Related to torch.optim label Aug 12, 2019
@soumith soumith requested a review from vincentqb August 12, 2019 20:59
Copy link
Contributor

@vincentqb vincentqb left a comment

Choose a reason for hiding this comment

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

This looks good to me. I can merge after the comment is answered.

@@ -88,7 +88,7 @@ def step(self, closure=None):
if group['centered']:
grad_avg = state['grad_avg']
grad_avg.mul_(alpha).add_(1 - alpha, grad)
avg = square_avg.addcmul(-1, grad_avg, grad_avg).sqrt().add_(group['eps'])
avg = square_avg.addcmul(-1, grad_avg, grad_avg).sqrt_().add_(group['eps'])
else:
avg = square_avg.sqrt().add_(group['eps'])
Copy link
Contributor

@vincentqb vincentqb Aug 13, 2019

Choose a reason for hiding this comment

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

We can use sqrt_ here too, is that correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. Since square_avg is a state that we maintain, we should not modify it here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, good point.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@vincentqb has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@vincentqb merged this pull request in bd054e7.

@meijieru meijieru deleted the reduce_rmsprop_memory_usage branch August 14, 2019 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants