Skip to content

[Autograd] expand_as instead of clone to get AccumulateGrad#96356

Closed
awgu wants to merge 1 commit intogh/awgu/345/basefrom
gh/awgu/345/head
Closed

[Autograd] expand_as instead of clone to get AccumulateGrad#96356
awgu wants to merge 1 commit intogh/awgu/345/basefrom
gh/awgu/345/head

Conversation

@awgu
Copy link
Collaborator

@awgu awgu commented Mar 8, 2023

Stack from ghstack (oldest at bottom):

This PR makes a minor change to the multi-grad hook implementation. This should decrease peak memory since we avoid one clone() per tensor passed into the multi-grad hook. Let me know if there are technical reasons why we need to clone. If so, is there a way for some use cases to not clone?

Before with clone():
Screenshot 2023-03-08 at 6 08 41 PM

After with expand_as() -- no more "Memcpy DtoD" kernels:
Screenshot 2023-03-08 at 6 08 48 PM

cc @ezyang @albanD @zou3519 @gqchen @pearu @nikitaved @soulitzer @lezcano @Varal7

@pytorch-bot
Copy link

pytorch-bot bot commented Mar 8, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/96356

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit f71c335:
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

awgu pushed a commit that referenced this pull request Mar 8, 2023
@awgu awgu added topic: not user facing topic category module: autograd Related to torch.autograd, and the autograd engine in general labels Mar 8, 2023
@soulitzer
Copy link
Contributor

I don't think there's any reason to clone, good catch!

@awgu awgu marked this pull request as ready for review March 9, 2023 02:40
@awgu awgu requested review from albanD and soulitzer as code owners March 9, 2023 02:40
@awgu awgu added the ciflow/trunk Trigger trunk jobs on your pull request label Mar 9, 2023
@awgu
Copy link
Collaborator Author

awgu commented Mar 9, 2023

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

cyyever pushed a commit to cyyever/pytorch_private that referenced this pull request Mar 12, 2023
…6356)

This PR makes a minor change to the multi-grad hook implementation. This should decrease peak memory since we avoid one `clone()` per tensor passed into the multi-grad hook. Let me know if there are technical reasons why we need to clone. If so, is there a way for some use cases to not clone?

Before with `clone()`:
![Screenshot 2023-03-08 at 6 08 41 PM](https://user-images.githubusercontent.com/31054793/223873111-ad9105ab-2958-45a1-a2f5-18e9b254c710.png)

After with `expand_as()` -- no more "Memcpy DtoD" kernels:
![Screenshot 2023-03-08 at 6 08 48 PM](https://user-images.githubusercontent.com/31054793/223873104-670b6abc-cd5c-4d1e-a316-cea1bef5832a.png)

Pull Request resolved: pytorch/pytorch#96356
Approved by: https://github.com/soulitzer
ydwu4 added a commit to ydwu4/pytorch that referenced this pull request Mar 13, 2023
…torch#96356)

This PR makes a minor change to the multi-grad hook implementation. This should decrease peak memory since we avoid one `clone()` per tensor passed into the multi-grad hook. Let me know if there are technical reasons why we need to clone. If so, is there a way for some use cases to not clone?

Before with `clone()`:
![Screenshot 2023-03-08 at 6 08 41 PM](https://user-images.githubusercontent.com/31054793/223873111-ad9105ab-2958-45a1-a2f5-18e9b254c710.png)

After with `expand_as()` -- no more "Memcpy DtoD" kernels:
![Screenshot 2023-03-08 at 6 08 48 PM](https://user-images.githubusercontent.com/31054793/223873104-670b6abc-cd5c-4d1e-a316-cea1bef5832a.png)

Pull Request resolved: pytorch#96356
Approved by: https://github.com/soulitzer
@facebook-github-bot facebook-github-bot deleted the gh/awgu/345/head branch June 8, 2023 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged module: autograd Related to torch.autograd, and the autograd engine in general topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants