Skip to content

[CD] Refactor manywheel build scripts (split env setup, deps, wheel, repair) - #182409

Closed
atalman wants to merge 10 commits into
gh/atalman/15/basefrom
gh/atalman/15/head
Closed

atalman wants to merge 10 commits into
gh/atalman/15/basefrom
gh/atalman/15/head

Conversation

@atalman

@atalman atalman commented May 5, 2026 •

Copy link
Copy Markdown
Collaborator

Stack from ghstack (oldest at bottom):

Split the monolithic .ci/manywheel/build_cuda.sh and the duplicated
sections of build_cpu.sh / build_common.sh into focused, reusable
scripts:

  • build_env_setup.sh GPU/toolchain environment setup (CUDA, ROCm, XPU)
  • build_install_deps.sh shared build-time dependency install
  • build_wheel.sh the actual wheel build (python -m build)
  • repair_wheel.sh auditwheel-style repair using the wheel python
    package (unpack/pack/tags), bundling aarch64
    BLAS/LAPACK/ACL when needed

Drops build_cuda.sh (its logic is now in build_env_setup.sh +
build_wheel.sh) and trims x86/aarch64-specific branches out of
build_cpu.sh / build_common.sh. The legacy entry point .ci/manywheel/build.sh
now dispatches x86/aarch64 cuda/cpu through the new chain
(set_desired_python -> build_env_setup -> build_install_deps -> build_wheel
-> repair_wheel) and keeps rocm/xpu/cpu-s390x on the legacy build_*.sh
helpers.

Also drops obsolete numpy version pins in .ci/pytorch/run_tests.sh.

The matching workflow / Jinja-template rework that originally lived in
this branch is no longer needed -- the matrix-driven binary workflows
already landed via #181586 (and follow-ups #181599, #182018), so the
new scripts plug into the existing _binary-build-linux.yml.

Authored with Claude.

…repair)

Split the monolithic .ci/manywheel/build_cuda.sh and the duplicated
sections of build_cpu.sh / build_common.sh into focused, reusable
scripts:

- build_env_setup.sh    GPU/toolchain environment setup (CUDA, ROCm, XPU)
- build_install_deps.sh shared build-time dependency install
- build_wheel.sh        the actual wheel build (python -m build)
- repair_wheel.sh       auditwheel-style repair using the `wheel` python
                        package (unpack/pack/tags), bundling aarch64
                        BLAS/LAPACK/ACL when needed

Drops build_cuda.sh (its logic is now in build_env_setup.sh +
build_wheel.sh) and trims x86/aarch64-specific branches out of
build_cpu.sh / build_common.sh. The legacy entry point .ci/manywheel/build.sh
now dispatches x86/aarch64 cuda/cpu through the new chain
(set_desired_python -> build_env_setup -> build_install_deps -> build_wheel
-> repair_wheel) and keeps rocm/xpu/cpu-s390x on the legacy build_*.sh
helpers.

Also drops obsolete numpy version pins in .ci/pytorch/run_tests.sh.

The matching workflow / Jinja-template rework that originally lived in
this branch is no longer needed -- the matrix-driven binary workflows
already landed via #181586 (and follow-ups #181599, #182018), so the
new scripts plug into the existing _binary-build-linux.yml.

Authored with Claude.

[ghstack-poisoned]
@atalman
atalman requested a review from a team as a code owner May 5, 2026 03:03
@pytorch-bot

pytorch-bot Bot commented May 5, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⏳ No Failures, 6 Pending, 22 Unclassified Failures

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

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

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

@pytorch-bot

pytorch-bot Bot commented May 5, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

…ps, wheel, repair)"

Split the monolithic .ci/manywheel/build_cuda.sh and the duplicated
sections of build_cpu.sh / build_common.sh into focused, reusable
scripts:

- build_env_setup.sh    GPU/toolchain environment setup (CUDA, ROCm, XPU)
- build_install_deps.sh shared build-time dependency install
- build_wheel.sh        the actual wheel build (python -m build)
- repair_wheel.sh       auditwheel-style repair using the `wheel` python
                        package (unpack/pack/tags), bundling aarch64
                        BLAS/LAPACK/ACL when needed

Drops build_cuda.sh (its logic is now in build_env_setup.sh +
build_wheel.sh) and trims x86/aarch64-specific branches out of
build_cpu.sh / build_common.sh. The legacy entry point .ci/manywheel/build.sh
now dispatches x86/aarch64 cuda/cpu through the new chain
(set_desired_python -> build_env_setup -> build_install_deps -> build_wheel
-> repair_wheel) and keeps rocm/xpu/cpu-s390x on the legacy build_*.sh
helpers.

Also drops obsolete numpy version pins in .ci/pytorch/run_tests.sh.

The matching workflow / Jinja-template rework that originally lived in
this branch is no longer needed -- the matrix-driven binary workflows
already landed via #181586 (and follow-ups #181599, #182018), so the
new scripts plug into the existing _binary-build-linux.yml.

Authored with Claude.

[ghstack-poisoned]
atalman added a commit that referenced this pull request May 5, 2026
Split the monolithic .ci/manywheel/build_cuda.sh and the duplicated
sections of build_cpu.sh / build_common.sh into focused, reusable
helpers, and write the new helpers in Python rather than shell:

- build_env_setup.py    GPU/toolchain environment setup (CUDA, ROCm, XPU)
- build_install_deps.py shared build-time dependency install
- build_wheel.py        the actual wheel build (python -m build)
- repair_wheel.py       auditwheel-style repair using the `wheel` python
                        package (unpack/pack/tags), bundling aarch64
                        BLAS/LAPACK/ACL when needed

Drops build_cuda.sh (its logic is now in build_env_setup.py +
build_wheel.py) and trims x86/aarch64-specific branches out of
build_cpu.sh / build_common.sh. The legacy entry point .ci/manywheel/build.sh
now dispatches x86/aarch64 cuda/cpu through the new chain
(set_desired_python -> build_env_setup -> build_install_deps -> build_wheel
-> repair_wheel) and keeps rocm/xpu/cpu-s390x on the legacy build_*.sh
helpers.

build_env_setup.py writes its build-flag exports (USE_CUDA,
TH_BINARY_BUILD, ...) to a file via --env-out which build.sh sources;
this is what lets those flags reach the wheel-build subprocess (a plain
`bash build_env_setup.sh` would have dropped them).

Also drops obsolete numpy version pins in .ci/pytorch/run_tests.sh.

The matching workflow / Jinja-template rework that originally lived in
this branch is no longer needed -- the matrix-driven binary workflows
already landed via #181586 (and follow-ups #181599, #182018), so the
new scripts plug into the existing _binary-build-linux.yml.

Authored with Claude.

ghstack-source-id: 1c609c3
Pull Request resolved: #182409
@atalman atalman added the ciflow/binaries Trigger all binary build and upload jobs on the PR label May 5, 2026
…ps, wheel, repair)"

Split the monolithic .ci/manywheel/build_cuda.sh and the duplicated
sections of build_cpu.sh / build_common.sh into focused, reusable
scripts:

- build_env_setup.sh    GPU/toolchain environment setup (CUDA, ROCm, XPU)
- build_install_deps.sh shared build-time dependency install
- build_wheel.sh        the actual wheel build (python -m build)
- repair_wheel.sh       auditwheel-style repair using the `wheel` python
                        package (unpack/pack/tags), bundling aarch64
                        BLAS/LAPACK/ACL when needed

Drops build_cuda.sh (its logic is now in build_env_setup.sh +
build_wheel.sh) and trims x86/aarch64-specific branches out of
build_cpu.sh / build_common.sh. The legacy entry point .ci/manywheel/build.sh
now dispatches x86/aarch64 cuda/cpu through the new chain
(set_desired_python -> build_env_setup -> build_install_deps -> build_wheel
-> repair_wheel) and keeps rocm/xpu/cpu-s390x on the legacy build_*.sh
helpers.

Also drops obsolete numpy version pins in .ci/pytorch/run_tests.sh.

The matching workflow / Jinja-template rework that originally lived in
this branch is no longer needed -- the matrix-driven binary workflows
already landed via #181586 (and follow-ups #181599, #182018), so the
new scripts plug into the existing _binary-build-linux.yml.

Authored with Claude.

[ghstack-poisoned]
atalman added a commit that referenced this pull request May 5, 2026
Split the monolithic .ci/manywheel/build_cuda.sh and the duplicated
sections of build_cpu.sh / build_common.sh into focused, reusable
helpers, and write the new helpers in Python rather than shell:

- build_env_setup.py    GPU/toolchain environment setup (CUDA, ROCm, XPU)
- build_install_deps.py shared build-time dependency install
- build_wheel.py        the actual wheel build (python -m build)
- repair_wheel.py       auditwheel-style repair using the `wheel` python
                        package (unpack/pack/tags), bundling aarch64
                        BLAS/LAPACK/ACL when needed

Drops build_cuda.sh (its logic is now in build_env_setup.py +
build_wheel.py) and trims x86/aarch64-specific branches out of
build_cpu.sh / build_common.sh. The legacy entry point .ci/manywheel/build.sh
now dispatches x86/aarch64 cuda/cpu through the new chain
(set_desired_python -> build_env_setup -> build_install_deps -> build_wheel
-> repair_wheel) and keeps rocm/xpu/cpu-s390x on the legacy build_*.sh
helpers.

build_env_setup.py writes its build-flag exports (USE_CUDA,
TH_BINARY_BUILD, ...) to a file via --env-out which build.sh sources;
this is what lets those flags reach the wheel-build subprocess (a plain
`bash build_env_setup.sh` would have dropped them).

Also drops obsolete numpy version pins in .ci/pytorch/run_tests.sh.

The matching workflow / Jinja-template rework that originally lived in
this branch is no longer needed -- the matrix-driven binary workflows
already landed via #181586 (and follow-ups #181599, #182018), so the
new scripts plug into the existing _binary-build-linux.yml.

Authored with Claude.

ghstack-source-id: 0e8b802
Pull Request resolved: #182409
…ps, wheel, repair)"

Split the monolithic .ci/manywheel/build_cuda.sh and the duplicated
sections of build_cpu.sh / build_common.sh into focused, reusable
scripts:

- build_env_setup.sh    GPU/toolchain environment setup (CUDA, ROCm, XPU)
- build_install_deps.sh shared build-time dependency install
- build_wheel.sh        the actual wheel build (python -m build)
- repair_wheel.sh       auditwheel-style repair using the `wheel` python
                        package (unpack/pack/tags), bundling aarch64
                        BLAS/LAPACK/ACL when needed

Drops build_cuda.sh (its logic is now in build_env_setup.sh +
build_wheel.sh) and trims x86/aarch64-specific branches out of
build_cpu.sh / build_common.sh. The legacy entry point .ci/manywheel/build.sh
now dispatches x86/aarch64 cuda/cpu through the new chain
(set_desired_python -> build_env_setup -> build_install_deps -> build_wheel
-> repair_wheel) and keeps rocm/xpu/cpu-s390x on the legacy build_*.sh
helpers.

Also drops obsolete numpy version pins in .ci/pytorch/run_tests.sh.

The matching workflow / Jinja-template rework that originally lived in
this branch is no longer needed -- the matrix-driven binary workflows
already landed via #181586 (and follow-ups #181599, #182018), so the
new scripts plug into the existing _binary-build-linux.yml.

Authored with Claude.

[ghstack-poisoned]
atalman added a commit that referenced this pull request May 5, 2026
Split the monolithic .ci/manywheel/build_cuda.sh and the duplicated
sections of build_cpu.sh / build_common.sh into focused, reusable
helpers, and write the new helpers in Python rather than shell:

- build_env_setup.py    GPU/toolchain environment setup (CUDA, ROCm, XPU)
- build_install_deps.py shared build-time dependency install
- build_wheel.py        the actual wheel build (python -m build)
- repair_wheel.py       auditwheel-style repair using the `wheel` python
                        package (unpack/pack/tags), bundling aarch64
                        BLAS/LAPACK/ACL when needed

Drops build_cuda.sh (its logic is now in build_env_setup.py +
build_wheel.py) and trims x86/aarch64-specific branches out of
build_cpu.sh / build_common.sh. The legacy entry point .ci/manywheel/build.sh
now dispatches x86/aarch64 cuda/cpu through the new chain
(set_desired_python -> build_env_setup -> build_install_deps -> build_wheel
-> repair_wheel) and keeps rocm/xpu/cpu-s390x on the legacy build_*.sh
helpers.

build_env_setup.py writes its build-flag exports (USE_CUDA,
TH_BINARY_BUILD, ...) to a file via --env-out which build.sh sources;
this is what lets those flags reach the wheel-build subprocess (a plain
`bash build_env_setup.sh` would have dropped them).

Also drops obsolete numpy version pins in .ci/pytorch/run_tests.sh.

The matching workflow / Jinja-template rework that originally lived in
this branch is no longer needed -- the matrix-driven binary workflows
already landed via #181586 (and follow-ups #181599, #182018), so the
new scripts plug into the existing _binary-build-linux.yml.

Authored with Claude.

ghstack-source-id: 55d543d
Pull Request resolved: #182409
…ps, wheel, repair)"

Split the monolithic .ci/manywheel/build_cuda.sh and the duplicated
sections of build_cpu.sh / build_common.sh into focused, reusable
scripts:

- build_env_setup.sh    GPU/toolchain environment setup (CUDA, ROCm, XPU)
- build_install_deps.sh shared build-time dependency install
- build_wheel.sh        the actual wheel build (python -m build)
- repair_wheel.sh       auditwheel-style repair using the `wheel` python
                        package (unpack/pack/tags), bundling aarch64
                        BLAS/LAPACK/ACL when needed

Drops build_cuda.sh (its logic is now in build_env_setup.sh +
build_wheel.sh) and trims x86/aarch64-specific branches out of
build_cpu.sh / build_common.sh. The legacy entry point .ci/manywheel/build.sh
now dispatches x86/aarch64 cuda/cpu through the new chain
(set_desired_python -> build_env_setup -> build_install_deps -> build_wheel
-> repair_wheel) and keeps rocm/xpu/cpu-s390x on the legacy build_*.sh
helpers.

Also drops obsolete numpy version pins in .ci/pytorch/run_tests.sh.

The matching workflow / Jinja-template rework that originally lived in
this branch is no longer needed -- the matrix-driven binary workflows
already landed via #181586 (and follow-ups #181599, #182018), so the
new scripts plug into the existing _binary-build-linux.yml.

Authored with Claude.

[ghstack-poisoned]
atalman added a commit that referenced this pull request May 5, 2026
Split the monolithic .ci/manywheel/build_cuda.sh and the duplicated
sections of build_cpu.sh / build_common.sh into focused, reusable
helpers, and write the new helpers in Python rather than shell:

- build_env_setup.py    GPU/toolchain environment setup (CUDA, ROCm, XPU)
- build_install_deps.py shared build-time dependency install
- build_wheel.py        the actual wheel build (python -m build)
- repair_wheel.py       auditwheel-style repair using the `wheel` python
                        package (unpack/pack/tags), bundling aarch64
                        BLAS/LAPACK/ACL when needed

Drops build_cuda.sh (its logic is now in build_env_setup.py +
build_wheel.py) and trims x86/aarch64-specific branches out of
build_cpu.sh / build_common.sh. The legacy entry point .ci/manywheel/build.sh
now dispatches x86/aarch64 cuda/cpu through the new chain
(set_desired_python -> build_env_setup -> build_install_deps -> build_wheel
-> repair_wheel) and keeps rocm/xpu/cpu-s390x on the legacy build_*.sh
helpers.

build_env_setup.py writes its build-flag exports (USE_CUDA,
TH_BINARY_BUILD, ...) to a file via --env-out which build.sh sources;
this is what lets those flags reach the wheel-build subprocess (a plain
`bash build_env_setup.sh` would have dropped them).

Also drops obsolete numpy version pins in .ci/pytorch/run_tests.sh.

The matching workflow / Jinja-template rework that originally lived in
this branch is no longer needed -- the matrix-driven binary workflows
already landed via #181586 (and follow-ups #181599, #182018), so the
new scripts plug into the existing _binary-build-linux.yml.

Authored with Claude.

ghstack-source-id: fc09f27
Pull Request resolved: #182409
…ps, wheel, repair)"

Split the monolithic .ci/manywheel/build_cuda.sh and the duplicated
sections of build_cpu.sh / build_common.sh into focused, reusable
scripts:

- build_env_setup.sh    GPU/toolchain environment setup (CUDA, ROCm, XPU)
- build_install_deps.sh shared build-time dependency install
- build_wheel.sh        the actual wheel build (python -m build)
- repair_wheel.sh       auditwheel-style repair using the `wheel` python
                        package (unpack/pack/tags), bundling aarch64
                        BLAS/LAPACK/ACL when needed

Drops build_cuda.sh (its logic is now in build_env_setup.sh +
build_wheel.sh) and trims x86/aarch64-specific branches out of
build_cpu.sh / build_common.sh. The legacy entry point .ci/manywheel/build.sh
now dispatches x86/aarch64 cuda/cpu through the new chain
(set_desired_python -> build_env_setup -> build_install_deps -> build_wheel
-> repair_wheel) and keeps rocm/xpu/cpu-s390x on the legacy build_*.sh
helpers.

Also drops obsolete numpy version pins in .ci/pytorch/run_tests.sh.

The matching workflow / Jinja-template rework that originally lived in
this branch is no longer needed -- the matrix-driven binary workflows
already landed via #181586 (and follow-ups #181599, #182018), so the
new scripts plug into the existing _binary-build-linux.yml.

Authored with Claude.

[ghstack-poisoned]
atalman added a commit that referenced this pull request May 5, 2026
Split the monolithic .ci/manywheel/build_cuda.sh and the duplicated
sections of build_cpu.sh / build_common.sh into focused, reusable
helpers, and write the new helpers in Python rather than shell:

- build_env_setup.py    GPU/toolchain environment setup (CUDA, ROCm, XPU)
- build_install_deps.py shared build-time dependency install
- build_wheel.py        the actual wheel build (python -m build)
- repair_wheel.py       auditwheel-style repair using the `wheel` python
                        package (unpack/pack/tags), bundling aarch64
                        BLAS/LAPACK/ACL when needed

Drops build_cuda.sh (its logic is now in build_env_setup.py +
build_wheel.py) and trims x86/aarch64-specific branches out of
build_cpu.sh / build_common.sh. The legacy entry point .ci/manywheel/build.sh
now dispatches x86/aarch64 cuda/cpu through the new chain
(set_desired_python -> build_env_setup -> build_install_deps -> build_wheel
-> repair_wheel) and keeps rocm/xpu/cpu-s390x on the legacy build_*.sh
helpers.

build_env_setup.py writes its build-flag exports (USE_CUDA,
TH_BINARY_BUILD, ...) to a file via --env-out which build.sh sources;
this is what lets those flags reach the wheel-build subprocess (a plain
`bash build_env_setup.sh` would have dropped them).

Also drops obsolete numpy version pins in .ci/pytorch/run_tests.sh.

The matching workflow / Jinja-template rework that originally lived in
this branch is no longer needed -- the matrix-driven binary workflows
already landed via #181586 (and follow-ups #181599, #182018), so the
new scripts plug into the existing _binary-build-linux.yml.

Authored with Claude.

ghstack-source-id: e620cd3
Pull Request resolved: #182409
…ps, wheel, repair)"

Split the monolithic .ci/manywheel/build_cuda.sh and the duplicated
sections of build_cpu.sh / build_common.sh into focused, reusable
scripts:

- build_env_setup.sh    GPU/toolchain environment setup (CUDA, ROCm, XPU)
- build_install_deps.sh shared build-time dependency install
- build_wheel.sh        the actual wheel build (python -m build)
- repair_wheel.sh       auditwheel-style repair using the `wheel` python
                        package (unpack/pack/tags), bundling aarch64
                        BLAS/LAPACK/ACL when needed

Drops build_cuda.sh (its logic is now in build_env_setup.sh +
build_wheel.sh) and trims x86/aarch64-specific branches out of
build_cpu.sh / build_common.sh. The legacy entry point .ci/manywheel/build.sh
now dispatches x86/aarch64 cuda/cpu through the new chain
(set_desired_python -> build_env_setup -> build_install_deps -> build_wheel
-> repair_wheel) and keeps rocm/xpu/cpu-s390x on the legacy build_*.sh
helpers.

Also drops obsolete numpy version pins in .ci/pytorch/run_tests.sh.

The matching workflow / Jinja-template rework that originally lived in
this branch is no longer needed -- the matrix-driven binary workflows
already landed via #181586 (and follow-ups #181599, #182018), so the
new scripts plug into the existing _binary-build-linux.yml.

Authored with Claude.

[ghstack-poisoned]
atalman added a commit that referenced this pull request May 6, 2026
Split the monolithic .ci/manywheel/build_cuda.sh and the duplicated
sections of build_cpu.sh / build_common.sh into focused, reusable
helpers, and write the new helpers in Python rather than shell:

- build_env_setup.py    GPU/toolchain environment setup (CUDA, ROCm, XPU)
- build_install_deps.py shared build-time dependency install
- build_wheel.py        the actual wheel build (python -m build)
- repair_wheel.py       auditwheel-style repair using the `wheel` python
                        package (unpack/pack/tags), bundling aarch64
                        BLAS/LAPACK/ACL when needed

Drops build_cuda.sh (its logic is now in build_env_setup.py +
build_wheel.py) and trims x86/aarch64-specific branches out of
build_cpu.sh / build_common.sh. The legacy entry point .ci/manywheel/build.sh
now dispatches x86/aarch64 cuda/cpu through the new chain
(set_desired_python -> build_env_setup -> build_install_deps -> build_wheel
-> repair_wheel) and keeps rocm/xpu/cpu-s390x on the legacy build_*.sh
helpers.

build_env_setup.py writes its build-flag exports (USE_CUDA,
TH_BINARY_BUILD, ...) to a file via --env-out which build.sh sources;
this is what lets those flags reach the wheel-build subprocess (a plain
`bash build_env_setup.sh` would have dropped them).

Also drops obsolete numpy version pins in .ci/pytorch/run_tests.sh.

The matching workflow / Jinja-template rework that originally lived in
this branch is no longer needed -- the matrix-driven binary workflows
already landed via #181586 (and follow-ups #181599, #182018), so the
new scripts plug into the existing _binary-build-linux.yml.

Authored with Claude.

ghstack-source-id: d892d0d
Pull Request resolved: #182409
…ps, wheel, repair)"

Split the monolithic .ci/manywheel/build_cuda.sh and the duplicated
sections of build_cpu.sh / build_common.sh into focused, reusable
scripts:

- build_env_setup.sh    GPU/toolchain environment setup (CUDA, ROCm, XPU)
- build_install_deps.sh shared build-time dependency install
- build_wheel.sh        the actual wheel build (python -m build)
- repair_wheel.sh       auditwheel-style repair using the `wheel` python
                        package (unpack/pack/tags), bundling aarch64
                        BLAS/LAPACK/ACL when needed

Drops build_cuda.sh (its logic is now in build_env_setup.sh +
build_wheel.sh) and trims x86/aarch64-specific branches out of
build_cpu.sh / build_common.sh. The legacy entry point .ci/manywheel/build.sh
now dispatches x86/aarch64 cuda/cpu through the new chain
(set_desired_python -> build_env_setup -> build_install_deps -> build_wheel
-> repair_wheel) and keeps rocm/xpu/cpu-s390x on the legacy build_*.sh
helpers.

Also drops obsolete numpy version pins in .ci/pytorch/run_tests.sh.

The matching workflow / Jinja-template rework that originally lived in
this branch is no longer needed -- the matrix-driven binary workflows
already landed via #181586 (and follow-ups #181599, #182018), so the
new scripts plug into the existing _binary-build-linux.yml.

Authored with Claude.

[ghstack-poisoned]
atalman added a commit that referenced this pull request May 6, 2026
Split the monolithic .ci/manywheel/build_cuda.sh and the duplicated
sections of build_cpu.sh / build_common.sh into focused, reusable
helpers, and write the new helpers in Python rather than shell:

- build_env_setup.py    GPU/toolchain environment setup (CUDA, ROCm, XPU)
- build_install_deps.py shared build-time dependency install
- build_wheel.py        the actual wheel build (python -m build)
- repair_wheel.py       auditwheel-style repair using the `wheel` python
                        package (unpack/pack/tags), bundling aarch64
                        BLAS/LAPACK/ACL when needed

Drops build_cuda.sh (its logic is now in build_env_setup.py +
build_wheel.py) and trims x86/aarch64-specific branches out of
build_cpu.sh / build_common.sh. The legacy entry point .ci/manywheel/build.sh
now dispatches x86/aarch64 cuda/cpu through the new chain
(set_desired_python -> build_env_setup -> build_install_deps -> build_wheel
-> repair_wheel) and keeps rocm/xpu/cpu-s390x on the legacy build_*.sh
helpers.

build_env_setup.py writes its build-flag exports (USE_CUDA,
TH_BINARY_BUILD, ...) to a file via --env-out which build.sh sources;
this is what lets those flags reach the wheel-build subprocess (a plain
`bash build_env_setup.sh` would have dropped them).

Also drops obsolete numpy version pins in .ci/pytorch/run_tests.sh.

The matching workflow / Jinja-template rework that originally lived in
this branch is no longer needed -- the matrix-driven binary workflows
already landed via #181586 (and follow-ups #181599, #182018), so the
new scripts plug into the existing _binary-build-linux.yml.

Authored with Claude.

ghstack-source-id: a6345a5
Pull Request resolved: #182409
Comment thread .ci/manywheel/build_common.sh Outdated
mv $(basename $pkg) $pkg
fi
# zip up the wheel back
zip -rq $(basename $pkg) $PREIX*

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This keeps the repaired ROCm wheel under its original linux_x86_64 filename/tag. build_common.sh is still used by build_rocm.sh, but this PR removed the PLATFORM=manylinux_2_28_x86_64 assignment and the rename/WHEEL metadata rewrite below. Before this change, ROCm wheels built on AlmaLinux were retagged to manylinux_2_28_x86_64; after it, the upload artifact will be tagged linux_x86_64, which pip will not treat as a manylinux wheel. Can we keep the old retagging path for the legacy ROCm/XPU/s390x script, or move ROCm to the new repair_wheel.py retagging path too?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done: keep retag in build_common.sh for legacy script.
Created ROCm PR on top of this one.

Comment thread .ci/manywheel/build_env_setup.py Resolved
…ps, wheel, repair)"

Split the monolithic .ci/manywheel/build_cuda.sh and the duplicated
sections of build_cpu.sh / build_common.sh into focused, reusable
scripts:

- build_env_setup.sh    GPU/toolchain environment setup (CUDA, ROCm, XPU)
- build_install_deps.sh shared build-time dependency install
- build_wheel.sh        the actual wheel build (python -m build)
- repair_wheel.sh       auditwheel-style repair using the `wheel` python
                        package (unpack/pack/tags), bundling aarch64
                        BLAS/LAPACK/ACL when needed

Drops build_cuda.sh (its logic is now in build_env_setup.sh +
build_wheel.sh) and trims x86/aarch64-specific branches out of
build_cpu.sh / build_common.sh. The legacy entry point .ci/manywheel/build.sh
now dispatches x86/aarch64 cuda/cpu through the new chain
(set_desired_python -> build_env_setup -> build_install_deps -> build_wheel
-> repair_wheel) and keeps rocm/xpu/cpu-s390x on the legacy build_*.sh
helpers.

Also drops obsolete numpy version pins in .ci/pytorch/run_tests.sh.

The matching workflow / Jinja-template rework that originally lived in
this branch is no longer needed -- the matrix-driven binary workflows
already landed via #181586 (and follow-ups #181599, #182018), so the
new scripts plug into the existing _binary-build-linux.yml.

Authored with Claude.

[ghstack-poisoned]
atalman added a commit that referenced this pull request May 6, 2026
Split the monolithic .ci/manywheel/build_cuda.sh and the duplicated
sections of build_cpu.sh / build_common.sh into focused, reusable
helpers, and write the new helpers in Python rather than shell:

- build_env_setup.py    GPU/toolchain environment setup (CUDA, ROCm, XPU)
- build_install_deps.py shared build-time dependency install
- build_wheel.py        the actual wheel build (python -m build)
- repair_wheel.py       auditwheel-style repair using the `wheel` python
                        package (unpack/pack/tags), bundling aarch64
                        BLAS/LAPACK/ACL when needed

