Skip to content

[Windows] Depend on PyPI CUDA runtime packages in wheels - #194056

Closed
akarale-nv wants to merge 6 commits into
pytorch:mainfrom
akarale-nv:windows-cuda-pypi
Closed

akarale-nv wants to merge 6 commits into
pytorch:mainfrom
akarale-nv:windows-cuda-pypi

Conversation

@akarale-nv

@akarale-nv akarale-nv commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR teaches Windows PyTorch CUDA wheels to locate their CUDA runtime DLLs from installed NVIDIA PyPI packages (via cuda-pathfinder) rather than bundling them inside torch/lib/. It adds per-OS wheel dependency metadata, updates the build matrix generator, adjusts CMake to skip bundling when using PyPI-sourced runtimes, and adds a Windows smoke test that validates the declared cuda-toolkit version matches the build.

  • torch/__init__.py : On Windows CUDA builds, cuda-pathfinder is called to load each CUDA library

  • Build matrix / workflows: PYTORCH_EXTRA_INSTALL_REQUIREMENTS is restructured from flat strings to {linux, windows} dicts; Windows CUDA entries gain cuda-toolkit, cuda-pathfinder, nvidia-cudnn-cuXX, nvidia-cusparselt-cuXX, and nvidia-nvjitlink-cuXX requirements. CPU and macOS entries that incorrectly carried Linux-scoped requirements are cleaned up.
    Windows and Linux use different CUDA Toolkit patch versions and dependency sets, so the binary-workflow generator now represents those requirements independently.

  • cmake/PostBuildSteps.cmake: CUDA DLL bundling is conditionally skipped for PyPI wheel builds; NvToolsExt install is moved outside that guard, so it is always included for CUDA builds regardless of packaging mode.

  • smoke_test.py: The Windows smoke test checks the full major.minor.patch CUDA Toolkit version because older CUPTI DLL naming does not provide compatible discovery across all patch versions. This is addressed upstream with future CTK versions.

Motivation

This reduces Windows torch wheel size to 277 MB and avoids cross-DLL-boundary problems when multiple Python packages in one process ship their own CUDA DLL copies. Relying on shared PyPI CUDA packages avoids duplicate runtime copies and improves mixed-package deployments.

Test Plan

  • Locally validated tests added to smoke_test.py.
  • Validate the packaging change in Windows x86 OOT CI and investigate additional failures.

cc @peterjc123 @mszhanyi @skyline75489 @nbcsm @iremyux @Blackhex @nkhasbag-nv

@akarale-nv
akarale-nv requested a review from a team as a code owner August 19, 2026 09:28
@pytorch-bot

pytorch-bot Bot commented Aug 19, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit d8bb29a with merge base d2f3a9d (image):
💚 Looks good so far! There are no failures yet. 💚

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

@pytorch-bot pytorch-bot Bot added the release notes: releng release notes category label Aug 19, 2026
@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 19, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@akarale-nv
akarale-nv marked this pull request as draft August 19, 2026 09:36
@akarale-nv
akarale-nv marked this pull request as ready for review August 19, 2026 09:52
@akarale-nv
akarale-nv marked this pull request as draft August 19, 2026 15:07
@akarale-nv
akarale-nv force-pushed the windows-cuda-pypi branch 2 times, most recently from 802e898 to 52229ae Compare August 20, 2026 11:06
@akarale-nv
akarale-nv marked this pull request as ready for review August 20, 2026 16:16
@akarale-nv

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "module: windows"

@pytorch-bot pytorch-bot Bot added the module: windows Windows support for PyTorch label Aug 20, 2026
@janeyx99 janeyx99 added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Aug 21, 2026
@akarale-nv
akarale-nv force-pushed the windows-cuda-pypi branch 2 times, most recently from 09e7057 to bbc4d95 Compare August 24, 2026 16:18
@akarale-nv

Copy link
Copy Markdown
Contributor Author

Hi maintainers, gentle ping for review when you have bandwidth. This PR significantly reduces Windows CUDA wheel size (~277 MB) and avoids duplicate CUDA DLLs across packages, improving mixed-package deployments. Feedback on the packaging approach and Windows CI validation would be greatly appreciated. Thank you!

@Skylion007 I have fixed the linter errors as well. The windows native version of lintrunner keeps failing silently, hence missed this. Can you please help re-trigger the pipelines?

@atalman atalman added ciflow/binaries Trigger all binary build and upload jobs on the PR ciflow/binaries_wheel Trigger binary build and upload jobs for wheel on the PR labels Sep 2, 2026
@pytorch-bot

pytorch-bot Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@pytorch-bot

pytorch-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown

The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:

  • ciflow/binaries
  • ciflow/binaries_wheel

Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows.

@atalman

atalman commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

HI @akarale-nv we need to make sure all the build and test pass

@akarale-nv

Copy link
Copy Markdown
Contributor Author

Hi @atalman, seems like between the rebases I missed updating the pypi CuDNN version for Windows. It should be good to go now.

Good thing we have a test case to verify that :D

@akarale-nv

akarale-nv commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor Author

The current 13.4 test failures are due to the mismatch in CTK patch version of AMI and the wheel dependency. Since the new AMI is on CTK 13.4.2, re-running this after rebasing should fix the issue. This issue will also be fixed for good next CTK release onwards

@atalman atalman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, please merge once windows builds are passing. We should target this to 2.16 release

