Repository navigation
Conversation
An inplace operator mutates its first positional argument and returns it. For custom operators (defined via torch.library), the first argument must be a plain Tensor(a!), must be the only mutable argument, and the operator must return exactly that tensor. Native operators have relaxed requirements (e.g. Tensor[] self, multiple mutable args) but this is subject to change. This PR adds a Tag.inplace tag, auto-applies it to all native inplace operators via torchgen, and validates the schema when custom operators are defined with this tag via torch.library.define. Test Plan: - python test/custom_operator/test_inplace.py Authored with Claude. [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/181099
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 6e0403e with merge base a55ca57 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
| other_mutable = [ | ||
| arg | ||
| for arg in args[1:] | ||
| if not arg.kwarg_only | ||
| if arg.alias_info is not None and arg.alias_info.is_write | ||
| ] | ||
| kwarg_mutable = [ | ||
| arg | ||
| for arg in args | ||
| if arg.kwarg_only | ||
| if arg.alias_info is not None and arg.alias_info.is_write | ||
| ] |
There was a problem hiding this comment.
nit: why not just check all args[1:]?
An inplace operator mutates its first positional argument and returns it. For custom operators (defined via torch.library), the first argument must be a plain Tensor(a!), must be the only mutable argument, and the operator must return exactly that tensor. Native operators have relaxed requirements (e.g. Tensor[] self, multiple mutable args) but this is subject to change. This PR adds a Tag.inplace tag, auto-applies it to all native inplace operators via torchgen, and validates the schema when custom operators are defined with this tag via torch.library.define. Test Plan: - python test/custom_operator/test_inplace.py Authored with Claude. [ghstack-poisoned]
An inplace operator mutates its first positional argument and returns it. For custom operators (defined via torch.library), the first argument must be a plain Tensor(a!), must be the only mutable argument, and the operator must return exactly that tensor. Native operators have relaxed requirements (e.g. Tensor[] self, multiple mutable args) but this is subject to change. This PR adds a Tag.inplace tag, auto-applies it to all native inplace operators via torchgen, and validates the schema when custom operators are defined with this tag via torch.library.define. Test Plan: - python test/custom_operator/test_inplace.py Authored with Claude. [ghstack-poisoned]
|
Starting merge as part of PR stack under #181100 |
1 similar comment
|
Starting merge as part of PR stack under #181100 |
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: #181100 Approved by: https://github.com/aorenste, https://github.com/angelayi ghstack dependencies: #181380, #180987, #181099
An inplace operator mutates its first positional argument and returns it. For custom operators (defined via torch.library), the first argument must be a plain Tensor(a!), must be the only mutable argument, and the operator must return exactly that tensor. Native operators have relaxed requirements (e.g. Tensor[] self, multiple mutable args) but this is subject to change. This PR adds a Tag.inplace tag, auto-applies it to all native inplace operators via torchgen, and validates the schema when custom operators are defined with this tag via torch.library.define. Test Plan: - python test/custom_operator/test_inplace.py Authored with Claude. Pull Request resolved: pytorch#181099 Approved by: https://github.com/angelayi ghstack dependencies: pytorch#181380, pytorch#180987
) 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
An inplace operator mutates its first positional argument and returns it. For custom operators (defined via torch.library), the first argument must be a plain Tensor(a!), must be the only mutable argument, and the operator must return exactly that tensor. Native operators have relaxed requirements (e.g. Tensor[] self, multiple mutable args) but this is subject to change. This PR adds a Tag.inplace tag, auto-applies it to all native inplace operators via torchgen, and validates the schema when custom operators are defined with this tag via torch.library.define. Test Plan: - python test/custom_operator/test_inplace.py Authored with Claude. Pull Request resolved: pytorch#181099 Approved by: https://github.com/angelayi ghstack dependencies: pytorch#181380, pytorch#180987
) 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
An inplace operator mutates its first positional argument and returns it. For custom operators (defined via torch.library), the first argument must be a plain Tensor(a!), must be the only mutable argument, and the operator must return exactly that tensor. Native operators have relaxed requirements (e.g. Tensor[] self, multiple mutable args) but this is subject to change. This PR adds a Tag.inplace tag, auto-applies it to all native inplace operators via torchgen, and validates the schema when custom operators are defined with this tag via torch.library.define. Test Plan: - python test/custom_operator/test_inplace.py Authored with Claude. Pull Request resolved: pytorch#181099 Approved by: https://github.com/angelayi ghstack dependencies: pytorch#181380, pytorch#180987
) 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):
An inplace operator mutates its first positional argument and returns
it. For custom operators (defined via torch.library), the first argument
must be a plain Tensor(a!), must be the only mutable argument, and the
operator must return exactly that tensor. Native operators have relaxed
requirements (e.g. Tensor[] self, multiple mutable args) but this is
subject to change.
This PR adds a Tag.inplace tag, auto-applies it to all native inplace
operators via torchgen, and validates the schema when custom operators
are defined with this tag via torch.library.define.
Test Plan:
Authored with Claude.