Repository navigation
Conversation
Allow custom operators tagged with torch.Tag.inplace to go through auto_functionalize during torch.compile. The functional form of e.g. `foo_(Tensor(a!) self, Tensor other) -> Tensor(a!)` passes self as a base in _all_bases (with view info) so that the reinplacing pass can do clone analysis—unlike out= ops where the mutable args are write-only and clones are never needed. Test Plan: - python test/test_inplace_tag.py [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/181100
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: ✅ No FailuresAs of commit 9069f47 with merge base a55ca57 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
aorenste
left a comment
There was a problem hiding this comment.
Does it need a test for a duplicated base (add_(x, x))?
Approving w/ comments
| return ctx.wrap_tensors(unwrapped_outs) # type: ignore[arg-type] | ||
|
|
||
|
|
||
| def _do_auto_functionalize_v2_for_inplace_operator( |
There was a problem hiding this comment.
Maybe this should be merged with _do_auto_functionalize_v2_for_generic_mutable_operator? If we don't care about specific perf then I think _do_auto_functionalize_v2_for_generic_mutable_operator will just do the same thing - otherwise we could make a helper that takes lambdas to compute the details slightly more optimally for the inplace operator case.
There was a problem hiding this comment.
_do_auto_functionalize_v2_for_generic_mutable_operator -> the auto_functionalized in this case returns (output_of_operator, all_cloned_mutated_inputs).
in the inplace case, this would end up returning (cloned_mutated_input, cloned_mutated_input), which is redundant.
To make it look more like the native pytorch operator situation (where the functional variant returns just (cloned_mutated_input,)) we special case it here.
NB: the code for this is fairly simple, the inplace case is only one input being mutated and returned, so I'd prefer to have the code duplication around
Allow custom operators tagged with torch.Tag.inplace to go through auto_functionalize during torch.compile. The functional form of e.g. `foo_(Tensor(a!) self, Tensor other) -> Tensor(a!)` passes self as a base in _all_bases (with view info) so that the reinplacing pass can do clone analysis—unlike out= ops where the mutable args are write-only and clones are never needed. Test Plan: - python test/test_inplace_tag.py [ghstack-poisoned]
Allow custom operators tagged with torch.Tag.inplace to go through auto_functionalize during torch.compile. The functional form of e.g. `foo_(Tensor(a!) self, Tensor other) -> Tensor(a!)` passes self as a base in _all_bases (with view info) so that the reinplacing pass can do clone analysis—unlike out= ops where the mutable args are write-only and clones are never needed. Test Plan: - python test/test_inplace_tag.py ghstack-source-id: 4630767 Pull Request resolved: #181100
I added the test. This one is interesting because a lot of custom operators won't support this pattern. The bad case is if the kernel is clobbering values it needs to read from |
Allow custom operators tagged with torch.Tag.inplace to go through auto_functionalize during torch.compile. The functional form of e.g. `foo_(Tensor(a!) self, Tensor other) -> Tensor(a!)` passes self as a base in _all_bases (with view info) so that the reinplacing pass can do clone analysis—unlike out= ops where the mutable args are write-only and clones are never needed. Test Plan: - python test/test_inplace_tag.py [ghstack-poisoned]
Allow custom operators tagged with torch.Tag.inplace to go through auto_functionalize during torch.compile. The functional form of e.g. `foo_(Tensor(a!) self, Tensor other) -> Tensor(a!)` passes self as a base in _all_bases (with view info) so that the reinplacing pass can do clone analysis—unlike out= ops where the mutable args are write-only and clones are never needed. Test Plan: - python test/test_inplace_tag.py ghstack-source-id: 8e63c22 Pull Request resolved: #181100
|
@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 mandatory check(s) failed. The first few are: Dig deeper by viewing the failures on hud |
|
@pytorchbot merge -f "unrelated failure" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
) Allow custom operators tagged with torch.Tag.inplace to go through auto_functionalize during torch.compile. The functional form of e.g. `foo_(Tensor(a!) self, Tensor other) -> Tensor(a!)` passes self as a base in _all_bases (with view info) so that the reinplacing pass can do clone analysis—unlike out= ops where the mutable args are write-only and clones are never needed. Test Plan: - python test/test_inplace_tag.py Pull Request resolved: pytorch#181100 Approved by: https://github.com/aorenste, https://github.com/angelayi ghstack dependencies: pytorch#181380, pytorch#180987, pytorch#181099
) Allow custom operators tagged with torch.Tag.inplace to go through auto_functionalize during torch.compile. The functional form of e.g. `foo_(Tensor(a!) self, Tensor other) -> Tensor(a!)` passes self as a base in _all_bases (with view info) so that the reinplacing pass can do clone analysis—unlike out= ops where the mutable args are write-only and clones are never needed. Test Plan: - python test/test_inplace_tag.py Pull Request resolved: pytorch#181100 Approved by: https://github.com/aorenste, https://github.com/angelayi ghstack dependencies: pytorch#181380, pytorch#180987, pytorch#181099
) Allow custom operators tagged with torch.Tag.inplace to go through auto_functionalize during torch.compile. The functional form of e.g. `foo_(Tensor(a!) self, Tensor other) -> Tensor(a!)` passes self as a base in _all_bases (with view info) so that the reinplacing pass can do clone analysis—unlike out= ops where the mutable args are write-only and clones are never needed. Test Plan: - python test/test_inplace_tag.py Pull Request resolved: pytorch#181100 Approved by: https://github.com/aorenste, https://github.com/angelayi ghstack dependencies: pytorch#181380, pytorch#180987, pytorch#181099
Stack from ghstack (oldest at bottom):
Allow custom operators tagged with torch.Tag.inplace to go through
auto_functionalize during torch.compile. The functional form of e.g.
foo_(Tensor(a!) self, Tensor other) -> Tensor(a!)passes self as abase in _all_bases (with view info) so that the reinplacing pass can
do clone analysis—unlike out= ops where the mutable args are write-only
and clones are never needed.
Test Plan: