Repository navigation
Conversation
An out= operator must: - have the "Tag::out" tag. - All of the mutable arguments must be write-only buffers (not read before write) - it must return all mutable arguments in order. - all of the mutable arguments must be kwarg-only arguments. The last three restrictions are already restrictions that torchgen places on native pytorch out= operators. This PR: - renames "Tag::out_variant" to "Tag::out". This is not being used in the wild so there are no BC-concerns. We added this API in PyTorch 2.10 but didn't have a good user. I prefer not calling it a "variant" because a user may just have a custom operator that is an "out operator" and not have a functional variant of the operator, so I don't want to call it an "out variant". - makes it so that all native out=operators get the out tag too. - torch.library.define (the Python api) validates the schema for the above three constraints. Test Plan: - existing and new tests - previously we did allow `Tag::out_variant` ops to return None/void. Again, this is not actually being used in the wild, so I'm breaking BC here. Authored with Claude. [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/180851
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 70a5f06 with merge base b72c0ac ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
An out= operator must: - have the "Tag::out" tag. - All of the mutable arguments must be write-only buffers (not read before write) - it must return all mutable arguments in order. - all of the mutable arguments must be kwarg-only arguments. The last three restrictions are already restrictions that torchgen places on native pytorch out= operators. This PR: - renames "Tag::out_variant" to "Tag::out". This is not being used in the wild so there are no BC-concerns. We added this API in PyTorch 2.10 but didn't have a good user. I prefer not calling it a "variant" because a user may just have a custom operator that is an "out operator" and not have a functional variant of the operator, so I don't want to call it an "out variant". - makes it so that all native out=operators get the out tag too. - torch.library.define (the Python api) validates the schema for the above three constraints. Test Plan: - existing and new tests - previously we did allow `Tag::out_variant` ops to return None/void. Again, this is not actually being used in the wild, so I'm breaking BC here. Authored with Claude. [ghstack-poisoned]
| This tag indicates that an operator performs a reduction operation, computing aggregate values | ||
| (sum, mean, max, min, etc.) across one or more dimensions of the input tensor(s). | ||
| - tag: out_variant | ||
| - tag: out |
There was a problem hiding this comment.
Do we have a linter we can run to check if this tag is missing on the op when it should be there?
There was a problem hiding this comment.
I'm not convinced a linter is able to detect this. There is testing in this PR.
There was a problem hiding this comment.
Yeah, I was thinking if we could check that it a kwarg out= implies it should have this tag.
An out= operator must: - have the "Tag::out" tag. - All of the mutable arguments must be write-only buffers (not read before write) - it must return all mutable arguments in order. - all of the mutable arguments must be kwarg-only arguments. The last three restrictions are already restrictions that torchgen places on native pytorch out= operators. This PR: - renames "Tag::out_variant" to "Tag::out". This is not being used in the wild so there are no BC-concerns. We added this API in PyTorch 2.10 but didn't have a good user. I prefer not calling it a "variant" because a user may just have a custom operator that is an "out operator" and not have a functional variant of the operator, so I don't want to call it an "out variant". - makes it so that all native out=operators get the out tag too. - torch.library.define (the Python api) validates the schema for the above three constraints. Test Plan: - existing and new tests - previously we did allow `Tag::out_variant` ops to return None/void. Again, this is not actually being used in the wild, so I'm breaking BC here. Authored with Claude. [ghstack-poisoned]
An out= operator must: - have the "Tag::out" tag. - All of the mutable arguments must be write-only buffers (not read before write) - it must return all mutable arguments in order. - all of the mutable arguments must be kwarg-only arguments. The last three restrictions are already restrictions that torchgen places on native pytorch out= operators. This PR: - renames "Tag::out_variant" to "Tag::out". This is not being used in the wild so there are no BC-concerns. We added this API in PyTorch 2.10 but didn't have a good user. I prefer not calling it a "variant" because a user may just have a custom operator that is an "out operator" and not have a functional variant of the operator, so I don't want to call it an "out variant". - makes it so that all native out=operators get the out tag too. - torch.library.define (the Python api) validates the schema for the above three constraints. Test Plan: - existing and new tests - previously we did allow `Tag::out_variant` ops to return None/void. Again, this is not actually being used in the wild, so I'm breaking BC here. Authored with Claude. [ghstack-poisoned]
An out= operator must: - have the "Tag::out" tag. - All of the mutable arguments must be write-only buffers (not read before write) - it must return all mutable arguments in order. - all of the mutable arguments must be kwarg-only arguments. The last three restrictions are already restrictions that torchgen places on native pytorch out= operators. This PR: - renames "Tag::out_variant" to "Tag::out". This is not being used in the wild so there are no BC-concerns. We added this API in PyTorch 2.10 but didn't have a good user. I prefer not calling it a "variant" because a user may just have a custom operator that is an "out operator" and not have a functional variant of the operator, so I don't want to call it an "out variant". - makes it so that all native out=operators get the out tag too. - torch.library.define (the Python api) validates the schema for the above three constraints. Test Plan: - existing and new tests - previously we did allow `Tag::out_variant` ops to return None/void. Again, this is not actually being used in the wild, so I'm breaking BC here. Authored with Claude. [ghstack-poisoned]
|
@claude review this |
|
Claude finished @albanD's task in 4m 33s —— View job PR Review: #180851SummaryThis PR formalizes the definition of out= operators by renaming Code Quality
Testing
API Design
Backward Compatibility
RecommendationRequest Changes The |
An out= operator must: - have the "Tag::out" tag. - All of the mutable arguments must be write-only buffers (not read before write) - it must return all mutable arguments in order. - all of the mutable arguments must be kwarg-only arguments. The last three restrictions are already restrictions that torchgen places on native pytorch out= operators. This PR: - renames "Tag::out_variant" to "Tag::out". This is not being used in the wild so there are no BC-concerns. We added this API in PyTorch 2.10 but didn't have a good user. I prefer not calling it a "variant" because a user may just have a custom operator that is an "out operator" and not have a functional variant of the operator, so I don't want to call it an "out variant". - makes it so that all native out=operators get the out tag too. - torch.library.define (the Python api) validates the schema for the above three constraints. Test Plan: - existing and new tests - previously we did allow `Tag::out_variant` ops to return None/void. Again, this is not actually being used in the wild, so I'm breaking BC here. Authored with Claude. [ghstack-poisoned]
An out= operator must: - have the "Tag::out" tag. - All of the mutable arguments must be write-only buffers (not read before write) - it must return all mutable arguments in order. - all of the mutable arguments must be kwarg-only arguments. The last three restrictions are already restrictions that torchgen places on native pytorch out= operators. This PR: - renames "Tag::out_variant" to "Tag::out". This is not being used in the wild so there are no BC-concerns. We added this API in PyTorch 2.10 but didn't have a good user. I prefer not calling it a "variant" because a user may just have a custom operator that is an "out operator" and not have a functional variant of the operator, so I don't want to call it an "out variant". - makes it so that all native out=operators get the out tag too. - torch.library.define (the Python api) validates the schema for the above three constraints. Test Plan: - existing and new tests - previously we did allow `Tag::out_variant` ops to return None/void. Again, this is not actually being used in the wild, so I'm breaking BC here. Authored with Claude. [ghstack-poisoned]
| f"Got: {schema}" | ||
| ) | ||
| for i, (ret, arg) in enumerate(zip(returns, mutable_args, strict=True)): | ||
| if ret.alias_info is None or arg.alias_info is None: |
There was a problem hiding this comment.
nit: since we already know all of the mutable_args have alias_info is not None?
| if ret.alias_info is None or arg.alias_info is None: | |
| if ret.alias_info is None: |
An out= operator must: - have the "Tag::out" tag. - All of the mutable arguments must be write-only buffers (not read before write) - it must return all mutable arguments in order. - all of the mutable arguments must be kwarg-only arguments. The last three restrictions are already restrictions that torchgen places on native pytorch out= operators. This PR: - renames "Tag::out_variant" to "Tag::out". This is not being used in the wild so there are no BC-concerns. We added this API in PyTorch 2.10 but didn't have a good user. I prefer not calling it a "variant" because a user may just have a custom operator that is an "out operator" and not have a functional variant of the operator, so I don't want to call it an "out variant". - makes it so that all native out=operators get the out tag too. - torch.library.define (the Python api) validates the schema for the above three constraints. Test Plan: - existing and new tests - previously we did allow `Tag::out_variant` ops to return None/void. Again, this is not actually being used in the wild, so I'm breaking BC here. Authored with Claude. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy kadeng muchulee8 amjames chauhang aakhundov coconutruben jataylo [ghstack-poisoned]
An out= operator must: - have the "Tag::out" tag. - All of the mutable arguments must be write-only buffers (not read before write) - it must return all mutable arguments in order. - all of the mutable arguments must be kwarg-only arguments. The last three restrictions are already restrictions that torchgen places on native pytorch out= operators. This PR: - renames "Tag::out_variant" to "Tag::out". This is not being used in the wild so there are no BC-concerns. We added this API in PyTorch 2.10 but didn't have a good user. I prefer not calling it a "variant" because a user may just have a custom operator that is an "out operator" and not have a functional variant of the operator, so I don't want to call it an "out variant". - makes it so that all native out=operators get the out tag too. - torch.library.define (the Python api) validates the schema for the above three constraints. Test Plan: - existing and new tests - previously we did allow `Tag::out_variant` ops to return None/void. Again, this is not actually being used in the wild, so I'm breaking BC here. Authored with Claude. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy kadeng muchulee8 amjames chauhang aakhundov coconutruben jataylo [ghstack-poisoned]
An out= operator must: - have the "Tag::out" tag. - All of the mutable arguments must be write-only buffers (not read before write) - it must return all mutable arguments in order. - all of the mutable arguments must be kwarg-only arguments. The last three restrictions are already restrictions that torchgen places on native pytorch out= operators. This PR: - renames "Tag::out_variant" to "Tag::out". This is not being used in the wild so there are no BC-concerns. We added this API in PyTorch 2.10 but didn't have a good user. I prefer not calling it a "variant" because a user may just have a custom operator that is an "out operator" and not have a functional variant of the operator, so I don't want to call it an "out variant". - makes it so that all native out=operators get the out tag too. - torch.library.define (the Python api) validates the schema for the above three constraints. Test Plan: - existing and new tests - previously we did allow `Tag::out_variant` ops to return None/void. Again, this is not actually being used in the wild, so I'm breaking BC here. Authored with Claude. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy kadeng muchulee8 amjames chauhang aakhundov coconutruben jataylo [ghstack-poisoned]
|
Starting merge as part of PR stack under #180987 |
Allow custom operators tagged with torch.Tag.out to go through auto_functionalize during torch.compile. Previously these were rejected because their returns have alias annotations. - the functional form of e.g. `foo_out(Tensor x, *, Tensor(a!) out) -> Tensor(a!)` is auto_functionalized(foo, x, out_shape, out_stride, out_dtype, out_device). The semantics of this operator are `foo(Tensor x) -> Tensor`. This is because the out= args are write-only, and we need to store the metadata to know how to allocate the output. - Re-inplacing this operator is easy. We just use empty_like to allocate the output tensor and call foo_out. Authored with Claude. Pull Request resolved: #180852 Approved by: https://github.com/angelayi ghstack dependencies: #180851
Operators tagged with Tag.out have well-defined fake kernel semantics: return the out= arguments in declaration order. This extends the existing auto-fake-kernel mechanism (which handles mutable ops with no returns) to also cover Tag.out ops, removing the need for users to manually write trivial fake/meta kernels for these operators. Also warns when users manually register a Meta kernel for a non-builtin Tag.out operator, since the automatic registration is preferred and the manual version is easy to get wrong. Authored with Claude. Pull Request resolved: #180987 Approved by: https://github.com/angelayi ghstack dependencies: #180851, #180852
| # Try multi-output .out() lowering for custom ops with the out tag. | ||
| if ( | ||
| isinstance(kernel, torch._ops.OpOverload) | ||
| and not torch._library.utils.is_builtin(kernel) |
There was a problem hiding this comment.
@zou3519 Why are builtins disabled from this pass? If its to preserve existing functional behaviour could we add a config option (I'm happy to add this if its okay)? For example we can use the memory pool functionality supported in inductor with out= aten overloads
There was a problem hiding this comment.
this was just to preserve existing intended behavior, which was that this code only applies to custom operators
) An out= operator must: - have the "Tag::out" tag. - All of the mutable arguments must be write-only buffers (not read before write) - it must return all mutable arguments in order. - all of the mutable arguments must be kwarg-only arguments. The last three restrictions are already restrictions that torchgen places on native pytorch out= operators. This PR: - renames "Tag::out_variant" to "Tag::out". This is not being used in the wild so there are no BC-concerns. We added this API in PyTorch 2.10 but didn't have a good user. I prefer not calling it a "variant" because a user may just have a custom operator that is an "out operator" and not have a functional variant of the operator, so I don't want to call it an "out variant". - makes it so that all native out=operators get the out tag too. - torch.library.define (the Python api) validates the schema for the above three constraints. Test Plan: - existing and new tests - previously we did allow `Tag::out_variant` ops to return None/void. Again, this is not actually being used in the wild, so I'm breaking BC here. Authored with Claude. Pull Request resolved: pytorch#180851 Approved by: https://github.com/angelayi
Allow custom operators tagged with torch.Tag.out to go through auto_functionalize during torch.compile. Previously these were rejected because their returns have alias annotations. - the functional form of e.g. `foo_out(Tensor x, *, Tensor(a!) out) -> Tensor(a!)` is auto_functionalized(foo, x, out_shape, out_stride, out_dtype, out_device). The semantics of this operator are `foo(Tensor x) -> Tensor`. This is because the out= args are write-only, and we need to store the metadata to know how to allocate the output. - Re-inplacing this operator is easy. We just use empty_like to allocate the output tensor and call foo_out. Authored with Claude. Pull Request resolved: pytorch#180852 Approved by: https://github.com/angelayi ghstack dependencies: pytorch#180851
Operators tagged with Tag.out have well-defined fake kernel semantics: return the out= arguments in declaration order. This extends the existing auto-fake-kernel mechanism (which handles mutable ops with no returns) to also cover Tag.out ops, removing the need for users to manually write trivial fake/meta kernels for these operators. Also warns when users manually register a Meta kernel for a non-builtin Tag.out operator, since the automatic registration is preferred and the manual version is easy to get wrong. Authored with Claude. Pull Request resolved: pytorch#180987 Approved by: https://github.com/angelayi ghstack dependencies: pytorch#180851, pytorch#180852
…torch#181098) test/custom_operator/** tests are not actually run in CI (except for one of them...) Pull Request resolved: pytorch#181098 Approved by: https://github.com/angelayi ghstack dependencies: pytorch#180851, pytorch#180852, pytorch#180987
) An out= operator must: - have the "Tag::out" tag. - All of the mutable arguments must be write-only buffers (not read before write) - it must return all mutable arguments in order. - all of the mutable arguments must be kwarg-only arguments. The last three restrictions are already restrictions that torchgen places on native pytorch out= operators. This PR: - renames "Tag::out_variant" to "Tag::out". This is not being used in the wild so there are no BC-concerns. We added this API in PyTorch 2.10 but didn't have a good user. I prefer not calling it a "variant" because a user may just have a custom operator that is an "out operator" and not have a functional variant of the operator, so I don't want to call it an "out variant". - makes it so that all native out=operators get the out tag too. - torch.library.define (the Python api) validates the schema for the above three constraints. Test Plan: - existing and new tests - previously we did allow `Tag::out_variant` ops to return None/void. Again, this is not actually being used in the wild, so I'm breaking BC here. Authored with Claude. Pull Request resolved: pytorch#180851 Approved by: https://github.com/angelayi
Allow custom operators tagged with torch.Tag.out to go through auto_functionalize during torch.compile. Previously these were rejected because their returns have alias annotations. - the functional form of e.g. `foo_out(Tensor x, *, Tensor(a!) out) -> Tensor(a!)` is auto_functionalized(foo, x, out_shape, out_stride, out_dtype, out_device). The semantics of this operator are `foo(Tensor x) -> Tensor`. This is because the out= args are write-only, and we need to store the metadata to know how to allocate the output. - Re-inplacing this operator is easy. We just use empty_like to allocate the output tensor and call foo_out. Authored with Claude. Pull Request resolved: pytorch#180852 Approved by: https://github.com/angelayi ghstack dependencies: pytorch#180851
Operators tagged with Tag.out have well-defined fake kernel semantics: return the out= arguments in declaration order. This extends the existing auto-fake-kernel mechanism (which handles mutable ops with no returns) to also cover Tag.out ops, removing the need for users to manually write trivial fake/meta kernels for these operators. Also warns when users manually register a Meta kernel for a non-builtin Tag.out operator, since the automatic registration is preferred and the manual version is easy to get wrong. Authored with Claude. Pull Request resolved: pytorch#180987 Approved by: https://github.com/angelayi ghstack dependencies: pytorch#180851, pytorch#180852
…torch#181098) test/custom_operator/** tests are not actually run in CI (except for one of them...) Pull Request resolved: pytorch#181098 Approved by: https://github.com/angelayi ghstack dependencies: pytorch#180851, pytorch#180852, pytorch#180987
) An out= operator must: - have the "Tag::out" tag. - All of the mutable arguments must be write-only buffers (not read before write) - it must return all mutable arguments in order. - all of the mutable arguments must be kwarg-only arguments. The last three restrictions are already restrictions that torchgen places on native pytorch out= operators. This PR: - renames "Tag::out_variant" to "Tag::out". This is not being used in the wild so there are no BC-concerns. We added this API in PyTorch 2.10 but didn't have a good user. I prefer not calling it a "variant" because a user may just have a custom operator that is an "out operator" and not have a functional variant of the operator, so I don't want to call it an "out variant". - makes it so that all native out=operators get the out tag too. - torch.library.define (the Python api) validates the schema for the above three constraints. Test Plan: - existing and new tests - previously we did allow `Tag::out_variant` ops to return None/void. Again, this is not actually being used in the wild, so I'm breaking BC here. Authored with Claude. Pull Request resolved: pytorch#180851 Approved by: https://github.com/angelayi
Allow custom operators tagged with torch.Tag.out to go through auto_functionalize during torch.compile. Previously these were rejected because their returns have alias annotations. - the functional form of e.g. `foo_out(Tensor x, *, Tensor(a!) out) -> Tensor(a!)` is auto_functionalized(foo, x, out_shape, out_stride, out_dtype, out_device). The semantics of this operator are `foo(Tensor x) -> Tensor`. This is because the out= args are write-only, and we need to store the metadata to know how to allocate the output. - Re-inplacing this operator is easy. We just use empty_like to allocate the output tensor and call foo_out. Authored with Claude. Pull Request resolved: pytorch#180852 Approved by: https://github.com/angelayi ghstack dependencies: pytorch#180851
Operators tagged with Tag.out have well-defined fake kernel semantics: return the out= arguments in declaration order. This extends the existing auto-fake-kernel mechanism (which handles mutable ops with no returns) to also cover Tag.out ops, removing the need for users to manually write trivial fake/meta kernels for these operators. Also warns when users manually register a Meta kernel for a non-builtin Tag.out operator, since the automatic registration is preferred and the manual version is easy to get wrong. Authored with Claude. Pull Request resolved: pytorch#180987 Approved by: https://github.com/angelayi ghstack dependencies: pytorch#180851, pytorch#180852
…torch#181098) test/custom_operator/** tests are not actually run in CI (except for one of them...) Pull Request resolved: pytorch#181098 Approved by: https://github.com/angelayi ghstack dependencies: pytorch#180851, pytorch#180852, pytorch#180987
Stack from ghstack (oldest at bottom):
An out= operator must:
before write)
The last three restrictions are already restrictions that torchgen
places on native pytorch out= operators.
This PR:
so there are no BC-concerns. We added this API in PyTorch 2.10 but
didn't have a good user. I prefer not calling it a "variant" because a
user may just have a custom operator that is an "out operator" and not
have a functional variant of the operator, so I don't want to call it
an "out variant".
above three constraints.
Test Plan:
Tag::out_variantops to return None/void.Again, this is not actually being used in the wild, so I'm breaking BC
here.
Authored with Claude.
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo