Skip to content

Don't include ATen/Context.h from generated per-operator headers - #200676

Closed
ezyang wants to merge 7 commits into
gh/ezyang/3619/basefrom
gh/ezyang/3619/head
Closed

ezyang wants to merge 7 commits into
gh/ezyang/3619/basefrom
gh/ezyang/3619/head

Conversation

@ezyang

@ezyang ezyang commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Every generated ATen/ops/.h includes ATen/Context.h, but the
generated code in those headers doesn't use anything from it. Since most
of aten/src/ATen/native is built with per-operator headers, this makes
nearly every kernel TU depend on Context.h, which changes often (new
global settings: TF32/precision flags, BLAS/SDPA backend knobs, ...),
and every such change recompiles most of the tree.

Drop the include from the template. Based on a static include-graph scan
of in-tree sources with AT_PER_OPERATOR_HEADERS defined, the number of
translation units that depend on ATen/Context.h drops from about 1520 to
about 1030 of about 2500. ATen/Functions.h and ATen/ATen.h still include
ATen/Context.h, so code using those is unaffected. Out-of-tree code that
includes only ATen/ops/*.h and uses at::globalContext() must now include
ATen/Context.h itself.

UnaryOps.cpp used M_SQRT1_2, which MSVC only defines when
_USE_MATH_DEFINES is set; it was getting that through ATen/Context.h ->
ATen/CPUGeneratorImpl.h -> ATen/core/MT19937RNGEngine.h. Use
c10::frac_sqrt_2 from c10/util/MathConstants.h (already
included) instead.

Three torch-xpu-ops kernels called globalContext() without including
ATen/Context.h; intel/torch-xpu-ops#5749
(intel/torch-xpu-ops#5749) fixed them, and
third_party/xpu.txt already points at a torch-xpu-ops commit that
includes it (#201371).

Test plan: regenerated the headers with torchgen, then ran every
non-third-party host C++ TU of a Linux CUDA build (MKLDNN, XNNPACK and
NNPACK off) with -fsyntax-only (1905 TUs) and compiled with nvcc every
CUDA TU that no longer reaches Context.h (64 TUs); all pass. MKLDNN-,
ROCm-, MPS-, XPU- and Windows-only code, and torch-xpu-ops at the
current pin, were checked only by static scans for uses of Context.h
symbols and of M_* math constants without _USE_MATH_DEFINES.

…xt.h from generated per-op headers

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

PR Status: Approved 🚀

Please fix all CI failures and trigger merge by commenting "@pytorchbot merge".

✅ AUTOMATED REVIEW - OUTDATED (earlier commit) - Ready for human review:

The PR removes `#include <ATen/Context.h>` from
`aten/src/ATen/templates/Function.h`, the template behind every generated
`ATen/ops/<op>.h`. Static include tracing found no in-tree breakage in any
configuration, though the change breaks the source of out-of-tree extensions.
Recommendation: Approve, with a release note or BC-breaking label needed before
landing.

Findings (1):

[minor] aten/src/ATen/templates/Function.h:5
Out-of-tree C++ extensions and backends that include only `ATen/ops/<op>.h` lose
more than `at::globalContext()`. The PR description mentions only
`globalContext()`, but these headers also stop providing everything Context.h
brings in: `at::Context` and `globalContext()`; the `LegacyTypeDispatch` guards
(`at::AutoDispatchBelowAutograd`, `AutoDispatchBelowADInplaceOrView`);
`CPUGeneratorImpl` and `at::detail::getDefaultCPUGenerator`; all
`at::detail::*HooksInterface` getters (`getCUDAHooks`, `getMPSHooks`,
`getXPUHooks`, PrivateUse1 hooks, ); the `BlasBackend`, `LinalgBackend`,
`SDPBacken

Reviewed commit: e931e10 (NOT the current head 6b10e23)

Review run

🔗 Helpful Links

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

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

❌ 1 Unclassified Failure

As of commit 6b10e23 with merge base 090a616 (image):

🟡 GREEN LIGHT - OUTDATED (earlier commit) - PR requires human review:

  • Socialization
    • Removing #include <ATen/Context.h> from aten/src/ATen/templates/Function.h drops it from every generated ATen/ops/<op>.h
    • PR body states out-of-tree code including only ATen/ops/*.h and using at::globalContext() must now add the include itself
  • Breadth
    • One template line fans out to every per-operator header and every TU that relied on the transitive include
    • PR body says MPS, XPU and ROCm sources were checked only by static scan, not compiled
  • Triviality
    • Not a runtime no-op or mechanical refactor: it changes the public header surface C++ extension authors build against

reason: needs_socialization
Reviewed commit: 0ee6ae0 (NOT the current head 6b10e23)

Inference job

🐛 Report a wrong verdict

UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:

  • .github/workflows/trunk.yml (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)

    AI verdict: AI verdict: inconclusive

    The signal has no completed events: the suspect's events[] is empty and there's no baseline. The PR's head has no trunk.yml checks, and its other checks are still pending. The change could plausibly break a build because it drops #include &lt;ATen/Context.h&gt; from the generated per-operator headers, but no failure log exists to confirm that.

    Full reasoning on HUD →

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

ezyang added a commit that referenced this pull request Oct 12, 2026
Every generated ATen/ops/<op>.h includes ATen/Context.h, but the
generated code in those headers doesn't use anything from it. Since most
of aten/src/ATen/native is built with per-operator headers, this makes
nearly every kernel TU depend on Context.h, which changes often (new
global settings: TF32/precision flags, BLAS/SDPA backend knobs, ...),
and every such change recompiles most of the tree.

Drop the include from the template. Based on a static include-graph scan
of in-tree sources with AT_PER_OPERATOR_HEADERS defined, the number of
translation units that depend on ATen/Context.h drops from about 1510 to
about 1020 of about 2500. ATen/Functions.h and ATen/ATen.h still include
ATen/Context.h, so code using those is unaffected. Out-of-tree code that
includes only ATen/ops/*.h and uses at::globalContext() must now include
ATen/Context.h itself.

Test plan: regenerated the headers with torchgen, then ran every
non-third-party host C++ TU of a Linux CUDA build with -fsyntax-only (1846
TUs) and compiled with nvcc every CUDA TU that no longer reaches
Context.h (64 TUs); all pass. MPS, XPU and ROCm sources were checked
only by a static scan for uses of Context.h symbols.


ghstack-source-id: bba1b34
Pull-Request: #200676
@ezyang
ezyang marked this pull request as ready for review October 12, 2026 20:50
@ezyang
ezyang requested review from drisspg and removed request for SherlockNoMad, antoniojkim, bdhirsh and miladm October 12, 2026 20:50
… code (fixes Activation.cpp build break)

[ghstack-poisoned]
ezyang added a commit that referenced this pull request Oct 13, 2026
Every generated ATen/ops/<op>.h includes ATen/Context.h, but the
generated code in those headers doesn't use anything from it. Since most
of aten/src/ATen/native is built with per-operator headers, this makes
nearly every kernel TU depend on Context.h, which changes often (new
global settings: TF32/precision flags, BLAS/SDPA backend knobs, ...),
and every such change recompiles most of the tree.

Drop the include from the template. Based on a static include-graph scan
of in-tree sources with AT_PER_OPERATOR_HEADERS defined, the number of
translation units that depend on ATen/Context.h drops from about 1510 to
about 1020 of about 2500. ATen/Functions.h and ATen/ATen.h still include
ATen/Context.h, so code using those is unaffected. Out-of-tree code that
includes only ATen/ops/*.h and uses at::globalContext() must now include
ATen/Context.h itself.

Test plan: regenerated the headers with torchgen, then ran every non-
third-party host C++ TU of a Linux CUDA build (MKLDNN, XNNPACK and
NNPACK off) with -fsyntax-only (1846 TUs) and compiled with nvcc every
CUDA TU that no longer reaches Context.h (64 TUs); all pass. MKLDNN-,
ROCm-, MPS- and XPU-only code was checked only by a static scan for uses
of Context.h symbols.

ghstack-source-id: 7818dd9
Pull-Request: #200676
ezyang added a commit that referenced this pull request Oct 13, 2026
Every generated ATen/ops/<op>.h includes ATen/Context.h, but the
generated code in those headers doesn't use anything from it. Since most
of aten/src/ATen/native is built with per-operator headers, this makes
nearly every kernel TU depend on Context.h, which changes often (new
global settings: TF32/precision flags, BLAS/SDPA backend knobs, ...),
and every such change recompiles most of the tree.

Drop the include from the template. Based on a static include-graph scan
of in-tree sources with AT_PER_OPERATOR_HEADERS defined, the number of
translation units that depend on ATen/Context.h drops from about 1510 to
about 1020 of about 2500. ATen/Functions.h and ATen/ATen.h still include
ATen/Context.h, so code using those is unaffected. Out-of-tree code that
includes only ATen/ops/*.h and uses at::globalContext() must now include
ATen/Context.h itself.

Test plan: regenerated the headers with torchgen, then ran every non-
third-party host C++ TU of a Linux CUDA build (MKLDNN, XNNPACK and
NNPACK off) with -fsyntax-only (1846 TUs) and compiled with nvcc every
CUDA TU that no longer reaches Context.h (64 TUs); all pass. MKLDNN-,
ROCm-, MPS- and XPU-only code was checked only by a static scan for uses
of Context.h symbols.

ghstack-source-id: 1ff2b3e
Pull-Request: #200676
@ezyang

ezyang commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

blocked on xpu updates

ezyang added a commit that referenced this pull request Oct 13, 2026
Every generated ATen/ops/<op>.h includes ATen/Context.h, but the
generated code in those headers doesn't use anything from it. Since most
of aten/src/ATen/native is built with per-operator headers, this makes
nearly every kernel TU depend on Context.h, which changes often (new
global settings: TF32/precision flags, BLAS/SDPA backend knobs, ...),
and every such change recompiles most of the tree.

Drop the include from the template. Based on a static include-graph scan
of in-tree sources with AT_PER_OPERATOR_HEADERS defined, the number of
translation units that depend on ATen/Context.h drops from about 1510 to
about 1020 of about 2500. ATen/Functions.h and ATen/ATen.h still include
ATen/Context.h, so code using those is unaffected. Out-of-tree code that
includes only ATen/ops/*.h and uses at::globalContext() must now include
ATen/Context.h itself.

This depends on third_party/torch-xpu-ops: several of its kernels call
globalContext() without including ATen/Context.h, so the XPU build fails
until intel/torch-xpu-ops adds the include and third_party/xpu.txt is
bumped.

Test plan: regenerated the headers with torchgen, then ran every non-
third-party host C++ TU of a Linux CUDA build (MKLDNN, XNNPACK and
NNPACK off) with -fsyntax-only (1846 TUs) and compiled with nvcc every
CUDA TU that no longer reaches Context.h (64 TUs); all pass. MKLDNN-,
ROCm-, MPS- and XPU-only code was checked only by a static scan for uses
of Context.h symbols.

ghstack-source-id: 1ff2b3e
Pull-Request: #200676
@pytorchbot pytorchbot added the in progress PR is being worked on by the author, until the automated review accepts it label Oct 16, 2026
github-actions[bot]

This comment was marked as outdated.

guangyey pushed a commit to intel/torch-xpu-ops that referenced this pull request Oct 18, 2026
AdaptiveAveragePooling3d.cpp, DilatedMaxPool3d.cpp and
FractionalMaxPool3d.cpp call globalContext().alertNotDeterministic()
without including ATen/Context.h. They currently get it transitively
through the generated per-operator headers (ATen/ops/*.h), which
include ATen/Context.h.

PyTorch is removing that include from the per-operator header template
to cut the rebuild cost of edits to ATen/Context.h
(pytorch/pytorch#200676). Include the header
directly so these files keep building. No functional change; this
builds against current PyTorch too.
@guangyey

Copy link
Copy Markdown
Collaborator

XPU commit pin is intel/torch-xpu-ops@4260c03

@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

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 4 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team

Raised by workflow job

Failing merge rule: Core Maintainers

@pytorchgreenlight pytorchgreenlight Bot added the GL/superseded GreenLight review is superseded by changes label Oct 27, 2026
@ezyang

ezyang commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -r

@ezyang ezyang added the mergedog mergedog is watching this PR label Oct 27, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

[ghstack-poisoned]
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased gh/ezyang/3619/orig onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via ghstack checkout https://github.com/pytorch/pytorch/pull/200676)

pytorchmergebot pushed a commit that referenced this pull request Oct 27, 2026
Every generated ATen/ops/<op>.h includes ATen/Context.h, but the
generated code in those headers doesn't use anything from it. Since most
of aten/src/ATen/native is built with per-operator headers, this makes
nearly every kernel TU depend on Context.h, which changes often (new
global settings: TF32/precision flags, BLAS/SDPA backend knobs, ...),
and every such change recompiles most of the tree.

Drop the include from the template. Based on a static include-graph scan
of in-tree sources with AT_PER_OPERATOR_HEADERS defined, the number of
translation units that depend on ATen/Context.h drops from about 1520 to
about 1030 of about 2500. ATen/Functions.h and ATen/ATen.h still include
ATen/Context.h, so code using those is unaffected. Out-of-tree code that
includes only ATen/ops/*.h and uses at::globalContext() must now include
ATen/Context.h itself.

UnaryOps.cpp used M_SQRT1_2, which MSVC only defines when
_USE_MATH_DEFINES is set; it was getting that through ATen/Context.h ->
ATen/CPUGeneratorImpl.h -> ATen/core/MT19937RNGEngine.h. Use
c10::frac_sqrt_2<double> from c10/util/MathConstants.h (already
included) instead.

Three torch-xpu-ops kernels called globalContext() without including
ATen/Context.h; intel/torch-xpu-ops#5749
(intel/torch-xpu-ops#5749) fixed them, and
third_party/xpu.txt already points at a torch-xpu-ops commit that
includes it (#201371).

Test plan: regenerated the headers with torchgen, then ran every
non-third-party host C++ TU of a Linux CUDA build (MKLDNN, XNNPACK and
NNPACK off) with -fsyntax-only (1905 TUs) and compiled with nvcc every
CUDA TU that no longer reaches Context.h (64 TUs); all pass. MKLDNN-,
ROCm-, MPS-, XPU- and Windows-only code, and torch-xpu-ops at the
current pin, were checked only by static scans for uses of Context.h
symbols and of M_* math constants without _USE_MATH_DEFINES.

ghstack-source-id: 11c0756
Pull-Request: #200676
@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

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 2 jobs have failed, first few of them are: .github/workflows/trunk.yml, .github/workflows/lint.yml

Details for Dev Infra team

Raised by workflow job

@ezyang

ezyang commented Oct 27, 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

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: trunk

Details for Dev Infra team

Raised by workflow job

@ezyang

ezyang commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

mergedog handoff

Note

This PR is being shepherded by mergedog, an automation tool run by a maintainer. It watches CI and may push fixes; the PR author does not need to act unless a maintainer asks.

All CI is green (or skipped). Ready for human review and @pytorchbot merge.

Current PR head: e750d5094f6780c54c41b21982fc22f28138a0ad.

Autonomous changes pushed

  • None.

CI notes at handoff

mergedog is treating these still-failing checks as unrelated/spurious. Please verify before merging:

  • Test collect_env

Warning: mergedog's suppressed check list differs from the latest Dr. CI summary.

Suppressed by mergedog but not listed by Dr. CI:

  • Test collect_env
Latest Dr. CI summary
## PR Status: Approved 🚀

Please fix all CI failures and trigger merge by commenting "@pytorchbot merge".


<details><summary>✅ <b>AUTOMATED REVIEW</b> - OUTDATED (earlier commit) - Ready for human review:</summary><p>

The PR removes #include <ATen/Context.h> from
aten/src/ATen/templates/Function.h, the template behind every generated
ATen/ops/<op>.h. Static include tracing found no in-tree breakage in any
configuration, though the change breaks the source of out-of-tree extensions.
Recommendation: Approve, with a release note or BC-breaking label needed before
landing.


**Findings (1):**

[minor] aten/src/ATen/templates/Function.h:5
Out-of-tree C++ extensions and backends that include only ATen/ops/<op>.h lose
more than at::globalContext(). The PR description mentions only
globalContext(), but these headers also stop providing everything Context.h
brings in: at::Context and globalContext(); the LegacyTypeDispatch guards
(at::AutoDispatchBelowAutograd, AutoDispatchBelowADInplaceOrView);
CPUGeneratorImpl and at::detail::getDefaultCPUGenerator; all
at::detail::*HooksInterface getters (getCUDAHooks, getMPSHooks,
getXPUHooks, PrivateUse1 hooks, ); the BlasBackend, LinalgBackend,
`SDPBacken


Reviewed commit: `e931e10` (NOT the current head `6b10e23`)

[Review run](https://github.com/pytorch/pytorch/actions/runs/39184928074)

</p></details>

## :link: Helpful Links
### :test_tube: See artifacts and rendered test results at [hud.pytorch.org/pr/200676](https://hud.pytorch.org/pr/200676)
* :page_facing_up: Preview [Python docs built from this PR](https://docs-preview.pytorch.org/pytorch/pytorch/200676/index.html)
* :page_facing_up: Preview [C++ docs built from this PR](https://docs-preview.pytorch.org/pytorch/pytorch/200676/cppdocs/index.html)
* :question: Need help or want to give feedback on the CI? Visit the [bot commands wiki](https://github.com/pytorch/pytorch/wiki/Bot-commands)

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


## :x: 1 Pending, 1 Unclassified Failure
As of commit 6b10e23c936a9c54be8425c47537e834dec1b094 with merge base 090a616f58c9f26eb8057ade7170ee00995014ef (<sub><sub><img alt="image" width=70 src="https://img.shields.io/date/1793093392?label=&color=FFFFFF&style=flat-square"></sub></sub>):
<details><summary>🟡 <b>GREEN LIGHT</b> - OUTDATED (earlier commit) - PR requires human review:</summary><p>

<ul><li><b>Socialization</b><ul><li>Removing <code>#include &lt;ATen/Context.h&gt;</code> from <code>aten/src/ATen/templates/Function.h</code> drops it from every generated <code>ATen/ops/&lt;op&gt;.h</code></li><li>PR body states out-of-tree code including only <code>ATen/ops/*.h</code> and using <code>at::globalContext()</code> must now add the include itself</li></ul></li><li><b>Breadth</b><ul><li>One template line fans out to every per-operator header and every TU that relied on the transitive include</li><li>PR body says MPS, XPU and ROCm sources were checked only by static scan, not compiled</li></ul></li><li><b>Triviality</b><ul><li>Not a runtime no-op or mechanical refactor: it changes the public header surface C++ extension authors build against</li></ul></li></ul>

reason: `needs_socialization`
Reviewed commit: `0ee6ae0` (NOT the current head `6b10e23`)

[Inference job](https://github.com/pytorch/test-infra/actions/runs/38423927053)

[:bug: Report a wrong verdict](https://hud.pytorch.org/pytorch/pytorch/pull/200676?sha=0ee6ae007085eabb00792b93dd4f16c998b13427&greenlightReport=1)

</p></details>
<details open><summary><b>UNCLASSIFIED FAILURE</b> - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:</summary><p>

* [.github/workflows/trunk.yml](https://hud.pytorch.org/pr/pytorch/pytorch/200676#40535629420) ([gh](https://github.com/pytorch/pytorch/actions/runs/40535629420)) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
  <details><summary>AI verdict: <a href="https://hud.pytorch.org/pr/pytorch/pytorch/200676#40535629420"><img alt="AI verdict: inconclusive" src="https://hud.pytorch.org/api/drci/advisorBadge?owner=pytorch&repo=pytorch&sha=6b10e23c936a9c54be8425c47537e834dec1b094&job=.github%2Fworkflows%2Ftrunk.yml"></a></summary><blockquote>

  The signal has no completed events: the suspect&#39;s events[] is empty and there&#39;s no baseline. The PR&#39;s head has no trunk.yml checks, and its other checks are still pending. The change could plausibly break a build because it drops `#include &lt;ATen/Context.h&gt;` from the generated per-operator headers, but no failure log exists to confirm that.

  <a href="https://hud.pytorch.org/pr/pytorch/pytorch/200676#40535629420">Full reasoning on HUD &rarr;</a>
  </blockquote></details>
</p></details>


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

During shepherding, the configured LLM was invoked 1 time. If any CI shows red, it judged that failure unrelated to this PR's changes — please verify below before merging.

Session 1 — fix-CI (2026-10-27T16:00:55+00:00)

  • Before: 8f42cb4d5a68
  • Verdict: judged failures spurious (no commit) — rationale: Dismissing: "Test collect_env" (.github/workflows/lint.yml, test_collect_env matrix). This job only sets up a Python interpreter, optionally pip-installs a released PyPI torch==2.* wheel (with_torch) or none at all, and runs python3 torch/utils/collect_env.py. It never builds PyTorch from this checkout. The PR only touches C++ sources (aten/src/ATen/templates/Function.h and aten/src/ATen/native/UnaryOps.cpp: removing/adding an include), which cannot affect collect_env.py or a prebuilt wheel. No logs were available; the failure must be an infra/runner, pip, or PyPI issue unrelated to this change.
LLM transcript
claude session b05e6876
claude → Bash: cd .; git diff HEAD~1 --stat; grep -n -A40 "collect_env\|collect-env" .github/workflows/lint.yml | head -80
claude → Bash: cd .; sed -n 288,301p .github/workflows/lint.yml; cat > .mergedog-spurious <<'EOF'
               Dismissing: "Test collect_env" (.github/workflows/lint.yml, test_collect_env matrix).
               
               This job only sets up a Python interpreter, optionally pip-installs a prebuilt
               nightly torch wheel (with_torch) or none at all, and runs
               `python3 torch/utils/collect_env.py`. It never builds PyTorch from this
               checkout. The PR only touches C++ sources (aten/src/ATen/templates/Function.h
               and aten/src/ATen/native/UnaryOps.cpp: removing/adding an include), which cannot
               affect collect_env.py or a prebuilt wheel. No logs were available; the failure
               must be an infra/runner, pip, or nightly-wheel issue unrelated to this change.
               EOF
claude → Bash: cd .; sed -i 's/optionally pip-installs a prebuilt/optionally pip-installs a released PyPI/; s/nightly torch wheel (with_torch)/torch==2.* wheel (with_torch)/; s/pip, or nightly-wheel issue/pip, or PyPI issue/' .mergedog-spurious; cat .mergedog-spurious; git status --short
claude: I marked the one failing check, "Test collect_env", as spurious. My reasoning is in `.mergedog-spurious`; I made no commit.
claude: The job never builds PyTorch from this checkout. It sets up Python, installs a released `torch==2.*` wheel from PyPI in the `with_torch` variant (nothing in the others), and runs `python3 torch/utils/collect_env.py`. This PR only changes two C++ files: it removes an include from `aten/src/ATen/templates/Function.h` and adds one to `aten/src/ATen/native/UnaryOps.cpp`. Neither can affect that script or the PyPI wheel.
claude: No logs were available for the failure, so I couldn't see the actual error. I'm calling it a runner, pip or PyPI problem because the PR's changes can't reach what this job runs, not because I saw the cause.
claude finished: success (cost $0.2909)

@ezyang

ezyang commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -f "looks good"

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use -f as last resort and instead consider -i/--ignore-current to continue the merge ignoring current failures. This will allow currently pending tests to finish and report signal before the merge.

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

minmingzhu pushed a commit to minmingzhu/torch-xpu-ops that referenced this pull request Oct 28, 2026
AdaptiveAveragePooling3d.cpp, DilatedMaxPool3d.cpp and
FractionalMaxPool3d.cpp call globalContext().alertNotDeterministic()
without including ATen/Context.h. They currently get it transitively
through the generated per-operator headers (ATen/ops/*.h), which
include ATen/Context.h.

PyTorch is removing that include from the per-operator header template
to cut the rebuild cost of edits to ATen/Context.h
(pytorch/pytorch#200676). Include the header
directly so these files keep building. No functional change; this
builds against current PyTorch too.
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 5, 2026
…orch#200676)

Every generated ATen/ops/<op>.h includes ATen/Context.h, but the
generated code in those headers doesn't use anything from it. Since most
of aten/src/ATen/native is built with per-operator headers, this makes
nearly every kernel TU depend on Context.h, which changes often (new
global settings: TF32/precision flags, BLAS/SDPA backend knobs, ...),
and every such change recompiles most of the tree.

Drop the include from the template. Based on a static include-graph scan
of in-tree sources with AT_PER_OPERATOR_HEADERS defined, the number of
translation units that depend on ATen/Context.h drops from about 1520 to
about 1030 of about 2500. ATen/Functions.h and ATen/ATen.h still include
ATen/Context.h, so code using those is unaffected. Out-of-tree code that
includes only ATen/ops/*.h and uses at::globalContext() must now include
ATen/Context.h itself.

UnaryOps.cpp used M_SQRT1_2, which MSVC only defines when
_USE_MATH_DEFINES is set; it was getting that through ATen/Context.h ->
ATen/CPUGeneratorImpl.h -> ATen/core/MT19937RNGEngine.h. Use
c10::frac_sqrt_2<double> from c10/util/MathConstants.h (already
included) instead.

Three torch-xpu-ops kernels called globalContext() without including
ATen/Context.h; intel/torch-xpu-ops#5749
(intel/torch-xpu-ops#5749) fixed them, and
third_party/xpu.txt already points at a torch-xpu-ops commit that
includes it (pytorch#201371).

Test plan: regenerated the headers with torchgen, then ran every
non-third-party host C++ TU of a Linux CUDA build (MKLDNN, XNNPACK and
NNPACK off) with -fsyntax-only (1905 TUs) and compiled with nvcc every
CUDA TU that no longer reaches Context.h (64 TUs); all pass. MKLDNN-,
ROCm-, MPS-, XPU- and Windows-only code, and torch-xpu-ops at the
current pin, were checked only by static scans for uses of Context.h
symbols and of M_* math constants without _USE_MATH_DEFINES.
Pull Request resolved: pytorch#200676
Approved by: https://github.com/Skylion007, https://github.com/guangyey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request GL/superseded GreenLight review is superseded by changes mergedog mergedog is watching this PR mergedX1 ready for review Automated review passed, ready for a final review by a maintainer. release notes: cpp release notes category topic: bc breaking topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants