From ca8f53f739c8fdd497084d4b72c1e3b4994b307f Mon Sep 17 00:00:00 2001 From: Anthony Shoumikhin Date: Thu, 22 Oct 2026 13:11:44 -0700 Subject: [PATCH] Keep the caller's numpy when setting up the Core ML backend 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. --- backends/apple/coreml/scripts/install_requirements.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backends/apple/coreml/scripts/install_requirements.sh b/backends/apple/coreml/scripts/install_requirements.sh index f57df535d86..2858960820b 100755 --- a/backends/apple/coreml/scripts/install_requirements.sh +++ b/backends/apple/coreml/scripts/install_requirements.sh @@ -13,7 +13,7 @@ SCRIPT_DIR_PATH="$( )" # TODO(jathu): remove the need to fetch coremltools to build deps for coreml_executor_runner. -# Keep this version in sync with: pyproject.toml +# Keep this version in sync with setup.py, and re-check the pip install below when bumping it. COREMLTOOLS_VERSION="9.0" # Safe colors (no TERM noise in CI) @@ -75,12 +75,14 @@ if [[ "$(uname)" == "Darwin" ]]; then fi echo "${green}ExecuTorch: Installing coremltools dependencies.${reset}" +# Not coremltools' reqs/build.pip, whose old numpy pin would downgrade the caller's numpy. +# Its CMake build only needs numpy (for the include path) and setuptools (to build kmeans1d). SDKROOT="$HOST_SDKROOT" \ CC="$HOST_CC" \ CXX="$HOST_CXX" \ CFLAGS="$HOST_CFLAGS" \ CXXFLAGS="$HOST_CXXFLAGS" \ -python -m pip install -r "$COREMLTOOLS_DIR_PATH/reqs/build.pip" +python -m pip install numpy setuptools STATUS=$? if [ $STATUS -ne 0 ]; then echo "${red}ExecuTorch: Failed to install coremltools dependencies.${reset}"