Skip to content

Bump the Python 3.15 numpy pin to 2.5.2 - #194741

Closed
atalman wants to merge 1 commit into
mainfrom
atalman/numpy-2.5.2
Closed

atalman wants to merge 1 commit into
mainfrom
atalman/numpy-2.5.2

Conversation

@atalman

@atalman atalman commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

Bumps the Python 3.15 numpy pin from 2.5.1 to 2.5.2 in the two build-dependency tables that were still on 2.5.1.

 .ci/manywheel/build_install_deps.py
-    ((3, 15), "2.5.1"),
+    ((3, 15), "2.5.2"),

 .ci/macwheel/build_install_deps.py
-    "3.15": "2.5.1",
+    "3.15": "2.5.2",

Only the 3.15 entry changes; 3.14 and below keep their pins.

Why this matters beyond a version bump

numpy 2.5.1 shipped no cp315 wheels at all. 2.5.2 ships 22 of them:

platform cp315 cp315t
manylinux_2_28_x86_64 yes yes
manylinux_2_28_aarch64 yes yes
macOS (x86_64 + arm64) yes yes
win_amd64 / win_arm64 yes yes
musllinux yes yes

That is what the from-source path in .ci/manywheel/build_install_deps.py exists for — its docstring says "cp315 has no numpy wheel, so numpy is built from source", with is_rocm_py315() / prefer_target_python_pkgconfig() working around the ROCm image resolving pkg-config python3 to Python 3.6 during numpy's meson Cython check. With 2.5.2, pip should resolve a manylinux wheel instead of building, so 3.15 wheel builds get faster and stop depending on that workaround.

Consistency

Windows was already on 2.5.2:

