Skip to content

[ROCm] Fix Python 3.15 manywheel build: redirect pkg-config to target Python (ROCm cp315 only) - #189722

Closed
atalman wants to merge 2 commits into
mainfrom
atalman/fix-rocm-py315-numpy-pkgconfig
Closed

atalman wants to merge 2 commits into
mainfrom
atalman/fix-rocm-py315-numpy-pkgconfig

Conversation

@atalman

@atalman atalman commented Jul 13, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #189852

Summary

The nightly ROCm py3_15 / py3_15t manywheel builds fail in .ci/manywheel/build_install_deps.py. cp315 has no numpy wheel on any index, so numpy is built from source. On the ROCm manylinux image that build fails because the distro's system python3-devel (Python 3.6) has its python3.pc on pkg-config's default search path, so numpy's meson Cython check resolves pkg-config python3 to 3.6:

`pkg-config --cflags python3` -> -I/usr/include/python3.6m
Run-time dependency python3 found: YES 3.6
sanity_check_for_cython.c:23:6: error: #error Cython requires Python 3.8+.

Why linux x86 (CUDA/XPU/CPU) passes but ROCm fails

Neither image pre-provisions numpy — they all build numpy from source for cp315. The difference is purely the image's pkg-config environment: the CUDA/XPU/CPU manylinux images have no stray system python3.pc, so pkg-config python3 resolves to the cp315 interpreter and the source build succeeds. Only the ROCm image ships the system 3.6 python3.pc that hijacks the lookup. So this is ROCm-only.

Fix (.ci/manywheel/build_install_deps.py) — ROCm cp315 only

  • prefer_target_python_pkgconfig() — prepend the target interpreter's own pkgconfig dir to PKG_CONFIG_PATH so pkg-config python3 resolves the CPython we're building for instead of the ROCm image's system 3.6. Called only for ROCm cp315 (is_rocm_py315()), so CUDA/XPU/CPU are untouched (their from-source build already resolves correctly).
  • numpy_pin() — "cp315".startswith("cp31") wrongly bucketed 3.15 to numpy==2.1.0 (unbuildable on 3.15); switch to a (major, minor) floor with cp315 -> 2.5.1. This is the version every cp315 build compiles (ROCm and non-ROCm alike).

All non-cp315 Pythons and all non-ROCm platforms are unchanged.

Test plan

  • ROCm manywheel-py3_15-rocm* / py3_15t-rocm*: numpy source build resolves /opt/python/cp315-cp315[t] and compiles.
  • XPU / CUDA / CPU cp315 builds continue to pass (redirect not invoked there).

cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @pragupta @jerrymannil @xinyazhang

@atalman
atalman requested a review from a team as a code owner July 13, 2026 15:56
@pytorch-bot

pytorch-bot Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⏳ No Failures, 7 Pending

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

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

@pytorch-bot pytorch-bot Bot added the module: rocm AMD GPU support for Pytorch label Jul 13, 2026
@pytorch-bot

pytorch-bot Bot commented Jul 13, 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.

@atalman
atalman force-pushed the atalman/fix-rocm-py315-numpy-pkgconfig branch from 8ea4662 to 6abbcf6 Compare July 13, 2026 15:57
@atalman atalman added the ciflow/binaries Trigger all binary build and upload jobs on the PR label Jul 13, 2026
Comment thread .ci/manywheel/build_common.sh Resolved
Comment thread .ci/manywheel/build_install_deps.py Resolved
@atalman
atalman force-pushed the atalman/fix-rocm-py315-numpy-pkgconfig branch 4 times, most recently from b92120c to e537320 Compare July 14, 2026 02:29
@atalman
atalman force-pushed the atalman/fix-rocm-py315-numpy-pkgconfig branch 2 times, most recently from 6dae871 to 3dc8912 Compare July 14, 2026 19:43
@atalman atalman changed the title [ROCm] Fix Python 3.15 manywheel build: resolve numpy source build against target Python [ROCm] Fix Python 3.15 manywheel build: reuse the image's pre-provisioned numpy Jul 14, 2026
@atalman
atalman requested a review from albanD July 14, 2026 19:49
@atalman
atalman force-pushed the atalman/fix-rocm-py315-numpy-pkgconfig branch from 3dc8912 to 9f14f8c Compare July 14, 2026 19:55
@atalman atalman changed the title [ROCm] Fix Python 3.15 manywheel build: reuse the image's pre-provisioned numpy [ROCm] Fix Python 3.15 manywheel build: resolve numpy source build against target Python Jul 14, 2026

@jithunnair-amd jithunnair-amd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@atalman
atalman force-pushed the atalman/fix-rocm-py315-numpy-pkgconfig branch from 9f14f8c to 68117be Compare July 14, 2026 20:25
@atalman atalman changed the title [ROCm] Fix Python 3.15 manywheel build: resolve numpy source build against target Python [ROCm] Fix Python 3.15 manywheel build: reuse the ROCm image's pre-provisioned numpy Jul 14, 2026
@atalman
atalman force-pushed the atalman/fix-rocm-py315-numpy-pkgconfig branch from 68117be to 02c33d4 Compare July 14, 2026 21:02
@atalman atalman changed the title [ROCm] Fix Python 3.15 manywheel build: reuse the ROCm image's pre-provisioned numpy [ROCm] Fix Python 3.15 manywheel build: redirect pkg-config to target Python (ROCm cp315 only) Jul 14, 2026
… Python (ROCm cp315 only)

cp315 has no numpy wheel on any index, so numpy is built from source. On the
ROCm manylinux image that fails: the distro's system python3-devel (3.6) has its
python3.pc on pkg-config's default search path, so numpy's meson Cython check
resolves `pkg-config python3` to 3.6 ("Cython requires Python 3.8+"). The
CUDA / XPU / CPU images have no such stray python3.pc, so the same from-source
numpy build resolves the correct interpreter and passes -- this is ROCm-only.

For ROCm cp315 only, prepend the target interpreter's own pkgconfig dir to
PKG_CONFIG_PATH so `pkg-config python3` resolves the CPython we're building for.
Gated to ROCm cp315 so CUDA/XPU/CPU are untouched.

Also fix numpy_pin(): "cp315".startswith("cp31") wrongly bucketed 3.15 to 2.1.0
(unbuildable on 3.15); switch to a (major, minor) floor with cp315 -> 2.5.1.
@atalman
atalman force-pushed the atalman/fix-rocm-py315-numpy-pkgconfig branch from 02c33d4 to 13d6caf Compare July 14, 2026 21:24
@jithunnair-amd

jithunnair-amd commented Jul 15, 2026 •

Copy link
Copy Markdown
Collaborator

@atalman Faa had a PR to attempt a fix for the same issue: #189266. That PR also had a change to .ci/pytorch/binary_linux_test.sh to address the same problem in the test job. Do we need that change as well?

