Skip to content
Latchkey

How to Install and Run PyTorch in CI Without Failures

Installing plain torch in CI silently pulls the CUDA build - gigabytes of GPU libraries you do not need - making jobs slow and prone to timeouts and OOM.

PyTorch ships separate CPU and CUDA wheels served from its own package index. The default pip install torch often grabs the CUDA variant, dragging in gigabytes of NVIDIA libraries that a CPU-only runner cannot use. The fix is to install the CPU build from the correct index URL.

Why it fails in CI

PyTorch wheels are large and version/Python-specific, and the CUDA build adds gigabytes of cuDNN/cuBLAS. On a CPU runner those are dead weight that slow installs, blow disk and memory budgets, and can time out. A too-new Python or musl image has no wheel at all.

  • Multi-GB download and No space left on device from CUDA libraries on a CPU runner.
  • Could not find a version that satisfies the requirement torch on a new Python/Alpine.
  • ReadTimeoutError pulling the wheel; exit 137 OOM during model load.

Install it reliably

Install the CPU build explicitly from PyTorch’s CPU index unless you are on a GPU runner. Pin a Python version PyTorch supports and stay on a glibc image.

Terminal
# CPU-only: pull the CPU wheel, not the multi-GB CUDA one
pip install torch --index-url https://download.pytorch.org/whl/cpu

# Pin a supported interpreter
- uses: actions/setup-python@v5
  with:
    python-version: '3.11'

Cache & speed

Cache ~/.cache/pip so the wheel is fetched once, raise the pip timeout for the large download, and prefer a runner with enough disk/RAM for model jobs over retrying OOM/disk failures.

.github/workflows/ci.yml
- uses: actions/cache@v4
  with:
    path: ~/.cache/pip
    key: pip-torch-cpu-${{ hashFiles('requirements*.txt') }}
- run: pip install --timeout 120 torch --index-url https://download.pytorch.org/whl/cpu

Common errors

ErrorCauseFix
No space left on deviceCUDA build pulled on CPU runnerUse the CPU index URL
Could not find a version that satisfies torchNo wheel for Python/platformPin a supported Python; use glibc
ReadTimeoutError pulling wheelHuge download timed outRaise --timeout; cache pip
Exit 137 on model loadOOM-killedBigger runner; CPU build

Key takeaways

  • Install the CPU build via --index-url .../whl/cpu on non-GPU runners.
  • Pin a PyTorch-supported Python on a glibc image.
  • Cache the wheel, raise the timeout, and watch disk/OOM.

Related guides

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