Drops build_cuda.sh (its logic is now in build_env_setup.py +
build_wheel.py) and trims x86/aarch64-specific branches out of
build_cpu.sh / build_common.sh. The legacy entry point .ci/manywheel/build.sh
now dispatches x86/aarch64 cuda/cpu through the new chain
(set_desired_python -> build_env_setup -> build_install_deps -> build_wheel
-> repair_wheel) and keeps rocm/xpu/cpu-s390x on the legacy build_*.sh
helpers.

build_env_setup.py writes its build-flag exports (USE_CUDA,
TH_BINARY_BUILD, ...) to a file via --env-out which build.sh sources;
this is what lets those flags reach the wheel-build subprocess (a plain
`bash build_env_setup.sh` would have dropped them).

Also drops obsolete numpy version pins in .ci/pytorch/run_tests.sh.

The matching workflow / Jinja-template rework that originally lived in
this branch is no longer needed -- the matrix-driven binary workflows
already landed via #181586 (and follow-ups #181599, #182018), so the
new scripts plug into the existing _binary-build-linux.yml.

Authored with Claude.

ghstack-source-id: 7a45e73
Pull Request resolved: #182409
…ps, wheel, repair)"

Split the monolithic .ci/manywheel/build_cuda.sh and the duplicated
sections of build_cpu.sh / build_common.sh into focused, reusable
scripts:

- build_env_setup.sh    GPU/toolchain environment setup (CUDA, ROCm, XPU)
- build_install_deps.sh shared build-time dependency install
- build_wheel.sh        the actual wheel build (python -m build)
- repair_wheel.sh       auditwheel-style repair using the `wheel` python
                        package (unpack/pack/tags), bundling aarch64
                        BLAS/LAPACK/ACL when needed

Drops build_cuda.sh (its logic is now in build_env_setup.sh +
build_wheel.sh) and trims x86/aarch64-specific branches out of
build_cpu.sh / build_common.sh. The legacy entry point .ci/manywheel/build.sh
now dispatches x86/aarch64 cuda/cpu through the new chain
(set_desired_python -> build_env_setup -> build_install_deps -> build_wheel
-> repair_wheel) and keeps rocm/xpu/cpu-s390x on the legacy build_*.sh
helpers.

Also drops obsolete numpy version pins in .ci/pytorch/run_tests.sh.

The matching workflow / Jinja-template rework that originally lived in
this branch is no longer needed -- the matrix-driven binary workflows
already landed via #181586 (and follow-ups #181599, #182018), so the
new scripts plug into the existing _binary-build-linux.yml.

Authored with Claude.

[ghstack-poisoned]
@pytorch-bot pytorch-bot Bot added the release notes: releng release notes category label May 7, 2026
@atalman atalman added the ciflow/trunk Trigger trunk jobs on your pull request label May 7, 2026
zklaus added a commit to zklaus/pytorch that referenced this pull request Jun 16, 2026
Windows analog of .ci/manywheel/build_install_deps.py from pytorchgh-182409.
Replaces the pip-install + libuv-extract portion of the legacy
setup_build.bat: per-Python numpy pin, the fixed build-time pip set
(cmake, pyyaml, mkl-include/static, boto3, requests, ninja,
typing_extensions, setuptools==78.1.1, scikit-build-core), spin clean,
and libuv tarball extraction into the running Python's prefix. Emits
libuv_ROOT via --env-out so the parent bash wrapper picks it up.

Package list stays hardcoded for parity with setup_build.bat; the
requirements unification work (pytorchgh-183913) will centralize this later.
Not yet wired into binary_windows_build.sh.

Authored by Claude.
zklaus added a commit to zklaus/pytorch that referenced this pull request Jun 16, 2026
x86_64 wheel builds now flow through the new
set_desired_python.sh -> build_env_setup.py -> build_install_deps.py
-> build_wheel.py chain instead of the legacy
internal/build_wheels.bat -> build_pytorch.bat -> {cpu,cuda,xpu}.bat
-> internal/setup.bat dispatch.

The GPU_ARCH_TYPE (cpu/cuda/xpu) selector is derived from DESIRED_CUDA
and exported for build_env_setup.py to dispatch on. The bash wrapper
sources two intermediate ENV_FILEs (one from env_setup, one from
install_deps) so build flags, libuv_ROOT, and vcvarsall's PATH/LIB
reach the eventual `python -m build` subprocess.

windows-arm64 wheels, libtorch zip artifacts, and cpu-s390x are
intentionally left on the legacy bat chain in this PR -- same scoping
discipline as pytorchgh-182409 on the Linux side.

Authored by Claude.
zklaus added a commit to zklaus/pytorch that referenced this pull request Jun 16, 2026
Reviewers comparing the new Windows pipeline to the Linux template
(pytorchgh-182409) will notice the missing repair_wheel.py step. Spelled out
why it isn't needed on Windows so the asymmetry doesn't read as an
oversight: DLL discovery doesn't use RPATH, and CUDA DLLs already
land in torch/lib/ during the build.

Wheel-content diff against the latest published nightly cpu wheel
confirms parity: identical DLL set (9 DLLs, 13 libs) in torch/lib/.
pytorchmergebot pushed a commit that referenced this pull request Jun 16, 2026
## Summary

Port the Windows x86_64 wheel CD build off the legacy `.bat` chain onto a
Python pipeline, mirroring the Linux split landed in #182409. CPU, CUDA, and
XPU wheel builds now run through a small set of Python scripts instead of the
`build_pytorch.bat -> cpu/cuda/xpu.bat -> internal/setup.bat` chain.

The new entry chain on x86_64 wheel builds:

```
binary_windows_build.sh
  -> windows/internal/vc_install_helper.bat   (ensure VS2022 BuildTools)
  -> windows/set_desired_python.sh            (install Python.org Python)
  -> python windows/build_env_setup.py        (vcvarsall + CUDA/XPU env + MAGMA + sccache)
  -> python windows/build_install_deps.py     (pip deps + libuv)
  -> python windows/build_wheel.py            (python -m build --wheel)
```

The three Python steps are driven through the interpreter
`set_desired_python.sh` selected (exported as `DESIRED_PYTHON_EXE`), not a
bare `python`, so the wheel ABI tag and pip build deps track
`DESIRED_PYTHON` for free-threaded builds (see Build-correctness fixes).

vcvarsall env capture mirrors `torch.utils.cpp_extension._jit._get_vc_env`
from #180707 (vswhere discovery, `cmd /u /c` for UTF-16LE output, diff
against current env so additions layer on top).

`internal/cuda_install.bat`, `internal/xpu_install.bat`, and
`internal/vc_install_helper.bat` are kept as Python/bash-invoked installers --
same pragmatic precedent as the Linux refactor (`install_cuda.sh` etc.).
Heavy installer logic stays in bash/cmd; orchestration moves to Python.
`set_desired_python.sh` inlines what `internal/install_python.bat` did (the
`bash -> cmd /c` boundary was unreliable for the python.org installer), so
the wheel path no longer invokes `install_python.bat`.

## Removing the legacy bat chain

The x86_64 wheel build was the last consumer of the legacy
`build_pytorch.bat -> {cpu,cuda,xpu}.bat -> internal/setup.bat` chain, so
porting it to the Python pipeline lets that chain go. This PR deletes:

- `build_pytorch.bat`, `cpu/cuda/xpu.bat`, `setup_build.bat`, and
  `internal/{build_wheels,check_deps,check_nvtx,check_opts,clean,clone,
  cuda_config,init,setup}.bat`.

These are now orphaned -- nothing in the tree invokes them. The only
remaining mentions are provenance comments in the new Python scripts (e.g.
"Mirrors the MAGMA block in the legacy build_pytorch.bat"), plus the separate
`arm64/build_pytorch.bat` and `win-test-helpers/build_pytorch.bat`, which are
different files left untouched.

Note on debug libtorch: upstream has already stopped shipping the Windows
debug libtorch builds and removed their nightly workflows, and this branch is
rebased on top of that -- so it carries no `.github/workflows` or
`generate_ci_workflows.py` changes. (Earlier revisions of this PR removed
those workflows here; those commits were dropped in the rebase once the
upstream removal landed.) The release path is unaffected: release libtorch is
still produced by extraction from the release wheel
(`extract_libtorch_from_wheel.py`, the same mechanism as on Linux), and those
wheels are now built by this Python pipeline.

## Build-correctness fixes (surfaced by the wheel smoke tests)

With the builds green, the `wheel-*-test` smoke jobs ran and caught two gaps
the legacy bat chain had handled implicitly:

- **Free-threaded wheels (`DESIRED_PYTHON=3.14t`).** A free-threaded
  python.org install ships both `python.exe` and `python3.14t.exe` under the
  same prefix, so a bare `python` resolved to the regular interpreter and
  `python -m build` produced a `cp314` wheel that the `cp314t` test job
  rejected ("not a supported wheel on this platform"). Fix: export the
  selected interpreter as `DESIRED_PYTHON_EXE` and drive all three pipeline
  steps through it, so deps and the wheel ABI tag match `DESIRED_PYTHON`.
- **XPU MKL availability.** `CMAKE_PREFIX_PATH` was assigned
  `<sys.prefix>/Library` (the pip `mkl-static`/`mkl-include` prefix) before
  the per-device setup ran, and the XPU oneAPI `vars.bat` then overwrote it
  with its own value -- so the XPU build configured BLAS as Eigen and
  `torch.backends.mkl.is_available()` was False (the smoke test asserts on
  it). cpu/cuda were unaffected because nothing else touches
  `CMAKE_PREFIX_PATH` there. Fix: set `CMAKE_PREFIX_PATH` after the device
  dispatch and prepend the MKL prefix to whatever the device contributed, so
  both the pip MKL and the oneAPI compiler prefix stay on the search path.

## Python patch pinning

`set_desired_python.sh` selects the python.org installer from an explicit
per-minor patch table (e.g. 3.13 -> 3.13.14) rather than the `.0` patch the
legacy `install_python.bat` used. The `.0` pin froze each minor on its
oldest, CVE-laden release; floating to the newest installer was rejected
because python.org serves source-only (no-installer) releases for
security-only minors, which would require scraping the release index and
HEAD-probing candidates on every build. Security-only minors (3.10-3.12) are
pinned to their last release that shipped a Windows installer; bugfix minors
(3.13, 3.14) point at the current newest installer and are bumped here in
review. The table must stay in sync with the matrix in
`generated-windows-binary-wheel-nightly.yml`.

## Divergences from the Linux template (#182409)

Where this PR deviates from the Linux pipeline, why:

- **No `repair_wheel.py` step.** Windows DLL discovery uses PATH /
  `AddDllDirectory` rather than RPATH, so there's nothing for patchelf to
  do. CUDA DLLs already ship inside `torch/lib/`. Wheel-content diff against
  the latest published nightly cpu wheel confirms parity: identical DLL set
  in `torch/lib/`.
- **`set_desired_python.sh` installs Python from python.org** rather than
  picking from a baked image (the Windows CI AMI doesn't ship Pythons
  preinstalled).
- **`build_env_setup.py` downloads MAGMA / sccache / randomtemp** during the
  build rather than baking them into a Docker image. (These downloads now go
  through `urllib` with default TLS verification, replacing the legacy
  `curl -k` which disabled cert checking.)
- **MKL comes from pip** (`mkl-static` / `mkl-include`), put on
  `CMAKE_PREFIX_PATH` via the `<sys.prefix>/Library` prefix, rather than the
  legacy `check_opts.bat` `LIB`/`MKLProductDir` system-MKL prepend.
- **No cuda-aarch64 / rocm / cpu-cxx11-abi branches** (not applicable on
  Windows).
- **`build_install_deps.py` hardcodes the pip dep list** (matches what
  `setup_build.bat` did) rather than reading `requirements*.txt` like Linux.
  Migrating to `requirements*.txt` is a worthwhile follow-up but out of scope
  here.

The binary-build env knobs the legacy chain set are preserved in
`COMMON_BUILD_ENV` (`PYTORCH_BINARY_BUILD`, `TH_BINARY_BUILD`, `BUILD_TEST=0`,
`INSTALL_TEST=0`, `MSSdk`, `DISTUTILS_USE_SDK`).

## Out of scope

- `windows-arm64` wheels (separate `arm64/build_pytorch.bat` chain,
  untouched).
- Windows pull-CI build (uses a separate `win-test-helpers/build_pytorch.bat`,
  untouched).
- `cpu-s390x` (Linux only).

## Test plan

Builds are green across the full x86_64 wheel matrix:

- [x] x86_64 cpu wheel build x Python 3.10-3.14 + 3.14t
- [x] x86_64 cuda wheel build (12.6, 13.0, 13.2) x the same Python set
- [x] x86_64 xpu wheel build x the same Python set
- [x] Wheel content verified equivalent to the published nightly cpu wheel
      (same DLL set in `torch/lib/`)
- [x] sccache enabled on CPU + CUDA host compilation; server lifecycle
      confirmed via build logs
- [x] cpu / cuda smoke tests (`wheel-*-test`) green
- [x] windows-arm64 wheel + libtorch builds unaffected (path goes through
      `arm64/build_pytorch.bat`, untouched)

Smoke-test status for the two build-correctness fixes above (free-threaded
ABI tag, XPU MKL) is being re-validated on the current head; the prior run
caught both at the `wheel-*-test` stage and the fixes target exactly those
failures.

Earlier-run note (resolved): the `cuda13_0` / `cuda13_2` wheel builds had
failed at the cuDNN download step because the
`cudnn-...-9.23.1.3_cuda13-archive.zip` object was briefly missing from
`ossci-windows` (uploaded ~19 min after the build fetched it). It is present
and valid now and the cuda13 builds are green; unrelated to this PR.

## Follow-ups (deferred, captured separately)

- **Migrate `build_install_deps.py` to read `requirements*.txt`** rather than
  hardcoded `PIP_PACKAGES`, matching the Linux pattern.
- Remaining self-review cleanup items: `CMAKE_GENERATOR` explicit for
  CPU/XPU, env-handoff fragilities, PATH conversion guard, numpy pin for a
  future Python 3.15, and bumping the python patch table / keeping it in sync
  with the wheel matrix.

Authored with [Claude Code](https://claude.com/claude-code).

Pull Request resolved: #184407
Approved by: https://github.com/atalman
aperson30 pushed a commit to aperson30/pytorch that referenced this pull request Jun 20, 2026
…repair) (pytorch#182409)

Split the monolithic .ci/manywheel/build_cuda.sh and the duplicated
sections of build_cpu.sh / build_common.sh into focused, reusable
scripts:

- build_env_setup.sh    GPU/toolchain environment setup (CUDA, ROCm, XPU)
- build_install_deps.sh shared build-time dependency install
- build_wheel.sh        the actual wheel build (python -m build)
- repair_wheel.sh       auditwheel-style repair using the `wheel` python
                        package (unpack/pack/tags), bundling aarch64
                        BLAS/LAPACK/ACL when needed

Drops build_cuda.sh (its logic is now in build_env_setup.sh +
build_wheel.sh) and trims x86/aarch64-specific branches out of
build_cpu.sh / build_common.sh. The legacy entry point .ci/manywheel/build.sh
now dispatches x86/aarch64 cuda/cpu through the new chain
(set_desired_python -> build_env_setup -> build_install_deps -> build_wheel
-> repair_wheel) and keeps rocm/xpu/cpu-s390x on the legacy build_*.sh
helpers.

Also drops obsolete numpy version pins in .ci/pytorch/run_tests.sh.

The matching workflow / Jinja-template rework that originally lived in
this branch is no longer needed -- the matrix-driven binary workflows
already landed via pytorch#181586 (and follow-ups pytorch#181599, pytorch#182018), so the
new scripts plug into the existing _binary-build-linux.yml.

Authored with Claude.
Pull Request resolved: pytorch#182409
Approved by: https://github.com/seemethere, https://github.com/huydhn
aperson30 pushed a commit to aperson30/pytorch that referenced this pull request Jun 20, 2026
…ytorch#183320)

## Summary

Follow-up to pytorch#182409, addressing the review observation that the new `build_env_setup.py` duplicated the OS-package list already baked into the manywheel builder image (`.ci/docker/manywheel/Dockerfile_2_28`), with no CI use case for the duplication. The drift risk between the Dockerfile and the Python script and the broadened wheel-build-time supply-chain surface (fresh yum/apt fetches vs. the image's frozen baseline) provide no benefit on the standard CI path.

This PR restores the legacy "trust the image" contract for the OS-package list only:

- `install_os_packages` now installs only `zip` + `openssl` on RHEL/Ubuntu (the original `build_common.sh` set). All other yum/apt packages come from `Dockerfile_2_28` at image-build time.
- The nvidia-apt list mangling on Ubuntu is removed (no longer needed once the install set is trimmed).

The CUDA + MAGMA + MKL bootstrap paths (`install_cuda_toolkit`, the `install_magma.sh` fallback in `setup_cuda`, and the `install_mkl.sh` fallback in `main()`) are kept so the script remains usable on a lean manylinux base when those toolkits aren't already staged.

Net diff: 1 file, +15 / -42.

Authored with Claude.

## Test plan

- [ ] Nightly manywheel CUDA / CPU / aarch64 build jobs (Linux) succeed.
- [ ] No regressions from the trimmed OS-package install on Dockerfile_2_28.
Pull Request resolved: pytorch#183320
Approved by: https://github.com/malfet
zklaus added a commit to zklaus/pytorch that referenced this pull request Jun 23, 2026
Port the macOS arm64 CD wheel build from the monolithic build_wheel.sh to
the same staged Python pipeline used for Linux (pytorch#182409) and Windows
(pytorch#184407): build_env_setup.py emits the macOS build flags to an env file,
build_install_deps.py installs the pinned build/runtime deps (and libomp
when not staged), build_wheel.py runs `python -m build`, and repair_wheel.py
delocates the wheel in place. A per-Python build.sh owns the stage contract;
build_all_macos_wheels.sh selects the interpreter and loops.

Delocation moves into the per-Python build (repair_wheel.py) instead of a
separate workflow step, so the template drops the "Delocate all wheels" step
and the generated workflow is regenerated to match.

build_wheel.sh and delocate_wheels.sh are removed: the former's wheel path is
superseded by the Python modules and its BUILD_PYTHONLESS/libtorch branch was
dead code (macOS ships no libtorch package; libtorch is built on Linux via
.ci/libtorch/), and the latter's logic now lives in repair_wheel.py.

Review in pipeline order: build.sh (the contract) first, then the four stage
modules, then build_all_macos_wheels.sh and the workflow template.

Test Plan:
Static checks only so far (no macOS runner in this environment):

```
python3 -m py_compile .ci/wheel/*.py
bash -n .ci/wheel/build.sh .ci/wheel/build_all_macos_wheels.sh
python3 .github/scripts/generate_ci_workflows.py   # regen, clean diff
lintrunner .ci/wheel/*.py .ci/wheel/*.sh \
    .github/templates/macos_binary_build_workflow.yml.j2 \
    .github/workflows/generated-macos-arm64-binary-wheel-nightly.yml
```

End-to-end validation on a macOS arm64 runner (the nightly wheel matrix) is
pending and will be exercised via ciflow/binaries.

Authored with assistance from Claude Code.
zklaus added a commit to zklaus/pytorch that referenced this pull request Jun 30, 2026
Port the macOS arm64 CD wheel build from the monolithic build_wheel.sh to
the same staged Python pipeline used for Linux (pytorch#182409) and Windows
(pytorch#184407): build_env_setup.py emits the macOS build flags to an env file,
build_install_deps.py installs the pinned build/runtime deps (and libomp
when not staged), build_wheel.py runs `python -m build`, and repair_wheel.py
delocates the wheel in place. A per-Python build.sh owns the stage contract;
build_all_macos_wheels.sh selects the interpreter and loops.

Delocation moves into the per-Python build (repair_wheel.py) instead of a
separate workflow step, so the template drops the "Delocate all wheels" step
and the generated workflow is regenerated to match.

build_wheel.sh and delocate_wheels.sh are removed: the former's wheel path is
superseded by the Python modules and its BUILD_PYTHONLESS/libtorch branch was
dead code (macOS ships no libtorch package; libtorch is built on Linux via
.ci/libtorch/), and the latter's logic now lives in repair_wheel.py.

Review in pipeline order: build.sh (the contract) first, then the four stage
modules, then build_all_macos_wheels.sh and the workflow template.

Test Plan:
Static checks only so far (no macOS runner in this environment):

```
python3 -m py_compile .ci/wheel/*.py
bash -n .ci/wheel/build.sh .ci/wheel/build_all_macos_wheels.sh
python3 .github/scripts/generate_ci_workflows.py   # regen, clean diff
lintrunner .ci/wheel/*.py .ci/wheel/*.sh \
    .github/templates/macos_binary_build_workflow.yml.j2 \
    .github/workflows/generated-macos-arm64-binary-wheel-nightly.yml
```

End-to-end validation on a macOS arm64 runner (the nightly wheel matrix) is
pending and will be exercised via ciflow/binaries.

Authored with assistance from Claude Code.
pytorchmergebot pushed a commit that referenced this pull request Jul 1, 2026
## Summary

Refactors the macOS arm64 CD wheel build from the monolithic `build_wheel.sh` into the same staged Python pipeline already adopted for Linux (#182409) and Windows (#184407). This is the third and final platform, bringing macOS in line with the cross-platform structure.

Following the Linux template, the build is split into four single-responsibility modules under `.ci/macwheel/`, driven by a per-Python `build.sh` orchestrator that owns the stage contract:

- `build_env_setup.py` — emits the macOS build flags (`USE_DISTRIBUTED`, deployment target, Metal/CoreML, libomp prefix) to an `--env-out` file the orchestrator sources
- `build_install_deps.py` — pinned build/runtime deps + numpy pin; libomp via Homebrew when not staged
- `build_wheel.py` — sets the arm64 host platform / `ARCHFLAGS` and runs `python -m build --wheel --no-isolation`
- `repair_wheel.py` — delocates the wheel in place (the macOS analog of Linux's `auditwheel`/patchelf; Windows needs no repair)

`build_all_macos_wheels.sh` selects each interpreter and loops, reusing the ABI-free `libtorch_cpu` across Python versions via `SKIP_SETUP_CLEAN` (same incremental-build trick as Linux).

### Notable points

- **macOS is arm64-only.** Main builds no Intel-Mac wheels (the matrix emits only `macos-arm64`), so the pipeline is arm64-only by design — and the dead `x86_64`/`BUILD_PYTHONLESS` libtorch branches in the old `build_wheel.sh` are removed. macOS still ships a libtorch artifact, but it is *extracted from the finished wheel* by a later workflow job (`.ci/libtorch/extract_libtorch_from_wheel.py`), not produced by a separate `BUILD_PYTHONLESS` build.
- **Delocation moves inline** into the per-Python build (`repair_wheel.py`), so the workflow drops its separate "Delocate all wheels" step.
- **Directory renamed** `.ci/wheel/` → `.ci/macwheel/`, parallel to Linux's `.ci/manywheel/` (the old name was too generic for a macOS-only build).
- `build_install_deps.py` uses **`spin clean`** rather than `setup.py clean`, matching Windows and surviving the eventual `setup.py` removal.

### Review order

1. `build.sh` (the stage contract), then the four stage modules
2. `build_all_macos_wheels.sh` and the workflow template
3. The second commit is a pure rename + `spin clean` switch

## Test Plan

Static + structural checks locally:

```
python3 -m py_compile .ci/macwheel/*.py
bash -n .ci/macwheel/build.sh .ci/macwheel/build_all_macos_wheels.sh
python3 .github/scripts/generate_ci_workflows.py   # only the macOS workflow changes
lintrunner .ci/macwheel/* .github/templates/macos_binary_build_workflow.yml.j2
```

A from-source build on a dev Mac exercised the pipeline through environment setup, dependency install, CMake configure, and compilation, confirming the orchestration contract (venv handoff, `--env-out` sourcing, `python -m build` invocation). End-to-end wheel production + delocation is validated by this PR's `ciflow/binaries` run on the `macos-arm64` runner.

Opening as a draft for a first round of CI.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Pull Request resolved: #187944
Approved by: https://github.com/atalman
zklaus added a commit to zklaus/pytorch that referenced this pull request Jul 9, 2026
Fourth consolidation step, and the point of the exercise: the three CD
wheel pipelines carried copy-pasted helpers and three drifted numpy pin
tables. Extract .ci/wheel/_common.py (retry, pip_install, numpy_pin,
shell_quote, write_env_exports, download) and have the three
build_install_deps.py import from it. The Windows _common.py, already the
most complete, is promoted to the shared location; its write_env_exports
(POSIX PATH conversion + bash-identifier filter) is a safe superset -- the
PATH branch is a no-op where PATH has no ';' (Linux/macOS), and the filter
only skips keys bash could never source anyway.

numpy pin -- the tables disagreed for every Python, and Linux's greedy
`cp31` prefix silently overrode its own 2.0.2 default for 3.10-3.12 (and
mis-pinned 3.15). Replaced with one explicit dict + fail-loud (the macOS
design). Each entry is the oldest numpy *minor* that ships a wheel for that
interpreter (verified on PyPI -- widest runtime-numpy range), pinned at the
newest *patch* of that minor already shipped in production by one of the
platforms, so the reconciliation drops no numpy bugfix:

    3.10/3.11/3.12 -> 2.0.2   3.13 -> 2.1.2   3.14 -> 2.3.4

The only genuine floor change is Linux 3.10-3.12 (2.1.0 -> 2.0.2), undoing
the greedy-prefix accident to match the 2.0.2 that Windows and macOS already
use there; 3.13 and 3.14 converge on the newer of the two patches in use
(Windows' 2.1.2, Linux/macOS' 2.3.4 -- the latter is numpy's 3.14.0-final
release). A read of the 2.1.1/2.1.2 and 2.3.3/2.3.4 notes confirmed the
dropped-vs-kept patch deltas are numpy-internal runtime or numpy's-own-build
fixes, none touching the C-API surface torch compiles against. 3.15 has no
numpy wheels yet, so it now fails loudly everywhere instead of silently
building an unusable pin. Provenance (pytorchgh-182409/184407/187944) found none of
the original drift deliberate; Linux's incidental `--pre` is dropped (every
pin is an exact stable release).

These pipelines run only in the nightly CD workflows, which this PR's CI
does not exercise; verified by import/path simulation, the numpy table
against PyPI, and lint rather than a green build. build_env_setup.py on
Linux/macOS still carry their own shell_quote/write_env_exports copies;
deduping those is the next commit.

## Test plan

```
# helpers resolve + table is the evidence-based one
python - <<'PY'
import importlib.util as u
m=u.module_from_spec(s:=u.spec_from_file_location("_common",".ci/wheel/_common.py")); s.loader.exec_module(m)
assert m.NUMPY_PINS=={"3.10":"2.0.2","3.11":"2.0.2","3.12":"2.0.2","3.13":"2.1.2","3.14":"2.3.4"}
assert all(hasattr(m,h) for h in ["retry","pip_install","numpy_pin","download","write_env_exports","shell_quote"])
PY
# each pipeline resolves _common via its own sys.path math (parents[1] == .ci/wheel)
lintrunner .ci/wheel/_common.py .ci/wheel/*/build_install_deps.py .ci/wheel/windows/build_env_setup.py
```

Authored with assistance from Claude Code.
pytorchmergebot pushed a commit to zklaus/pytorch that referenced this pull request Jul 9, 2026
Fourth consolidation step, and the point of the exercise: the three CD
wheel pipelines carried copy-pasted helpers and three drifted numpy pin
tables. Extract .ci/wheel/_common.py (retry, pip_install, numpy_pin,
shell_quote, write_env_exports, download) and have the three
build_install_deps.py import from it. The Windows _common.py, already the
most complete, is promoted to the shared location; its write_env_exports
(POSIX PATH conversion + bash-identifier filter) is a safe superset -- the
PATH branch is a no-op where PATH has no ';' (Linux/macOS), and the filter
only skips keys bash could never source anyway.

numpy pin -- the tables disagreed for every Python, and Linux's greedy
`cp31` prefix silently overrode its own 2.0.2 default for 3.10-3.12 (and
mis-pinned 3.15). Replaced with one explicit dict + fail-loud (the macOS
design). Each entry is the oldest numpy *minor* that ships a wheel for that
interpreter (verified on PyPI -- widest runtime-numpy range), pinned at the
newest *patch* of that minor already shipped in production by one of the
platforms, so the reconciliation drops no numpy bugfix:

    3.10/3.11/3.12 -> 2.0.2   3.13 -> 2.1.2   3.14 -> 2.3.4

The only genuine floor change is Linux 3.10-3.12 (2.1.0 -> 2.0.2), undoing
the greedy-prefix accident to match the 2.0.2 that Windows and macOS already
use there; 3.13 and 3.14 converge on the newer of the two patches in use
(Windows' 2.1.2, Linux/macOS' 2.3.4 -- the latter is numpy's 3.14.0-final
release). A read of the 2.1.1/2.1.2 and 2.3.3/2.3.4 notes confirmed the
dropped-vs-kept patch deltas are numpy-internal runtime or numpy's-own-build
fixes, none touching the C-API surface torch compiles against. 3.15 has no
numpy wheels yet, so it now fails loudly everywhere instead of silently
building an unusable pin. Provenance (pytorchgh-182409/184407/187944) found none of
the original drift deliberate; Linux's incidental `--pre` is dropped (every
pin is an exact stable release).

These pipelines run only in the nightly CD workflows, which this PR's CI
does not exercise; verified by import/path simulation, the numpy table
against PyPI, and lint rather than a green build. build_env_setup.py on
Linux/macOS still carry their own shell_quote/write_env_exports copies;
deduping those is the next commit.

## Test plan

```
# helpers resolve + table is the evidence-based one
python - <<'PY'
import importlib.util as u
m=u.module_from_spec(s:=u.spec_from_file_location("_common",".ci/wheel/_common.py")); s.loader.exec_module(m)
assert m.NUMPY_PINS=={"3.10":"2.0.2","3.11":"2.0.2","3.12":"2.0.2","3.13":"2.1.2","3.14":"2.3.4"}
assert all(hasattr(m,h) for h in ["retry","pip_install","numpy_pin","download","write_env_exports","shell_quote"])
PY
# each pipeline resolves _common via its own sys.path math (parents[1] == .ci/wheel)
lintrunner .ci/wheel/_common.py .ci/wheel/*/build_install_deps.py .ci/wheel/windows/build_env_setup.py
```

Authored with assistance from Claude Code.
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…repair) (pytorch#182409)

Split the monolithic .ci/manywheel/build_cuda.sh and the duplicated
sections of build_cpu.sh / build_common.sh into focused, reusable
scripts:

- build_env_setup.sh    GPU/toolchain environment setup (CUDA, ROCm, XPU)
- build_install_deps.sh shared build-time dependency install
- build_wheel.sh        the actual wheel build (python -m build)
- repair_wheel.sh       auditwheel-style repair using the `wheel` python
                        package (unpack/pack/tags), bundling aarch64
                        BLAS/LAPACK/ACL when needed

Drops build_cuda.sh (its logic is now in build_env_setup.sh +
build_wheel.sh) and trims x86/aarch64-specific branches out of
build_cpu.sh / build_common.sh. The legacy entry point .ci/manywheel/build.sh
now dispatches x86/aarch64 cuda/cpu through the new chain
(set_desired_python -> build_env_setup -> build_install_deps -> build_wheel
-> repair_wheel) and keeps rocm/xpu/cpu-s390x on the legacy build_*.sh
helpers.

Also drops obsolete numpy version pins in .ci/pytorch/run_tests.sh.

The matching workflow / Jinja-template rework that originally lived in
this branch is no longer needed -- the matrix-driven binary workflows
already landed via pytorch#181586 (and follow-ups pytorch#181599, pytorch#182018), so the
new scripts plug into the existing _binary-build-linux.yml.

Authored with Claude.
Pull Request resolved: pytorch#182409
Approved by: https://github.com/seemethere, https://github.com/huydhn
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…ytorch#183320)

## Summary

Follow-up to pytorch#182409, addressing the review observation that the new `build_env_setup.py` duplicated the OS-package list already baked into the manywheel builder image (`.ci/docker/manywheel/Dockerfile_2_28`), with no CI use case for the duplication. The drift risk between the Dockerfile and the Python script and the broadened wheel-build-time supply-chain surface (fresh yum/apt fetches vs. the image's frozen baseline) provide no benefit on the standard CI path.

This PR restores the legacy "trust the image" contract for the OS-package list only:

- `install_os_packages` now installs only `zip` + `openssl` on RHEL/Ubuntu (the original `build_common.sh` set). All other yum/apt packages come from `Dockerfile_2_28` at image-build time.
- The nvidia-apt list mangling on Ubuntu is removed (no longer needed once the install set is trimmed).

The CUDA + MAGMA + MKL bootstrap paths (`install_cuda_toolkit`, the `install_magma.sh` fallback in `setup_cuda`, and the `install_mkl.sh` fallback in `main()`) are kept so the script remains usable on a lean manylinux base when those toolkits aren't already staged.

Net diff: 1 file, +15 / -42.

Authored with Claude.

## Test plan

- [ ] Nightly manywheel CUDA / CPU / aarch64 build jobs (Linux) succeed.
- [ ] No regressions from the trimmed OS-package install on Dockerfile_2_28.
Pull Request resolved: pytorch#183320
Approved by: https://github.com/malfet
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
## Summary

Port the XPU manylinux build from the legacy bash scripts (`build_xpu.sh` + `build_common.sh`) to the Python pipeline (`build_env_setup.py` + `build_install_deps.py` + `build_wheel.py` + `repair_wheel.py`), following the same pattern as pytorch#182409 (CUDA/CPU) and pytorch#182696 (ROCm).

- Add `XPU_BUILD_ENV` and `source_oneapi_env()` to `build_env_setup.py` to source Intel oneAPI environment and set build flags
- Always build small wheel for XPU, following the same practice as CUDA
- Add XPU RPATH handling in `repair_wheel.py` (following CUDA pattern — runtime libs from pypi packages)
- XPU wheels are now retagged to `manylinux_2_28_x86_64`
- Delete `build_xpu.sh`

cpu-s390x continues to flow through `build_common.sh` unchanged.

Pull Request resolved: pytorch#182942
Approved by: https://github.com/atalman
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…184407)

## Summary

Port the Windows x86_64 wheel CD build off the legacy `.bat` chain onto a
Python pipeline, mirroring the Linux split landed in pytorch#182409. CPU, CUDA, and
XPU wheel builds now run through a small set of Python scripts instead of the
`build_pytorch.bat -> cpu/cuda/xpu.bat -> internal/setup.bat` chain.

The new entry chain on x86_64 wheel builds:

```
binary_windows_build.sh
  -> windows/internal/vc_install_helper.bat   (ensure VS2022 BuildTools)
  -> windows/set_desired_python.sh            (install Python.org Python)
  -> python windows/build_env_setup.py        (vcvarsall + CUDA/XPU env + MAGMA + sccache)
  -> python windows/build_install_deps.py     (pip deps + libuv)
  -> python windows/build_wheel.py            (python -m build --wheel)
```

The three Python steps are driven through the interpreter
`set_desired_python.sh` selected (exported as `DESIRED_PYTHON_EXE`), not a
bare `python`, so the wheel ABI tag and pip build deps track
`DESIRED_PYTHON` for free-threaded builds (see Build-correctness fixes).

vcvarsall env capture mirrors `torch.utils.cpp_extension._jit._get_vc_env`
from pytorch#180707 (vswhere discovery, `cmd /u /c` for UTF-16LE output, diff
against current env so additions layer on top).

`internal/cuda_install.bat`, `internal/xpu_install.bat`, and
`internal/vc_install_helper.bat` are kept as Python/bash-invoked installers --
same pragmatic precedent as the Linux refactor (`install_cuda.sh` etc.).
Heavy installer logic stays in bash/cmd; orchestration moves to Python.
`set_desired_python.sh` inlines what `internal/install_python.bat` did (the
`bash -> cmd /c` boundary was unreliable for the python.org installer), so
the wheel path no longer invokes `install_python.bat`.

## Removing the legacy bat chain

The x86_64 wheel build was the last consumer of the legacy
`build_pytorch.bat -> {cpu,cuda,xpu}.bat -> internal/setup.bat` chain, so
porting it to the Python pipeline lets that chain go. This PR deletes:

- `build_pytorch.bat`, `cpu/cuda/xpu.bat`, `setup_build.bat`, and
  `internal/{build_wheels,check_deps,check_nvtx,check_opts,clean,clone,
  cuda_config,init,setup}.bat`.

These are now orphaned -- nothing in the tree invokes them. The only
remaining mentions are provenance comments in the new Python scripts (e.g.
"Mirrors the MAGMA block in the legacy build_pytorch.bat"), plus the separate
`arm64/build_pytorch.bat` and `win-test-helpers/build_pytorch.bat`, which are
different files left untouched.

Note on debug libtorch: upstream has already stopped shipping the Windows
debug libtorch builds and removed their nightly workflows, and this branch is
rebased on top of that -- so it carries no `.github/workflows` or
`generate_ci_workflows.py` changes. (Earlier revisions of this PR removed
those workflows here; those commits were dropped in the rebase once the
upstream removal landed.) The release path is unaffected: release libtorch is
still produced by extraction from the release wheel
(`extract_libtorch_from_wheel.py`, the same mechanism as on Linux), and those
wheels are now built by this Python pipeline.

## Build-correctness fixes (surfaced by the wheel smoke tests)

With the builds green, the `wheel-*-test` smoke jobs ran and caught two gaps
the legacy bat chain had handled implicitly:

- **Free-threaded wheels (`DESIRED_PYTHON=3.14t`).** A free-threaded
  python.org install ships both `python.exe` and `python3.14t.exe` under the
  same prefix, so a bare `python` resolved to the regular interpreter and
  `python -m build` produced a `cp314` wheel that the `cp314t` test job
  rejected ("not a supported wheel on this platform"). Fix: export the
  selected interpreter as `DESIRED_PYTHON_EXE` and drive all three pipeline
  steps through it, so deps and the wheel ABI tag match `DESIRED_PYTHON`.
- **XPU MKL availability.** `CMAKE_PREFIX_PATH` was assigned
  `<sys.prefix>/Library` (the pip `mkl-static`/`mkl-include` prefix) before
  the per-device setup ran, and the XPU oneAPI `vars.bat` then overwrote it
  with its own value -- so the XPU build configured BLAS as Eigen and
  `torch.backends.mkl.is_available()` was False (the smoke test asserts on
  it). cpu/cuda were unaffected because nothing else touches
  `CMAKE_PREFIX_PATH` there. Fix: set `CMAKE_PREFIX_PATH` after the device
  dispatch and prepend the MKL prefix to whatever the device contributed, so
  both the pip MKL and the oneAPI compiler prefix stay on the search path.

## Python patch pinning

`set_desired_python.sh` selects the python.org installer from an explicit
per-minor patch table (e.g. 3.13 -> 3.13.14) rather than the `.0` patch the
legacy `install_python.bat` used. The `.0` pin froze each minor on its
oldest, CVE-laden release; floating to the newest installer was rejected
because python.org serves source-only (no-installer) releases for
security-only minors, which would require scraping the release index and
HEAD-probing candidates on every build. Security-only minors (3.10-3.12) are
pinned to their last release that shipped a Windows installer; bugfix minors
(3.13, 3.14) point at the current newest installer and are bumped here in
review. The table must stay in sync with the matrix in
`generated-windows-binary-wheel-nightly.yml`.

## Divergences from the Linux template (pytorch#182409)

Where this PR deviates from the Linux pipeline, why:

- **No `repair_wheel.py` step.** Windows DLL discovery uses PATH /
  `AddDllDirectory` rather than RPATH, so there's nothing for patchelf to
  do. CUDA DLLs already ship inside `torch/lib/`. Wheel-content diff against
  the latest published nightly cpu wheel confirms parity: identical DLL set
  in `torch/lib/`.
- **`set_desired_python.sh` installs Python from python.org** rather than
  picking from a baked image (the Windows CI AMI doesn't ship Pythons
  preinstalled).
- **`build_env_setup.py` downloads MAGMA / sccache / randomtemp** during the
  build rather than baking them into a Docker image. (These downloads now go
  through `urllib` with default TLS verification, replacing the legacy
  `curl -k` which disabled cert checking.)
- **MKL comes from pip** (`mkl-static` / `mkl-include`), put on
  `CMAKE_PREFIX_PATH` via the `<sys.prefix>/Library` prefix, rather than the
  legacy `check_opts.bat` `LIB`/`MKLProductDir` system-MKL prepend.
- **No cuda-aarch64 / rocm / cpu-cxx11-abi branches** (not applicable on
  Windows).
- **`build_install_deps.py` hardcodes the pip dep list** (matches what
  `setup_build.bat` did) rather than reading `requirements*.txt` like Linux.
  Migrating to `requirements*.txt` is a worthwhile follow-up but out of scope
  here.

The binary-build env knobs the legacy chain set are preserved in
`COMMON_BUILD_ENV` (`PYTORCH_BINARY_BUILD`, `TH_BINARY_BUILD`, `BUILD_TEST=0`,
`INSTALL_TEST=0`, `MSSdk`, `DISTUTILS_USE_SDK`).

## Out of scope

- `windows-arm64` wheels (separate `arm64/build_pytorch.bat` chain,
  untouched).
- Windows pull-CI build (uses a separate `win-test-helpers/build_pytorch.bat`,
  untouched).
- `cpu-s390x` (Linux only).

## Test plan

Builds are green across the full x86_64 wheel matrix:

- [x] x86_64 cpu wheel build x Python 3.10-3.14 + 3.14t
- [x] x86_64 cuda wheel build (12.6, 13.0, 13.2) x the same Python set
- [x] x86_64 xpu wheel build x the same Python set
- [x] Wheel content verified equivalent to the published nightly cpu wheel
      (same DLL set in `torch/lib/`)
- [x] sccache enabled on CPU + CUDA host compilation; server lifecycle
      confirmed via build logs
- [x] cpu / cuda smoke tests (`wheel-*-test`) green
- [x] windows-arm64 wheel + libtorch builds unaffected (path goes through
      `arm64/build_pytorch.bat`, untouched)

Smoke-test status for the two build-correctness fixes above (free-threaded
ABI tag, XPU MKL) is being re-validated on the current head; the prior run
caught both at the `wheel-*-test` stage and the fixes target exactly those
failures.

Earlier-run note (resolved): the `cuda13_0` / `cuda13_2` wheel builds had
failed at the cuDNN download step because the
`cudnn-...-9.23.1.3_cuda13-archive.zip` object was briefly missing from
`ossci-windows` (uploaded ~19 min after the build fetched it). It is present
and valid now and the cuda13 builds are green; unrelated to this PR.

## Follow-ups (deferred, captured separately)

- **Migrate `build_install_deps.py` to read `requirements*.txt`** rather than
  hardcoded `PIP_PACKAGES`, matching the Linux pattern.
- Remaining self-review cleanup items: `CMAKE_GENERATOR` explicit for
  CPU/XPU, env-handoff fragilities, PATH conversion guard, numpy pin for a
  future Python 3.15, and bumping the python patch table / keeping it in sync
  with the wheel matrix.

Authored with [Claude Code](https://claude.com/claude-code).

Pull Request resolved: pytorch#184407
Approved by: https://github.com/atalman
vishalgoyal316 pushed a commit to vishalgoyal316/pytorch that referenced this pull request Jul 16, 2026
…#187944)

## Summary

Refactors the macOS arm64 CD wheel build from the monolithic `build_wheel.sh` into the same staged Python pipeline already adopted for Linux (pytorch#182409) and Windows (pytorch#184407). This is the third and final platform, bringing macOS in line with the cross-platform structure.

Following the Linux template, the build is split into four single-responsibility modules under `.ci/macwheel/`, driven by a per-Python `build.sh` orchestrator that owns the stage contract:

- `build_env_setup.py` — emits the macOS build flags (`USE_DISTRIBUTED`, deployment target, Metal/CoreML, libomp prefix) to an `--env-out` file the orchestrator sources
- `build_install_deps.py` — pinned build/runtime deps + numpy pin; libomp via Homebrew when not staged
- `build_wheel.py` — sets the arm64 host platform / `ARCHFLAGS` and runs `python -m build --wheel --no-isolation`
- `repair_wheel.py` — delocates the wheel in place (the macOS analog of Linux's `auditwheel`/patchelf; Windows needs no repair)

`build_all_macos_wheels.sh` selects each interpreter and loops, reusing the ABI-free `libtorch_cpu` across Python versions via `SKIP_SETUP_CLEAN` (same incremental-build trick as Linux).

### Notable points

- **macOS is arm64-only.** Main builds no Intel-Mac wheels (the matrix emits only `macos-arm64`), so the pipeline is arm64-only by design — and the dead `x86_64`/`BUILD_PYTHONLESS` libtorch branches in the old `build_wheel.sh` are removed. macOS still ships a libtorch artifact, but it is *extracted from the finished wheel* by a later workflow job (`.ci/libtorch/extract_libtorch_from_wheel.py`), not produced by a separate `BUILD_PYTHONLESS` build.
- **Delocation moves inline** into the per-Python build (`repair_wheel.py`), so the workflow drops its separate "Delocate all wheels" step.
- **Directory renamed** `.ci/wheel/` → `.ci/macwheel/`, parallel to Linux's `.ci/manywheel/` (the old name was too generic for a macOS-only build).
- `build_install_deps.py` uses **`spin clean`** rather than `setup.py clean`, matching Windows and surviving the eventual `setup.py` removal.

### Review order

1. `build.sh` (the stage contract), then the four stage modules
2. `build_all_macos_wheels.sh` and the workflow template
3. The second commit is a pure rename + `spin clean` switch

## Test Plan

Static + structural checks locally:

```
python3 -m py_compile .ci/macwheel/*.py
bash -n .ci/macwheel/build.sh .ci/macwheel/build_all_macos_wheels.sh
python3 .github/scripts/generate_ci_workflows.py   # only the macOS workflow changes
lintrunner .ci/macwheel/* .github/templates/macos_binary_build_workflow.yml.j2
```

A from-source build on a dev Mac exercised the pipeline through environment setup, dependency install, CMake configure, and compilation, confirming the orchestration contract (venv handoff, `--env-out` sourcing, `python -m build` invocation). End-to-end wheel production + delocation is validated by this PR's `ciflow/binaries` run on the `macos-arm64` runner.

Opening as a draft for a first round of CI.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Pull Request resolved: pytorch#187944
Approved by: https://github.com/atalman
DamJanusz pushed a commit to DamJanusz/pytorch that referenced this pull request Jul 21, 2026
…#187944)

## Summary

Refactors the macOS arm64 CD wheel build from the monolithic `build_wheel.sh` into the same staged Python pipeline already adopted for Linux (pytorch#182409) and Windows (pytorch#184407). This is the third and final platform, bringing macOS in line with the cross-platform structure.

Following the Linux template, the build is split into four single-responsibility modules under `.ci/macwheel/`, driven by a per-Python `build.sh` orchestrator that owns the stage contract:

- `build_env_setup.py` — emits the macOS build flags (`USE_DISTRIBUTED`, deployment target, Metal/CoreML, libomp prefix) to an `--env-out` file the orchestrator sources
- `build_install_deps.py` — pinned build/runtime deps + numpy pin; libomp via Homebrew when not staged
- `build_wheel.py` — sets the arm64 host platform / `ARCHFLAGS` and runs `python -m build --wheel --no-isolation`
- `repair_wheel.py` — delocates the wheel in place (the macOS analog of Linux's `auditwheel`/patchelf; Windows needs no repair)

`build_all_macos_wheels.sh` selects each interpreter and loops, reusing the ABI-free `libtorch_cpu` across Python versions via `SKIP_SETUP_CLEAN` (same incremental-build trick as Linux).

### Notable points

- **macOS is arm64-only.** Main builds no Intel-Mac wheels (the matrix emits only `macos-arm64`), so the pipeline is arm64-only by design — and the dead `x86_64`/`BUILD_PYTHONLESS` libtorch branches in the old `build_wheel.sh` are removed. macOS still ships a libtorch artifact, but it is *extracted from the finished wheel* by a later workflow job (`.ci/libtorch/extract_libtorch_from_wheel.py`), not produced by a separate `BUILD_PYTHONLESS` build.
- **Delocation moves inline** into the per-Python build (`repair_wheel.py`), so the workflow drops its separate "Delocate all wheels" step.
- **Directory renamed** `.ci/wheel/` → `.ci/macwheel/`, parallel to Linux's `.ci/manywheel/` (the old name was too generic for a macOS-only build).
- `build_install_deps.py` uses **`spin clean`** rather than `setup.py clean`, matching Windows and surviving the eventual `setup.py` removal.

### Review order

1. `build.sh` (the stage contract), then the four stage modules
2. `build_all_macos_wheels.sh` and the workflow template
3. The second commit is a pure rename + `spin clean` switch

## Test Plan

Static + structural checks locally:

```
python3 -m py_compile .ci/macwheel/*.py
bash -n .ci/macwheel/build.sh .ci/macwheel/build_all_macos_wheels.sh
python3 .github/scripts/generate_ci_workflows.py   # only the macOS workflow changes
lintrunner .ci/macwheel/* .github/templates/macos_binary_build_workflow.yml.j2
```

A from-source build on a dev Mac exercised the pipeline through environment setup, dependency install, CMake configure, and compilation, confirming the orchestration contract (venv handoff, `--env-out` sourcing, `python -m build` invocation). End-to-end wheel production + delocation is validated by this PR's `ciflow/binaries` run on the `macos-arm64` runner.

Opening as a draft for a first round of CI.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Pull Request resolved: pytorch#187944
Approved by: https://github.com/atalman
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…repair) (pytorch#182409)

Split the monolithic .ci/manywheel/build_cuda.sh and the duplicated
sections of build_cpu.sh / build_common.sh into focused, reusable
scripts:

- build_env_setup.sh    GPU/toolchain environment setup (CUDA, ROCm, XPU)
- build_install_deps.sh shared build-time dependency install
- build_wheel.sh        the actual wheel build (python -m build)
- repair_wheel.sh       auditwheel-style repair using the `wheel` python
                        package (unpack/pack/tags), bundling aarch64
                        BLAS/LAPACK/ACL when needed

Drops build_cuda.sh (its logic is now in build_env_setup.sh +
build_wheel.sh) and trims x86/aarch64-specific branches out of
build_cpu.sh / build_common.sh. The legacy entry point .ci/manywheel/build.sh
now dispatches x86/aarch64 cuda/cpu through the new chain
(set_desired_python -> build_env_setup -> build_install_deps -> build_wheel
-> repair_wheel) and keeps rocm/xpu/cpu-s390x on the legacy build_*.sh
helpers.

Also drops obsolete numpy version pins in .ci/pytorch/run_tests.sh.

The matching workflow / Jinja-template rework that originally lived in
this branch is no longer needed -- the matrix-driven binary workflows
already landed via pytorch#181586 (and follow-ups pytorch#181599, pytorch#182018), so the
new scripts plug into the existing _binary-build-linux.yml.

Authored with Claude.
Pull Request resolved: pytorch#182409
Approved by: https://github.com/seemethere, https://github.com/huydhn
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…ytorch#183320)

## Summary

Follow-up to pytorch#182409, addressing the review observation that the new `build_env_setup.py` duplicated the OS-package list already baked into the manywheel builder image (`.ci/docker/manywheel/Dockerfile_2_28`), with no CI use case for the duplication. The drift risk between the Dockerfile and the Python script and the broadened wheel-build-time supply-chain surface (fresh yum/apt fetches vs. the image's frozen baseline) provide no benefit on the standard CI path.

This PR restores the legacy "trust the image" contract for the OS-package list only:

- `install_os_packages` now installs only `zip` + `openssl` on RHEL/Ubuntu (the original `build_common.sh` set). All other yum/apt packages come from `Dockerfile_2_28` at image-build time.
- The nvidia-apt list mangling on Ubuntu is removed (no longer needed once the install set is trimmed).

The CUDA + MAGMA + MKL bootstrap paths (`install_cuda_toolkit`, the `install_magma.sh` fallback in `setup_cuda`, and the `install_mkl.sh` fallback in `main()`) are kept so the script remains usable on a lean manylinux base when those toolkits aren't already staged.

Net diff: 1 file, +15 / -42.

Authored with Claude.

## Test plan

- [ ] Nightly manywheel CUDA / CPU / aarch64 build jobs (Linux) succeed.
- [ ] No regressions from the trimmed OS-package install on Dockerfile_2_28.
Pull Request resolved: pytorch#183320
Approved by: https://github.com/malfet
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
## Summary

Port the XPU manylinux build from the legacy bash scripts (`build_xpu.sh` + `build_common.sh`) to the Python pipeline (`build_env_setup.py` + `build_install_deps.py` + `build_wheel.py` + `repair_wheel.py`), following the same pattern as pytorch#182409 (CUDA/CPU) and pytorch#182696 (ROCm).

- Add `XPU_BUILD_ENV` and `source_oneapi_env()` to `build_env_setup.py` to source Intel oneAPI environment and set build flags
- Always build small wheel for XPU, following the same practice as CUDA
- Add XPU RPATH handling in `repair_wheel.py` (following CUDA pattern — runtime libs from pypi packages)
- XPU wheels are now retagged to `manylinux_2_28_x86_64`
- Delete `build_xpu.sh`

cpu-s390x continues to flow through `build_common.sh` unchanged.

Pull Request resolved: pytorch#182942
Approved by: https://github.com/atalman
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…184407)

## Summary

Port the Windows x86_64 wheel CD build off the legacy `.bat` chain onto a
Python pipeline, mirroring the Linux split landed in pytorch#182409. CPU, CUDA, and
XPU wheel builds now run through a small set of Python scripts instead of the
`build_pytorch.bat -> cpu/cuda/xpu.bat -> internal/setup.bat` chain.

The new entry chain on x86_64 wheel builds:

```
binary_windows_build.sh
  -> windows/internal/vc_install_helper.bat   (ensure VS2022 BuildTools)
  -> windows/set_desired_python.sh            (install Python.org Python)
  -> python windows/build_env_setup.py        (vcvarsall + CUDA/XPU env + MAGMA + sccache)
  -> python windows/build_install_deps.py     (pip deps + libuv)
  -> python windows/build_wheel.py            (python -m build --wheel)
```

The three Python steps are driven through the interpreter
`set_desired_python.sh` selected (exported as `DESIRED_PYTHON_EXE`), not a
bare `python`, so the wheel ABI tag and pip build deps track
`DESIRED_PYTHON` for free-threaded builds (see Build-correctness fixes).

vcvarsall env capture mirrors `torch.utils.cpp_extension._jit._get_vc_env`
from pytorch#180707 (vswhere discovery, `cmd /u /c` for UTF-16LE output, diff
against current env so additions layer on top).

`internal/cuda_install.bat`, `internal/xpu_install.bat`, and
`internal/vc_install_helper.bat` are kept as Python/bash-invoked installers --
same pragmatic precedent as the Linux refactor (`install_cuda.sh` etc.).
Heavy installer logic stays in bash/cmd; orchestration moves to Python.
`set_desired_python.sh` inlines what `internal/install_python.bat` did (the
`bash -> cmd /c` boundary was unreliable for the python.org installer), so
the wheel path no longer invokes `install_python.bat`.

## Removing the legacy bat chain

The x86_64 wheel build was the last consumer of the legacy
`build_pytorch.bat -> {cpu,cuda,xpu}.bat -> internal/setup.bat` chain, so
porting it to the Python pipeline lets that chain go. This PR deletes:

- `build_pytorch.bat`, `cpu/cuda/xpu.bat`, `setup_build.bat`, and
  `internal/{build_wheels,check_deps,check_nvtx,check_opts,clean,clone,
  cuda_config,init,setup}.bat`.

These are now orphaned -- nothing in the tree invokes them. The only
remaining mentions are provenance comments in the new Python scripts (e.g.
"Mirrors the MAGMA block in the legacy build_pytorch.bat"), plus the separate
`arm64/build_pytorch.bat` and `win-test-helpers/build_pytorch.bat`, which are
different files left untouched.

Note on debug libtorch: upstream has already stopped shipping the Windows
debug libtorch builds and removed their nightly workflows, and this branch is
rebased on top of that -- so it carries no `.github/workflows` or
`generate_ci_workflows.py` changes. (Earlier revisions of this PR removed
those workflows here; those commits were dropped in the rebase once the
upstream removal landed.) The release path is unaffected: release libtorch is
still produced by extraction from the release wheel
(`extract_libtorch_from_wheel.py`, the same mechanism as on Linux), and those
wheels are now built by this Python pipeline.

## Build-correctness fixes (surfaced by the wheel smoke tests)

With the builds green, the `wheel-*-test` smoke jobs ran and caught two gaps
the legacy bat chain had handled implicitly:

- **Free-threaded wheels (`DESIRED_PYTHON=3.14t`).** A free-threaded
  python.org install ships both `python.exe` and `python3.14t.exe` under the
  same prefix, so a bare `python` resolved to the regular interpreter and
  `python -m build` produced a `cp314` wheel that the `cp314t` test job
  rejected ("not a supported wheel on this platform"). Fix: export the
  selected interpreter as `DESIRED_PYTHON_EXE` and drive all three pipeline
  steps through it, so deps and the wheel ABI tag match `DESIRED_PYTHON`.
- **XPU MKL availability.** `CMAKE_PREFIX_PATH` was assigned
  `<sys.prefix>/Library` (the pip `mkl-static`/`mkl-include` prefix) before
  the per-device setup ran, and the XPU oneAPI `vars.bat` then overwrote it
  with its own value -- so the XPU build configured BLAS as Eigen and
  `torch.backends.mkl.is_available()` was False (the smoke test asserts on
  it). cpu/cuda were unaffected because nothing else touches
  `CMAKE_PREFIX_PATH` there. Fix: set `CMAKE_PREFIX_PATH` after the device
  dispatch and prepend the MKL prefix to whatever the device contributed, so
  both the pip MKL and the oneAPI compiler prefix stay on the search path.

## Python patch pinning

`set_desired_python.sh` selects the python.org installer from an explicit
per-minor patch table (e.g. 3.13 -> 3.13.14) rather than the `.0` patch the
legacy `install_python.bat` used. The `.0` pin froze each minor on its
oldest, CVE-laden release; floating to the newest installer was rejected
because python.org serves source-only (no-installer) releases for
security-only minors, which would require scraping the release index and
HEAD-probing candidates on every build. Security-only minors (3.10-3.12) are
pinned to their last release that shipped a Windows installer; bugfix minors
(3.13, 3.14) point at the current newest installer and are bumped here in
review. The table must stay in sync with the matrix in
`generated-windows-binary-wheel-nightly.yml`.

## Divergences from the Linux template (pytorch#182409)

Where this PR deviates from the Linux pipeline, why:

- **No `repair_wheel.py` step.** Windows DLL discovery uses PATH /
  `AddDllDirectory` rather than RPATH, so there's nothing for patchelf to
  do. CUDA DLLs already ship inside `torch/lib/`. Wheel-content diff against
  the latest published nightly cpu wheel confirms parity: identical DLL set
  in `torch/lib/`.
- **`set_desired_python.sh` installs Python from python.org** rather than
  picking from a baked image (the Windows CI AMI doesn't ship Pythons
  preinstalled).
- **`build_env_setup.py` downloads MAGMA / sccache / randomtemp** during the
  build rather than baking them into a Docker image. (These downloads now go
  through `urllib` with default TLS verification, replacing the legacy
  `curl -k` which disabled cert checking.)
- **MKL comes from pip** (`mkl-static` / `mkl-include`), put on
  `CMAKE_PREFIX_PATH` via the `<sys.prefix>/Library` prefix, rather than the
  legacy `check_opts.bat` `LIB`/`MKLProductDir` system-MKL prepend.
- **No cuda-aarch64 / rocm / cpu-cxx11-abi branches** (not applicable on
  Windows).
- **`build_install_deps.py` hardcodes the pip dep list** (matches what
  `setup_build.bat` did) rather than reading `requirements*.txt` like Linux.
  Migrating to `requirements*.txt` is a worthwhile follow-up but out of scope
  here.

The binary-build env knobs the legacy chain set are preserved in
`COMMON_BUILD_ENV` (`PYTORCH_BINARY_BUILD`, `TH_BINARY_BUILD`, `BUILD_TEST=0`,
`INSTALL_TEST=0`, `MSSdk`, `DISTUTILS_USE_SDK`).

## Out of scope

- `windows-arm64` wheels (separate `arm64/build_pytorch.bat` chain,
  untouched).
- Windows pull-CI build (uses a separate `win-test-helpers/build_pytorch.bat`,
  untouched).
- `cpu-s390x` (Linux only).

## Test plan

Builds are green across the full x86_64 wheel matrix:

- [x] x86_64 cpu wheel build x Python 3.10-3.14 + 3.14t
- [x] x86_64 cuda wheel build (12.6, 13.0, 13.2) x the same Python set
- [x] x86_64 xpu wheel build x the same Python set
- [x] Wheel content verified equivalent to the published nightly cpu wheel
      (same DLL set in `torch/lib/`)
- [x] sccache enabled on CPU + CUDA host compilation; server lifecycle
      confirmed via build logs
- [x] cpu / cuda smoke tests (`wheel-*-test`) green
- [x] windows-arm64 wheel + libtorch builds unaffected (path goes through
      `arm64/build_pytorch.bat`, untouched)

Smoke-test status for the two build-correctness fixes above (free-threaded
ABI tag, XPU MKL) is being re-validated on the current head; the prior run
caught both at the `wheel-*-test` stage and the fixes target exactly those
failures.

Earlier-run note (resolved): the `cuda13_0` / `cuda13_2` wheel builds had
failed at the cuDNN download step because the
`cudnn-...-9.23.1.3_cuda13-archive.zip` object was briefly missing from
`ossci-windows` (uploaded ~19 min after the build fetched it). It is present
and valid now and the cuda13 builds are green; unrelated to this PR.

## Follow-ups (deferred, captured separately)

- **Migrate `build_install_deps.py` to read `requirements*.txt`** rather than
  hardcoded `PIP_PACKAGES`, matching the Linux pattern.
- Remaining self-review cleanup items: `CMAKE_GENERATOR` explicit for
  CPU/XPU, env-handoff fragilities, PATH conversion guard, numpy pin for a
  future Python 3.15, and bumping the python patch table / keeping it in sync
  with the wheel matrix.

Authored with [Claude Code](https://claude.com/claude-code).

Pull Request resolved: pytorch#184407
Approved by: https://github.com/atalman
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…#187944)

## Summary

Refactors the macOS arm64 CD wheel build from the monolithic `build_wheel.sh` into the same staged Python pipeline already adopted for Linux (pytorch#182409) and Windows (pytorch#184407). This is the third and final platform, bringing macOS in line with the cross-platform structure.

Following the Linux template, the build is split into four single-responsibility modules under `.ci/macwheel/`, driven by a per-Python `build.sh` orchestrator that owns the stage contract:

- `build_env_setup.py` — emits the macOS build flags (`USE_DISTRIBUTED`, deployment target, Metal/CoreML, libomp prefix) to an `--env-out` file the orchestrator sources
- `build_install_deps.py` — pinned build/runtime deps + numpy pin; libomp via Homebrew when not staged
- `build_wheel.py` — sets the arm64 host platform / `ARCHFLAGS` and runs `python -m build --wheel --no-isolation`
- `repair_wheel.py` — delocates the wheel in place (the macOS analog of Linux's `auditwheel`/patchelf; Windows needs no repair)

`build_all_macos_wheels.sh` selects each interpreter and loops, reusing the ABI-free `libtorch_cpu` across Python versions via `SKIP_SETUP_CLEAN` (same incremental-build trick as Linux).

### Notable points

- **macOS is arm64-only.** Main builds no Intel-Mac wheels (the matrix emits only `macos-arm64`), so the pipeline is arm64-only by design — and the dead `x86_64`/`BUILD_PYTHONLESS` libtorch branches in the old `build_wheel.sh` are removed. macOS still ships a libtorch artifact, but it is *extracted from the finished wheel* by a later workflow job (`.ci/libtorch/extract_libtorch_from_wheel.py`), not produced by a separate `BUILD_PYTHONLESS` build.
- **Delocation moves inline** into the per-Python build (`repair_wheel.py`), so the workflow drops its separate "Delocate all wheels" step.
- **Directory renamed** `.ci/wheel/` → `.ci/macwheel/`, parallel to Linux's `.ci/manywheel/` (the old name was too generic for a macOS-only build).
- `build_install_deps.py` uses **`spin clean`** rather than `setup.py clean`, matching Windows and surviving the eventual `setup.py` removal.

### Review order

1. `build.sh` (the stage contract), then the four stage modules
2. `build_all_macos_wheels.sh` and the workflow template
3. The second commit is a pure rename + `spin clean` switch

## Test Plan

Static + structural checks locally:

```
python3 -m py_compile .ci/macwheel/*.py
bash -n .ci/macwheel/build.sh .ci/macwheel/build_all_macos_wheels.sh
python3 .github/scripts/generate_ci_workflows.py   # only the macOS workflow changes
lintrunner .ci/macwheel/* .github/templates/macos_binary_build_workflow.yml.j2
```

A from-source build on a dev Mac exercised the pipeline through environment setup, dependency install, CMake configure, and compilation, confirming the orchestration contract (venv handoff, `--env-out` sourcing, `python -m build` invocation). End-to-end wheel production + delocation is validated by this PR's `ciflow/binaries` run on the `macos-arm64` runner.

Opening as a draft for a first round of CI.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Pull Request resolved: pytorch#187944
Approved by: https://github.com/atalman
zklaus added a commit to zklaus/pytorch that referenced this pull request Aug 25, 2026
Fourth consolidation step, and the point of the exercise: the three CD
wheel pipelines carried copy-pasted helpers and three drifted numpy pin
tables. Extract .ci/wheel/_common.py (retry, pip_install, numpy_pin,
shell_quote, write_env_exports, download) and have the three
build_install_deps.py import from it. The Windows _common.py, already the
most complete, is promoted to the shared location; its write_env_exports
(POSIX PATH conversion + bash-identifier filter) is a safe superset -- the
PATH branch is a no-op where PATH has no ';' (Linux/macOS), and the filter
only skips keys bash could never source anyway.

numpy pin -- the tables disagreed for every Python, and Linux's greedy
`cp31` prefix silently overrode its own 2.0.2 default for 3.10-3.12 (and
mis-pinned 3.15). Replaced with one explicit dict + fail-loud (the macOS
design). Each entry is the oldest numpy *minor* that ships a wheel for that
interpreter (verified on PyPI -- widest runtime-numpy range), pinned at the
newest *patch* of that minor already shipped in production by one of the
platforms, so the reconciliation drops no numpy bugfix:

    3.10/3.11/3.12 -> 2.0.2   3.13 -> 2.1.2   3.14 -> 2.3.4

The only genuine floor change is Linux 3.10-3.12 (2.1.0 -> 2.0.2), undoing
the greedy-prefix accident to match the 2.0.2 that Windows and macOS already
use there; 3.13 and 3.14 converge on the newer of the two patches in use
(Windows' 2.1.2, Linux/macOS' 2.3.4 -- the latter is numpy's 3.14.0-final
release). A read of the 2.1.1/2.1.2 and 2.3.3/2.3.4 notes confirmed the
dropped-vs-kept patch deltas are numpy-internal runtime or numpy's-own-build
fixes, none touching the C-API surface torch compiles against. 3.15 has no
numpy wheels yet, so it now fails loudly everywhere instead of silently
building an unusable pin. Provenance (pytorchgh-182409/184407/187944) found none of
the original drift deliberate; Linux's incidental `--pre` is dropped (every
pin is an exact stable release).

These pipelines run only in the nightly CD workflows, which this PR's CI
does not exercise; verified by import/path simulation, the numpy table
against PyPI, and lint rather than a green build. build_env_setup.py on
Linux/macOS still carry their own shell_quote/write_env_exports copies;
deduping those is the next commit.

## Test plan

```
# helpers resolve + table is the evidence-based one
python - <<'PY'
import importlib.util as u
m=u.module_from_spec(s:=u.spec_from_file_location("_common",".ci/wheel/_common.py")); s.loader.exec_module(m)
assert m.NUMPY_PINS=={"3.10":"2.0.2","3.11":"2.0.2","3.12":"2.0.2","3.13":"2.1.2","3.14":"2.3.4","3.15":"2.5.2"}
assert all(hasattr(m,h) for h in ["retry","pip_install","numpy_pin","download","write_env_exports","shell_quote"])
PY
# each pipeline resolves _common via its own sys.path math (parents[1] == .ci/wheel)
lintrunner .ci/wheel/_common.py .ci/wheel/*/build_install_deps.py .ci/wheel/windows/build_env_setup.py
```

Authored with assistance from Claude Code.
zklaus added a commit to zklaus/pytorch that referenced this pull request Aug 25, 2026
Fourth consolidation step, and the point of the exercise: the three CD
wheel pipelines carried copy-pasted helpers and three drifted numpy pin
tables. Extract .ci/wheel/_common.py (retry, pip_install, numpy_pin,
shell_quote, write_env_exports, download) and have the three
build_install_deps.py import from it. The Windows _common.py, already the
most complete, is promoted to the shared location; its write_env_exports
(POSIX PATH conversion + bash-identifier filter) is a safe superset -- the
PATH branch is a no-op where PATH has no ';' (Linux/macOS), and the filter
only skips keys bash could never source anyway.

numpy pin -- the tables disagreed for every Python, and Linux's greedy
`cp31` prefix silently overrode its own 2.0.2 default for 3.10-3.12 (and
mis-pinned 3.15). Replaced with one explicit dict + fail-loud (the macOS
design). Each entry is the oldest numpy *minor* that ships a wheel for that
interpreter (verified on PyPI -- widest runtime-numpy range), pinned at the
newest *patch* of that minor already shipped in production by one of the
platforms, so the reconciliation drops no numpy bugfix:

    3.10/3.11/3.12 -> 2.0.2   3.13 -> 2.1.2   3.14 -> 2.3.4

The only genuine floor change is Linux 3.10-3.12 (2.1.0 -> 2.0.2), undoing
the greedy-prefix accident to match the 2.0.2 that Windows and macOS already
use there; 3.13 and 3.14 converge on the newer of the two patches in use
(Windows' 2.1.2, Linux/macOS' 2.3.4 -- the latter is numpy's 3.14.0-final
release). A read of the 2.1.1/2.1.2 and 2.3.3/2.3.4 notes confirmed the
dropped-vs-kept patch deltas are numpy-internal runtime or numpy's-own-build
fixes, none touching the C-API surface torch compiles against. 3.15 has no
numpy wheels yet, so it now fails loudly everywhere instead of silently
building an unusable pin. Provenance (pytorchgh-182409/184407/187944) found none of
the original drift deliberate; Linux's incidental `--pre` is dropped (every
pin is an exact stable release).

These pipelines run only in the nightly CD workflows, which this PR's CI
does not exercise; verified by import/path simulation, the numpy table
against PyPI, and lint rather than a green build. build_env_setup.py on
Linux/macOS still carry their own shell_quote/write_env_exports copies;
deduping those is the next commit.

## Test plan

```
# helpers resolve + table is the evidence-based one
python - <<'PY'
import importlib.util as u
m=u.module_from_spec(s:=u.spec_from_file_location("_common",".ci/wheel/_common.py")); s.loader.exec_module(m)
assert m.NUMPY_PINS=={"3.10":"2.0.2","3.11":"2.0.2","3.12":"2.0.2","3.13":"2.1.2","3.14":"2.3.4","3.15":"2.5.2"}
assert all(hasattr(m,h) for h in ["retry","pip_install","numpy_pin","download","write_env_exports","shell_quote"])
PY
# each pipeline resolves _common via its own sys.path math (parents[1] == .ci/wheel)
lintrunner .ci/wheel/_common.py .ci/wheel/*/build_install_deps.py .ci/wheel/windows/build_env_setup.py
```

Authored with assistance from Claude Code.
zklaus added a commit to zklaus/pytorch that referenced this pull request Sep 8, 2026
Fourth consolidation step, and the point of the exercise: the three CD
wheel pipelines carried copy-pasted helpers and three drifted numpy pin
tables. Extract .ci/wheel/_common.py (retry, pip_install, numpy_pin,
shell_quote, write_env_exports, download) and have the three
build_install_deps.py import from it. The Windows _common.py, already the
most complete, is promoted to the shared location; its write_env_exports
(POSIX PATH conversion + bash-identifier filter) is a safe superset -- the
PATH branch is a no-op where PATH has no ';' (Linux/macOS), and the filter
only skips keys bash could never source anyway.

numpy pin -- the tables disagreed for every Python, and Linux's greedy
`cp31` prefix silently overrode its own 2.0.2 default for 3.10-3.12 (and
mis-pinned 3.15). Replaced with one explicit dict + fail-loud (the macOS
design). Each entry is the oldest numpy *minor* that ships a wheel for that
interpreter (verified on PyPI -- widest runtime-numpy range), pinned at the
newest *patch* of that minor already shipped in production by one of the
platforms, so the reconciliation drops no numpy bugfix:

    3.10/3.11/3.12 -> 2.0.2   3.13 -> 2.1.2   3.14 -> 2.3.4   3.15 -> 2.5.2

The only genuine floor change is Linux 3.10-3.12 (2.1.0 -> 2.0.2), undoing
the greedy-prefix accident to match the 2.0.2 that Windows and macOS already
use there; 3.13 and 3.14 converge on the newer of the two patches in use
(Windows' 2.1.2, Linux/macOS' 2.3.4 -- the latter is numpy's 3.14.0-final
release). A read of the 2.1.1/2.1.2 and 2.3.3/2.3.4 notes confirmed the
dropped-vs-kept patch deltas are numpy-internal runtime or numpy's-own-build
fixes, none touching the C-API surface torch compiles against. 3.15 takes
2.5.2, the first numpy with cp315 wheels and the pin every platform now
carries upstream (pytorch#194618, pytorch#194734, pytorch#194741). Provenance
(pytorchgh-182409/184407/187944) found none of the original drift deliberate;
Linux's incidental `--pre` is dropped (every pin is an exact stable release).

These pipelines run only in the nightly CD workflows, which this PR's CI
does not exercise; verified by import/path simulation, the numpy table
against PyPI, and lint rather than a green build. build_env_setup.py on
Linux/macOS still carry their own shell_quote/write_env_exports copies;
deduping those is the next commit.

```
python - <<'PY'
import importlib.util as u
m=u.module_from_spec(s:=u.spec_from_file_location("_common",".ci/wheel/_common.py")); s.loader.exec_module(m)
assert m.NUMPY_PINS=={"3.10":"2.0.2","3.11":"2.0.2","3.12":"2.0.2","3.13":"2.1.2","3.14":"2.3.4","3.15":"2.5.2"}
assert all(hasattr(m,h) for h in ["retry","pip_install","numpy_pin","download","write_env_exports","shell_quote"])
PY
lintrunner .ci/wheel/_common.py .ci/wheel/*/build_install_deps.py .ci/wheel/windows/build_env_setup.py
```

Authored with assistance from Claude Code.
zklaus added a commit to zklaus/pytorch that referenced this pull request Sep 11, 2026
Fourth consolidation step, and the point of the exercise: the three CD
wheel pipelines carried copy-pasted helpers and three drifted numpy pin
tables. Extract .ci/wheel/_common.py (retry, pip_install, numpy_pin,
shell_quote, write_env_exports, download) and have the three
build_install_deps.py import from it. The Windows _common.py, already the
most complete, is promoted to the shared location; its write_env_exports
(POSIX PATH conversion + bash-identifier filter) is a safe superset -- the
PATH branch is a no-op where PATH has no ';' (Linux/macOS), and the filter
only skips keys bash could never source anyway.

numpy pin -- the tables disagreed for every Python, and Linux's greedy
`cp31` prefix silently overrode its own 2.0.2 default for 3.10-3.12 (and
mis-pinned 3.15). Replaced with one explicit dict + fail-loud (the macOS
design). Each entry is the oldest numpy *minor* that ships a wheel for that
interpreter (verified on PyPI -- widest runtime-numpy range), pinned at the
newest *patch* of that minor already shipped in production by one of the
platforms, so the reconciliation drops no numpy bugfix:

    3.10/3.11/3.12 -> 2.0.2   3.13 -> 2.1.2   3.14 -> 2.3.4   3.15 -> 2.5.2

The only genuine floor change is Linux 3.10-3.12 (2.1.0 -> 2.0.2), undoing
the greedy-prefix accident to match the 2.0.2 that Windows and macOS already
use there; 3.13 and 3.14 converge on the newer of the two patches in use
(Windows' 2.1.2, Linux/macOS' 2.3.4 -- the latter is numpy's 3.14.0-final
release). A read of the 2.1.1/2.1.2 and 2.3.3/2.3.4 notes confirmed the
dropped-vs-kept patch deltas are numpy-internal runtime or numpy's-own-build
fixes, none touching the C-API surface torch compiles against. 3.15 takes
2.5.2, the first numpy with cp315 wheels and the pin every platform now
carries upstream (pytorch#194618, pytorch#194734, pytorch#194741). Provenance
(pytorchgh-182409/184407/187944) found none of the original drift deliberate;
Linux's incidental `--pre` is dropped (every pin is an exact stable release).

These pipelines run only in the nightly CD workflows, which this PR's CI
does not exercise; verified by import/path simulation, the numpy table
against PyPI, and lint rather than a green build. build_env_setup.py on
Linux/macOS still carry their own shell_quote/write_env_exports copies;
deduping those is the next commit.

```
python - <<'PY'
import importlib.util as u
m=u.module_from_spec(s:=u.spec_from_file_location("_common",".ci/wheel/_common.py")); s.loader.exec_module(m)
assert m.NUMPY_PINS=={"3.10":"2.0.2","3.11":"2.0.2","3.12":"2.0.2","3.13":"2.1.2","3.14":"2.3.4","3.15":"2.5.2"}
assert all(hasattr(m,h) for h in ["retry","pip_install","numpy_pin","download","write_env_exports","shell_quote"])
PY
lintrunner .ci/wheel/_common.py .ci/wheel/*/build_install_deps.py .ci/wheel/windows/build_env_setup.py
```

Authored with assistance from Claude Code.
zklaus added a commit to zklaus/pytorch that referenced this pull request Sep 16, 2026
Fourth consolidation step, and the point of the exercise: the three CD
wheel pipelines carried copy-pasted helpers and three drifted numpy pin
tables. Extract .ci/wheel/_common.py (retry, pip_install, numpy_pin,
shell_quote, write_env_exports, download) and have the three
build_install_deps.py import from it. The Windows _common.py, already the
most complete, is promoted to the shared location; its write_env_exports
(POSIX PATH conversion + bash-identifier filter) is a safe superset -- the
PATH branch is a no-op where PATH has no ';' (Linux/macOS), and the filter
only skips keys bash could never source anyway.

numpy pin -- the tables disagreed for every Python, and Linux's greedy
`cp31` prefix silently overrode its own 2.0.2 default for 3.10-3.12 (and
mis-pinned 3.15). Replaced with one explicit dict + fail-loud (the macOS
design). Each entry is the oldest numpy *minor* that ships a wheel for that
interpreter (verified on PyPI -- widest runtime-numpy range), pinned at the
newest *patch* of that minor already shipped in production by one of the
platforms, so the reconciliation drops no numpy bugfix:

    3.10/3.11/3.12 -> 2.0.2   3.13 -> 2.1.2   3.14 -> 2.3.4   3.15 -> 2.5.2

The only genuine floor change is Linux 3.10-3.12 (2.1.0 -> 2.0.2), undoing
the greedy-prefix accident to match the 2.0.2 that Windows and macOS already
use there; 3.13 and 3.14 converge on the newer of the two patches in use
(Windows' 2.1.2, Linux/macOS' 2.3.4 -- the latter is numpy's 3.14.0-final
release). A read of the 2.1.1/2.1.2 and 2.3.3/2.3.4 notes confirmed the
dropped-vs-kept patch deltas are numpy-internal runtime or numpy's-own-build
fixes, none touching the C-API surface torch compiles against. 3.15 takes
2.5.2, the first numpy with cp315 wheels and the pin every platform now
carries upstream (pytorch#194618, pytorch#194734, pytorch#194741). Provenance
(pytorchgh-182409/184407/187944) found none of the original drift deliberate;
Linux's incidental `--pre` is dropped (every pin is an exact stable release).

These pipelines run only in the nightly CD workflows, which this PR's CI
does not exercise; verified by import/path simulation, the numpy table
against PyPI, and lint rather than a green build. build_env_setup.py on
Linux/macOS still carry their own shell_quote/write_env_exports copies;
deduping those is the next commit.

```
python - <<'PY'
import importlib.util as u
m=u.module_from_spec(s:=u.spec_from_file_location("_common",".ci/wheel/_common.py")); s.loader.exec_module(m)
assert m.NUMPY_PINS=={"3.10":"2.0.2","3.11":"2.0.2","3.12":"2.0.2","3.13":"2.1.2","3.14":"2.3.4","3.15":"2.5.2"}
assert all(hasattr(m,h) for h in ["retry","pip_install","numpy_pin","download","write_env_exports","shell_quote"])
PY
lintrunner .ci/wheel/_common.py .ci/wheel/*/build_install_deps.py .ci/wheel/windows/build_env_setup.py
```

Authored with assistance from Claude Code.
pytorchmergebot pushed a commit to zklaus/pytorch that referenced this pull request Sep 16, 2026
Fourth consolidation step, and the point of the exercise: the three CD
wheel pipelines carried copy-pasted helpers and three drifted numpy pin
tables. Extract .ci/wheel/_common.py (retry, pip_install, numpy_pin,
shell_quote, write_env_exports, download) and have the three
build_install_deps.py import from it. The Windows _common.py, already the
most complete, is promoted to the shared location; its write_env_exports
(POSIX PATH conversion + bash-identifier filter) is a safe superset -- the
PATH branch is a no-op where PATH has no ';' (Linux/macOS), and the filter
only skips keys bash could never source anyway.

numpy pin -- the tables disagreed for every Python, and Linux's greedy
`cp31` prefix silently overrode its own 2.0.2 default for 3.10-3.12 (and
mis-pinned 3.15). Replaced with one explicit dict + fail-loud (the macOS
design). Each entry is the oldest numpy *minor* that ships a wheel for that
interpreter (verified on PyPI -- widest runtime-numpy range), pinned at the
newest *patch* of that minor already shipped in production by one of the
platforms, so the reconciliation drops no numpy bugfix:

    3.10/3.11/3.12 -> 2.0.2   3.13 -> 2.1.2   3.14 -> 2.3.4   3.15 -> 2.5.2

The only genuine floor change is Linux 3.10-3.12 (2.1.0 -> 2.0.2), undoing
the greedy-prefix accident to match the 2.0.2 that Windows and macOS already
use there; 3.13 and 3.14 converge on the newer of the two patches in use
(Windows' 2.1.2, Linux/macOS' 2.3.4 -- the latter is numpy's 3.14.0-final
release). A read of the 2.1.1/2.1.2 and 2.3.3/2.3.4 notes confirmed the
dropped-vs-kept patch deltas are numpy-internal runtime or numpy's-own-build
fixes, none touching the C-API surface torch compiles against. 3.15 takes
2.5.2, the first numpy with cp315 wheels and the pin every platform now
carries upstream (pytorch#194618, pytorch#194734, pytorch#194741). Provenance
(pytorchgh-182409/184407/187944) found none of the original drift deliberate;
Linux's incidental `--pre` is dropped (every pin is an exact stable release).

These pipelines run only in the nightly CD workflows, which this PR's CI
does not exercise; verified by import/path simulation, the numpy table
against PyPI, and lint rather than a green build. build_env_setup.py on
Linux/macOS still carry their own shell_quote/write_env_exports copies;
deduping those is the next commit.

```
python - <<'PY'
import importlib.util as u
m=u.module_from_spec(s:=u.spec_from_file_location("_common",".ci/wheel/_common.py")); s.loader.exec_module(m)
assert m.NUMPY_PINS=={"3.10":"2.0.2","3.11":"2.0.2","3.12":"2.0.2","3.13":"2.1.2","3.14":"2.3.4","3.15":"2.5.2"}
assert all(hasattr(m,h) for h in ["retry","pip_install","numpy_pin","download","write_env_exports","shell_quote"])
PY
lintrunner .ci/wheel/_common.py .ci/wheel/*/build_install_deps.py .ci/wheel/windows/build_env_setup.py
```

Authored with assistance from Claude Code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/binaries Trigger all binary build and upload jobs on the PR ciflow/trunk Trigger trunk jobs on your pull request Merged release notes: releng release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants