Skip to content

CUDA wheel: check every dependency, and give torch_cpu_library targets torch's compile settings back - #24087

Merged
shoumikhin merged 3 commits into
pytorch:mainfrom
shoumikhin:cuda-wheel-dep-followups
Oct 23, 2026
Merged

shoumikhin merged 3 commits into
pytorch:mainfrom
shoumikhin:cuda-wheel-dep-followups

Conversation

@shoumikhin

@shoumikhin shoumikhin commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem

#24060 made the Linux CUDA wheel load next to a CPU-only PyTorch by linking torch_cpu_library instead of torch. Three things were too weak.

  1. The check looked only for libtorch_cuda.so and libc10_cuda.so. libnvrtc.so.13 and other CUDA libraries slipped through.
  2. The relinked targets lost torch's compile settings. Linking torch also brings its include directories as system headers, TORCH_CXX_FLAGS, and on recent torch a C++ standard. torch_cpu_library misses most of them. So warnings inside torch's headers are reported as ours, and a configured TORCH_CXX_FLAGS is dropped.
  3. The comments at the five link sites did not say why torch_cpu_library is used. At aten_bridge the reason was wrong.

Fix

  • Allow list in the CUDA wheel smoke test. Every dependency a shipped library records must be in the wheel, a torch library that a CPU-only torch also has, a system library the manylinux policy allows, or from a package a plain install requires.
  • Comments. Each site now says torch records libtorch_cuda with a CUDA build of PyTorch, and torch_cpu_library does not. aten_bridge is now STATIC, as its comment assumes.
  • Compile settings. find_package_torch copies torch's interface include directories, compile options and compile features to torch_cpu_library once, so every target in the build that links torch_cpu_library gets them. The CUDA settings a CUDA build of PyTorch adds to torch are not copied. If there is no torch_cpu_library, as with a static libtorch, nothing is copied.

Testing

  • A new CMake test checks that targets linking torch_cpu_library, also through a PUBLIC link, get the C++ API include directory, TORCH_CXX_FLAGS and, when torch sets one (the 2.16 nightly does, 2.14 does not), the C++ standard, also when torch was found first. A second test checks that find_package_torch configures when only a torch target exists. Both pass on Linux x86-64 with torch 2.14.0 (CPU, CUDA 13.0) and a 2.16 CUDA 13.2 nightly, and on macOS arm64 with 2.14.0 CPU. Each fails without its part of the change.
  • On Linux x86-64, the new wheel check passes on a CUDA wheel built with Link torch_cpu_library, not torch, so the CUDA wheel imports with a CPU-only torch #24060, next to a CPU-only torch. It fails on a CUDA 13.2 nightly from before Link torch_cpu_library, not torch, so the CUDA wheel imports with a CPU-only torch #24060, naming libnvrtc.so.13 and three more.
  • With torch 2.14.0+cpu and GCC 11, the six relinked targets build. op_allclose.cpp with -Wall -Wextra -Werror: 25 errors in torch headers without the change, none with it.
  • With BUILD_SHARED_LIBS=ON, aten_bridge is now static and _training_lib builds.

@shoumikhin shoumikhin added the release notes: build Changes related to build, including dependency upgrades, build flags, optimizations, etc. label Oct 22, 2026
Copilot AI balanced review requested due to automatic review settings October 22, 2026 18:51
@shoumikhin shoumikhin added the release notes: build Changes related to build, including dependency upgrades, build flags, optimizations, etc. label Oct 22, 2026
@pytorch-bot

pytorch-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit 9cb582b with merge base b578b2e (image):

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 22, 2026

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI balanced review requested due to automatic review settings October 22, 2026 20:48
@shoumikhin
shoumikhin force-pushed the cuda-wheel-dep-followups branch from dad4443 to c520aa1 Compare October 22, 2026 20:48

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI balanced review requested due to automatic review settings October 23, 2026 10:15
@shoumikhin
shoumikhin force-pushed the cuda-wheel-dep-followups branch from c520aa1 to 76d4404 Compare October 23, 2026 10:15

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI balanced review requested due to automatic review settings October 23, 2026 11:06
@shoumikhin
shoumikhin force-pushed the cuda-wheel-dep-followups branch from 76d4404 to 9cb582b Compare October 23, 2026 11:06

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI balanced review requested due to automatic review settings October 23, 2026 17:45
@shoumikhin
shoumikhin force-pushed the cuda-wheel-dep-followups branch from 9cb582b to 76c4b48 Compare October 23, 2026 17:45

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

Copilot AI balanced review requested due to automatic review settings October 23, 2026 18:58
@shoumikhin
shoumikhin force-pushed the cuda-wheel-dep-followups branch from 76c4b48 to 8209f88 Compare October 23, 2026 18:58

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

The CUDA wheel smoke test checked that no shipped library records
libtorch_cuda.so or libc10_cuda.so. That misses other libraries that
only a CUDA build of torch installs. The wheel before the linking fix
also recorded libnvrtc.so.13 on the LLM runner module. With the two
names removed, the old check passed while that module still failed to
import next to a CPU-only torch.

Turn it into an allow list. Every recorded dependency must be shipped in
the wheel, be one of the torch libraries a CPU-only torch also has, be
part of the C and C++ system runtime, or be installed by a package that
a plain install of the wheel requires (today that is the CUDA runtime).
A requirement behind an extra, or for another platform, is skipped, so
an optional package that happens to be installed does not widen the
list. The check compares names only. It does not load anything.
The same three-line comment sat at five link sites. It explained why the
line does not link torch, but not what torch_cpu_library does
differently, and "in a CUDA build" read as our own CUDA option rather
than how PyTorch was built.

Each site now says that torch records libtorch_cuda with a CUDA build of
PyTorch, so a CPU-only torch could not load the library, and that
torch_cpu_library does not.

At aten_bridge the old reason did not apply. aten_bridge is a static
library and is never loaded on its own. Its link matters because it is
passed on to _training_lib. But it was only static by default: with
BUILD_SHARED_LIBS=ON it became a shared library. Mark it STATIC so the
comment holds in every layout. Nothing installs it and only
_training_lib links it.
Linking the torch target does more than link. TorchConfig also gives it
TORCH_INCLUDE_DIRS, which CMake treats as system headers because the
target is imported, TORCH_CXX_FLAGS, and on recent torch a minimum C++
standard (C++20). torch_cpu_library, which our targets now link instead
so that a CPU-only torch can load them, only passes on torch/include.

So those targets changed. torch/csrc/api/include became a
normal include directory, so warnings inside torch's headers are now
reported as if they were our code. And a TORCH_CXX_FLAGS set at
configure time no longer reached them. For example, compiling
kernels/portable/cpu/op_allclose.cpp with -Wall -Wextra -Werror went
from no errors to 25 errors, all inside torch's headers. Default builds
were not affected.

find_package_torch now copies torch's interface include directories,
compile options and compile features to torch_cpu_library. It does this
once, also when the project found torch before calling it. Every target
that links torch_cpu_library, directly or through a PUBLIC link such as
custom_ops_aot_lib, now gets these settings, and a new link site cannot
forget them. With a CUDA build of PyTorch, torch also carries the CUDA
include directory and definitions of torch_cuda_library. Those are not
copied, since these targets do not use CUDA. Changing torch_cpu_library
itself also affects any other target in the build that links it. When
there is no torch_cpu_library, for example with a static libtorch or a
parent project that defines its own torch target, nothing is copied.

A new test configures a small project and checks that a target linking
torch_cpu_library, directly or through a PUBLIC link, gets torch's C++
API include directory, TORCH_CXX_FLAGS and, when torch sets one, its C++
standard. It checks both when find_package_torch finds torch and when
the project found it first. A second test checks that
find_package_torch still configures when only a torch target exists.
Both pass with CPU and CUDA builds of torch. The first fails without
this change, and the second fails if the copy does not first check that
torch_cpu_library exists.
@shoumikhin
shoumikhin force-pushed the cuda-wheel-dep-followups branch from 8209f88 to 12e8521 Compare October 23, 2026 19:54
Copilot AI balanced review requested due to automatic review settings October 23, 2026 19:54

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@shoumikhin
shoumikhin merged commit 7d9eb71 into pytorch:main Oct 23, 2026
458 of 460 checks passed
@pytorch-bot
pytorch-bot Bot deployed to upload-benchmark-results October 24, 2026 01:02 Active

This branch was successfully deployed

1 active deployment
upload-benchmark-results — 12e8521a Deployed Oct 24, 2026 by pytorch-bot[bot] via upload-benchmark-results #21260
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/cuda CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. release notes: build Changes related to build, including dependency upgrades, build flags, optimizations, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants