Skip to content

Keep the caller's numpy when setting up the Core ML backend - #24090

Merged
shoumikhin merged 1 commit into
pytorch:mainfrom
shoumikhin:coreml-keep-numpy
Oct 23, 2026
Merged

shoumikhin merged 1 commit into
pytorch:mainfrom
shoumikhin:coreml-keep-numpy

Conversation

@shoumikhin

@shoumikhin shoumikhin commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem

backends/apple/coreml/scripts/install_requirements.sh clones coremltools and runs pip install -r reqs/build.pip before it builds the mlmodel library. That file pins numpy==2.0.0 on Python 3.9 to 3.12. So running the script quietly downgrades numpy in whatever environment called it.

This used to be harmless. pandas 3.1.0 (released October 22, 2026) requires numpy>=2.0.2, so after the downgrade import pandas fails:

ImportError: Please upgrade numpy to >= 2.0.2 to use this pandas version.
Your numpy version is 2.0.0.

The ExecuTorch devtools import pandas, so examples/apple/coreml/scripts/export.py fails, and so do most Core ML jobs in CI (for example test-coreml-delegate, test-models-macos-coreml, build-demo-ios). A few jobs that run the script still pass, because nothing imports pandas after it.

Fix

The coremltools 9.0 CMake build only needs two Python packages:

  • numpy, because CMake asks it for its include path
  • setuptools, because CMake builds the bundled kmeans1d helper with setup.py

Install just those two, unpinned. If numpy is already installed, pip leaves it alone. A comment says why each one is there.

This also fixes a plain Python 3.12 virtual environment. It has no setuptools, and build.pip adds setuptools only for Python 3.13 and newer, so there the old script stopped at the CMake configure step.

The note next to COREMLTOOLS_VERSION now points at setup.py, where the coremltools pin lives today, and asks to re-check this package list when the version changes.

Testing

On macOS with Python 3.12:

Environment mlmodel builds numpy after import pandas
numpy 2.4.6, pandas 3.1.0, setuptools; before yes 2.0.0 fails
same; after yes 2.4.6 works
brand new venv with only pip; after yes 2.5.4 (installed) not installed

In every "yes" row the protobuf sources the runtime needs are copied to runtime/sdk/format/. The new venv run used CMake 3.31, matching the cmake<4 pin in requirements-dev.txt.

To check that both packages are needed, I configured coremltools with only one of them. With only numpy, configure fails building kmeans1d. With only setuptools, it fails to find the numpy include path.

In CI, test-coreml-delegate, test-models-macos-coreml (all models), test-static-llama-ane and test-llama-runner-mac (coreml) ran with this install line and passed. Their logs show numpy and setuptools already installed, numpy kept at 2.4.6, and mlmodel built.

@shoumikhin
shoumikhin requested a review from metascroy as a code owner October 22, 2026 20:12
@shoumikhin shoumikhin added the release notes: apple Changes to the Apple backend delegate label Oct 22, 2026
Copilot AI balanced review requested due to automatic review settings October 22, 2026 20:12
@shoumikhin shoumikhin added the release notes: apple Changes to the Apple backend delegate label Oct 22, 2026
@pytorch-bot

pytorch-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit ca8f53f with merge base d533adf (image):

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

CXX="$HOST_CXX" \
CFLAGS="$HOST_CFLAGS" \
CXXFLAGS="$HOST_CXXFLAGS" \
python -m pip install -r "$COREMLTOOLS_DIR_PATH/reqs/build.pip"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is there any othr places using build.pip if that's out of date now? if not maybe we need to remove build.pip if that's a et controled file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

build.pip is not an ExecuTorch file. It comes from Apple's coremltools repo, which this script clones at the 9.0 tag. After this change nothing in ExecuTorch uses it, so there is nothing for us to remove.

Copilot AI balanced review requested due to automatic review settings October 23, 2026 08:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

backends/apple/coreml/scripts/install_requirements.sh clones coremltools
and installs its reqs/build.pip before building the mlmodel library.
That file pins numpy==2.0.0 for Python 3.9 to 3.12, so running the script
silently downgrades numpy in the caller's environment.

pandas 3.1.0 (released October 22, 2026) requires numpy>=2.0.2, so after
the downgrade `import pandas` fails, and anything that imports the
ExecuTorch devtools (for example examples/apple/coreml/scripts/export.py)
breaks with "Please upgrade numpy to >= 2.0.2". Most Core ML jobs in CI
hit this.

The coremltools 9.0 CMake build only needs numpy (it asks numpy for its
include path) and setuptools (it builds the bundled kmeans1d helper with
setup.py). Install just those, unpinned, so an existing numpy is left
alone. This also fixes a plain Python 3.12 venv, which has no setuptools:
there the old script stopped at the CMake configure step.

The comment next to COREMLTOOLS_VERSION now points at setup.py, where the
coremltools pin lives, and asks to re-check this package list on a bump.

Test plan:
- Python 3.12 venv with numpy 2.4.6, pandas 3.1.0 and setuptools, script
  before and after this change. Before: mlmodel builds, numpy drops to
  2.0.0, `import pandas` fails. After: mlmodel builds, numpy stays 2.4.6,
  `import pandas` works.
- Brand new Python 3.12 venv with only pip, CMake 3.31: the script
  installs numpy and setuptools, builds mlmodel and copies the protobuf
  sources.
- Configuring coremltools with only numpy fails at kmeans1d, and with
  only setuptools fails at the numpy include path, so both are needed.
Copilot AI balanced review requested due to automatic review settings October 23, 2026 17:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@shoumikhin
shoumikhin merged commit 867a600 into pytorch:main Oct 23, 2026
571 of 575 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. release notes: apple Changes to the Apple backend delegate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants