Skip to content

fix: keep the CPU torch index out of git installs of wsidata - #76

Merged
Mr-Milk merged 1 commit into
mainfrom
fix/torch-cpu-index-leak
Sep 30, 2026
Merged

Mr-Milk merged 1 commit into
mainfrom
fix/torch-cpu-index-leak

Conversation

@Mr-Milk

@Mr-Milk Mr-Milk commented Sep 30, 2026

Copy link
Copy Markdown
Member

Problem

#69 routed torch and torchvision to the PyTorch CPU index on Linux through tool.uv.sources. Its comment says that only affects uv sync/uv lock in this repo, which is wrong for git and path installs, because uv applies a dependency's tool.uv.sources to the project that installs it.

rendeirolab/lazyslide-tutorials depends on wsidata @ git+...@main. Its CI got Linux torch 2.14.0+cpu from download.pytorch.org. torchvision is only in wsidata's dev group, so its source never applies downstream, and it came from PyPI as a CUDA build. The builds did not match, and 7 notebooks failed with RuntimeError: operator torchvision::nms does not exist. Any Linux GPU user who installs wsidata from git with uv also gets a CPU-only torch without noticing.

Fix

Both sources get group = "dev", and torch is added to the dev group, because a group-scoped source only applies to requirements declared in that group. A dependent only resolves wsidata's project.dependencies, so it now gets torch from PyPI. group on sources has been in uv since 0.5.4.

uv locks one torch per platform, so no resolved version in this repo's uv.lock changes. The diff is metadata only: requires-dist drops the index, and dev gains torch. CI, Read the Docs and local Linux environments keep the CPU build, whether or not the dev group is installed.

Alternatives considered:

  • Drop the sources. Every Linux job and every RTD build goes back to downloading the ~2.5 GB CUDA stack. The setup-uv cache would not save it, because prune-cache (on by default) drops pre-built wheels before saving.
  • Swap in CPU torch in the workflow. Running uv pip install after uv sync --locked still downloads the CUDA build first. Avoiding that download means passing --no-install-package for every nvidia-* package and using --no-sync from then on. It would also leave RTD on CUDA.

Verification

Scratch project with wsidata @ git+https://github.com/rendeirolab/wsidata@<ref> and torchvision, then uv lock:

ref download.pytorch.org in uv.lock torch torchvision
main 3 2.14.1 PyPI + 2.14.1+cpu CPU index (Linux) 0.29.1 PyPI
this branch (f4f39f6) 0 2.14.1 PyPI 0.29.1 PyPI

In this repo, uv lock --check passes. uv export of the CI set (--no-default-groups --group dev --group cucim), the RTD set (--all-extras --group docs) and the base set (--no-default-groups) all give torch==2.13.0+cpu / torchvision==0.28.0+cpu on Linux. None of them pulls the CUDA stack; the one nvidia-* package, nvidia-nvimgcodec-cu12, comes from cucim, as before.

Follow-up

After this merges, the override-dependencies = ["torch>=2.1"] workaround in rendeirolab/lazyslide-tutorials#5 can go, along with a uv lock --upgrade-package wsidata there.

PR #69 routed torch and torchvision to the PyTorch CPU index on Linux via
tool.uv.sources, and its comment said this only affects `uv sync`/`uv lock`
in this repo. That is wrong for git and path installs: uv applies a
dependency's tool.uv.sources to the project that installs it. A project
depending on `wsidata @ git+https://...` got Linux torch as a `+cpu` build
from download.pytorch.org, while torchvision, which wsidata lists only in
its dev group, came from PyPI as a CUDA build. The mismatched builds fail
with "RuntimeError: operator torchvision::nms does not exist", which broke
7 lazyslide-tutorials notebooks, and any Linux GPU user installing wsidata
from git with uv silently got a CPU-only torch.

Scope both sources to the dev group and repeat torch there, since a
group-scoped source only applies to requirements declared in that group.
Dependents only resolve wsidata's project dependencies, so they now get
torch from PyPI. uv locks one torch per platform, so resolved versions in
this repo's lock do not change: CI, Read the Docs and local Linux
environments keep the CPU build, with or without the dev group.
Copilot AI balanced review requested due to automatic review settings September 30, 2026 20:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Mr-Milk
Mr-Milk merged commit d797633 into main Sep 30, 2026
15 checks passed
@Mr-Milk
Mr-Milk deleted the fix/torch-cpu-index-leak branch September 30, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants