-
Notifications
You must be signed in to change notification settings - Fork 966
Centralize torch-family version pins in torch_pin.py #19155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| release/2.11 | ||
| release/2.11 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import importlib | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def pin(): | ||
| """Yield a fresh import of torch_pin so tests can mutate CHANNEL safely.""" | ||
| import torch_pin | ||
|
|
||
| yield torch_pin | ||
| importlib.reload(torch_pin) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "channel, expected_torch, expected_url", | ||
| [ | ||
| ( | ||
| "nightly", | ||
| "torch=={TORCH_VERSION}.{NIGHTLY_VERSION}", | ||
| "https://download.pytorch.org/whl/nightly", | ||
| ), | ||
| ("test", "torch=={TORCH_VERSION}", "https://download.pytorch.org/whl/test"), | ||
| ("release", "torch=={TORCH_VERSION}", "https://download.pytorch.org/whl"), | ||
| ], | ||
| ) | ||
| def test_channel_resolution(pin, channel, expected_torch, expected_url): | ||
| pin.CHANNEL = channel | ||
| expected = expected_torch.format( | ||
| TORCH_VERSION=pin.TORCH_VERSION, NIGHTLY_VERSION=pin.NIGHTLY_VERSION | ||
| ) | ||
| assert pin.torch_spec() == expected | ||
| assert pin.torch_index_url_base() == expected_url | ||
|
|
||
|
|
||
| def test_all_specs_share_nightly_suffix(pin): | ||
| pin.CHANNEL = "nightly" | ||
| suffix = f".{pin.NIGHTLY_VERSION}" | ||
| assert pin.torch_spec().endswith(suffix) | ||
| assert pin.torchaudio_spec().endswith(suffix) | ||
| assert pin.torchcodec_spec().endswith(suffix) | ||
| assert pin.torchvision_spec().endswith(suffix) | ||
|
|
||
|
|
||
| def test_specs_drop_suffix_off_nightly(pin): | ||
| pin.CHANNEL = "test" | ||
| assert pin.torch_spec() == f"torch=={pin.TORCH_VERSION}" | ||
| assert pin.torchaudio_spec() == f"torchaudio=={pin.TORCHAUDIO_VERSION}" | ||
| assert pin.torchcodec_spec() == f"torchcodec=={pin.TORCHCODEC_VERSION}" | ||
| assert pin.torchvision_spec() == f"torchvision=={pin.TORCHVISION_VERSION}" | ||
|
|
||
|
|
||
| def test_torch_branch_derived_from_version(pin): | ||
| assert pin.torch_branch() == f"release/{pin.TORCH_VERSION.rsplit('.', 1)[0]}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,7 +53,7 @@ dedupe_macos_loader_path_rpaths() { | |
| pushd .. | ||
| torch_lib_dir=$(python -c "import importlib.util; print(importlib.util.find_spec('torch').submodule_search_locations[0])")/lib | ||
| popd | ||
|
|
||
| if [[ -z "${torch_lib_dir}" || ! -d "${torch_lib_dir}" ]]; then | ||
| return | ||
| fi | ||
|
|
@@ -89,6 +89,30 @@ install_domains() { | |
| } | ||
|
|
||
| install_pytorch_and_domains() { | ||
| # CWD is the executorch repo root, where torch_pin.py lives. | ||
| TORCH_CHANNEL=$(python -c "from torch_pin import CHANNEL; print(CHANNEL)") | ||
|
|
||
| if [ "${TORCH_CHANNEL}" != "nightly" ]; then | ||
| # Test/release: install the published wheels directly from torch_pin.py's | ||
| # channel index, skipping the source-build path entirely. RC wheels at | ||
| # /whl/test/ get re-uploaded under the same version, so use --no-cache-dir | ||
| # there to avoid stale cache hits. | ||
| local torch_spec=$(python -c "from torch_pin import torch_spec; print(torch_spec())") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this is fine, but it seems like a weird way to do it rather then just parsing it from like a json file or txt. At the very least could you just do it all in one python invocation |
||
| local torchvision_spec=$(python -c "from torch_pin import torchvision_spec; print(torchvision_spec())") | ||
| local torchaudio_spec=$(python -c "from torch_pin import torchaudio_spec; print(torchaudio_spec())") | ||
| local torch_index_url=$(python -c "from torch_pin import torch_index_url_base; print(torch_index_url_base())") | ||
| local cache_flag="" | ||
| if [ "${TORCH_CHANNEL}" = "test" ]; then | ||
| cache_flag="--no-cache-dir" | ||
| fi | ||
| pip install --force-reinstall ${cache_flag} \ | ||
| "${torch_spec}" "${torchvision_spec}" "${torchaudio_spec}" \ | ||
| --index-url "${torch_index_url}/cpu" | ||
|
mergennachin marked this conversation as resolved.
|
||
| return | ||
| fi | ||
|
mergennachin marked this conversation as resolved.
|
||
|
|
||
| # Nightly: source-build pytorch from the pinned SHA so CI catches upstream | ||
| # regressions; pytorch's own audio/vision pins drive those installs. | ||
| pushd .ci/docker || return | ||
| TORCH_VERSION=$(cat ci_commit_pins/pytorch.txt) | ||
| popd || return | ||
|
|
@@ -140,10 +164,10 @@ install_pytorch_and_domains() { | |
| fi | ||
|
|
||
| dedupe_macos_loader_path_rpaths | ||
| # Grab the pinned audio and vision commits from PyTorch | ||
| TORCHAUDIO_VERSION=release/2.11 | ||
| # We're on the nightly path here; defer to PyTorch's own pinned commits. | ||
| TORCHAUDIO_VERSION=$(cat .github/ci_commit_pins/audio.txt) | ||
| export TORCHAUDIO_VERSION | ||
| TORCHVISION_VERSION=release/0.26 | ||
| TORCHVISION_VERSION=$(cat .github/ci_commit_pins/vision.txt) | ||
| export TORCHVISION_VERSION | ||
|
|
||
| install_domains | ||
|
|
@@ -218,17 +242,21 @@ download_stories_model_artifacts() { | |
| } | ||
|
|
||
| do_not_use_nightly_on_ci() { | ||
| # An assert to make sure that we are not using PyTorch nightly on CI to prevent | ||
| # regression as documented in https://github.com/pytorch/executorch/pull/6564 | ||
| TORCH_VERSION=$(pip list | grep -w 'torch ' | awk -F ' ' {'print $2'} | tr -d '\n') | ||
| # Sanity check that prevents accidentally landing a PR that pins to PyTorch | ||
| # nightly without exercising the source-build path (see #6564). | ||
| # | ||
| # For CHANNEL=nightly, CI source-builds pytorch from the SHA in pytorch.txt, | ||
| # so the installed torch shows up as e.g. 2.13.0a0+gitc8a648d — assert that. | ||
| # For CHANNEL=test/release, we install published wheels by design (e.g. | ||
| # 2.11.0), so the +git assertion doesn't apply. | ||
| TORCH_CHANNEL=$(python -c "from torch_pin import CHANNEL; print(CHANNEL)") | ||
| if [ "${TORCH_CHANNEL}" != "nightly" ]; then | ||
| return 0 | ||
| fi | ||
|
|
||
| # The version of PyTorch building from source looks like 2.6.0a0+gitc8a648d that | ||
| # includes the commit while nightly (2.6.0.dev20241019+cpu) or release (2.6.0) | ||
| # won't have that. Note that we couldn't check for the exact commit from the pin | ||
| # ci_commit_pins/pytorch.txt here because the value will be different when running | ||
| # this on PyTorch CI | ||
| TORCH_VERSION=$(pip list | grep -w 'torch ' | awk -F ' ' {'print $2'} | tr -d '\n') | ||
| if [[ "${TORCH_VERSION}" != *"+git"* ]]; then | ||
| echo "Unexpected torch version. Expected binary built from source, got ${TORCH_VERSION}" | ||
| echo "Unexpected torch version. Expected binary built from source for CHANNEL=nightly, got ${TORCH_VERSION}" | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.