GPU & CUDA · PyTorch / Windows, Linux, WSL2

PyTorch Cannot Detect CUDA GPU

Error messagetorch.cuda.is_available() == False

Why it happens

Either a CPU-only PyTorch wheel is installed, the NVIDIA driver is missing or unloaded, or environment/container settings hide the GPU.

How to fix it

  1. Run nvidia-smi to confirm the OS sees the GPU; if it fails, install or reboot into the NVIDIA driver (on WSL2, install the driver on Windows only, never inside WSL).
  2. Check your PyTorch build with python -c "import torch; print(torch.__version__, torch.version.cuda)"; if torch.version.cuda is None or version ends in +cpu, reinstall from a CUDA wheel index.
  3. Uninstall and reinstall CUDA-enabled PyTorch (for example CUDA 12.8): pip uninstall -y torch torchvision torchaudio && pip install torch torchvision torchaudio –index-url https://download.pytorch.org/whl/cu128.
  4. Verify CUDA_VISIBLE_DEVICES is not empty or out of range, and pass –gpus all when running Docker containers.
python -c "import torch; print(torch.__version__, torch.version.cuda, torch.cuda.is_available())"

Seeing a different message? Paste it into the Error Code Fixer

Related errors

Fixes are reviewed by ComputerTech against current documentation, and software changes fast. If a step differs on your version, tell us. Back up important data before changing drivers, BIOS or system files.