Skip to content

Commit 0a7ef9c

Browse files
authored
ci: use selected Python for pinned PyTorch installs (#23919)
Route PyTorch, torchvision, and torchaudio installation through PYTHON_EXECUTABLE, falling back to python from PATH. This keeps pip tied to the active interpreter and supports conda and virtual environments. Drop `--user` for domain packages because virtual environments reject it. Keep the existing cache and source-build flow unchanged. Authored with Codex. Signed-off-by: Zingo Andersen <Zingo.Andersen@arm.com>
1 parent 98042ae commit 0a7ef9c

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

‎.ci/scripts/utils.sh‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
# Copyright (c) Meta Platforms, Inc. and affiliates.
33
# All rights reserved.
4-
# Copyright 2024 Arm Limited and/or its affiliates.
4+
# Copyright 2024,2026 Arm Limited and/or its affiliates.
55
#
66
# This source code is licensed under the BSD-style license found in the
77
# LICENSE file in the root directory of this source tree.
@@ -50,8 +50,9 @@ dedupe_macos_loader_path_rpaths() {
5050
fi
5151

5252
local torch_lib_dir
53+
local python_executable=${PYTHON_EXECUTABLE:-python}
5354
pushd ..
54-
torch_lib_dir=$(python -c "import importlib.util; print(importlib.util.find_spec('torch').submodule_search_locations[0])")/lib
55+
torch_lib_dir=$("${python_executable}" -c "import importlib.util; print(importlib.util.find_spec('torch').submodule_search_locations[0])")/lib
5556
popd
5657

5758
if [[ -z "${torch_lib_dir}" || ! -d "${torch_lib_dir}" ]]; then
@@ -83,12 +84,16 @@ dedupe_macos_loader_path_rpaths() {
8384
}
8485

8586
install_domains() {
87+
local python_executable=${PYTHON_EXECUTABLE:-python}
8688
echo "Install torchvision and torchaudio"
87-
pip install --no-build-isolation --user "git+https://github.com/pytorch/audio.git@${TORCHAUDIO_VERSION}"
88-
pip install --no-build-isolation --user "git+https://github.com/pytorch/vision.git@${TORCHVISION_VERSION}"
89+
"${python_executable}" -m pip install --no-build-isolation \
90+
"git+https://github.com/pytorch/audio.git@${TORCHAUDIO_VERSION}"
91+
"${python_executable}" -m pip install --no-build-isolation \
92+
"git+https://github.com/pytorch/vision.git@${TORCHVISION_VERSION}"
8993
}
9094

9195
install_pytorch_and_domains() {
96+
local python_executable=${PYTHON_EXECUTABLE:-python}
9297
pushd .ci/docker || return
9398
TORCH_VERSION=$(cat ci_commit_pins/pytorch.txt)
9499
popd || return
@@ -101,9 +106,9 @@ install_pytorch_and_domains() {
101106

102107
local system_name=$(uname)
103108
if [[ "${system_name}" == "Darwin" ]]; then
104-
local platform=$(python -c 'import sysconfig; import platform; v=platform.mac_ver()[0].split(".")[0]; platform=sysconfig.get_platform().split("-"); platform[1]=f"{v}_0"; print("_".join(platform))')
109+
local platform=$("${python_executable}" -c 'import sysconfig; import platform; v=platform.mac_ver()[0].split(".")[0]; platform=sysconfig.get_platform().split("-"); platform[1]=f"{v}_0"; print("_".join(platform))')
105110
fi
106-
local python_version=$(python -c 'import platform; v=platform.python_version_tuple(); print(f"{v[0]}{v[1]}")')
111+
local python_version=$("${python_executable}" -c 'import platform; v=platform.python_version_tuple(); print(f"{v[0]}{v[1]}")')
107112
local torch_release=$(cat version.txt)
108113
# Download key must match the upload key below (basename of dist/*.whl,
109114
# which always carries the build's resolved +gitHASH). Branch-ref pins
@@ -118,7 +123,7 @@ install_pytorch_and_domains() {
118123
# of the Docker image
119124
local torch_wheel_not_found=0
120125
if [[ "${system_name}" == "Darwin" ]]; then
121-
pip install "${cached_torch_wheel}" || torch_wheel_not_found=1
126+
"${python_executable}" -m pip install "${cached_torch_wheel}" || torch_wheel_not_found=1
122127
else
123128
torch_wheel_not_found=1
124129
fi
@@ -138,14 +143,14 @@ install_pytorch_and_domains() {
138143
# Keep in sync with pytorch/pyproject.toml [build-system].requires.
139144
local build_venv=/tmp/pytorch-build-venv
140145
rm -rf "${build_venv}"
141-
python -m venv --system-site-packages "${build_venv}"
146+
"${python_executable}" -m venv --system-site-packages "${build_venv}"
142147
"${build_venv}/bin/pip" install build "scikit-build-core>=1.0" ninja \
143148
"packaging>=24.2" "typing-extensions>=4.10.0" pyyaml six numpy
144149
USE_DISTRIBUTED=1 "${build_venv}/bin/python" -m build --wheel --no-isolation
145150
rm -rf "${build_venv}"
146-
pip install "$(echo dist/*.whl)"
151+
"${python_executable}" -m pip install "$(echo dist/*.whl)"
147152
# A build with no BLAS succeeds silently, so check rather than assume.
148-
(cd / && python -c "
153+
(cd / && "${python_executable}" -c "
149154
import torch
150155
assert torch._C.has_lapack, 'built without LAPACK'
151156
torch.linalg.qr(torch.randn(4, 4))

0 commit comments

Comments
 (0)