@@ -53,7 +53,7 @@ dedupe_macos_loader_path_rpaths() {
5353 pushd ..
5454 torch_lib_dir=$( python -c " import importlib.util; print(importlib.util.find_spec('torch').submodule_search_locations[0])" ) /lib
5555 popd
56-
56+
5757 if [[ -z " ${torch_lib_dir} " || ! -d " ${torch_lib_dir} " ]]; then
5858 return
5959 fi
@@ -89,6 +89,30 @@ install_domains() {
8989}
9090
9191install_pytorch_and_domains () {
92+ # CWD is the executorch repo root, where torch_pin.py lives.
93+ TORCH_CHANNEL=$( python -c " from torch_pin import CHANNEL; print(CHANNEL)" )
94+
95+ if [ " ${TORCH_CHANNEL} " != " nightly" ]; then
96+ # Test/release: install the published wheels directly from torch_pin.py's
97+ # channel index, skipping the source-build path entirely. RC wheels at
98+ # /whl/test/ get re-uploaded under the same version, so use --no-cache-dir
99+ # there to avoid stale cache hits.
100+ local torch_spec=$( python -c " from torch_pin import torch_spec; print(torch_spec())" )
101+ local torchvision_spec=$( python -c " from torch_pin import torchvision_spec; print(torchvision_spec())" )
102+ local torchaudio_spec=$( python -c " from torch_pin import torchaudio_spec; print(torchaudio_spec())" )
103+ local torch_index_url=$( python -c " from torch_pin import torch_index_url_base; print(torch_index_url_base())" )
104+ local cache_flag=" "
105+ if [ " ${TORCH_CHANNEL} " = " test" ]; then
106+ cache_flag=" --no-cache-dir"
107+ fi
108+ pip install --force-reinstall ${cache_flag} \
109+ " ${torch_spec} " " ${torchvision_spec} " " ${torchaudio_spec} " \
110+ --index-url " ${torch_index_url} /cpu"
111+ return
112+ fi
113+
114+ # Nightly: source-build pytorch from the pinned SHA so CI catches upstream
115+ # regressions; pytorch's own audio/vision pins drive those installs.
92116 pushd .ci/docker || return
93117 TORCH_VERSION=$( cat ci_commit_pins/pytorch.txt)
94118 popd || return
@@ -140,10 +164,10 @@ install_pytorch_and_domains() {
140164 fi
141165
142166 dedupe_macos_loader_path_rpaths
143- # Grab the pinned audio and vision commits from PyTorch
144- TORCHAUDIO_VERSION=release/2.11
167+ # We're on the nightly path here; defer to PyTorch's own pinned commits.
168+ TORCHAUDIO_VERSION=$( cat .github/ci_commit_pins/audio.txt )
145169 export TORCHAUDIO_VERSION
146- TORCHVISION_VERSION=release/0.26
170+ TORCHVISION_VERSION=$( cat .github/ci_commit_pins/vision.txt )
147171 export TORCHVISION_VERSION
148172
149173 install_domains
@@ -218,17 +242,21 @@ download_stories_model_artifacts() {
218242}
219243
220244do_not_use_nightly_on_ci () {
221- # An assert to make sure that we are not using PyTorch nightly on CI to prevent
222- # regression as documented in https://github.com/pytorch/executorch/pull/6564
223- TORCH_VERSION=$( pip list | grep -w ' torch ' | awk -F ' ' {' print $2' } | tr -d ' \n' )
245+ # Sanity check that prevents accidentally landing a PR that pins to PyTorch
246+ # nightly without exercising the source-build path (see #6564).
247+ #
248+ # For CHANNEL=nightly, CI source-builds pytorch from the SHA in pytorch.txt,
249+ # so the installed torch shows up as e.g. 2.13.0a0+gitc8a648d — assert that.
250+ # For CHANNEL=test/release, we install published wheels by design (e.g.
251+ # 2.11.0), so the +git assertion doesn't apply.
252+ TORCH_CHANNEL=$( python -c " from torch_pin import CHANNEL; print(CHANNEL)" )
253+ if [ " ${TORCH_CHANNEL} " != " nightly" ]; then
254+ return 0
255+ fi
224256
225- # The version of PyTorch building from source looks like 2.6.0a0+gitc8a648d that
226- # includes the commit while nightly (2.6.0.dev20241019+cpu) or release (2.6.0)
227- # won't have that. Note that we couldn't check for the exact commit from the pin
228- # ci_commit_pins/pytorch.txt here because the value will be different when running
229- # this on PyTorch CI
257+ TORCH_VERSION=$( pip list | grep -w ' torch ' | awk -F ' ' {' print $2' } | tr -d ' \n' )
230258 if [[ " ${TORCH_VERSION} " != * " +git" * ]]; then
231- echo " Unexpected torch version. Expected binary built from source, got ${TORCH_VERSION} "
259+ echo " Unexpected torch version. Expected binary built from source for CHANNEL=nightly , got ${TORCH_VERSION} "
232260 exit 1
233261 fi
234262}
0 commit comments