AssertionError: Torch not compiled with CUDA enabled (tested)
AssertionError: Torch not compiled with CUDA enabled means the installed torch is a CPU-only build (torch.version.cuda is None, version ends in +cpu). Reinstall a CUDA build from pytorch.org if you have an NVIDIA GPU; otherwise select the device with torch.cuda.is_available(). Reproduced below next to the related Found no NVIDIA driver error.
1. Reproduce
b1.py prints what the installed torch was built with, then moves a tensor to the GPU:
import torch
print("torch", torch.__version__, "| built with CUDA:", torch.version.cuda)
print("cuda available:", torch.cuda.is_available())
try:
torch.zeros(3).to("cuda")
except Exception as e:
print(type(e).__name__ + ":", e)
With the CPU-only build (installed from https://download.pytorch.org/whl/cpu):
torch 2.14.1+cpu | built with CUDA: None
cuda available: False
AssertionError: Torch not compiled with CUDA enabled
With a CUDA build on the same machine, which has no NVIDIA GPU or driver:
torch 2.14.1+cu130 | built with CUDA: 13.0
cuda available: False
RuntimeError: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from http://www.nvidia.com/Download/index.aspx
Same line, two different errors. AssertionError: Torch not compiled with CUDA enabled is about the package: torch.version.cuda is None and the version ends in +cpu, so no GPU code exists in it. Found no NVIDIA driver is about the machine: the package supports CUDA but the driver/GPU is missing. In both cases torch.cuda.is_available() is False.
2. Check which build you have
# Which build is installed? (+cpu = no CUDA support compiled in)
python -c "import torch; print(torch.__version__, torch.version.cuda, torch.cuda.is_available())"
Output for the two environments above:
2.14.1+cpu None False
2.14.1+cu130 13.0 False
Run it with the same interpreter your script or notebook uses: a CPU build in one venv and a CUDA build in another is a common cause of "it works in the terminal but not in Jupyter".
3. Fix
- You have an NVIDIA GPU: uninstall torch and reinstall a CUDA build using the exact command from the selector on pytorch.org (it adds an
--index-url https://download.pytorch.org/whl/cuXXXmatching your driver). Not tested here: this machine has no GPU. - You don't (or the code must run anywhere): pick the device at runtime and remap checkpoints with
map_location:
import torch
# Device-agnostic: use the GPU when this build + machine can, else fall back to CPU
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
x = torch.ones(3, device=device) * 2
print("device:", device, "| result:", x.tolist())
# Loading a checkpoint saved on a GPU machine: remap it instead of crashing
torch.save(torch.ones(2), "/tmp/tc419/t.pt")
print("loaded on:", torch.load("/tmp/tc419/t.pt", map_location=device).device)
device: cpu | result: [2.0, 2.0, 2.0]
loaded on: cpu
Related: PyTorch RuntimeError: Numpy is not available, pip install torch: no matching distribution found.
Frequently asked questions
What does Torch not compiled with CUDA enabled mean?
Your torch package is a CPU-only build: torch.version.cuda is None and the version ends in +cpu. Moving a tensor to "cuda" raises this AssertionError.
How do I check if my torch has CUDA?
python -c "import torch; print(torch.__version__, torch.version.cuda, torch.cuda.is_available())". A +cpu version with None means no CUDA support.
Why do I get Found no NVIDIA driver on your system instead?
Your torch is a CUDA build but the machine has no NVIDIA GPU or driver. torch.cuda.is_available() is False in both cases.
Written with AI assistance. Measured on 2026-10-24 with torch 2.14.1+cpu and 2.14.1+cu130 on Python 3.13.5, Linux x86_64 without an NVIDIA GPU. The scripts ran verbatim and the output was pasted unedited. PlainTables is our extension; PyTorch is free.