Skip to content

ci: install CPU-only torch in Python CI - #2164

Merged
dangusev merged 2 commits into
mainfrom
ci/cpu-torch
Nov 20, 2026
Merged

dangusev merged 2 commits into
mainfrom
ci/cpu-torch

Conversation

@dangusev

@dangusev dangusev commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Why

The Python CI jobs (lint and test) restore a 3.4 GB uv cache entry. It is the largest entry in the repository's Actions cache. The repository uses 11.05 GB of the 10 GB limit, so GitHub deletes entries. The Go cache of CI (Go) is one of them: on 2026-11-20, 6 of 11 CI (Go) runs had no cache and took 15–18 min instead of 4–5 min.

About 2.6 GB of the 3.4 GB is torch and its CUDA packages. On Linux, torch from PyPI is the CUDA build. The runners have no GPU.

How it works

python-uv-setup with cpu-torch: "true"
├─ uv export     -> names of torch, torchvision, torchaudio and of the
│                   Linux-only nvidia-*, cuda-* and triton packages
├─ uv sync       --no-install-package <each of those names>
├─ uv pip install --no-deps --index-url download.pytorch.org/whl/cpu
│                torch==2.12.1+cpu torchvision==0.27.1+cpu
│                torchaudio==2.11.0+cpu   (versions read from uv.lock)
└─ UV_NO_SYNC=1  -> $GITHUB_ENV, so no later uv run puts CUDA back
Before (main) After (run 44776834482)
torch build on CI CUDA, from PyPI (507 MiB) CPU, from download.pytorch.org (183 MiB)
CUDA packages installed 19 (nvidia-*, cuda-*, triton) 0
uv cache entry 3,278 MB 1,037 MB
Cache key suffix 3.12.13 3.12.13-cpu-torch
pyproject.toml, uv.lock unchanged

Changes

  • python-uv-setup: a new input cpu-torch, off by default. When it is on, the cache key gets -cpu-torch, so the old 3.4 GB entry is not restored, and the action sets UV_NO_SYNC=1 for the rest of the job. torch is in the default dependency set, so a uv run that syncs would install the CUDA build again. dev.py mypy starts its own uv run mypy (dev.py:101, dev.py:109), so a flag on the workflow's own uv run calls is not enough.
  • run_tests.yml: the lint and test jobs turn cpu-torch on.

The published package does not change: the job that builds it in release.yml does not turn the input on, and the wheels take their dependencies from pyproject.toml.

Tradeoffs: CI tests the CPU build of the locked torch version, not the locked wheel. This also applies to the callers of run_tests.yml: the integration job before a release (release.yml) and the daily integration run (daily.yml). download.pytorch.org is a new host that Python CI needs. onnxruntime-gpu (270 MB) stays: it installs the same module as onnxruntime, so a change to it is a separate PR.

Validation

  • Run 44776834482 (commit 0a58f02): lint and test pass. The unit tests: 966 passed, then 1,315 passed and 7 skipped. Both mypy passes find no issues.
  • In both jobs, uv sync installs 393 packages with no CUDA package, then the step installs torch==2.12.1+cpu, torchvision==0.27.1+cpu and torchaudio==2.11.0+cpu. No later step syncs or downloads a CUDA package.
  • The new cache entry is 1,037 MB. The entry on main is 3,278 MB.
  • The first attempt (run 44775320155, commit 8b0b722) passed but saved a 3,429 MB entry: the uv run inside dev.py mypy synced to the lock again and installed the CUDA build. 0a58f02 fixes that, and that entry was deleted.
  • UV_NO_SYNC=1 with a script that has inline metadata (plugins/stream/generate.py): uv prints a warning that it has no effect and installs the script's dependencies as before.
  • Unverified: the restore time of the 1 GB entry. It shows on the next run that finds the entry.

🤖 Generated with Claude Code

On Linux, torch from PyPI is the CUDA build. It brings about 3 GB of
CUDA packages, which made the uv cache entry of the Python CI jobs
3.4 GB. The runners have no GPU.

The lint and test jobs now skip torch, torchvision, torchaudio and the
Linux-only nvidia-*, cuda-* and triton packages in uv sync, and install
the +cpu builds of the locked versions from the PyTorch CPU index.
pyproject.toml and uv.lock do not change.
@dangusev
dangusev marked this pull request as ready for review November 20, 2026 16:37
dev.py mypy starts its own uv run, which synced the environment to
uv.lock again and replaced the CPU build of torch with the CUDA build
and its CUDA packages. The setup action now sets UV_NO_SYNC for the
rest of the job, so the --no-sync flags in run_tests.yml are not
needed.
@dangusev
dangusev merged commit 9fdfb39 into main Nov 20, 2026
8 checks passed
@dangusev
dangusev deleted the ci/cpu-torch branch November 20, 2026 17:02
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