# .ci/pytorch/windows/build_install_deps.py
NUMPY_PINS: list[tuple[str, str]] = [
    ("cp315", "2.5.2"),

so this brings manywheel and macwheel in line rather than moving to a new version unilaterally.

Follow-ups, deliberately not in this PR

  1. The ROCm cp315 source-build workaround is now dead code on the happy path, and its comment is factually stale. I left it in place: it is the fallback if a cp315 wheel is ever unavailable again, and removing it touches a ROCm-only path I cannot exercise here. Worth a separate cleanup (or at least a comment update) once a 3.15 ROCm build confirms the wheel is picked up.
  2. .ci/docker/requirements-ci.txt has no 3.15 entry — its top pin is numpy==2.3.4; python_version >= "3.14", and 2.3.4 has no cp315 wheels. Not touched here since it never referenced 2.5.1, but it will need a 3.15 line before CI tests on 3.15.
  3. --pre is still passed on the manywheel numpy install; with a final release pinned exactly it is a no-op, but it could be dropped.

Verification

Pin resolution after the change (manywheel's floor-matching logic):

py3.15 -> 2.5.2
py3.14 -> 2.3.4
py3.13 -> 2.1.0
py3.10 -> 2.1.0
py3.9  -> 2.0.2   (DEFAULT_NUMPY)

macwheel table parses to {'3.10': '2.0.2', ..., '3.14': '2.3.4', '3.15': '2.5.2'}. numpy 2.5.2 confirmed present on PyPI (current latest) with an sdist plus the wheels above.

@atalman
atalman requested a review from a team as a code owner August 25, 2026 15:10
@pytorch-bot

pytorch-bot Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ You can merge normally! (1 Unrelated Failure), 1 Unclassified Failure

As of commit f64ed02 with merge base 0303631 (image):

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

  • macos-arm64-binary-wheel / wheel-build (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
    ninja: build stopped: subcommand failed

    AI verdict: AI verdict: not related

    The build failure is pyyaml segfaulting (exit code -11/SIGSEGV) when trying to build its wheel on Python 3.15 beta. This is an upstream pyyaml/CPython 3.15 compatibility issue completely unrelated to the numpy version pin bump from 2.5.1 to 2.5.2.

    Full reasoning on HUD →

FLAKY - The following job failed but was likely due to flakiness present on trunk:

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

@pytorch-bot

pytorch-bot Bot commented Aug 25, 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.

@pytorchgreenlight

pytorchgreenlight Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

PR approved to be merged without human review

Why
Two-line build-time numpy pin bump for Python 3.15 only: NUMPY_PINS in .ci/manywheel/build_install_deps.py (((3, 15), "2.5.1") -> "2.5.2") and .ci/macwheel/build_install_deps.py ("3.15": "2.5.1" -> "2.5.2"). No logic, control-flow, or error-handling change -- numpy_pin() in both files is untouched and pins for 3.14 and below are unchanged; .ci/pytorch/windows/build_install_deps.py already pinned cp315 to 2.5.2 in-tree, so this aligns manywheel/macwheel with the existing Windows pin rather than introducing a new version, and grep confirms no 2.5.1 numpy reference remains. Data-only pin change to a bleeding-edge (3.15) binary-build path needs no test coverage, and a bad pin would fail the build loudly at pip install rather than ship a silent regression.

reason: clean

Inference job

@malfet malfet added the ciflow/binaries Trigger all binary build and upload jobs on the PR label Aug 25, 2026
atalman added a commit to pytorch/test-infra that referenced this pull request Aug 25, 2026
numpy **2.5.2** publishes cp315 and cp315t wheels on PyPI, so the
workarounds built for their absence are no longer needed. Removes both
halves.

## Why it is safe now

2.5.1 shipped **zero** cp315 wheels; 2.5.2 ships 22, covering every
platform we validate:

| platform | cp315 | cp315t |
|---|---|---|
| `manylinux_2_28_x86_64` / `_aarch64` | yes | yes |
| macOS (x86_64 + arm64) | yes | yes |
| `win_amd64` / `win_arm64` | yes | yes |
| musllinux | yes | yes |

Windows was the case that motivated the special-casing (MSVC failing on
`stdalign.h` during a source build), and it now has both wheels.

Paired with pytorch/pytorch#194741, which moves the 3.15 build pin from
2.5.1 to 2.5.2.

## 1. `s3_management/update_dependencies.py`

Removes the preview-wheel merge: `PREVIEW_PYTHON_TAGS`,
`PREVIEW_WHEEL_INJECT_PACKAGES`, `PREVIEW_WHEEL_INJECT_PREFIXES`,
`PREVIEW_NUMPY_INDEX_URL`, `PREVIEW_NUMPY_INDEX_BASE`,
`PREVIEW_NUMPY_VERSION`, the two functions
`fetch_preview_numpy_anchors()` / `append_preview_numpy_wheels()`, and
the call site in the index-processing path.

The nightly and test numpy indexes now serve exactly what PyPI
publishes, with no links merged in from the scientific-python nightly
wheelhouse.

`normalize_pkg_name()` is **kept** — it is also used by
`append_retained_wheels()` for `RETAINED_WHEELS`.

## 2. `.github/scripts/validate_binaries.sh`

```diff
-        if [[ ${MATRIX_PYTHON_VERSION} == "3.15" || ${MATRIX_PYTHON_VERSION} == "3.15t" ]]; then
-            pip3 install --pre numpy --upgrade --force-reinstall \
-                --only-binary=:all: \
-                --index-url https://download.pytorch.org/whl/nightly
-        else
-            pip3 install numpy --upgrade --force-reinstall
-        fi
+        pip3 install numpy --upgrade --force-reinstall
```

This is the more valuable half: 3.15 validation was resolving numpy from
download.pytorch.org, so it was not exercising what a user gets from
PyPI. Now every Python version takes the same path.

## Verification

- No dangling `PREVIEW_*` references (AST check: no such names remain).
- `normalize_pkg_name` and `append_retained_wheels` still defined; both
preview functions gone.
- `py_compile` clean; `pyfmt_linter.py` clean under the repo-pinned
toolchain (usort 1.0.8.post1 / isort 6.0.1 / ruff 0.14.4).
- `bash -n` clean on the validation script.

## Note on ordering

The injection targeted the **2.6.0** line (`PREVIEW_NUMPY_VERSION =
"2.6.0"`), i.e. pre-release wheels ahead of PyPI. Nothing pins numpy
2.6.0.dev*, so dropping it should not change any resolution; 3.15 builds
and validation will land on 2.5.2 from PyPI. If a future CPython again
lands before numpy ships wheels, this mechanism is worth restoring — it
was generic apart from the hard-coded version.

Co-authored-by: Andrey Talman <[email protected]>
@atalman

atalman commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchmergebot merge -f "all looks good, lets merge"

@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

@atalman

atalman commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchmergebot cherry-pick --onto release/2.14 -c critical

@pytorchbot

Copy link
Copy Markdown
Collaborator

Cherry picking #194741

The cherry pick PR is at #194821 and it is recommended to link a critical cherry pick PR with an issue. The following tracker issues are updated:

Details for Dev Infra team Raised by workflow job

atalman added a commit that referenced this pull request Aug 26, 2026
Bump the Python 3.15 numpy pin to 2.5.2 (#194741)

Bumps the Python 3.15 numpy pin from 2.5.1 to 2.5.2 in the two build-dependency tables that were still on 2.5.1.

```diff
 .ci/manywheel/build_install_deps.py
-    ((3, 15), "2.5.1"),
+    ((3, 15), "2.5.2"),

 .ci/macwheel/build_install_deps.py
-    "3.15": "2.5.1",
+    "3.15": "2.5.2",
```

Only the 3.15 entry changes; 3.14 and below keep their pins.

## Why this matters beyond a version bump

**numpy 2.5.1 shipped no cp315 wheels at all.** 2.5.2 ships 22 of them:

| platform | cp315 | cp315t |
|---|---|---|
| `manylinux_2_28_x86_64` | yes | yes |
| `manylinux_2_28_aarch64` | yes | yes |
| macOS (x86_64 + arm64) | yes | yes |
| `win_amd64` / `win_arm64` | yes | yes |
| musllinux | yes | yes |

That is what the from-source path in `.ci/manywheel/build_install_deps.py` exists for — its docstring says *"cp315 has no numpy wheel, so numpy is built from source"*, with `is_rocm_py315()` / `prefer_target_python_pkgconfig()` working around the ROCm image resolving `pkg-config python3` to Python 3.6 during numpy's meson Cython check. With 2.5.2, pip should resolve a manylinux wheel instead of building, so 3.15 wheel builds get faster and stop depending on that workaround.

## Consistency

Windows was already on 2.5.2:

```python
# .ci/pytorch/windows/build_install_deps.py
NUMPY_PINS: list[tuple[str, str]] = [
    ("cp315", "2.5.2"),
```

so this brings manywheel and macwheel in line rather than moving to a new version unilaterally.

## Follow-ups, deliberately not in this PR

1. **The ROCm cp315 source-build workaround is now dead code** on the happy path, and its comment is factually stale. I left it in place: it is the fallback if a cp315 wheel is ever unavailable again, and removing it touches a ROCm-only path I cannot exercise here. Worth a separate cleanup (or at least a comment update) once a 3.15 ROCm build confirms the wheel is picked up.
2. **`.ci/docker/requirements-ci.txt` has no 3.15 entry** — its top pin is `numpy==2.3.4; python_version >= "3.14"`, and 2.3.4 has no cp315 wheels. Not touched here since it never referenced 2.5.1, but it will need a 3.15 line before CI tests on 3.15.
3. `--pre` is still passed on the manywheel numpy install; with a final release pinned exactly it is a no-op, but it could be dropped.

## Verification

Pin resolution after the change (manywheel's floor-matching logic):

```
py3.15 -> 2.5.2
py3.14 -> 2.3.4
py3.13 -> 2.1.0
py3.10 -> 2.1.0
py3.9  -> 2.0.2   (DEFAULT_NUMPY)
```

macwheel table parses to `{'3.10': '2.0.2', ..., '3.14': '2.3.4', '3.15': '2.5.2'}`. numpy 2.5.2 confirmed present on PyPI (current latest) with an sdist plus the wheels above.
Pull Request resolved: #194741
Approved by: https://github.com/pytorchgreenlight, https://github.com/malfet

(cherry picked from commit c2143af)

Co-authored-by: Andrey Talman <[email protected]>
@atalman atalman mentioned this pull request Aug 31, 2026
60 of 63 tasks
orrangetabby17 pushed a commit to orrangetabby17/pytorch that referenced this pull request Sep 2, 2026
Bumps the Python 3.15 numpy pin from 2.5.1 to 2.5.2 in the two build-dependency tables that were still on 2.5.1.

```diff
 .ci/manywheel/build_install_deps.py
-    ((3, 15), "2.5.1"),
+    ((3, 15), "2.5.2"),

 .ci/macwheel/build_install_deps.py
-    "3.15": "2.5.1",
+    "3.15": "2.5.2",
```

Only the 3.15 entry changes; 3.14 and below keep their pins.

## Why this matters beyond a version bump

**numpy 2.5.1 shipped no cp315 wheels at all.** 2.5.2 ships 22 of them:

| platform | cp315 | cp315t |
|---|---|---|
| `manylinux_2_28_x86_64` | yes | yes |
| `manylinux_2_28_aarch64` | yes | yes |
| macOS (x86_64 + arm64) | yes | yes |
| `win_amd64` / `win_arm64` | yes | yes |
| musllinux | yes | yes |

That is what the from-source path in `.ci/manywheel/build_install_deps.py` exists for — its docstring says *"cp315 has no numpy wheel, so numpy is built from source"*, with `is_rocm_py315()` / `prefer_target_python_pkgconfig()` working around the ROCm image resolving `pkg-config python3` to Python 3.6 during numpy's meson Cython check. With 2.5.2, pip should resolve a manylinux wheel instead of building, so 3.15 wheel builds get faster and stop depending on that workaround.

## Consistency

Windows was already on 2.5.2:

```python
# .ci/pytorch/windows/build_install_deps.py
NUMPY_PINS: list[tuple[str, str]] = [
    ("cp315", "2.5.2"),
```

so this brings manywheel and macwheel in line rather than moving to a new version unilaterally.

## Follow-ups, deliberately not in this PR

1. **The ROCm cp315 source-build workaround is now dead code** on the happy path, and its comment is factually stale. I left it in place: it is the fallback if a cp315 wheel is ever unavailable again, and removing it touches a ROCm-only path I cannot exercise here. Worth a separate cleanup (or at least a comment update) once a 3.15 ROCm build confirms the wheel is picked up.
2. **`.ci/docker/requirements-ci.txt` has no 3.15 entry** — its top pin is `numpy==2.3.4; python_version >= "3.14"`, and 2.3.4 has no cp315 wheels. Not touched here since it never referenced 2.5.1, but it will need a 3.15 line before CI tests on 3.15.
3. `--pre` is still passed on the manywheel numpy install; with a final release pinned exactly it is a no-op, but it could be dropped.

## Verification

Pin resolution after the change (manywheel's floor-matching logic):

```
py3.15 -> 2.5.2
py3.14 -> 2.3.4
py3.13 -> 2.1.0
py3.10 -> 2.1.0
py3.9  -> 2.0.2   (DEFAULT_NUMPY)
```

macwheel table parses to `{'3.10': '2.0.2', ..., '3.14': '2.3.4', '3.15': '2.5.2'}`. numpy 2.5.2 confirmed present on PyPI (current latest) with an sdist plus the wheels above.
Pull Request resolved: pytorch#194741
Approved by: https://github.com/pytorchgreenlight, https://github.com/malfet
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 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
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
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
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
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
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
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
@github-actions
github-actions Bot deleted the atalman/numpy-2.5.2 branch November 9, 2026 01:47
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants