-
Notifications
You must be signed in to change notification settings - Fork 24.4k
[jit] bind autograd.backward and tensor.backward in TorchScript #23913
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
Conversation
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.
Alias analysis changes have some issues. There should be at least one test that ensures that optimization of grad tensors knows about the mutation of grad tensors.
@@ -665,6 +667,35 @@ void AliasDb::analyzeWait(Node* node) { | |||
} | |||
} | |||
|
|||
void AliasDb::analyzeBackward(Node* node) { |
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.
This function doesn't handle a ton of aliasing cases. For instance, what if the grad tensor is stored in a list inside a class somewhere. A better way to do this would be to mark backward as CONSERVATIVE.
torch/csrc/jit/register_prim_ops.cpp
Outdated
self.backward(gradient, keep_graph, create_graph); | ||
return 0; | ||
}, | ||
aliasAnalysisSpecialCase()), |
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.
Just put aliasAnalysisConservative here and this will be correct.
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.
The alias_analaysis does not allow me to make it a conservative kind because of the assertion here. So what I did is that I made them the special_case kind and call analyze_conservative
when handling these special cases, this happens before the assert so it should work properly.
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.
That assertion is bogus, just remove it.
torch/csrc/jit/register_prim_ops.cpp
Outdated
@@ -49,7 +49,16 @@ namespace jit { | |||
|
|||
namespace { | |||
|
|||
template<class T> | |||
// XXX: This function is to specialize IValue for tensor type in |
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.
This is a copy/paste that propagates a comment that is incorrect in this context. Let's just inline this instead:
auto gradient_ivalue = pop(stack);
auto gradient = gradient_ivalue.isNone() ? at::Tensor() : gradient_ivalue.toTensor()
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: Pull Request resolved: #23913
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: Pull Request resolved: #23913
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: Pull Request resolved: #23913
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: Pull Request resolved: #23913
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: Pull Request resolved: #23913
…cript" Summary: This PR bind torch.autograd.backward and tensor.backward to TorchScript, and make aliasing to the conservative for these two ops, this is mainly because backward op might write to every input tensors in the graph Test Plan: Reviewers: Subscribers: Tasks: Tags: Pull Request resolved: #23913
…cript" Summary: This PR bind torch.autograd.backward and tensor.backward to TorchScript, and make aliasing to the conservative for these two ops, this is mainly because backward op might write to every input tensors in the graph Test Plan: Reviewers: Subscribers: Tasks: Tags: Pull Request resolved: #23913
Summary: This PR bind torch.autograd.backward and tensor.backward to TorchScript, and make aliasing to the conservative for these two ops, this is mainly because backward op might write to every input tensors in the graph Test Plan: Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 6db038e Pull Request resolved: #23913
…cript" Summary: This PR bind torch.autograd.backward and tensor.backward to TorchScript, and make aliasing to the conservative for these two ops, this is mainly because backward op might write to every input tensors in the graph Test Plan: Reviewers: Subscribers: Tasks: Tags: Pull Request resolved: #23913 Differential Revision: [D16923272](https://our.internmc.facebook.com/intern/diff/D16923272)
Summary: This PR bind torch.autograd.backward and tensor.backward to TorchScript, and make aliasing to the conservative for these two ops, this is mainly because backward op might write to every input tensors in the graph Test Plan: Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: c15fc38 Pull Request resolved: #23913
… in TorchScript" Summary: This PR bind torch.autograd.backward and tensor.backward to TorchScript, and make aliasing to the conservative for these two ops, this is mainly because backward op might write to every input tensors in the graph Test Plan: Reviewers: Subscribers: Tasks: Tags: Pull Request resolved: #23913 Differential Revision: [D16923272](https://our.internmc.facebook.com/intern/diff/D16923272)
Summary: This PR bind torch.autograd.backward and tensor.backward to TorchScript, and make aliasing to the conservative for these two ops, this is mainly because backward op might write to every input tensors in the graph Test Plan: Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 97385c2 Pull Request resolved: #23913
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.
This is good, but let's fix aliasAnalysisConservative rather than special casing backward.
… autograd.backward and tensor.backward in TorchScript" Summary: This PR bind torch.autograd.backward and tensor.backward to TorchScript, and make aliasing to the conservative for these two ops, this is mainly because backward op might write to every input tensors in the graph Test Plan: Reviewers: Subscribers: Tasks: Tags: Pull Request resolved: #23913 Differential Revision: [D16923272](https://our.internmc.facebook.com/intern/diff/D16923272)
…n on "[jit] bind autograd.backward and tensor.backward in TorchScript" Summary: This PR bind torch.autograd.backward and tensor.backward to TorchScript, and make aliasing to the conservative for these two ops, this is mainly because backward op might write to every input tensors in the graph Test Plan: Reviewers: Subscribers: Tasks: Tags: Pull Request resolved: #23913 Differential Revision: [D16923272](https://our.internmc.facebook.com/intern/diff/D16923272)
…cript" Summary: This PR bind torch.autograd.backward and tensor.backward to TorchScript, and make aliasing to the conservative for these two ops, this is mainly because backward op might write to every input tensors in the graph Test Plan: Reviewers: Subscribers: Tasks: Tags: Pull Request resolved: #23913 Differential Revision: [D16923272](https://our.internmc.facebook.com/intern/diff/D16923272)
…ckward in TorchScript" Summary: This PR bind torch.autograd.backward and tensor.backward to TorchScript, and make aliasing to the conservative for these two ops, this is mainly because backward op might write to every input tensors in the graph Test Plan: Reviewers: Subscribers: Tasks: Tags: Pull Request resolved: #23913 Differential Revision: [D16923272](https://our.internmc.facebook.com/intern/diff/D16923272)
…cript" Summary: This PR bind torch.autograd.backward and tensor.backward to TorchScript, and make aliasing to the conservative for these two ops, this is mainly because backward op might write to every input tensors in the graph Test Plan: Reviewers: Subscribers: Tasks: Tags: Pull Request resolved: #23913 Differential Revision: [D16923272](https://our.internmc.facebook.com/intern/diff/D16923272)
…ckward in TorchScript" Summary: This PR bind torch.autograd.backward and tensor.backward to TorchScript, and make aliasing to the conservative for these two ops, this is mainly because backward op might write to every input tensors in the graph Test Plan: Reviewers: Subscribers: Tasks: Tags: Pull Request resolved: #23913 Differential Revision: [D16923272](https://our.internmc.facebook.com/intern/diff/D16923272)
Summary: This PR bind torch.autograd.backward and tensor.backward to TorchScript, and make aliasing to the conservative for these two ops, this is mainly because backward op might write to every input tensors in the graph Test Plan: Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: d66873c Pull Request resolved: #23913
Summary: Pull Request resolved: pytorch/pytorch#23913 This PR bind torch.autograd.backward and tensor.backward to TorchScript, and make aliasing to the conservative for these two ops, this is mainly because backward op might write to every input tensors in the graph Test Plan: Imported from OSS Differential Revision: D16923272 fbshipit-source-id: 8a4016c62e00d00e0dee3d8c599d3aca220202f7
This pull request has been merged in 969c918. |
Stack from ghstack:
Summary:
This PR bind torch.autograd.backward and tensor.backward to TorchScript,
and make aliasing to the conservative for these two ops, this is mainly
because backward op might write to every input tensors in the graph
Test Plan:
Reviewers:
Subscribers:
Tasks:
Tags:
Pull Request resolved: #23913
Differential Revision: D16923272