Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/179024
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit e509bb1 with merge base edda74b ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
Set INSTALL_TEST=0 to prevent aoti_custom_ops.dll from being installed into the wheel, and fix the uv.dll copy path to use bin/ (where cmake actually installs it) instead of lib/Release/. Both issues caused WinError 126 dll loading failures on Windows arm64 wheel tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) ghstack-source-id: 1bf1090 Pull-Request: #179024
Set INSTALL_TEST=0 to prevent aoti_custom_ops.dll from being installed into the wheel, and fix the uv.dll copy path to use bin/ (where cmake actually installs it) instead of lib/Release/. Both issues caused WinError 126 dll loading failures on Windows arm64 wheel tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) ghstack-source-id: 78cb8a1 Pull-Request: #179024
Set INSTALL_TEST=0 to prevent aoti_custom_ops.dll from being installed into the wheel, and fix the uv.dll copy path to use bin/ (where cmake actually installs it) instead of lib/Release/. Both issues caused WinError 126 dll loading failures on Windows arm64 wheel tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) ghstack-source-id: 18bd333 Pull-Request: #179024
|
@pytorchmergebot merge -f "Thank you @zklaus for fixing this" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…#179024) This fixes the `windows-arm64-binary-wheel / wheel-*-test`s that have been broken in nightlies since mid January. Set INSTALL_TEST=0 to prevent aoti_custom_ops.dll from being installed into the wheel, and fix the uv.dll copy path to use bin/ (where cmake actually installs it) instead of lib/Release/. Both issues caused WinError 126 dll loading failures on Windows arm64 wheel tests. This is analogous to .ci/pytorch/windows/build_pytorch.bat:97. It touches on pytorch#157128, pytorch#144931, and pytorch#146944. It seems the underlying reason why shipping the aoti_custom_ops shared library is a problem on Windows, but not on Linux, is that dlopen defers resolving symbols, whereas LoadLibraryExW loads everything eagerly. This PR is a backport of a fix from the scikit-build-core PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#179024 Approved by: https://github.com/atalman
…ript The windows-arm64-build-test job has been persistently red on trunk because the per-commit build script (.ps1) was missed when #179024 fixed the nightly build script (.bat). Set INSTALL_TEST=0 so aoti_custom_ops.dll (test-only) is not installed into the wheel -- on Windows, LoadLibraryExW eagerly resolves all DLL dependencies, so loading this test DLL at import-torch time fails. Fix the libuv copy path from lib\Release\uv.dll to bin\uv.dll to match where cmake actually installs it. Authored by Claude. ghstack-source-id: d7126ab Pull-Request: #182647
…ript The windows-arm64-build-test job has been persistently red on trunk because the per-commit build script (.ps1) was missed when #179024 fixed the nightly build script (.bat). Set INSTALL_TEST=0 so aoti_custom_ops.dll (test-only) is not installed into the wheel -- on Windows, LoadLibraryExW eagerly resolves all DLL dependencies, so loading this test DLL at import-torch time fails. Fix the libuv copy path from lib\Release\uv.dll to bin\uv.dll to match where cmake actually installs it. Explicitly initialize AutogradState bit fields in the constructor to work around an MSVC bug where default member initializers for bit fields are silently ignored. Authored by Claude. ghstack-source-id: f908ec9 Pull-Request: #182647
…ript The windows-arm64-build-test job has been persistently red on trunk because the per-commit build script (.ps1) was missed when #179024 fixed the nightly build script (.bat). Set INSTALL_TEST=0 so aoti_custom_ops.dll (test-only) is not installed into the wheel -- on Windows, LoadLibraryExW eagerly resolves all DLL dependencies, so loading this test DLL at import-torch time fails. Fix the libuv copy path from lib\Release\uv.dll to bin\uv.dll to match where cmake actually installs it. Explicitly initialize AutogradState bit fields in the constructor to work around an MSVC bug where default member initializers for bit fields are silently ignored. Authored by Claude. ghstack-source-id: 820bebc Pull-Request: #182647
…ript The windows-arm64-build-test job has been persistently red on trunk because the per-commit build script (.ps1) was missed when #179024 fixed the nightly build script (.bat). Set INSTALL_TEST=0 so aoti_custom_ops.dll (test-only) is not installed into the wheel -- on Windows, LoadLibraryExW eagerly resolves all DLL dependencies, so loading this test DLL at import-torch time fails. Fix the libuv copy path from lib\Release\uv.dll to bin\uv.dll to match where cmake actually installs it. Explicitly initialize AutogradState bit fields in the constructor to work around an MSVC bug where default member initializers for bit fields are silently ignored. Authored by Claude. ghstack-source-id: d7126ab Pull-Request: #182647
…ript The windows-arm64-build-test job has been persistently red on trunk because the per-commit build script (.ps1) was missed when #179024 fixed the nightly build script (.bat). Set INSTALL_TEST=0 so aoti_custom_ops.dll (test-only) is not installed into the wheel -- on Windows, LoadLibraryExW eagerly resolves all DLL dependencies, so loading this test DLL at import-torch time fails. Fix the libuv copy path from lib\Release\uv.dll to bin\uv.dll to match where cmake actually installs it. Explicitly initialize AutogradState bit fields in the constructor to work around an MSVC bug where default member initializers for bit fields are silently ignored. Authored by Claude. ghstack-source-id: e47c3fd Pull-Request: #182647
…ript The windows-arm64-build-test job has been persistently red on trunk because the per-commit build script (.ps1) was missed when #179024 fixed the nightly build script (.bat). Set INSTALL_TEST=0 so aoti_custom_ops.dll (test-only) is not installed into the wheel -- on Windows, LoadLibraryExW eagerly resolves all DLL dependencies, so loading this test DLL at import-torch time fails. Fix the libuv copy path from lib\Release\uv.dll to bin\uv.dll to match where cmake actually installs it. Explicitly initialize AutogradState bit fields in the constructor to work around an MSVC bug where default member initializers for bit fields are silently ignored. Authored by Claude. ghstack-source-id: d1baf93 Pull-Request: #182647
…ript The windows-arm64-build-test job has been persistently red on trunk because the per-commit build script (.ps1) was missed when #179024 fixed the nightly build script (.bat). Set INSTALL_TEST=0 so aoti_custom_ops.dll (test-only) is not installed into the wheel -- on Windows, LoadLibraryExW eagerly resolves all DLL dependencies, so loading this test DLL at import-torch time fails. Fix the libuv copy path from lib\Release\uv.dll to bin\uv.dll to match where cmake actually installs it. Explicitly initialize AutogradState bit fields in the constructor to work around an MSVC bug where default member initializers for bit fields are silently ignored. Authored by Claude. ghstack-source-id: 61f9e3c Pull-Request: #182647
…ript (#182647) The windows-arm64-build-test job has been persistently red on trunk because the per-commit build script (.ps1) was missed when #179024 fixed the nightly build script (.bat). Set INSTALL_TEST=0 so aoti_custom_ops.dll (test-only) is not installed into the wheel -- on Windows, LoadLibraryExW eagerly resolves all DLL dependencies, so loading this test DLL at import-torch time fails. Fix the libuv copy path from lib\Release\uv.dll to bin\uv.dll to match where cmake actually installs it. Explicitly initialize AutogradState bit fields in the constructor to work around an MSVC bug where default member initializers for bit fields are silently ignored. Authored by Claude. Pull Request resolved: #182647 Approved by: https://github.com/atalman, https://github.com/Skylion007
….ps1 script (pytorch#182647) The windows-arm64-build-test job has been persistently red on trunk because the per-commit build script (.ps1) was missed when pytorch#179024 fixed the nightly build script (.bat). Set INSTALL_TEST=0 so aoti_custom_ops.dll (test-only) is not installed into the wheel -- on Windows, LoadLibraryExW eagerly resolves all DLL dependencies, so loading this test DLL at import-torch time fails. Fix the libuv copy path from lib\Release\uv.dll to bin\uv.dll to match where cmake actually installs it. Explicitly initialize AutogradState bit fields in the constructor to work around an MSVC bug where default member initializers for bit fields are silently ignored. Authored by Claude. Pull Request resolved: pytorch#182647 Approved by: https://github.com/atalman, https://github.com/Skylion007
…#182123) In #179024 (and later #182647) it was surfaced that test artifacts like `aoti_custom_ops.dll` should not be installed in Windows wheel building because the way that symbol resolution is done eagerly on that platform means that the resulting wheels would not be functional. But if these shared libraries are not installed, we also don't need to build them, hence this PR proposes to not do that. Disable test building and default to Release mode in the Windows CI setup script for both libtorch and pytorch build paths. Co-Generated with [Claude Code](https://claude.com/claude-code) Replaces #180246 Pull Request resolved: #182123 Approved by: https://github.com/atalman
…pytorch#182123) In pytorch#179024 (and later pytorch#182647) it was surfaced that test artifacts like `aoti_custom_ops.dll` should not be installed in Windows wheel building because the way that symbol resolution is done eagerly on that platform means that the resulting wheels would not be functional. But if these shared libraries are not installed, we also don't need to build them, hence this PR proposes to not do that. Disable test building and default to Release mode in the Windows CI setup script for both libtorch and pytorch build paths. Co-Generated with [Claude Code](https://claude.com/claude-code) Replaces pytorch#180246 Pull Request resolved: pytorch#182123 Approved by: https://github.com/atalman
….ps1 script (pytorch#182647) The windows-arm64-build-test job has been persistently red on trunk because the per-commit build script (.ps1) was missed when pytorch#179024 fixed the nightly build script (.bat). Set INSTALL_TEST=0 so aoti_custom_ops.dll (test-only) is not installed into the wheel -- on Windows, LoadLibraryExW eagerly resolves all DLL dependencies, so loading this test DLL at import-torch time fails. Fix the libuv copy path from lib\Release\uv.dll to bin\uv.dll to match where cmake actually installs it. Explicitly initialize AutogradState bit fields in the constructor to work around an MSVC bug where default member initializers for bit fields are silently ignored. Authored by Claude. Pull Request resolved: pytorch#182647 Approved by: https://github.com/atalman, https://github.com/Skylion007
…#179024) This fixes the `windows-arm64-binary-wheel / wheel-*-test`s that have been broken in nightlies since mid January. Set INSTALL_TEST=0 to prevent aoti_custom_ops.dll from being installed into the wheel, and fix the uv.dll copy path to use bin/ (where cmake actually installs it) instead of lib/Release/. Both issues caused WinError 126 dll loading failures on Windows arm64 wheel tests. This is analogous to .ci/pytorch/windows/build_pytorch.bat:97. It touches on pytorch#157128, pytorch#144931, and pytorch#146944. It seems the underlying reason why shipping the aoti_custom_ops shared library is a problem on Windows, but not on Linux, is that dlopen defers resolving symbols, whereas LoadLibraryExW loads everything eagerly. This PR is a backport of a fix from the scikit-build-core PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#179024 Approved by: https://github.com/atalman
….ps1 script (pytorch#182647) The windows-arm64-build-test job has been persistently red on trunk because the per-commit build script (.ps1) was missed when pytorch#179024 fixed the nightly build script (.bat). Set INSTALL_TEST=0 so aoti_custom_ops.dll (test-only) is not installed into the wheel -- on Windows, LoadLibraryExW eagerly resolves all DLL dependencies, so loading this test DLL at import-torch time fails. Fix the libuv copy path from lib\Release\uv.dll to bin\uv.dll to match where cmake actually installs it. Explicitly initialize AutogradState bit fields in the constructor to work around an MSVC bug where default member initializers for bit fields are silently ignored. Authored by Claude. Pull Request resolved: pytorch#182647 Approved by: https://github.com/atalman, https://github.com/Skylion007
…pytorch#182123) In pytorch#179024 (and later pytorch#182647) it was surfaced that test artifacts like `aoti_custom_ops.dll` should not be installed in Windows wheel building because the way that symbol resolution is done eagerly on that platform means that the resulting wheels would not be functional. But if these shared libraries are not installed, we also don't need to build them, hence this PR proposes to not do that. Disable test building and default to Release mode in the Windows CI setup script for both libtorch and pytorch build paths. Co-Generated with [Claude Code](https://claude.com/claude-code) Replaces pytorch#180246 Pull Request resolved: pytorch#182123 Approved by: https://github.com/atalman
…#179024) This fixes the `windows-arm64-binary-wheel / wheel-*-test`s that have been broken in nightlies since mid January. Set INSTALL_TEST=0 to prevent aoti_custom_ops.dll from being installed into the wheel, and fix the uv.dll copy path to use bin/ (where cmake actually installs it) instead of lib/Release/. Both issues caused WinError 126 dll loading failures on Windows arm64 wheel tests. This is analogous to .ci/pytorch/windows/build_pytorch.bat:97. It touches on pytorch#157128, pytorch#144931, and pytorch#146944. It seems the underlying reason why shipping the aoti_custom_ops shared library is a problem on Windows, but not on Linux, is that dlopen defers resolving symbols, whereas LoadLibraryExW loads everything eagerly. This PR is a backport of a fix from the scikit-build-core PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#179024 Approved by: https://github.com/atalman
….ps1 script (pytorch#182647) The windows-arm64-build-test job has been persistently red on trunk because the per-commit build script (.ps1) was missed when pytorch#179024 fixed the nightly build script (.bat). Set INSTALL_TEST=0 so aoti_custom_ops.dll (test-only) is not installed into the wheel -- on Windows, LoadLibraryExW eagerly resolves all DLL dependencies, so loading this test DLL at import-torch time fails. Fix the libuv copy path from lib\Release\uv.dll to bin\uv.dll to match where cmake actually installs it. Explicitly initialize AutogradState bit fields in the constructor to work around an MSVC bug where default member initializers for bit fields are silently ignored. Authored by Claude. Pull Request resolved: pytorch#182647 Approved by: https://github.com/atalman, https://github.com/Skylion007
…pytorch#182123) In pytorch#179024 (and later pytorch#182647) it was surfaced that test artifacts like `aoti_custom_ops.dll` should not be installed in Windows wheel building because the way that symbol resolution is done eagerly on that platform means that the resulting wheels would not be functional. But if these shared libraries are not installed, we also don't need to build them, hence this PR proposes to not do that. Disable test building and default to Release mode in the Windows CI setup script for both libtorch and pytorch build paths. Co-Generated with [Claude Code](https://claude.com/claude-code) Replaces pytorch#180246 Pull Request resolved: pytorch#182123 Approved by: https://github.com/atalman
On Windows, `_load_dll_libraries` loads every DLL in torch/lib at import time. The glob was added in pytorch#35362 (2020-03) because `caffe2_nvrtc.dll` was loaded lazily by name from `CUDAHooks.cpp`, and plain `LoadLibraryW` does not search directories registered with `AddDllDirectory`, so the by-name load failed on Python 3.8. Two later changes made that moot: pytorch#45674 (2020-10) switched CUDA builds to the in-tree LazyNVRTC, so `caffe2_nvrtc.dll` is only loaded by name on ROCm, and pytorch#49781 (2021-01) switched `at::DynamicLibrary` to `LoadLibraryExW` with `LOAD_LIBRARY_SEARCH_DEFAULT_DIRS`, which does search the directories that `os.add_dll_directory` registers. The preload also has a cost: it loads libraries that are only meant to be loaded on demand, such as the INSTALL_TEST libraries (`aoti_custom_ops`, `torchbind_test`, `jitbackend_test`, `backend_with_compiler`), and any failure in one of them aborts `import torch` (pytorch#199894, pytorch#179024, pytorch#182123). This PR removes the glob and the fallback PATH patching that only mattered on systems without `AddDllDirectory`, keeping `os.add_dll_directory` for torch/lib and the other DLL directories. Everything that remains in torch/lib is a link-time dependency of `_C.pyd` or of a library it pulls in, which Windows resolves through the registered directories. Test Plan Trunk CI has no Windows CUDA test shards (removed in pytorch#139336); the Windows CPU build and all its test shards pass with this change, and the Windows CUDA build passes. The CUDA side was verified on a Windows 11 VM with an RTX 2060 (driver 610.88) using the 2026-10-26 cu132 nightly wheel with this change applied to its `torch/__init__.py`: import, `torch.cuda.is_available()`, cuDNN conv2d, cuBLAS matmul, cuFFT, cuRAND, cuSOLVER and a jiterator (NVRTC) kernel all pass, 8 of the 13 DLLs in torch/lib end up resident, and a deliberately broken stray DLL in torch/lib no longer aborts the import (with the glob it fails with WinError 193). Lint: ``` lintrunner -a torch/__init__.py ``` Authored with an AI assistant (Claude Code); the analysis and the change were reviewed by the human author. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
## Linked issue or supporting maintainer Part of #199894. Supersedes #200856 and #199925: without the preload there is no list of test-only DLLs to maintain. ## BC-breaking? No for the supported configurations. `import torch` no longer preloads every DLL in `torch/lib`; libraries that are loaded on demand are now loaded only on demand, and the `PATH` fallback for systems without `AddDllDirectory` (pre Windows 8 without KB2533623) is gone. ## Summary (human written only) On Windows we are preloading all libraries in torch/lib. This is somewhat costly and leads to occasional problems. Furthermore, it is likely no longer necessary because the loading code has become smarter and is now able to load dependencies on demand. This PR is here to test that hypothesis in CI. ## Agent details (if applicable) Analysis and change prepared with Claude Code, reviewed by me. The commit message carries the full reasoning. Agent notes: The Windows loader has preloaded every DLL in `torch/lib` since #35362, because `caffe2_nvrtc.dll` was loaded by name from `CUDAHooks.cpp` and plain `LoadLibraryW` did not search directories registered with `AddDllDirectory`. Two later changes made that moot: #45674 (2020-10) switched CUDA builds to the in-tree LazyNVRTC, so `caffe2_nvrtc.dll` is only loaded by name on ROCm, and #49781 (2021-01) moved `at::DynamicLibrary` to `LoadLibraryExW` with `LOAD_LIBRARY_SEARCH_DEFAULT_DIRS`, which searches what `os.add_dll_directory` registers. Meanwhile the preload keeps turning on-demand libraries into import-time failures (#199894, #179024, #182123). The glob only ever preloaded torch's own DLLs with the default search flags; the NVIDIA wheel directories come from the cuda-pathfinder loop (and, on CI, from the toolkit bin dir fallback), which this PR does not touch. Tested on hardware, since trunk has had no Windows CUDA test shards since #139336: Windows 11 VM with an RTX 2060 (driver 610.88), 2026-10-26 cu132 nightly wheel, `torch/__init__.py` replaced by this PR's version (hash-checked against the base commit). Results: - With the stock cuda-pathfinder 1.8.4 the import fails on a clean machine with and without this change, for a reason outside this PR (below). The failure point moves from a `WinError 126` on `shm.dll` in the glob to "DLL load failed while importing _C". - With a per-library `try` in the pathfinder loop (not part of this PR), import, `torch.cuda.is_available()`, cuDNN conv2d, cuBLAS matmul, cuFFT, cuRAND, cuSOLVER and a jiterator kernel (NVRTC) all pass with the glob removed. 8 of 13 `torch/lib` DLLs are resident afterwards; `caffe2_nvrtc`, `torch_global_deps`, `nvToolsExt64_1`, `libiompstubs5md` and `torch.dll` were never needed. - The #199894 mechanism reproduces: a broken stray `zz_broken_test.dll` in `torch/lib` aborts `import torch` with the glob (WinError 193) and is ignored without it. Found on the way, independent of this PR: the stock cu132 Windows nightly does not import on a clean machine. `nvidia-cuda-cupti` 13.2.86 ships `cupti64_2026.1.2.dll`, which cuda-pathfinder 1.8.4 does not know; the pathfinder loop in `torch/__init__.py` is one `try` around all eleven libraries, so the CUPTI miss also skips cuDNN, `nvidia\cudnn\bin` is never registered, and `cudnn64_9.dll` (a static import of `torch_python.dll` and `torch_cuda.dll`) cannot be found. CUPTI itself still resolves, because a later library in the loop registers the shared `nvidia\cu13\bin` directory. CI does not see this: the Windows CUDA wheel smoke test runs on a T4 with the CUDA toolkit and cuDNN installed under Program Files, and `torch/__init__.py` adds that directory to the search path. A per-library `try` fixes the import with a warning; a pathfinder release that knows the name fixes it silently. CI on this PR: the full CPU suite on the 12 `win-vs2022-cpu-py3` shards, the `win-vs2022-cuda13.2-py3` build, and the `binaries_wheel` smoke tests for every Python version (CUDA wheels on a T4: import, CUDA tensor, magma, cuDNN, RNN and CNN smoke; XPU wheels import on CPU runners). Not covered: the full CUDA test suite on Windows. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: #202206 Approved by: https://github.com/atalman
## Linked issue or supporting maintainer Part of pytorch#199894. Supersedes pytorch#200856 and pytorch#199925: without the preload there is no list of test-only DLLs to maintain. ## BC-breaking? No for the supported configurations. `import torch` no longer preloads every DLL in `torch/lib`; libraries that are loaded on demand are now loaded only on demand, and the `PATH` fallback for systems without `AddDllDirectory` (pre Windows 8 without KB2533623) is gone. ## Summary (human written only) On Windows we are preloading all libraries in torch/lib. This is somewhat costly and leads to occasional problems. Furthermore, it is likely no longer necessary because the loading code has become smarter and is now able to load dependencies on demand. This PR is here to test that hypothesis in CI. ## Agent details (if applicable) Analysis and change prepared with Claude Code, reviewed by me. The commit message carries the full reasoning. Agent notes: The Windows loader has preloaded every DLL in `torch/lib` since pytorch#35362, because `caffe2_nvrtc.dll` was loaded by name from `CUDAHooks.cpp` and plain `LoadLibraryW` did not search directories registered with `AddDllDirectory`. Two later changes made that moot: pytorch#45674 (2020-10) switched CUDA builds to the in-tree LazyNVRTC, so `caffe2_nvrtc.dll` is only loaded by name on ROCm, and pytorch#49781 (2021-01) moved `at::DynamicLibrary` to `LoadLibraryExW` with `LOAD_LIBRARY_SEARCH_DEFAULT_DIRS`, which searches what `os.add_dll_directory` registers. Meanwhile the preload keeps turning on-demand libraries into import-time failures (pytorch#199894, pytorch#179024, pytorch#182123). The glob only ever preloaded torch's own DLLs with the default search flags; the NVIDIA wheel directories come from the cuda-pathfinder loop (and, on CI, from the toolkit bin dir fallback), which this PR does not touch. Tested on hardware, since trunk has had no Windows CUDA test shards since pytorch#139336: Windows 11 VM with an RTX 2060 (driver 610.88), 2026-10-26 cu132 nightly wheel, `torch/__init__.py` replaced by this PR's version (hash-checked against the base commit). Results: - With the stock cuda-pathfinder 1.8.4 the import fails on a clean machine with and without this change, for a reason outside this PR (below). The failure point moves from a `WinError 126` on `shm.dll` in the glob to "DLL load failed while importing _C". - With a per-library `try` in the pathfinder loop (not part of this PR), import, `torch.cuda.is_available()`, cuDNN conv2d, cuBLAS matmul, cuFFT, cuRAND, cuSOLVER and a jiterator kernel (NVRTC) all pass with the glob removed. 8 of 13 `torch/lib` DLLs are resident afterwards; `caffe2_nvrtc`, `torch_global_deps`, `nvToolsExt64_1`, `libiompstubs5md` and `torch.dll` were never needed. - The pytorch#199894 mechanism reproduces: a broken stray `zz_broken_test.dll` in `torch/lib` aborts `import torch` with the glob (WinError 193) and is ignored without it. Found on the way, independent of this PR: the stock cu132 Windows nightly does not import on a clean machine. `nvidia-cuda-cupti` 13.2.86 ships `cupti64_2026.1.2.dll`, which cuda-pathfinder 1.8.4 does not know; the pathfinder loop in `torch/__init__.py` is one `try` around all eleven libraries, so the CUPTI miss also skips cuDNN, `nvidia\cudnn\bin` is never registered, and `cudnn64_9.dll` (a static import of `torch_python.dll` and `torch_cuda.dll`) cannot be found. CUPTI itself still resolves, because a later library in the loop registers the shared `nvidia\cu13\bin` directory. CI does not see this: the Windows CUDA wheel smoke test runs on a T4 with the CUDA toolkit and cuDNN installed under Program Files, and `torch/__init__.py` adds that directory to the search path. A per-library `try` fixes the import with a warning; a pathfinder release that knows the name fixes it silently. CI on this PR: the full CPU suite on the 12 `win-vs2022-cpu-py3` shards, the `win-vs2022-cuda13.2-py3` build, and the `binaries_wheel` smoke tests for every Python version (CUDA wheels on a T4: import, CUDA tensor, magma, cuDNN, RNN and CNN smoke; XPU wheels import on CPU runners). Not covered: the full CUDA test suite on Windows. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#202206 Approved by: https://github.com/atalman
## Linked issue or supporting maintainer Part of pytorch#199894. Supersedes pytorch#200856 and pytorch#199925: without the preload there is no list of test-only DLLs to maintain. ## BC-breaking? No for the supported configurations. `import torch` no longer preloads every DLL in `torch/lib`; libraries that are loaded on demand are now loaded only on demand, and the `PATH` fallback for systems without `AddDllDirectory` (pre Windows 8 without KB2533623) is gone. ## Summary (human written only) On Windows we are preloading all libraries in torch/lib. This is somewhat costly and leads to occasional problems. Furthermore, it is likely no longer necessary because the loading code has become smarter and is now able to load dependencies on demand. This PR is here to test that hypothesis in CI. ## Agent details (if applicable) Analysis and change prepared with Claude Code, reviewed by me. The commit message carries the full reasoning. Agent notes: The Windows loader has preloaded every DLL in `torch/lib` since pytorch#35362, because `caffe2_nvrtc.dll` was loaded by name from `CUDAHooks.cpp` and plain `LoadLibraryW` did not search directories registered with `AddDllDirectory`. Two later changes made that moot: pytorch#45674 (2020-10) switched CUDA builds to the in-tree LazyNVRTC, so `caffe2_nvrtc.dll` is only loaded by name on ROCm, and pytorch#49781 (2021-01) moved `at::DynamicLibrary` to `LoadLibraryExW` with `LOAD_LIBRARY_SEARCH_DEFAULT_DIRS`, which searches what `os.add_dll_directory` registers. Meanwhile the preload keeps turning on-demand libraries into import-time failures (pytorch#199894, pytorch#179024, pytorch#182123). The glob only ever preloaded torch's own DLLs with the default search flags; the NVIDIA wheel directories come from the cuda-pathfinder loop (and, on CI, from the toolkit bin dir fallback), which this PR does not touch. Tested on hardware, since trunk has had no Windows CUDA test shards since pytorch#139336: Windows 11 VM with an RTX 2060 (driver 610.88), 2026-10-26 cu132 nightly wheel, `torch/__init__.py` replaced by this PR's version (hash-checked against the base commit). Results: - With the stock cuda-pathfinder 1.8.4 the import fails on a clean machine with and without this change, for a reason outside this PR (below). The failure point moves from a `WinError 126` on `shm.dll` in the glob to "DLL load failed while importing _C". - With a per-library `try` in the pathfinder loop (not part of this PR), import, `torch.cuda.is_available()`, cuDNN conv2d, cuBLAS matmul, cuFFT, cuRAND, cuSOLVER and a jiterator kernel (NVRTC) all pass with the glob removed. 8 of 13 `torch/lib` DLLs are resident afterwards; `caffe2_nvrtc`, `torch_global_deps`, `nvToolsExt64_1`, `libiompstubs5md` and `torch.dll` were never needed. - The pytorch#199894 mechanism reproduces: a broken stray `zz_broken_test.dll` in `torch/lib` aborts `import torch` with the glob (WinError 193) and is ignored without it. Found on the way, independent of this PR: the stock cu132 Windows nightly does not import on a clean machine. `nvidia-cuda-cupti` 13.2.86 ships `cupti64_2026.1.2.dll`, which cuda-pathfinder 1.8.4 does not know; the pathfinder loop in `torch/__init__.py` is one `try` around all eleven libraries, so the CUPTI miss also skips cuDNN, `nvidia\cudnn\bin` is never registered, and `cudnn64_9.dll` (a static import of `torch_python.dll` and `torch_cuda.dll`) cannot be found. CUPTI itself still resolves, because a later library in the loop registers the shared `nvidia\cu13\bin` directory. CI does not see this: the Windows CUDA wheel smoke test runs on a T4 with the CUDA toolkit and cuDNN installed under Program Files, and `torch/__init__.py` adds that directory to the search path. A per-library `try` fixes the import with a warning; a pathfinder release that knows the name fixes it silently. CI on this PR: the full CPU suite on the 12 `win-vs2022-cpu-py3` shards, the `win-vs2022-cuda13.2-py3` build, and the `binaries_wheel` smoke tests for every Python version (CUDA wheels on a T4: import, CUDA tensor, magma, cuDNN, RNN and CNN smoke; XPU wheels import on CPU runners). Not covered: the full CUDA test suite on Windows. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#202206 Approved by: https://github.com/atalman
This fixes the
windows-arm64-binary-wheel / wheel-*-tests that have been broken in nightlies since mid January.Stack from ghstack (oldest at bottom):
Set INSTALL_TEST=0 to prevent aoti_custom_ops.dll from being installed
into the wheel, and fix the uv.dll copy path to use bin/ (where cmake
actually installs it) instead of lib/Release/.
Both issues caused WinError 126 dll loading failures on Windows arm64
wheel tests.
This is analogous to .ci/pytorch/windows/build_pytorch.bat:97.
It touches on #157128, #144931, and #146944.
It seems the underlying reason why shipping the aoti_custom_ops shared library is a problem on Windows, but not on Linux, is that dlopen defers resolving symbols, whereas LoadLibraryExW loads everything eagerly.
This PR is a backport of a fix from the scikit-build-core PR.
🤖 Generated with Claude Code