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.
AssertionError: Torch not compiled with CUDA enabled
# torch.cuda.is_available() -> False ; torch.version.cuda -> NoneCommon 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
- Pick the CUDA suffix matching the runner driver (for example cu121).
- Install torch from the PyTorch CUDA index.
- Verify
torch.cuda.is_available()returns True.
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.
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.