-
Notifications
You must be signed in to change notification settings - Fork 26.3k
[BE]: Follow detach().clone() pattern for SGD #144468
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
[BE]: Follow detach().clone() pattern for SGD #144468
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/144468
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ❌ 8 New FailuresAs of commit 84f1442 with merge base 8f54e56 ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
janeyx99
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, though practically speaking this is likely not changing much perf in most use cases as grad normally does not require grad.
|
@pytorchbot merge |
Merge startedYour 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 |
Merge failedReason: 1 jobs have failed, first few of them are: trunk / macos-py3-arm64 / test (default, 3, 3, macos-m1-stable) Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot merge -r |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
|
The merge job was canceled or timed out. This most often happen if two merge requests were issued for the same PR, or if merge job was waiting for more than 6 hours for tests to finish. In later case, please do not hesitate to reissue the merge command |
|
@janeyx99 Seems like a false positive, but I would like to get confirmation |
|
Ah I think you do have to modify the test now that the version counts are different. |
|
Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as |
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
|
Successfully rebased |
1b78678 to
84f1442
Compare
cyyever
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there still undiscovered clones like these?
|
|
||
| if buf is None: | ||
| buf = torch.clone(grad).detach() | ||
| buf = torch.clone(grad.detach()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use grad.detach().clone ? Since that is a common pattern in the code base.
| buf = device_momentum_buffer_list[i] = momentum_buffer_list[ | ||
| indices[i] | ||
| ] = torch.clone(device_grads[i]).detach() | ||
| ] = torch.clone(device_grads[i].detach()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as the above.
That is NOT true. |
janeyx99
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As clone does not copy gradients, can you update the PR description? We can still follow @cyyever's suggestions here to land cleaner code for BE, even though it will only be marginally better.
Clone() copies the gradients too, but we immediately detach them. Detach returns a view of the tensor without it's gradients, and the copies only that subset. Related to #144270