voznesenskym
0f4d2904be
[dynamo] compiled_autograd support for post_acc_grad hooks ( #112326 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/112326
Approved by: https://github.com/jansel
ghstack dependencies: #112325
2023-10-31 22:53:01 +00:00
Jason Ansel
a1154e673b
[Compiled Autograd] Turn accumulate_grad into an op ( #111700 )
...
Relands #111271
Pull Request resolved: https://github.com/pytorch/pytorch/pull/111700
Approved by: https://github.com/voznesenskym
2023-10-21 17:31:09 +00:00
PyTorch MergeBot
3eb5cae3af
Revert "[Compiled Autograd] Turn accumulate_grad into an op ( #111271 )"
...
This reverts commit 04b04c0686 .
Reverted https://github.com/pytorch/pytorch/pull/111271 on behalf of https://github.com/jeanschmidt due to Breaking internal CI ([comment](https://github.com/pytorch/pytorch/pull/111271#issuecomment-1768527932 ))
2023-10-18 14:02:34 +00:00
Jason Ansel
04b04c0686
[Compiled Autograd] Turn accumulate_grad into an op ( #111271 )
...
Rather than baking the behavior of `AccumulateGrad` nodes into the generated graph (either as `+=`, or as a return value of the graph). This creates a new `accumulate_grad_` dispatcher op that is included in the generated graph like:
```
def forward(self, inputs, sizes, hooks):
getitem = inputs[0]
getitem_1 = inputs[1]
getitem_2 = inputs[2]
getitem_3 = inputs[3]
getitem_4 = inputs[4]
getitem_5 = inputs[5]
getitem_6 = inputs[6]
getitem_7 = inputs[7]
getitem_8 = inputs[8]
getitem_9 = inputs[9]; inputs = None
expand = torch.ops.aten.expand.default(getitem, [2, 4]); getitem = None
threshold_backward = torch.ops.aten.threshold_backward.default(expand, getitem_1, 0); expand = getitem_1 = None
t = torch.ops.aten.t.default(getitem_3); getitem_3 = None
mm = torch.ops.aten.mm.default(threshold_backward, t); t = None
t_1 = torch.ops.aten.t.default(threshold_backward)
mm_1 = torch.ops.aten.mm.default(t_1, getitem_2); t_1 = getitem_2 = None
t_2 = torch.ops.aten.t.default(mm_1); mm_1 = None
sum_1 = torch.ops.aten.sum.dim_IntList(threshold_backward, [0], True); threshold_backward = None
view = torch.ops.aten.view.default(sum_1, [4]); sum_1 = None
t_3 = torch.ops.aten.t.default(t_2); t_2 = None
accumulate_grad_ = torch.ops.inductor.accumulate_grad_.default(getitem_4, t_3); getitem_4 = t_3 = None
threshold_backward_1 = torch.ops.aten.threshold_backward.default(mm, getitem_5, 0); mm = getitem_5 = None
t_4 = torch.ops.aten.t.default(threshold_backward_1)
mm_2 = torch.ops.aten.mm.default(t_4, getitem_6); t_4 = getitem_6 = None
t_5 = torch.ops.aten.t.default(mm_2); mm_2 = None
sum_2 = torch.ops.aten.sum.dim_IntList(threshold_backward_1, [0], True); threshold_backward_1 = None
view_1 = torch.ops.aten.view.default(sum_2, [4]); sum_2 = None
t_6 = torch.ops.aten.t.default(t_5); t_5 = None
accumulate_grad__1 = torch.ops.inductor.accumulate_grad_.default(getitem_7, t_6); getitem_7 = t_6 = None
accumulate_grad__2 = torch.ops.inductor.accumulate_grad_.default(getitem_8, view_1); getitem_8 = view_1 = None
accumulate_grad__3 = torch.ops.inductor.accumulate_grad_.default(getitem_9, view); getitem_9 = view = None
return []
```
The motivation here is `AccumulateGrad` nodes are causing trouble in FSDP tracing, since FSDP is in-place resizing parameters and parameter storage in hooks. We will model this mutation in dynamo, but not during the initial compiled autograd capture. This allows us to bypass failing shape checks in the initial capture.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/111271
Approved by: https://github.com/voznesenskym
2023-10-16 21:16:17 +00:00
Michael Voznesensky
7d98549ca9
retain_graph=True in compiled_autograd ( #110367 )
...
Adds support for retain_graph=True - known as keep_graph_ internally in the autograd engine.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/110367
Approved by: https://github.com/jansel
2023-10-06 08:22:10 +00:00
Edward Z. Yang
0351e2042b
Avoid throwing exception in ClosingTHPObjectPtr ( #109758 )
...
Previously, if ClosingTHPObjectPtr was destructed because we
were unwinding the stack from an exception, we would attempt to call
close() which just isn't going to work. Two fixes:
1. Detect if we're unwinding due to a Python error, and don't try
to do more Python stuff if so.
2. If close() fails somehow, write an unraisable exception, don't
try to throw because that will terminate if you're in an
exception.
Signed-off-by: Edward Z. Yang <ezyang@meta.com>
Pull Request resolved: https://github.com/pytorch/pytorch/pull/109758
Approved by: https://github.com/jansel
2023-09-21 17:04:14 +00:00
cyy
054f3f1d8f
[3/N] fix clang-tidy warnings in torch/csrc ( #108024 )
...
Apply fixes to some found issues by clang-tidy in torch/csrc.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/108024
Approved by: https://github.com/Skylion007 , https://github.com/albanD , https://github.com/malfet
2023-08-28 18:00:00 +00:00
Jason Ansel
d77e95c3bf
[Compiled Autograd] Improve nyi error messages ( #106176 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/106176
Approved by: https://github.com/eellison
2023-08-21 04:31:13 +00:00
Jason Ansel
bdecdfd202
[Compiled Autograd] Fix duplicate visits of same node ( #105887 )
...
The error fixed here happened when we had multiple autograd::Edge objects pointing to the same autograd::Node, causing before() to get called multiple times on the same object.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/105887
Approved by: https://github.com/albanD
2023-08-18 19:47:34 +00:00
Jason Ansel
23a1eda890
[Compiled Autograd] Inplace updates of gradients ( #105713 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/105713
Approved by: https://github.com/albanD
2023-07-28 15:58:49 +00:00
Jason Ansel
5a114f72bf
[Compiled Autograd] Move to torch::dynamo::autograd namespace ( #105854 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/105854
Approved by: https://github.com/albanD
2023-07-27 00:36:47 +00:00
PyTorch MergeBot
e60af5c8e4
Revert "[Compiled Autograd] Move to torch::dynamo::autograd namespace ( #105854 )"
...
This reverts commit 26e3b4020f .
Reverted https://github.com/pytorch/pytorch/pull/105854 on behalf of https://github.com/PaliC due to breaking internal embedded device tests (details shared with author) ([comment](https://github.com/pytorch/pytorch/pull/105854#issuecomment-1650559375 ))
2023-07-25 21:09:18 +00:00
Jason Ansel
26e3b4020f
[Compiled Autograd] Move to torch::dynamo::autograd namespace ( #105854 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/105854
Approved by: https://github.com/albanD
2023-07-25 01:14:04 +00:00
Jason Ansel
c902b84e0b
Compiled autograd ( #103822 )
...
This branch:
1) converts the autograd tape into an FX graph
2) caches that conversion using a "shadow" graph
3) compiles and runs the generated FX graph instead of the normal autograd
What works currently:
1) Caching, capture, and initial integration
2) Backwards hooks
3) Inlining AotAutograd generated subgraphs
4) torch.compiling the generated FX graph
5) Auto-detecting dynamic shapes based on changes
Future work
1) Larger scale testing
1) Boxed calling convention, so memory can be freed incrementally
1) Support hooks on SavedTensor
1) Additional testing by running eager autograd tests under compiled_autograd.enable()
Pull Request resolved: https://github.com/pytorch/pytorch/pull/103822
Approved by: https://github.com/ezyang , https://github.com/albanD
2023-07-24 21:12:05 +00:00