Repository navigation
Link torch_cpu_library, not torch, so the CUDA wheel imports with a CPU-only torch - #24060
Merged
Merged
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/24060
Note: Links to docs will display an error until the docs builds have been completed. ⏳ No Failures, 2 PendingAs of commit e5d9535 with merge base d1f7f1f ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
…PU-only torch Four libraries in the Linux CUDA wheel record a load-time dependency on libtorch_cuda.so (one also on libc10_cuda.so) without using anything from it: the training and LLM runner Python extensions and the custom and quantized operator libraries. They get it from linking the torch CMake target, which in a CUDA build of PyTorch adds libtorch_cuda.so under --no-as-needed. Next to a CPU-only torch those libraries then fail to load. Link torch_cpu_library instead. torch is torch_cpu_library plus torch_cuda_library, so the CPU part is linked exactly as before, including the --as-needed handling that keeps unused libraries such as MKL out of DT_NEEDED. Also add a check to the CUDA wheel smoke test that no shipped library depends on PyTorch's CUDA libraries.
shoumikhin
force-pushed
the
fix-cuda-overlink
branch
from
October 21, 2026 17:50
de31d2c to
e5d9535
Compare
SS-JIA
approved these changes
Oct 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Linux CUDA wheel cannot be used with a CPU-only PyTorch. Four of its libraries record a load-time dependency (
DT_NEEDED) onlibtorch_cuda.so, one also onlibc10_cuda.so:extension/training/pybindings/_training_libextension/llm/runner/_llm_runnerextension/llm/custom_ops/libcustom_ops_aot_lib.sokernels/quantized/libquantized_ops_aot_lib.soNone of them uses those libraries, yet with a CPU-only torch they fail to load:
It comes from linking the
torchCMake target (or${TORCH_LIBRARIES}). In a CUDA build of PyTorch that target addslibtorch_cuda.sowrapped in-Wl,--no-as-needed, so it is recorded even when unused, and--as-neededon our side cannot drop it.Fix
Link
torch_cpu_libraryinstead oftorchwhere these libraries are built.torchistorch_cpu_libraryplustorch_cuda_library, so the CPU half is linked exactly as before, including the--as-neededhandling that keeps unused libraries such as MKL out ofDT_NEEDED. With a CPU-only PyTorch the link is unchanged.The CUDA wheel smoke test gets a new check that fails if any shipped library depends on
libtorch_cuda.soorlibc10_cuda.so.Testing
Built the CUDA 13.0 wheel on Linux x86_64 before and after the change.
readelf -don_llm_runner, before:after:
The other three lose
libtorch_cuda.sothe same way.torch_cpuwould pull MKL intoDT_NEEDEDand the operator libraries then fail to load (undefined symbol: __kmpc_flush).torch_cpu_librarykeeps MKL out and they load.import executorchworks, all four modules import, and both operator libraries load.