Skip to content
Latchkey

PyTorch "Torch not compiled with CUDA enabled" in CI

The torch wheel installed is the CPU-only build, which has no CUDA support compiled in, yet the code asks for a CUDA device. PyTorch asserts immediately because there is no GPU backend to use.

What this error means

A .cuda() or .to("cuda") call fails with "AssertionError: Torch not compiled with CUDA enabled", and torch.version.cuda is None.

python
AssertionError: Torch not compiled with CUDA enabled
# torch.cuda.is_available() -> False ; torch.version.cuda -> None

Common causes

pip installed the default CPU-only wheel

Plain pip install torch from PyPI gives a build without CUDA on many platforms, so any GPU call asserts.

A requirements file pinned the CPU variant

A +cpu local version or the CPU index was used, locking in a build that has CUDA disabled.

How to fix it

Install a CUDA-enabled torch build

  1. Pick the CUDA suffix matching the runner driver (for example cu121).
  2. Install torch from the PyTorch CUDA index.
  3. Verify torch.cuda.is_available() returns True.
Terminal
pip install --index-url https://download.pytorch.org/whl/cu121 torch
python -c "import torch; print(torch.cuda.is_available(), torch.version.cuda)"

Guard GPU calls for CPU-only jobs

If a job is meant to run on CPU, select the device dynamically instead of forcing CUDA.

train.py
device = "cuda" if torch.cuda.is_available() else "cpu"

How to prevent it

  • Install torch from the CUDA index for GPU jobs, not bare PyPI.
  • Assert torch.cuda.is_available() in a setup step on GPU runners.
  • Keep CPU and GPU requirement sets separate and explicit.

Frequently asked questions

What causes ""Torch not compiled with CUDA enabled""?
Plain pip install torch from PyPI gives a build without CUDA on many platforms, so any GPU call asserts.
How do I fix "Torch not compiled with CUDA enabled"?
Install a CUDA-enabled torch build

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card