cp315 has no numpy wheel on any index, so the test-phase `pip install numpy`
builds it from source, which fails on the ROCm image (meson's Cython check
resolves pkg-config python3 to the image's system 3.6). The manywheel build
already handles this; the test phase installs numpy separately for its smoke
tests. Skip that numpy install for ROCm cp315 / cp315t (install the other test
deps only, like the cp312 no-numpy case). Other platforms/versions unchanged.
@albanD
albanD removed their request for review July 15, 2026 16:04
atalman added a commit that referenced this pull request Jul 15, 2026
…cp315 numpy builds

The ROCm manylinux builder is FROM rocm/dev-almalinux-8:*-complete (AMD's ROCm
dev image). That base ships the distro's system python3-devel (Python 3.6);
nothing in .ci/docker installs it. Its /usr/lib64/pkgconfig/python3.pc is on
pkg-config's default search path. cp315 has no numpy wheel on any index, so
numpy is built from source, and meson's Cython sanity check resolves
`pkg-config python3` to that 3.6 .pc and fails with "Cython requires Python
3.8+". CUDA/XPU/CPU images don't ship this package, so only ROCm cp315 hits it.

We never install python3-devel ourselves and never build against the system
interpreter (every wheel targets /opt/python/cp*), so rather than leave the
stray .pc to hijack the from-source build, remove the package outright in the
rocm_final stage. This is the root-cause fix and lets the in-tree workarounds
(the pkg-config redirect in .ci/manywheel/build_install_deps.py and the numpy
skip in .ci/pytorch/binary_linux_test.sh, #189722) be dropped once it lands.

Triggers a rebuild of the ROCm manylinux builder image; that rebuild (run on
this PR by build-manywheel-images) validates the removal doesn't break the
remaining ROCm image build steps.

Test Plan:

```
# after the image rebuilds, inside the ROCm builder:
rpm -q python3-devel            # -> not installed
pkg-config --exists python3 && echo present || echo absent   # -> absent
/opt/python/cp315-cp315t/bin/pip install numpy   # builds from source, resolves 3.15
```

Authored with the assistance of Claude (AI).
@atalman

atalman commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchmergebot merge -f "lint and rocm 3.15 build and test is successful."

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use -f as last resort and instead consider -i/--ignore-current to continue the merge ignoring current failures. This will allow currently pending tests to finish and report signal before the merge.

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

DamJanusz pushed a commit to DamJanusz/pytorch that referenced this pull request Jul 21, 2026
… Python (ROCm cp315 only) (pytorch#189722)

Fixes pytorch#189852

## Summary

The nightly **ROCm** `py3_15` / `py3_15t` manywheel builds fail in `.ci/manywheel/build_install_deps.py`. cp315 has no numpy wheel on any index, so numpy is built **from source**. On the ROCm manylinux image that build fails because the distro's system `python3-devel` (Python 3.6) has its `python3.pc` on pkg-config's default search path, so numpy's meson Cython check resolves `pkg-config python3` to **3.6**:

```
`pkg-config --cflags python3` -> -I/usr/include/python3.6m
Run-time dependency python3 found: YES 3.6
sanity_check_for_cython.c:23:6: error: #error Cython requires Python 3.8+.
```

## Why linux x86 (CUDA/XPU/CPU) passes but ROCm fails

Neither image pre-provisions numpy — they all build numpy from source for cp315. The difference is purely the image's **pkg-config environment**: the CUDA/XPU/CPU manylinux images have **no stray system `python3.pc`**, so `pkg-config python3` resolves to the cp315 interpreter and the source build succeeds. Only the **ROCm** image ships the system 3.6 `python3.pc` that hijacks the lookup. So this is ROCm-only.

## Fix (`.ci/manywheel/build_install_deps.py`) — ROCm cp315 only

- `prefer_target_python_pkgconfig()` — prepend the target interpreter's own `pkgconfig` dir to `PKG_CONFIG_PATH` so `pkg-config python3` resolves the CPython we're building for instead of the ROCm image's system 3.6. **Called only for ROCm cp315** (`is_rocm_py315()`), so CUDA/XPU/CPU are untouched (their from-source build already resolves correctly).
- `numpy_pin()` — `"cp315".startswith("cp31")` wrongly bucketed 3.15 to `numpy==2.1.0` (unbuildable on 3.15); switch to a `(major, minor)` floor with `cp315 -> 2.5.1`. This is the version every cp315 build compiles (ROCm and non-ROCm alike).

All non-cp315 Pythons and all non-ROCm platforms are unchanged.

## Test plan

- ROCm `manywheel-py3_15-rocm*` / `py3_15t-rocm*`: numpy source build resolves `/opt/python/cp315-cp315[t]` and compiles.
- XPU / CUDA / CPU cp315 builds continue to pass (redirect not invoked there).

Pull Request resolved: pytorch#189722
Approved by: https://github.com/jithunnair-amd, https://github.com/jeffdaily
youlituao pushed a commit to youlituao/pytorch that referenced this pull request Jul 28, 2026
… Python (ROCm cp315 only) (pytorch#189722)

Fixes pytorch#189852

## Summary

The nightly **ROCm** `py3_15` / `py3_15t` manywheel builds fail in `.ci/manywheel/build_install_deps.py`. cp315 has no numpy wheel on any index, so numpy is built **from source**. On the ROCm manylinux image that build fails because the distro's system `python3-devel` (Python 3.6) has its `python3.pc` on pkg-config's default search path, so numpy's meson Cython check resolves `pkg-config python3` to **3.6**:

```
`pkg-config --cflags python3` -> -I/usr/include/python3.6m
Run-time dependency python3 found: YES 3.6
sanity_check_for_cython.c:23:6: error: #error Cython requires Python 3.8+.
```

## Why linux x86 (CUDA/XPU/CPU) passes but ROCm fails

Neither image pre-provisions numpy — they all build numpy from source for cp315. The difference is purely the image's **pkg-config environment**: the CUDA/XPU/CPU manylinux images have **no stray system `python3.pc`**, so `pkg-config python3` resolves to the cp315 interpreter and the source build succeeds. Only the **ROCm** image ships the system 3.6 `python3.pc` that hijacks the lookup. So this is ROCm-only.

## Fix (`.ci/manywheel/build_install_deps.py`) — ROCm cp315 only

- `prefer_target_python_pkgconfig()` — prepend the target interpreter's own `pkgconfig` dir to `PKG_CONFIG_PATH` so `pkg-config python3` resolves the CPython we're building for instead of the ROCm image's system 3.6. **Called only for ROCm cp315** (`is_rocm_py315()`), so CUDA/XPU/CPU are untouched (their from-source build already resolves correctly).
- `numpy_pin()` — `"cp315".startswith("cp31")` wrongly bucketed 3.15 to `numpy==2.1.0` (unbuildable on 3.15); switch to a `(major, minor)` floor with `cp315 -> 2.5.1`. This is the version every cp315 build compiles (ROCm and non-ROCm alike).

All non-cp315 Pythons and all non-ROCm platforms are unchanged.

## Test plan

- ROCm `manywheel-py3_15-rocm*` / `py3_15t-rocm*`: numpy source build resolves `/opt/python/cp315-cp315[t]` and compiles.
- XPU / CUDA / CPU cp315 builds continue to pass (redirect not invoked there).

Pull Request resolved: pytorch#189722
Approved by: https://github.com/jithunnair-amd, https://github.com/jeffdaily
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
… Python (ROCm cp315 only) (pytorch#189722)

Fixes pytorch#189852

## Summary

The nightly **ROCm** `py3_15` / `py3_15t` manywheel builds fail in `.ci/manywheel/build_install_deps.py`. cp315 has no numpy wheel on any index, so numpy is built **from source**. On the ROCm manylinux image that build fails because the distro's system `python3-devel` (Python 3.6) has its `python3.pc` on pkg-config's default search path, so numpy's meson Cython check resolves `pkg-config python3` to **3.6**:

```
`pkg-config --cflags python3` -> -I/usr/include/python3.6m
Run-time dependency python3 found: YES 3.6
sanity_check_for_cython.c:23:6: error: #error Cython requires Python 3.8+.
```

## Why linux x86 (CUDA/XPU/CPU) passes but ROCm fails

Neither image pre-provisions numpy — they all build numpy from source for cp315. The difference is purely the image's **pkg-config environment**: the CUDA/XPU/CPU manylinux images have **no stray system `python3.pc`**, so `pkg-config python3` resolves to the cp315 interpreter and the source build succeeds. Only the **ROCm** image ships the system 3.6 `python3.pc` that hijacks the lookup. So this is ROCm-only.

## Fix (`.ci/manywheel/build_install_deps.py`) — ROCm cp315 only

- `prefer_target_python_pkgconfig()` — prepend the target interpreter's own `pkgconfig` dir to `PKG_CONFIG_PATH` so `pkg-config python3` resolves the CPython we're building for instead of the ROCm image's system 3.6. **Called only for ROCm cp315** (`is_rocm_py315()`), so CUDA/XPU/CPU are untouched (their from-source build already resolves correctly).
- `numpy_pin()` — `"cp315".startswith("cp31")` wrongly bucketed 3.15 to `numpy==2.1.0` (unbuildable on 3.15); switch to a `(major, minor)` floor with `cp315 -> 2.5.1`. This is the version every cp315 build compiles (ROCm and non-ROCm alike).

All non-cp315 Pythons and all non-ROCm platforms are unchanged.

## Test plan

- ROCm `manywheel-py3_15-rocm*` / `py3_15t-rocm*`: numpy source build resolves `/opt/python/cp315-cp315[t]` and compiles.
- XPU / CUDA / CPU cp315 builds continue to pass (redirect not invoked there).

Pull Request resolved: pytorch#189722
Approved by: https://github.com/jithunnair-amd, https://github.com/jeffdaily
@github-actions
github-actions Bot deleted the atalman/fix-rocm-py315-numpy-pkgconfig branch August 15, 2026 02:06
@zklaus zklaus mentioned this pull request Aug 25, 2026
60 of 63 tasks
zklaus added a commit to zklaus/pytorch that referenced this pull request Aug 25, 2026
The unified numpy table makes an unlisted Python fail loudly and
unconditionally. That is the wrong default for a CD matrix: it turns a
missing table entry into a hard build failure, and in the per-arch loop
builds (manywheel-cpu / cuda / aarch64) an abort at one Python discards the
wheels already built for every earlier one.

Replace numpy_pin() with install_numpy() in _common.py, encapsulating the
policy: a listed Python installs its exact pin; an unlisted one falls back
to a numpy already provisioned in the interpreter, logged with its version;
only when neither exists does it fail loudly.

Every Python in the matrix today is listed, so the fallback is a guard for
the next Python added before its pin lands, not a fix for a live failure.

One pin does move, and it is forced by unifying the table. Windows pins
cp315 at numpy 2.5.2 (pytorch#194618); Linux and macOS still pin 2.5.1, which has
no cp315 wheel and therefore builds numpy from source. A single table cannot
hold both, and taking 2.5.1 would drag Windows back to a from-source cp315
build and re-break the py3.15 Windows binaries pytorch#194618 just fixed. So the
table takes 2.5.2, and Linux and macOS cp315/cp315t switch from a
from-source numpy build to a wheel install. numpy 2.5.2 publishes cp315 and
cp315t wheels for manylinux, musllinux, macOS and Windows, so every
platform in the matrix is covered.

That makes the ROCm cp315 pkg-config workaround (is_rocm_py315 /
prefer_target_python_pkgconfig, added in pytorch#189722) inert, since it only
guards numpy's from-source meson Cython check. It is deliberately left in
place: it is cheap, and the failure it guards against is nightly-only and
image-specific, so it should not be removed in the same commit that stops
exercising it. Removing it wants its own change, after a green ROCm cp315
nightly on the wheel install.

Also drops the Linux-only `--pre` flag on the numpy install, which
install_numpy() does not carry. It was a no-op. The install is always an
exact `numpy==X` pin, and pip's prerelease filtering never narrows an exact
specifier -- including one naming a prerelease, because packaging enables
prereleases automatically when the specifier itself references one. So the
flag could not have changed resolution for any value NUMPY_PINS can hold.
It would only matter if the pin stopped being exact.

On Windows, preinstall_cp315_build_deps() (pytorch#194618) stays on the
PIP_PACKAGES install, which still builds sdists that Cython 3.3.0 crashes.
It is no longer applied to the numpy install, which now resolves to a wheel.

## Test plan

install_numpy() policy, all four branches:

```
python - <<'PY'
import importlib.util as u, collections
from unittest import mock
VI = collections.namedtuple("VI", "major minor micro")
s = u.spec_from_file_location("_common", ".ci/wheel/_common.py")
m = u.module_from_spec(s); s.loader.exec_module(m)
for ver, pin in [((3,12,0),"2.0.2"), ((3,14,0),"2.3.4"), ((3,15,0),"2.5.2")]:
    with mock.patch.object(m, "pip_install") as pi, mock.patch.object(m.sys, "version_info", VI(*ver)):
        m.install_numpy(); pi.assert_called_once_with("-q", f"numpy=={pin}")
with mock.patch.object(m, "pip_install") as pi, \
     mock.patch.object(m.sys, "version_info", VI(3,16,0)), \
     mock.patch.object(m.importlib.util, "find_spec", return_value=object()), \
     mock.patch.object(m.importlib.metadata, "version", return_value="2.6.0"):
    m.install_numpy(); pi.assert_not_called()
with mock.patch.object(m.sys, "version_info", VI(3,16,0)), \
     mock.patch.object(m.importlib.util, "find_spec", return_value=None):
    try: m.install_numpy(); raise AssertionError
    except SystemExit as e: assert "NUMPY_PINS" in str(e.code)
PY
```

`--pre` is a no-op against an exact pin (identical resolution, same wheel):

```
pip install --dry-run --no-deps --ignore-installed --report - numpy==2.0.2
pip install --dry-run --no-deps --ignore-installed --report - --pre numpy==2.0.2
```

Lint:

```
spin lint .ci/wheel/_common.py .ci/wheel/*/build_install_deps.py .ci/wheel/README.md
```

Full CD coverage still comes from a ciflow/binaries_wheel run; the cp315 and
cp315t jobs on every platform are the ones to watch, since they are the
builds this commit moves onto a wheel.

Authored with assistance from Claude Code.
zklaus added a commit to zklaus/pytorch that referenced this pull request Aug 25, 2026
The unified numpy table makes an unlisted Python fail loudly and
unconditionally. That is the wrong default for a CD matrix: it turns a
missing table entry into a hard build failure, and in the per-arch loop
builds (manywheel-cpu / cuda / aarch64) an abort at one Python discards the
wheels already built for every earlier one.

Replace numpy_pin() with install_numpy() in _common.py, encapsulating the
policy: a listed Python installs its exact pin; an unlisted one falls back
to a numpy already provisioned in the interpreter, logged with its version;
only when neither exists does it fail loudly.

Every Python in the matrix today is listed, so the fallback is a guard for
the next Python added before its pin lands, not a fix for a live failure.

The "already provisioned" check is a snapshot taken when _common.py is
imported, not a probe at call time. It has to be: on Linux and macOS the
stage installs requirements-build.txt -- which lists a bare `numpy` -- before
it calls install_numpy(), so a call-time probe would always find one and the
fail-loud branch could never fire. An unpinned Python would then quietly
build against whatever pip last resolved, which is the failure the explicit
table exists to prevent, and on macOS would be a regression from the
unconditional fail-loud it had before.

One pin does move, and it is forced by unifying the table. Windows pins
cp315 at numpy 2.5.2 (pytorch#194618); Linux and macOS still pin 2.5.1, which has
no cp315 wheel and therefore builds numpy from source. A single table cannot
hold both, and taking 2.5.1 would drag Windows back to a from-source cp315
build and re-break the py3.15 Windows binaries pytorch#194618 just fixed. So the
table takes 2.5.2, and Linux and macOS cp315/cp315t switch from a
from-source numpy build to a wheel install. numpy 2.5.2 publishes cp315 and
cp315t wheels for manylinux, musllinux, macOS and Windows, so every
platform in the matrix is covered.

That makes the ROCm cp315 pkg-config workaround (is_rocm_py315 /
prefer_target_python_pkgconfig, added in pytorch#189722) inert, since it only
guards numpy's from-source meson Cython check. It is deliberately left in
place: it is cheap, and the failure it guards against is nightly-only and
image-specific, so it should not be removed in the same commit that stops
exercising it. Removing it wants its own change, after a green ROCm cp315
nightly on the wheel install.

Also drops the Linux-only `--pre` flag on the numpy install, which
install_numpy() does not carry. It was a no-op. The install is always an
exact `numpy==X` pin, and pip's prerelease filtering never narrows an exact
specifier -- including one naming a prerelease, because packaging enables
prereleases automatically when the specifier itself references one. So the
flag could not have changed resolution for any value NUMPY_PINS can hold.
It would only matter if the pin stopped being exact.

On Windows, preinstall_cp315_build_deps() (pytorch#194618) still guards both
installs, so install_numpy() takes passthrough pip args. cp315 has no pyyaml
wheel, so PIP_PACKAGES really does build an sdist and needs the Cython pin to
reach it -- and PIP_CONSTRAINT cannot, which is why pytorch#194618 disables build
isolation instead. numpy resolves to a wheel at the current pin, which makes
the flags inert for that install rather than unnecessary; passing them anyway
keeps the guard in place for a future pin with no cp315 wheel, which is
exactly the case NUMPY_PINS is documented to serve.

## Test plan

install_numpy() policy, all four branches:

```
python - <<'PY'
import importlib.util as u, collections
from unittest import mock
VI = collections.namedtuple("VI", "major minor micro")
s = u.spec_from_file_location("_common", ".ci/wheel/_common.py")
m = u.module_from_spec(s); s.loader.exec_module(m)
for ver, pin in [((3,12,0),"2.0.2"), ((3,14,0),"2.3.4"), ((3,15,0),"2.5.2")]:
    with mock.patch.object(m, "pip_install") as pi, mock.patch.object(m.sys, "version_info", VI(*ver)):
        m.install_numpy(); pi.assert_called_once_with("-q", f"numpy=={pin}")
# passthrough args land where upstream put them, ahead of the requirement
with mock.patch.object(m, "pip_install") as pi, mock.patch.object(m.sys, "version_info", VI(3,15,0)):
    m.install_numpy("--no-build-isolation")
    pi.assert_called_once_with("-q", "--no-build-isolation", "numpy==2.5.2")
m._IMAGE_NUMPY = "2.6.0"
with mock.patch.object(m, "pip_install") as pi, mock.patch.object(m.sys, "version_info", VI(3,16,0)):
    m.install_numpy(); pi.assert_not_called()
m._IMAGE_NUMPY = None
# still fails loudly with numpy importable, proving the snapshot is what counts
with mock.patch.object(m.sys, "version_info", VI(3,16,0)), \
     mock.patch.object(m.importlib.util, "find_spec", return_value=object()):
    try: m.install_numpy(); raise AssertionError
    except SystemExit as e: assert "NUMPY_PINS" in str(e.code)
PY
```

`--pre` is a no-op against an exact pin (identical resolution, same wheel):

```
pip install --dry-run --no-deps --ignore-installed --report - numpy==2.0.2
pip install --dry-run --no-deps --ignore-installed --report - --pre numpy==2.0.2
```

Lint:

```
spin lint .ci/wheel/_common.py .ci/wheel/*/build_install_deps.py .ci/wheel/README.md
```

Full CD coverage still comes from a ciflow/binaries_wheel run; the cp315 and
cp315t jobs on every platform are the ones to watch, since they are the
builds this commit moves onto a wheel.

Authored with assistance from Claude Code.
zklaus added a commit to zklaus/pytorch that referenced this pull request Sep 8, 2026
The unified numpy table makes an unlisted Python fail loudly and
unconditionally. That is the wrong default for a CD matrix: it turns a
missing table entry into a hard build failure, and in the per-arch loop
builds (manywheel-cpu / cuda / aarch64) an abort at one Python discards the
wheels already built for every earlier one.

Replace numpy_pin() with install_numpy() in _common.py, encapsulating the
policy: a listed Python installs its exact pin; an unlisted one falls back
to a numpy already provisioned in the interpreter, logged with its version;
only when neither exists does it fail loudly.

Every Python in the matrix today is listed, so the fallback is a guard for
the next Python added before its pin lands, not a fix for a live failure.

The "already provisioned" check is a snapshot taken when _common.py is
imported, not a probe at call time. It has to be: on Linux and macOS the
stage installs requirements-build.txt -- which lists a bare `numpy` -- before
it calls install_numpy(), so a call-time probe would always find one and the
fail-loud branch could never fire. An unpinned Python would then quietly
build against whatever pip last resolved, which is the failure the explicit
table exists to prevent, and on macOS would be a regression from the
unconditional fail-loud it had before.

The cp315 pin question a single table raises was settled upstream rather
than here. Windows pinned cp315 at numpy 2.5.2 (pytorch#194618) while Linux and
macOS sat on 2.5.1, which has no cp315 wheel and built numpy from source;
one table cannot hold both. pytorch#194741 (Linux) and pytorch#194734 (macOS) have since
moved both to 2.5.2, so the unified table takes 2.5.2 and no platform's pin
changes in this commit. numpy 2.5.2 publishes cp315 and cp315t wheels for
manylinux, musllinux, macOS and Windows, so every platform in the matrix
installs a wheel.

That upstream move left the ROCm cp315 pkg-config workaround
(is_rocm_py315 / prefer_target_python_pkgconfig, added in pytorch#189722) inert,
since it only guards numpy's from-source meson Cython check. It is
deliberately left in place: it is cheap, the failure it guards against is
nightly-only and image-specific, and the change that stopped exercising it
is not this one. Removing it wants its own change, after a green ROCm cp315
nightly on the wheel install.

Also drops the Linux-only `--pre` flag on the numpy install, which
install_numpy() does not carry. It was a no-op. The install is always an
exact `numpy==X` pin, and pip's prerelease filtering never narrows an exact
specifier -- including one naming a prerelease, because packaging enables
prereleases automatically when the specifier itself references one. So the
flag could not have changed resolution for any value NUMPY_PINS can hold.
It would only matter if the pin stopped being exact.

On Windows and macOS, preinstall_cp315_build_deps() (pytorch#194618, pytorch#194734)
still guards the requirements installs, so install_numpy() takes passthrough
pip args. cp315 has no pyyaml
wheel, so PIP_PACKAGES really does build an sdist and needs the Cython pin to
reach it -- and PIP_CONSTRAINT cannot, which is why pytorch#194618 disables build
isolation instead. numpy resolves to a wheel at the current pin, which makes
the flags inert for that install rather than unnecessary; passing them anyway
keeps the guard in place for a future pin with no cp315 wheel, which is
exactly the case NUMPY_PINS is documented to serve.

install_numpy() policy, all four branches:

```
python - <<'PY'
import importlib.util as u, collections
from unittest import mock
VI = collections.namedtuple("VI", "major minor micro")
s = u.spec_from_file_location("_common", ".ci/wheel/_common.py")
m = u.module_from_spec(s); s.loader.exec_module(m)
for ver, pin in [((3,12,0),"2.0.2"), ((3,14,0),"2.3.4"), ((3,15,0),"2.5.2")]:
    with mock.patch.object(m, "pip_install") as pi, mock.patch.object(m.sys, "version_info", VI(*ver)):
        m.install_numpy(); pi.assert_called_once_with("-q", f"numpy=={pin}")
with mock.patch.object(m, "pip_install") as pi, mock.patch.object(m.sys, "version_info", VI(3,15,0)):
    m.install_numpy("--no-build-isolation")
    pi.assert_called_once_with("-q", "--no-build-isolation", "numpy==2.5.2")
m._IMAGE_NUMPY = "2.6.0"
with mock.patch.object(m, "pip_install") as pi, mock.patch.object(m.sys, "version_info", VI(3,16,0)):
    m.install_numpy(); pi.assert_not_called()
m._IMAGE_NUMPY = None
with mock.patch.object(m.sys, "version_info", VI(3,16,0)), \
     mock.patch.object(m.importlib.util, "find_spec", return_value=object()):
    try: m.install_numpy(); raise AssertionError
    except SystemExit as e: assert "NUMPY_PINS" in str(e.code)
PY
```

`--pre` is a no-op against an exact pin (identical resolution, same wheel):

```
pip install --dry-run --no-deps --ignore-installed --report - numpy==2.0.2
pip install --dry-run --no-deps --ignore-installed --report - --pre numpy==2.0.2
```

Lint:

```
spin lint .ci/wheel/_common.py .ci/wheel/*/build_install_deps.py .ci/wheel/README.md
```

Full CD coverage still comes from a ciflow/binaries_wheel run; the cp315 and
cp315t jobs on every platform are the ones to watch, since they are the
builds this commit moves onto a wheel.

Authored with assistance from Claude Code.
zklaus added a commit to zklaus/pytorch that referenced this pull request Sep 11, 2026
The unified numpy table makes an unlisted Python fail loudly and
unconditionally. That is the wrong default for a CD matrix: it turns a
missing table entry into a hard build failure, and in the per-arch loop
builds (manywheel-cpu / cuda / aarch64) an abort at one Python discards the
wheels already built for every earlier one.

Replace numpy_pin() with install_numpy() in _common.py, encapsulating the
policy: a listed Python installs its exact pin; an unlisted one falls back
to a numpy already provisioned in the interpreter, logged with its version;
only when neither exists does it fail loudly.

Every Python in the matrix today is listed, so the fallback is a guard for
the next Python added before its pin lands, not a fix for a live failure.

The "already provisioned" check is a snapshot taken when _common.py is
imported, not a probe at call time. It has to be: on Linux and macOS the
stage installs requirements-build.txt -- which lists a bare `numpy` -- before
it calls install_numpy(), so a call-time probe would always find one and the
fail-loud branch could never fire. An unpinned Python would then quietly
build against whatever pip last resolved, which is the failure the explicit
table exists to prevent, and on macOS would be a regression from the
unconditional fail-loud it had before.

The cp315 pin question a single table raises was settled upstream rather
than here. Windows pinned cp315 at numpy 2.5.2 (pytorch#194618) while Linux and
macOS sat on 2.5.1, which has no cp315 wheel and built numpy from source;
one table cannot hold both. pytorch#194741 (Linux) and pytorch#194734 (macOS) have since
moved both to 2.5.2, so the unified table takes 2.5.2 and no platform's pin
changes in this commit. numpy 2.5.2 publishes cp315 and cp315t wheels for
manylinux, musllinux, macOS and Windows, so every platform in the matrix
installs a wheel.

That upstream move left the ROCm cp315 pkg-config workaround
(is_rocm_py315 / prefer_target_python_pkgconfig, added in pytorch#189722) inert,
since it only guards numpy's from-source meson Cython check. It is
deliberately left in place: it is cheap, the failure it guards against is
nightly-only and image-specific, and the change that stopped exercising it
is not this one. Removing it wants its own change, after a green ROCm cp315
nightly on the wheel install.

Also drops the Linux-only `--pre` flag on the numpy install, which
install_numpy() does not carry. It was a no-op. The install is always an
exact `numpy==X` pin, and pip's prerelease filtering never narrows an exact
specifier -- including one naming a prerelease, because packaging enables
prereleases automatically when the specifier itself references one. So the
flag could not have changed resolution for any value NUMPY_PINS can hold.
It would only matter if the pin stopped being exact.

On Windows and macOS, preinstall_cp315_build_deps() (pytorch#194618, pytorch#194734)
still guards the requirements installs, so install_numpy() takes passthrough
pip args. cp315 has no pyyaml
wheel, so PIP_PACKAGES really does build an sdist and needs the Cython pin to
reach it -- and PIP_CONSTRAINT cannot, which is why pytorch#194618 disables build
isolation instead. numpy resolves to a wheel at the current pin, which makes
the flags inert for that install rather than unnecessary; passing them anyway
keeps the guard in place for a future pin with no cp315 wheel, which is
exactly the case NUMPY_PINS is documented to serve.

install_numpy() policy, all four branches:

```
python - <<'PY'
import importlib.util as u, collections
from unittest import mock
VI = collections.namedtuple("VI", "major minor micro")
s = u.spec_from_file_location("_common", ".ci/wheel/_common.py")
m = u.module_from_spec(s); s.loader.exec_module(m)
for ver, pin in [((3,12,0),"2.0.2"), ((3,14,0),"2.3.4"), ((3,15,0),"2.5.2")]:
    with mock.patch.object(m, "pip_install") as pi, mock.patch.object(m.sys, "version_info", VI(*ver)):
        m.install_numpy(); pi.assert_called_once_with("-q", f"numpy=={pin}")
with mock.patch.object(m, "pip_install") as pi, mock.patch.object(m.sys, "version_info", VI(3,15,0)):
    m.install_numpy("--no-build-isolation")
    pi.assert_called_once_with("-q", "--no-build-isolation", "numpy==2.5.2")
m._IMAGE_NUMPY = "2.6.0"
with mock.patch.object(m, "pip_install") as pi, mock.patch.object(m.sys, "version_info", VI(3,16,0)):
    m.install_numpy(); pi.assert_not_called()
m._IMAGE_NUMPY = None
with mock.patch.object(m.sys, "version_info", VI(3,16,0)), \
     mock.patch.object(m.importlib.util, "find_spec", return_value=object()):
    try: m.install_numpy(); raise AssertionError
    except SystemExit as e: assert "NUMPY_PINS" in str(e.code)
PY
```

`--pre` is a no-op against an exact pin (identical resolution, same wheel):

```
pip install --dry-run --no-deps --ignore-installed --report - numpy==2.0.2
pip install --dry-run --no-deps --ignore-installed --report - --pre numpy==2.0.2
```

Lint:

```
spin lint .ci/wheel/_common.py .ci/wheel/*/build_install_deps.py .ci/wheel/README.md
```

Full CD coverage still comes from a ciflow/binaries_wheel run; the cp315 and
cp315t jobs on every platform are the ones to watch, since they are the
builds this commit moves onto a wheel.

Authored with assistance from Claude Code.
zklaus added a commit to zklaus/pytorch that referenced this pull request Sep 16, 2026
The unified numpy table makes an unlisted Python fail loudly and
unconditionally. That is the wrong default for a CD matrix: it turns a
missing table entry into a hard build failure, and in the per-arch loop
builds (manywheel-cpu / cuda / aarch64) an abort at one Python discards the
wheels already built for every earlier one.

Replace numpy_pin() with install_numpy() in _common.py, encapsulating the
policy: a listed Python installs its exact pin; an unlisted one falls back
to a numpy already provisioned in the interpreter, logged with its version;
only when neither exists does it fail loudly.

Every Python in the matrix today is listed, so the fallback is a guard for
the next Python added before its pin lands, not a fix for a live failure.

The "already provisioned" check is a snapshot taken when _common.py is
imported, not a probe at call time. It has to be: on Linux and macOS the
stage installs requirements-build.txt -- which lists a bare `numpy` -- before
it calls install_numpy(), so a call-time probe would always find one and the
fail-loud branch could never fire. An unpinned Python would then quietly
build against whatever pip last resolved, which is the failure the explicit
table exists to prevent, and on macOS would be a regression from the
unconditional fail-loud it had before.

The cp315 pin question a single table raises was settled upstream rather
than here. Windows pinned cp315 at numpy 2.5.2 (pytorch#194618) while Linux and
macOS sat on 2.5.1, which has no cp315 wheel and built numpy from source;
one table cannot hold both. pytorch#194741 (Linux) and pytorch#194734 (macOS) have since
moved both to 2.5.2, so the unified table takes 2.5.2 and no platform's pin
changes in this commit. numpy 2.5.2 publishes cp315 and cp315t wheels for
manylinux, musllinux, macOS and Windows, so every platform in the matrix
installs a wheel.

That upstream move left the ROCm cp315 pkg-config workaround
(is_rocm_py315 / prefer_target_python_pkgconfig, added in pytorch#189722) inert,
since it only guards numpy's from-source meson Cython check. It is
deliberately left in place: it is cheap, the failure it guards against is
nightly-only and image-specific, and the change that stopped exercising it
is not this one. Removing it wants its own change, after a green ROCm cp315
nightly on the wheel install.

Also drops the Linux-only `--pre` flag on the numpy install, which
install_numpy() does not carry. It was a no-op. The install is always an
exact `numpy==X` pin, and pip's prerelease filtering never narrows an exact
specifier -- including one naming a prerelease, because packaging enables
prereleases automatically when the specifier itself references one. So the
flag could not have changed resolution for any value NUMPY_PINS can hold.
It would only matter if the pin stopped being exact.

On Windows and macOS, preinstall_cp315_build_deps() (pytorch#194618, pytorch#194734)
still guards the requirements installs, so install_numpy() takes passthrough
pip args. cp315 has no pyyaml
wheel, so PIP_PACKAGES really does build an sdist and needs the Cython pin to
reach it -- and PIP_CONSTRAINT cannot, which is why pytorch#194618 disables build
isolation instead. numpy resolves to a wheel at the current pin, which makes
the flags inert for that install rather than unnecessary; passing them anyway
keeps the guard in place for a future pin with no cp315 wheel, which is
exactly the case NUMPY_PINS is documented to serve.

install_numpy() policy, all four branches:

```
python - <<'PY'
import importlib.util as u, collections
from unittest import mock
VI = collections.namedtuple("VI", "major minor micro")
s = u.spec_from_file_location("_common", ".ci/wheel/_common.py")
m = u.module_from_spec(s); s.loader.exec_module(m)
for ver, pin in [((3,12,0),"2.0.2"), ((3,14,0),"2.3.4"), ((3,15,0),"2.5.2")]:
    with mock.patch.object(m, "pip_install") as pi, mock.patch.object(m.sys, "version_info", VI(*ver)):
        m.install_numpy(); pi.assert_called_once_with("-q", f"numpy=={pin}")
with mock.patch.object(m, "pip_install") as pi, mock.patch.object(m.sys, "version_info", VI(3,15,0)):
    m.install_numpy("--no-build-isolation")
    pi.assert_called_once_with("-q", "--no-build-isolation", "numpy==2.5.2")
m._IMAGE_NUMPY = "2.6.0"
with mock.patch.object(m, "pip_install") as pi, mock.patch.object(m.sys, "version_info", VI(3,16,0)):
    m.install_numpy(); pi.assert_not_called()
m._IMAGE_NUMPY = None
with mock.patch.object(m.sys, "version_info", VI(3,16,0)), \
     mock.patch.object(m.importlib.util, "find_spec", return_value=object()):
    try: m.install_numpy(); raise AssertionError
    except SystemExit as e: assert "NUMPY_PINS" in str(e.code)
PY
```

`--pre` is a no-op against an exact pin (identical resolution, same wheel):

```
pip install --dry-run --no-deps --ignore-installed --report - numpy==2.0.2
pip install --dry-run --no-deps --ignore-installed --report - --pre numpy==2.0.2
```

Lint:

```
spin lint .ci/wheel/_common.py .ci/wheel/*/build_install_deps.py .ci/wheel/README.md
```

Full CD coverage still comes from a ciflow/binaries_wheel run; the cp315 and
cp315t jobs on every platform are the ones to watch, since they are the
builds this commit moves onto a wheel.

Authored with assistance from Claude Code.
pytorchmergebot pushed a commit to zklaus/pytorch that referenced this pull request Sep 16, 2026
The unified numpy table makes an unlisted Python fail loudly and
unconditionally. That is the wrong default for a CD matrix: it turns a
missing table entry into a hard build failure, and in the per-arch loop
builds (manywheel-cpu / cuda / aarch64) an abort at one Python discards the
wheels already built for every earlier one.

Replace numpy_pin() with install_numpy() in _common.py, encapsulating the
policy: a listed Python installs its exact pin; an unlisted one falls back
to a numpy already provisioned in the interpreter, logged with its version;
only when neither exists does it fail loudly.

Every Python in the matrix today is listed, so the fallback is a guard for
the next Python added before its pin lands, not a fix for a live failure.

The "already provisioned" check is a snapshot taken when _common.py is
imported, not a probe at call time. It has to be: on Linux and macOS the
stage installs requirements-build.txt -- which lists a bare `numpy` -- before
it calls install_numpy(), so a call-time probe would always find one and the
fail-loud branch could never fire. An unpinned Python would then quietly
build against whatever pip last resolved, which is the failure the explicit
table exists to prevent, and on macOS would be a regression from the
unconditional fail-loud it had before.

The cp315 pin question a single table raises was settled upstream rather
than here. Windows pinned cp315 at numpy 2.5.2 (pytorch#194618) while Linux and
macOS sat on 2.5.1, which has no cp315 wheel and built numpy from source;
one table cannot hold both. pytorch#194741 (Linux) and pytorch#194734 (macOS) have since
moved both to 2.5.2, so the unified table takes 2.5.2 and no platform's pin
changes in this commit. numpy 2.5.2 publishes cp315 and cp315t wheels for
manylinux, musllinux, macOS and Windows, so every platform in the matrix
installs a wheel.

That upstream move left the ROCm cp315 pkg-config workaround
(is_rocm_py315 / prefer_target_python_pkgconfig, added in pytorch#189722) inert,
since it only guards numpy's from-source meson Cython check. It is
deliberately left in place: it is cheap, the failure it guards against is
nightly-only and image-specific, and the change that stopped exercising it
is not this one. Removing it wants its own change, after a green ROCm cp315
nightly on the wheel install.

Also drops the Linux-only `--pre` flag on the numpy install, which
install_numpy() does not carry. It was a no-op. The install is always an
exact `numpy==X` pin, and pip's prerelease filtering never narrows an exact
specifier -- including one naming a prerelease, because packaging enables
prereleases automatically when the specifier itself references one. So the
flag could not have changed resolution for any value NUMPY_PINS can hold.
It would only matter if the pin stopped being exact.

On Windows and macOS, preinstall_cp315_build_deps() (pytorch#194618, pytorch#194734)
still guards the requirements installs, so install_numpy() takes passthrough
pip args. cp315 has no pyyaml
wheel, so PIP_PACKAGES really does build an sdist and needs the Cython pin to
reach it -- and PIP_CONSTRAINT cannot, which is why pytorch#194618 disables build
isolation instead. numpy resolves to a wheel at the current pin, which makes
the flags inert for that install rather than unnecessary; passing them anyway
keeps the guard in place for a future pin with no cp315 wheel, which is
exactly the case NUMPY_PINS is documented to serve.

install_numpy() policy, all four branches:

```
python - <<'PY'
import importlib.util as u, collections
from unittest import mock
VI = collections.namedtuple("VI", "major minor micro")
s = u.spec_from_file_location("_common", ".ci/wheel/_common.py")
m = u.module_from_spec(s); s.loader.exec_module(m)
for ver, pin in [((3,12,0),"2.0.2"), ((3,14,0),"2.3.4"), ((3,15,0),"2.5.2")]:
    with mock.patch.object(m, "pip_install") as pi, mock.patch.object(m.sys, "version_info", VI(*ver)):
        m.install_numpy(); pi.assert_called_once_with("-q", f"numpy=={pin}")
with mock.patch.object(m, "pip_install") as pi, mock.patch.object(m.sys, "version_info", VI(3,15,0)):
    m.install_numpy("--no-build-isolation")
    pi.assert_called_once_with("-q", "--no-build-isolation", "numpy==2.5.2")
m._IMAGE_NUMPY = "2.6.0"
with mock.patch.object(m, "pip_install") as pi, mock.patch.object(m.sys, "version_info", VI(3,16,0)):
    m.install_numpy(); pi.assert_not_called()
m._IMAGE_NUMPY = None
with mock.patch.object(m.sys, "version_info", VI(3,16,0)), \
     mock.patch.object(m.importlib.util, "find_spec", return_value=object()):
    try: m.install_numpy(); raise AssertionError
    except SystemExit as e: assert "NUMPY_PINS" in str(e.code)
PY
```

`--pre` is a no-op against an exact pin (identical resolution, same wheel):

```
pip install --dry-run --no-deps --ignore-installed --report - numpy==2.0.2
pip install --dry-run --no-deps --ignore-installed --report - --pre numpy==2.0.2
```

Lint:

```
spin lint .ci/wheel/_common.py .ci/wheel/*/build_install_deps.py .ci/wheel/README.md
```

Full CD coverage still comes from a ciflow/binaries_wheel run; the cp315 and
cp315t jobs on every platform are the ones to watch, since they are the
builds this commit moves onto a wheel.

Authored with assistance from Claude Code.
pytorchmergebot pushed a commit that referenced this pull request Sep 16, 2026
…umpy pin (#189275)

## Summary

The three CD wheel-build pipelines (Linux, Windows, macOS) grew as three
independent Python ports and drifted apart: copy-pasted helpers, three
different `numpy` build-pin tables, and different directory homes. This PR
consolidates them under a common `.ci/wheel/` root with a single shared
`_common.py`, and reconciles the numpy pin -- fixing a latent bug where
Linux's greedy `cp31` prefix silently overrode its own numpy default.

A new `.ci/wheel/README.md` documents the resulting layout, the shared stage
sequence (including the Linux-CUDA-only native-AOT stage 2 that #194243
added to the Linux orchestrator), and the dependencies that live outside the
tree.

## Review order

The commits are a deliberate progression -- three mechanical moves first,
then the semantic change, then cleanup:

1. **Move macOS** `.ci/macwheel/` -> `.ci/wheel/mac/` (pure rename + regen).
2. **Move Linux** `.ci/manywheel/` -> `.ci/wheel/linux/` (pure rename + regen).
3. **Move Windows** pipeline -> `.ci/wheel/windows/`. Unlike Linux/macOS,
   `.ci/pytorch/windows/` is a *mixed* dir: only the 5 CD pipeline files
   move; the shared `internal/*.bat` installers and `arm64/` scripts stay
   (non-CD Windows CI uses them). `WIN_CI_DIR` is re-anchored to
   `.ci/pytorch/windows/` so the runtime workspace is byte-for-byte
   unchanged -- only the source files move.
4. **Share `_common.py` + unify numpy** -- the heart of the PR.
5. **Dedup** the `build_env_setup.py` env helpers into `_common.py`.
6. **Add the README.**
7. **Fix the dynamic Linux paths** the string sweep in commit 2 could not
   see (`.ci/${PACKAGE_TYPE}/build.sh`, the libtorch shim) plus, after the
   rebase onto #194243, the native-AOT tests and comments that open
   `.ci/manywheel/build.sh` by literal path.
8. **Fix depth-sensitive paths** inside the moved Linux scripts.
9. **Stop using `PACKAGE_TYPE` as a directory**; drop the dead libtorch shim.
10. **Fall back to an image-provisioned numpy** for a Python with no pin.

## numpy pin reconciliation

The three tables disagreed for almost every Python. Replaced with one
explicit dict + fail-loud (the design macOS already used):

| Python | pin |
|--------|-----|
| 3.10 / 3.11 / 3.12 | `2.0.2` |
| 3.13 | `2.1.2` |
| 3.14 | `2.3.4` |
| 3.15 | `2.5.2` |

Each entry is the oldest numpy *minor* that ships a wheel for that
interpreter, at the newest *patch* of that minor already shipped in
production by one of the platforms, so no numpy bugfix is dropped. Every
Python currently in the CD matrix has an entry; free-threaded builds share
their base version's pin, and numpy publishes `cp31Xt` wheels for every
entry above.

**Build-time pin changes, per platform** (all verified to have a real wheel
on PyPI for every interpreter/platform in the matrix):

| Python | Linux | macOS | Windows |
|---|---|---|---|
| 3.10 / 3.11 / 3.12 | `2.1.0` -> `2.0.2` | -- | -- |
| 3.13 | `2.1.0` -> `2.1.2` | `2.1.0` -> `2.1.2` | -- |
| 3.14 / 3.14t | -- | -- | `2.3.2` -> `2.3.4` |
| 3.15 / 3.15t | -- | -- | -- |

Two of these deserve a reviewer's attention:

- **Linux 3.10-3.12 (`2.1.0` -> `2.0.2`)** undoes the greedy-prefix accident
  and converges Linux onto what Windows and macOS already used. Note this is
  *not* an ABI-floor change: torch never defines `NPY_TARGET_VERSION`, so the
  shipped wheel's runtime numpy requirement is identical across 2.0.x-2.5.x.
- **3.15 / 3.15t** was the one row a single table could not reconcile:
  Windows pinned 2.5.2 (#194618) while Linux and macOS pinned 2.5.1, which
  has no `cp315` wheel and built numpy from source. Upstream has since moved
  Linux (#194741) and macOS (#194734) to 2.5.2 as well, so the unified table
  takes 2.5.2 and this PR changes no 3.15 pin. A side effect of that upstream
  move is that the ROCm cp315 pkg-config workaround (`is_rocm_py315` /
  `prefer_target_python_pkgconfig`, #189722) is now inert; it is deliberately
  left in place here rather than removed in a PR that did not stop
  exercising it.

**s390x keeps its own table, now synced.** `cpu-s390x` is the one Linux arch
that does not run the Python pipeline -- `build.sh` routes it to
`build_cpu.sh` -> `build_common.sh`, which pins numpy in shell. That table
had drifted (`cp31*` -> `2.1.0`, so 3.10-3.13 all got `2.1.0`) and upstream's
"keep in sync" reminder was attached to the table this PR deletes. It is now
updated to match `NUMPY_PINS` entry-for-entry, with a cross-reference in both
files. Absorbing s390x into the Python pipeline proper is a sensible
follow-up -- the image already ships `/opt/python/cpXXX` and
`build_common.sh` already builds via `python -m build` -- but it is a
behavioural port of an arch that only a nightly can validate, so it is
deliberately not bundled here.

Linux's incidental `--pre` is dropped: `install_numpy()` always emits an
exact `numpy==X` pin, and pip's prerelease filtering never narrows an exact
specifier -- including one naming a prerelease, since packaging enables
prereleases automatically when the specifier itself references one.

`install_numpy()` takes passthrough pip args so Windows (#194618) and macOS
(#194734) keep `--no-build-isolation` on the numpy install. cp315 has no
`pyyaml` wheel, so `PIP_PACKAGES` genuinely builds an sdist there and needs
the preinstalled `cython<3.3.0` to reach it (`PIP_CONSTRAINT` cannot -- pip
does not apply it to isolated build environments, which is why #194618
disables isolation instead). numpy resolves to a wheel at the current pin,
which makes those flags inert for that install rather than unnecessary; they
are passed anyway so a future pin without a cp315 wheel stays guarded.

The unpinned-Python fallback checks a snapshot taken when `_common.py` is
imported, not a probe at call time. It has to: on Linux and macOS the stage
installs `requirements-build.txt` -- which lists a bare `numpy` -- before
calling `install_numpy()`, so a call-time probe would always find one and the
fail-loud branch could never fire.

## Note on verification

`ciflow/binaries_wheel` exercises the build half of these pipelines, and is
running on this PR. What it does *not* cover is the nightly-only tail:
upload, the libtorch-extract job, and the s390x path. Those parts are
verified by import/path-math simulation, the numpy table checked against PyPI
wheel availability, and lint.

`install_numpy()`'s fallback is covered by a unit-style check of all three
branches (pinned / unpinned-with-image-numpy / unpinned-without), including
the case that proves the fail-loud branch is reachable -- see the test plan
in the final commit's message.

The two spots most worth a careful eye in review are the Windows
`WIN_CI_DIR` re-anchoring (commit 3) and Linux/macOS adopting the shared
(Windows-superset) `write_env_exports` (commit 5); both are argued to be
behavior-preserving in their commit messages.

Deferred (not a blocker, entangled with the scikit-build-core migration):
switching Linux's `setup.py clean` to `spin clean`, which also needs a
dependency reorder.

## Test plan

```
# helpers resolve from one source; numpy 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","install_numpy","download","write_env_exports","shell_quote"])
PY
# no stray refs to the old dirs; generated workflows reproduce with no diff
grep -rn -- .ci/macwheel .ci/manywheel .github .ci   # (empty)
python .github/scripts/generate_ci_workflows.py       # no-op
spin lint .ci/wheel/_common.py .ci/wheel/*/build_install_deps.py .ci/wheel/*/build_env_setup.py .ci/wheel/README.md
```

This PR was authored with the assistance of Claude Code.

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

Pull Request resolved: #189275
Approved by: https://github.com/atalman
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 Merged module: rocm AMD GPU support for Pytorch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ROCm] Python 3.15 manywheel build fails building numpy from source (pkg-config resolves python3 to system 3.6)

5 participants