@atalman
atalman self-requested a review October 8, 2026 19:10
Windows CUDA wheels locate their runtime DLL directories from installed NVIDIA wheel packages before configuring the DLL search path.

Test Plan:
```
python -c 'compile(open("torch/__init__.py", encoding="utf-8").read(), "torch/__init__.py", "exec")'
git diff --cached --check
```

This commit was authored with assistance from an AI assistant.
Configure the Windows CUDA wheel matrix with versioned NVIDIA runtime requirements, validate those requirements in smoke tests, and avoid duplicating the runtime package when CMake writes the wheel metadata.

Test Plan:
```
python .github/scripts/generate_binary_build_matrix.py
git diff --check
git diff --cached --check
```

This commit was authored with assistance from an AI assistant.
Load CUDA runtime DLLs from NVIDIA PyPI packages through cuda-pathfinder,
and keep Windows binary wheel requirements aligned with the CUDA installers
by using cuDNN 9.26.0.51. CUDA installations without cuda-pathfinder used to
fail while importing torch; warn and continue to the existing DLL loader when
the pathfinder import fails.

Test Plan:
```powershell
.\.venv\Scripts\python.exe -m py_compile torch/__init__.py
wsl.exe --cd /mnt/c/akarale/git/pytorch bash -lc "source .venv-wsl/bin/activate && lintrunner -a --skip FLAKE8 torch/__init__.py"
git diff --check
```

An isolated check of the pathfinder block with mocked imports verified both
the available and missing-pathfinder branches. FLAKE8 is skipped in WSL
because the /mnt/c mount reports this non-executable file as executable.

This commit was authored with assistance from an AI assistant.
The Windows wheel matrix inherited CUDA 13.4.1 from the Linux wheel pin,
while the Windows CI installer uses 13.4.2. Pin the Windows wheel to the
installer version and regenerate the Windows workflow. Keep the CUDA 13.2
wheel pin at 13.2.2, matching the updated installer on main.

Test Plan:
```powershell
.\.venv\Scripts\python.exe -m py_compile .github/scripts/generate_binary_build_matrix.py
.\.venv\Scripts\python.exe -c "import runpy; x=runpy.run_path('.github/scripts/generate_binary_build_matrix.py')['PYTORCH_EXTRA_INSTALL_REQUIREMENTS']; assert [x[v]['windows'].split('==')[1].split(';')[0] for v in ('13.2','13.4')] == ['13.2.2','13.4.2']"
wsl.exe --cd /mnt/c/akarale/git/pytorch bash -lc "source .venv-wsl/bin/activate && lintrunner -a .github/scripts/generate_binary_build_matrix.py && lintrunner -a --skip EXEC .github/workflows/generated-windows-binary-wheel-nightly.yml"
git diff --check
```

This commit was authored with assistance from an AI assistant.
@akarale-nv

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot

pytorch-bot Bot commented Oct 12, 2026

Copy link
Copy Markdown

Pull workflow has not been scheduled for the PR yet. It could be because author doesn't have permissions to run those or skip-checks keywords were added to PR/commits, aborting merge. Please get/give approval for the workflows and/or remove skip ci decorators before next merge attempt. If you think this is a mistake, please contact PyTorch Dev Infra.

@akarale-nv

akarale-nv commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

The Nvidia Windows OOT CI has discovered 2 corner cases:

  1. If the test env has cuda-pathfinder installed and the wheels are not added as a dep to the pytorch build, it fails to find the right cuda dlls. The probable fix is to move the load_nvidia_dynamic_lib(lib) inside try block and let the entire code fallback to pre-packaged DLLs.
  2. The Windows CI does not inherently enable cusparseLT so it should be removed from the discovery code, or it will fail consistently in local build.

Failure run: https://github.com/NVIDIA/pytorch-windows-ci/actions/runs/38208026143/job/114725947592

@akarale-nv

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 13, 2026
@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

@akarale-nv
akarale-nv deleted the windows-cuda-pypi branch October 13, 2026 05:11
pytorchmergebot pushed a commit that referenced this pull request Oct 23, 2026
Windows CUDA wheels built on main depend on the cuda-toolkit pip package and no longer bundle the CUDA or cuDNN DLLs (#194056), so cmake/PostBuildSteps.cmake never copies zlibwapi.dll into them. Drop that block and the install_zlib step in cuda_install.bat that downloads the 1.2.3 DLL into System32 for it. Related to #201626.

Please open this PR as a draft and mark it ready for review once the description and code are ready to be looked at.

Before submitting, please review:
- [PR lifecycle](https://github.com/pytorch/pytorch/blob/main/CONTRIBUTING.md#pr-lifecycle) in the contributing guide
- [AI-Assisted Development](https://github.com/pytorch/pytorch/blob/main/AI_POLICY.md) policy

Go through the following checklist
- [ ] Passes lint (`spin fixlint`)
- [ ] Added/updated tests
- [ ] Updated documentation (if applicable)
- [ ] Included benchmark results (for PRs impacting perf)

Created with Claude
Pull Request resolved: #201873
Approved by: https://github.com/Skylion007, https://github.com/huydhn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/binaries_wheel Trigger binary build and upload jobs for wheel on the PR ciflow/binaries Trigger all binary build and upload jobs on the PR ciflow/trunk Trigger trunk jobs on your pull request Merged module: windows Windows support for PyTorch open source release notes: releng release notes category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants