Skip to content

Auto-generate fake kernels for Tag.out custom operators - #180987

Closed
zou3519 wants to merge 7 commits into
gh/zou3519/3/basefrom
gh/zou3519/3/head
Closed

zou3519 wants to merge 7 commits into
gh/zou3519/3/basefrom
gh/zou3519/3/head

Conversation

@zou3519

@zou3519 zou3519 commented Apr 21, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

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.

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.

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Apr 21, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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:

✅ You can merge normally! (1 Unrelated Failure)

As of commit 16aa556 with merge base a55ca57 (image):

UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:

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

@pytorch-bot

pytorch-bot Bot commented Apr 21, 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
zou3519 requested review from angelayi and eellison April 21, 2026 15:18
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.

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

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

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

ghstack-source-id: 414f929
Pull Request resolved: #180987
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.

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

ghstack-source-id: 420dbf4
Pull Request resolved: #180987
@zou3519 zou3519 added the ciflow/trunk Trigger trunk jobs on your pull request label 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.

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

ghstack-source-id: aac8a79
Pull Request resolved: #180987
@zou3519

zou3519 commented Apr 22, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 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.

Details for Dev Infra team Raised by workflow job

@pytorch-bot

pytorch-bot Bot commented Apr 22, 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 zou3519 added the release notes: composability release notes category label Apr 22, 2026
@zou3519

zou3519 commented Apr 22, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

@zou3519

zou3519 commented Apr 24, 2026 •

Copy link
Copy Markdown
Contributor Author

The failure is interesting.
Basically we are not allowed to query the OpOverload during fake kernel (or any m.impl) registration, because it may not exist yet.
Checking if it does exist is also not a good idea, because materializing the OpOverload packet before all OpOverloads has been registered means that the future OpOverload registrations are ignored. (#123574)

Resolution is I'm deleting the warning but going to keep everything else.

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.

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

[ghstack-poisoned]
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Starting merge as part of PR stack under #181100

1 similar comment
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Starting merge as part of PR stack under #181100

pytorchmergebot pushed a commit that referenced this pull request Apr 25, 2026
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: #181099
Approved by: https://github.com/angelayi
ghstack dependencies: #181380, #180987
pytorchmergebot pushed a commit that referenced this pull request Apr 25, 2026
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
@github-actions
github-actions Bot deleted the gh/zou3519/3/head branch May 25, 2026 02:31
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
aperson30 pushed a commit to aperson30/pytorch that referenced this pull request Jun 20, 2026
…rch#180987)"

This reverts commit 9c406e3.

Reverted pytorch#180987 on behalf of https://github.com/ZainRizvi due to Sorry but this is breaking internally. See diff D102001674 and D102198161 for details. To validate your fixes internally, you can follow the instructions here: https://fburl.com/fixing-ghfirst-reverts ([comment](pytorch#180987 (comment)))
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#181380
aperson30 pushed a commit to aperson30/pytorch that referenced this pull request Jun 20, 2026
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
aperson30 pushed a commit to aperson30/pytorch that referenced this pull request Jun 20, 2026
)

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
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
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…rch#180987)"

This reverts commit 9c406e3.

Reverted pytorch#180987 on behalf of https://github.com/ZainRizvi due to Sorry but this is breaking internally. See diff D102001674 and D102198161 for details. To validate your fixes internally, you can follow the instructions here: https://fburl.com/fixing-ghfirst-reverts ([comment](pytorch#180987 (comment)))
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#181380
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
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
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
)

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
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
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…rch#180987)"

This reverts commit 9c406e3.

Reverted pytorch#180987 on behalf of https://github.com/ZainRizvi due to Sorry but this is breaking internally. See diff D102001674 and D102198161 for details. To validate your fixes internally, you can follow the instructions here: https://fburl.com/fixing-ghfirst-reverts ([comment](pytorch#180987 (comment)))
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#181380
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
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
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.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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-no-td Do not run TD on this PR ciflow/inductor ciflow/trunk Trigger trunk jobs on your pull request Merged release notes: composability release notes category Reverted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants