Skip to content
Latchkey

How to Install PyTorch in CI (CPU Wheels)

The default PyTorch wheel can pull multi-GB CUDA payloads you do not need on CPU CI. The fix is the CPU wheel index.

PyTorch publishes platform/accelerator-specific wheels through its own index. On CPU-only CI, installing from the CPU index avoids gigabytes of CUDA libraries and the timeouts they cause.

Why it fails in CI

  • The default install pulls CUDA-enabled torch (huge) on a CPU runner → slow/timeout.
  • A Python version with no matching torch wheel → no candidate.
  • Pinned torch/torchvision versions that are incompatible with each other.

Install it reliably

Install from the CPU index URL with matching torch/torchvision versions. Pin a supported Python first via setup-python.

Terminal
# CPU-only wheels (no CUDA payload)
pip install torch torchvision \
  --index-url https://download.pytorch.org/whl/cpu

# verify CPU build
python -c "import torch; print(torch.__version__, torch.cuda.is_available())"

Cache & speed

Cache ~/.cache/pip keyed on requirements. Even CPU wheels are large; the download is where faster/larger managed runners help and transient failures auto-retry.

.github/workflows/ci.yml
- uses: actions/cache@v4
  with:
    path: ~/.cache/pip
    key: pip-${{ runner.os }}-${{ hashFiles('**/requirements*.txt') }}

Common errors

  • Multi-GB download / timeout → use --index-url .../whl/cpu for CPU-only CI.
  • No matching distribution found for torch → Python too new or wrong index; pin Python.
  • torchvision ... compiled against a different version of torch → pin a matching pair.

Key takeaways

  • Install from the PyTorch CPU index to skip multi-GB CUDA wheels.
  • Pin torch and torchvision to a compatible pair.
  • Cache pip; even CPU wheels are large.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →