Skip to content

Set the pin to torch>=2.14 - #9680

Merged
NicolasHug merged 2 commits into
pytorch:mainfrom
NicolasHug:pinversion
Sep 28, 2026
Merged

NicolasHug merged 2 commits into
pytorch:mainfrom
NicolasHug:pinversion

Conversation

@NicolasHug

Copy link
Copy Markdown
Member

No description provided.

@pytorch-bot

pytorch-bot Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/9680

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

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

@meta-cla meta-cla Bot added the cla signed label Sep 28, 2026

@atalman atalman 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.

lgtm

@NicolasHug
NicolasHug merged commit 9769007 into pytorch:main Sep 28, 2026
32 of 35 checks passed
@NicolasHug
NicolasHug deleted the pinversion branch September 28, 2026 13:42
atalman added a commit that referenced this pull request Sep 28, 2026
SolerHo pushed a commit to SolerHo/TheRock that referenced this pull request Oct 11, 2026
…OCm#8778)

## Motivation

TheRock's torchvision wheels declare an unpinned `Requires-Dist: torch`,
so pip and uv can install a torchvision with a torch it was not built
against. The compiled ops in `torchvision._C` then fail to load, and
`import torchvision` raises:

```
RuntimeError: operator torchvision::nms does not exist
```

This happened on the stable `whl-next` index once torch 2.14.0 was
published before a matching stable torchvision. It broke the Ultralytics
AMD GPU CI job ([install
step](https://github.com/ultralytics/ultralytics/actions/runs/37434294246/job/112172201490#step:4:231),
[failing
test](https://github.com/ultralytics/ultralytics/actions/runs/37434294246/job/112172201490#step:6:49)):

```
uv pip install "torch[device-all]" "torchvision[device-all]" --index-url https://stable.repo.amd.com/rocm/whl-next/
 + torch==2.14.0+rocm10.1.0
 + torchvision==0.28.0+rocm10.1.0
```

Users hit this and expect the installer to prevent it. In
[ROCm#5374](ROCm#5374 (comment)),
a user wrote:

> What can I do, to prevent this?
> I thought this is the job of uv/pip 🤔

It is the installer's job, but only when the wheel metadata gives it the
constraint. The answers in
[ROCm#5374](ROCm#5374 (comment))
and
[ROCm#7754](ROCm#7754 (comment))
were to pin compatible versions by hand. With this change, the resolver
does that.

ISSUE ID : ROCm#5374

Fixes ROCm#5374

Related: ROCm#7754, ROCm#3134.

## Upstream does the same

Upstream PyTorch sets `PYTORCH_VERSION` from the installed torch before
building torchvision. The Linux and Windows steps remove the `+...`
local segment. The macOS step keeps it.

- Linux:
[`build_wheels_linux.yml#L277`](https://github.com/pytorch/test-infra/blob/c9f9538b321b0f88ac8d7747da9282b7b3bfa4ae/.github/workflows/build_wheels_linux.yml#L277)
and
[`#L288`](https://github.com/pytorch/test-infra/blob/c9f9538b321b0f88ac8d7747da9282b7b3bfa4ae/.github/workflows/build_wheels_linux.yml#L288)
- Windows:
[`build_wheels_windows.yml#L277`](https://github.com/pytorch/test-infra/blob/c9f9538b321b0f88ac8d7747da9282b7b3bfa4ae/.github/workflows/build_wheels_windows.yml#L277)
- macOS:
[`build_wheels_macos.yml#L200-L201`](https://github.com/pytorch/test-infra/blob/c9f9538b321b0f88ac8d7747da9282b7b3bfa4ae/.github/workflows/build_wheels_macos.yml#L200-L201)

```bash
export PYTORCH_VERSION="$(${CONDA_RUN} pip show torch | grep ^Version: | sed 's/Version: *//' | sed 's/+.\+//')"
```

torchvision's
[`setup.py#L90-L92`](https://github.com/pytorch/vision/blob/8fb87713a24951e639c494b0f2a8a81b5f8e33a6/setup.py#L90-L92)
turns that into the requirement:

```python
pytorch_dep = os.getenv("TORCH_PACKAGE_NAME", "torch")
if version_pin := os.getenv("PYTORCH_VERSION"):
    pytorch_dep += "==" + version_pin
```

Upstream wheels built this way pin the exact public version of torch.
For nightlies, that is the exact dated torch nightly:

| Wheel | `Requires-Dist` for torch |
|---|---|
| PyPI `torchvision==0.28.0` | `torch (==2.13.0)` |
| download.pytorch.org `0.28.0+cpu` | `torch (==2.13.0)` |
| download.pytorch.org `0.28.0+rocm7.1` | `torch (==2.13.0)` |
| download.pytorch.org nightly `0.29.0.dev20260807+rocm7.1` | `torch
(==2.14.0.dev20260804)` |
| stable.repo.amd.com `0.28.0+rocm10.1.0` (this repo) | `torch` |

Upstream torchvision 0.29 and later ignore `PYTORCH_VERSION` and require
`torch>=2.14` instead, because their ops moved to the stable ABI
([pytorch/vision#9680](pytorch/vision#9680),
[`release/0.29`
`setup.py#L104-L107`](https://github.com/pytorch/vision/blob/1f1a920d685d46dfbe187934b785b7ecb7a182f2/setup.py#L104-L107)).

TheRock builds torchvision from the ROCm/vision commits listed in
ROCm/pytorch `related_commits`. Those commits do not have that change
yet, so they still read `PYTORCH_VERSION`:

| ROCm/pytorch branch | ROCm/vision commit | Reads `PYTORCH_VERSION` |
|---|---|---|
| `release/2.13` | `release/0.28` @ `53881ee` | yes |
| `release/2.14` | `release/0.29` @
[`b7d540b`](https://github.com/ROCm/vision/blob/b7d540b22fab0df4673898fb0aec2fc6954cddac/setup.py#L91-L92)
(`0.29.0a0`) | yes |

The published `torchvision-0.29.0a0+rocm10.1.0` wheel also declares a
bare `torch` and still ships the legacy `torchvision/_C.so`. When
ROCm/vision picks up pytorch/vision#9680, its `setup.py` ignores the
variable and this change has no effect on those builds.

## Technical Details


[`do_build_pytorch_vision()`](https://github.com/Y-T-G/TheRock/blob/f6dd08ed5b8d3d011677bf8d76afac2c9817aeb9/external-builds/pytorch/build_prod_wheels.py#L1368-L1369)
now sets `PYTORCH_VERSION` to the full version of the installed torch,
which torchvision compiles against. The resulting requirement is, for
example, `torch==2.13.0+rocm10.1.0`.

The version comes from the existing `get_installed_package_version()`
helper, which already pins triton for the torch wheel. It runs `pip
show`, the same source upstream uses, and returns only the `Version:`
line. If torch is not installed or `pip show` has no `Version:` line, it
raises `ValueError` and the build fails. It does not fall back to an
unpinned wheel.

Upstream Linux and Windows builds strip the `+...` local segment. This
change keeps it:

1. TheRock encodes the build in the local segment (`+rocm10.1.0`,
`+rocm10.1.0a20260830`), where upstream nightlies encode it in the
public version (`2.14.0.dev20260804`). Keeping it is the equivalent of
upstream's exact nightly pin.
2. A bare `torch==2.13.0` also accepts `2.13.0` from PyPI, `2.13.0+cpu`,
and torch builds for other ROCm versions. pip and uv keep an
already-installed torch that satisfies the pin, so a ROCm torchvision
would install next to it and fail to load.
3. TheRock already pins its device wheels the same way, for example
`amd-torchvision-device-gfx1010 == 0.28.0+rocm10.1.0`.

The release workflows build torch and torchvision in one
`build_prod_wheels.py` run, so the pinned torch is the one built in that
run and is published with it. A vision-only build pins whichever torch
is installed, and the caller must publish that torch to the same index.
On 2026-10-06, every local suffix on both indexes had torch and
torchvision wheels:

| Index | torch versions (cp312, Linux) | torchvision versions (cp312,
Linux) | Local suffixes | Suffixes with only one of the two |
|---|---|---|---|---|
| `stable.repo.amd.com/rocm/whl-next` | 6 | 6 | 2 | 0 |
| `nightly.repo.amd.com/rocm/whl-next` | 176 | 176 | 44 | 0 |

torchaudio is not changed. Its upstream `setup.py` no longer passes any
torch requirement, whether or not `PYTORCH_VERSION` is set.

## Test Plan

1. Called `get_installed_package_version()` in a venv with torch
`2.13.0+cpu` installed: once normally, once with
`PYTHONWARNINGS=badoption` to add stderr output, and once for a package
that is not installed.
2. Ran torchvision `v0.28.0` `setup.py` with `setuptools.setup` stubbed,
with and without `PYTORCH_VERSION`, and recorded the torch entry in
`install_requires`.
3. Ran `promote_packages.rewrite_metadata_rocm_line` on the new
requirement for nightly to release, rc to release, and nightly to rc.
4. Checked which torch versions satisfy the requirement with
`packaging`.
5. Read the published `torchvision-0.28.0+rocm10.1.0` `METADATA` to
confirm the kpack split keeps the `setup.py` requirements and only
appends the `amd-torchvision-device-*` lines.

I have not run a full wheel build or the release workflow.

## Test Result

| Check | Result |
|---|---|
| `get_installed_package_version("torch")` | `'2.13.0+cpu'` |
| Same, with stderr warnings from `PYTHONWARNINGS=badoption` |
`'2.13.0+cpu'` |
| `get_installed_package_version()` for a missing package | `ValueError`
|
| torchvision `install_requires`, `PYTORCH_VERSION` unset | `['torch']`
|
| torchvision `install_requires`, `PYTORCH_VERSION=2.13.0+cpu` |
`['torch==2.13.0+cpu']` |

| Promotion | Requirement before | Requirement after |
|---|---|---|
| nightly to release | `torch==2.13.0+rocm10.1.0a20260830` |
`torch==2.13.0+rocm10.1.0` |
| rc to release | `torch==2.13.0+rocm10.1.0rc2` |
`torch==2.13.0+rocm10.1.0` |
| nightly to rc | `torch==2.13.0+rocm10.1.0a20260830` |
`torch==2.13.0+rocm10.1.0rc1` |

| Installed torch | Satisfies `torch==2.13.0+rocm10.0.0` |
|---|---|
| `2.13.0+rocm10.0.0` | yes |
| `2.13.0+rocm10.0.1` | no |
| `2.13.0+rocm10.1.0` | no |
| `2.13.0+rocm10.0.0a20260824` | no |
| `2.13.0` | no |
| `2.13.0+cpu` | no |
| `2.14.0+rocm10.1.0` | no |

`pre-commit run` passes on the changed file.

## Submission Checklist

- [x] Look over the contributing guidelines at
https://github.com/ROCm/TheRock/blob/main/CONTRIBUTING.md.

The code change and this description were drafted with an AI coding
assistant.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants