Skip to content

Support out-tagged custom operators in torch.compile - #180852

Closed
zou3519 wants to merge 12 commits into
gh/zou3519/2/basefrom
gh/zou3519/2/head
Closed

zou3519 wants to merge 12 commits into
gh/zou3519/2/basefrom
gh/zou3519/2/head

Conversation

@zou3519

@zou3519 zou3519 commented Apr 20, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

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.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo

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, ...). The semantics of this operator are
  `foo(Tensor x) -> Tensor`. This is because the out= args are
  write-only.
- Re-inplacing this operator is easy. We just use empty_like to allocate
  the output tensor and call foo_out.

Authored with Claude.

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Apr 20, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/180852

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ No Failures

As of commit b5760f4 with merge base b72c0ac (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot

pytorch-bot Bot commented Apr 20, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

zou3519 added a commit that referenced this pull request Apr 20, 2026
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, ...). The semantics of this operator are
  `foo(Tensor x) -> Tensor`. This is because the out= args are
  write-only.
- Re-inplacing this operator is easy. We just use empty_like to allocate
  the output tensor and call foo_out.

Authored with Claude.

ghstack-source-id: e203d1e
Pull Request resolved: #180852
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, ...). The semantics of this operator are
  `foo(Tensor x) -> Tensor`. This is because the out= args are
  write-only.
- Re-inplacing this operator is easy. We just use empty_like to allocate
  the output tensor and call foo_out.

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]
@zou3519
zou3519 marked this pull request as draft April 20, 2026 15:01
zou3519 added a commit that referenced this pull request Apr 20, 2026
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, ...). The semantics of this operator are
  `foo(Tensor x) -> Tensor`. This is because the out= args are
  write-only.
- Re-inplacing this operator is easy. We just use empty_like to allocate
  the output tensor and call foo_out.

Authored with Claude.

ghstack-source-id: 44bdf35
Pull Request resolved: #180852
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, ...). The semantics of this operator are
  `foo(Tensor x) -> Tensor`. This is because the out= args are
  write-only.
- Re-inplacing this operator is easy. We just use empty_like to allocate
  the output tensor and call foo_out.

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]
zou3519 added a commit that referenced this pull request Apr 21, 2026
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.

ghstack-source-id: dc881ad
Pull Request resolved: #180852
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.

[ghstack-poisoned]
zou3519 added a commit that referenced this pull request Apr 21, 2026
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.

ghstack-source-id: dc881ad
Pull Request resolved: #180852
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.

[ghstack-poisoned]
zou3519 added a commit that referenced this pull request Apr 21, 2026
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.

ghstack-source-id: dc881ad
Pull Request resolved: #180852
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.

[ghstack-poisoned]
zou3519 added a commit that referenced this pull request Apr 21, 2026
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.

ghstack-source-id: a5826f3
Pull Request resolved: #180852
@zou3519
zou3519 marked this pull request as ready for review April 21, 2026 13:40
@zou3519
zou3519 requested review from angelayi and eellison April 21, 2026 13:40
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.

[ghstack-poisoned]
zou3519 added a commit that referenced this pull request Apr 21, 2026
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.

ghstack-source-id: 4c8fe1f
Pull Request resolved: #180852
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.

[ghstack-poisoned]
zou3519 added a commit that referenced this pull request Apr 21, 2026
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.

ghstack-source-id: 095e2d2
Pull Request resolved: #180852
@zou3519

zou3519 commented Apr 21, 2026

Copy link
Copy Markdown
Contributor Author

My local claude pr-review has acquiesced on this, but feel free to request it on the PR

unwrapped_mutable_out = (
(unwrapped_outs,) if n_mutable == 1 else tuple(unwrapped_outs)
)
unwrapped_actual_out = (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isnt this the same as unwrapped_outs?

zou3519 added 4 commits April 21, 2026 11:03
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.

[ghstack-poisoned]
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.

[ghstack-poisoned]
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.

[ghstack-poisoned]
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.

[ghstack-poisoned]
@zou3519 zou3519 added the release notes: composability release notes category label Apr 22, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Starting merge as part of PR stack under #180987

pytorchmergebot pushed a commit that referenced this pull request Apr 22, 2026
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
pytorchmergebot pushed a commit that referenced this pull request Apr 23, 2026
…81098)

test/custom_operator/** tests are not actually run in CI (except for one
of them...)
Pull Request resolved: #181098
Approved by: https://github.com/angelayi
ghstack dependencies: #180851, #180852, #180987
@github-actions
github-actions Bot deleted the gh/zou3519/2/head branch May 23, 2026 02:29
aperson30 pushed a commit to aperson30/pytorch that referenced this pull request Jun 20, 2026
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
aperson30 pushed a commit to aperson30/pytorch that referenced this pull request Jun 20, 2026
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
aperson30 pushed a commit to aperson30/pytorch that referenced this pull request Jun 20, 2026
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
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
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
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
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
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
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
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
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants