TechBuzzPro

Torch GPU Not Available? Fix PyTorch CUDA Detection

· 6 min read · Windows & PC

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

If torch.cuda.is_available() returns False, PyTorch has not found a usable CUDA-capable GPU, and the usual cause is a CPU-only PyTorch build, a missing or outdated NVIDIA driver, or a CUDA toolkit mismatch. The fastest check is to print the build and driver state, then fix whichever piece is missing. Run python -c "import torch; print(torch.__version__, torch.version.cuda, torch.cuda.is_available())". If torch.version.cuda prints None, you installed a CPU-only wheel and no amount of driver work will help until you reinstall the CUDA build.

This guide covers the standard desktop situation: an NVIDIA GPU on Windows or Linux, a recent driver, and a PyTorch install from the official index. AMD and Apple GPUs are handled differently and are noted where relevant. Menu labels in installers and driver pages can differ slightly by version, device, and region, so treat exact wording as a guide.

What You'll Need

  • A CUDA-capable NVIDIA GPU (check the official CUDA GPUs list from NVIDIA if unsure).
  • An up-to-date NVIDIA display driver installed from NVIDIA's site or your distribution's package manager.
  • Python 3.9 or newer, ideally in a virtual environment so a bad install is easy to discard.
  • Command-line access (Command Prompt or PowerShell on Windows, a terminal on Linux).
  • Enough disk space for the CUDA-enabled PyTorch wheel, which is much larger than the CPU wheel.

Step-by-Step

  1. Confirm the GPU is visible to the operating system. On Windows, open Task Manager and check the Performance tab for your NVIDIA GPU; on Linux, run nvidia-smi. If the GPU does not appear or nvidia-smi reports no driver, stop here and install the NVIDIA driver first. Nothing in PyTorch can fix a missing driver.
  2. Check what PyTorch build you actually have. In Python, run import torch; print(torch.__version__); print(torch.version.cuda); print(torch.cuda.is_available()). A None for torch.version.cuda means a CPU-only build. A version string like 12.1 means the CUDA build is present, so the problem is elsewhere.
  3. Reinstall PyTorch with the CUDA wheel if you have a CPU build. Uninstall the current package first (pip uninstall torch torchvision torchaudio), then install from the official PyTorch index using the selector on pytorch.org. The selector produces the exact command for your OS, package manager, and CUDA version. Do not install from a generic mirror that may serve the CPU wheel.
  4. Match the CUDA build to your driver. Newer PyTorch CUDA builds require a reasonably recent driver. If torch.version.cuda is set but is_available() is still False, update the NVIDIA driver to the latest version for your GPU, reboot, and test again. The driver bundled with the CUDA build is not used; the system driver is.
  5. Verify the driver sees the GPU after the update. Run nvidia-smi again and note the driver version and the CUDA version it reports. That reported CUDA version is the maximum your driver supports; a PyTorch build compiled for a newer CUDA version than the driver supports will not work.
  6. Test a real tensor operation, not just the flag. Run x = torch.rand(3, 3).cuda(); print(x.device). If this succeeds, the GPU is genuinely usable. If it raises an error, read the message: it usually names the driver or the missing library.
  7. Check the device index on multi-GPU systems. If you have more than one GPU, confirm the count with torch.cuda.device_count() and select explicitly with torch.cuda.set_device(0) or .to('cuda:0'). A container or remote session may expose only one device.
  8. On Linux, confirm the user can access the device nodes. Check that /dev/nvidia0 exists and that your user is in the appropriate group, or run the same command with elevated permissions to see whether permissions are the blocker. Do not leave elevated permissions in place for normal work.
  9. In WSL, install the Windows NVIDIA driver, not a Linux one inside WSL. The Windows driver provides the GPU to WSL; installing a Linux display driver inside the WSL distribution commonly breaks detection. After installing the Windows driver, run nvidia-smi inside WSL to confirm the passthrough works, then reinstall the CUDA PyTorch wheel.
  10. In Docker, pass the GPU through explicitly. A container does not see the host GPU unless started with the NVIDIA Container Toolkit configured and the appropriate GPU flag. Confirm with nvidia-smi inside the container before blaming PyTorch.

Common Mistakes

  • Installing the CPU wheel by accident. The default pip install torch from some indexes serves a CPU build; always use the official index URL from the PyTorch selector.
  • Installing the CUDA toolkit and assuming that is enough. PyTorch wheels ship their own CUDA runtime libraries; the system toolkit is not what makes is_available() true.
  • Mixing environments. A CUDA build installed in one virtual environment does nothing for another; check which python or where python before reinstalling.
  • Ignoring the driver. A working CUDA build with an old driver still reports False.
  • Confusing AMD or Apple GPUs with CUDA. CUDA is NVIDIA-only; AMD uses ROCm builds and Apple silicon uses the MPS backend, which are separate installs and separate checks.
  • Assuming a laptop with switchable graphics is using the NVIDIA GPU. Some systems default to integrated graphics for the process; check the vendor's graphics settings.

Tips

  • Keep a short diagnostic command handy: print the PyTorch version, the CUDA version, the device count, and is_available() in one line so you can compare before and after a fix.
  • Pin your PyTorch version in a requirements file once everything works, so a later upgrade does not silently swap in a different CUDA build.
  • Reboot after driver changes. Many detection problems disappear after a clean restart.
  • If you do not need CUDA specifically, a CPU build is smaller and simpler; only install the CUDA wheel when you actually need GPU acceleration.

Troubleshooting

If torch.version.cuda is a version string but is_available() is False, the build is correct and the problem is between PyTorch and the driver. Update the driver, reboot, and retest. If nvidia-smi works but PyTorch does not, the wheel is likely compiled for a newer CUDA than the driver supports; install a PyTorch build matching an older CUDA version from the selector.

If nvidia-smi itself fails, the driver is missing, broken, or the GPU is disabled in the BIOS or device manager. Resolve that before touching Python. On Windows, check Device Manager for a warning icon on the display adapter. On Linux, check the kernel logs for driver load errors.

If everything works in a terminal but not in your IDE or notebook, the IDE is using a different interpreter. Point it at the environment where the CUDA build is installed. If it works on the host but not in a container, the GPU passthrough is missing. If it worked yesterday and not today, check whether an automatic package upgrade replaced the wheel.

Frequently Asked Questions

Does PyTorch need the full CUDA toolkit installed?

No. The official CUDA wheels bundle the runtime libraries they need. You need a compatible NVIDIA driver, not a separate toolkit install.

Why does torch.cuda.is_available() return False on a laptop with an NVIDIA GPU?

Usually the CPU wheel is installed, the driver is outdated, or the process is running on integrated graphics. Check the build first, then the driver.

Can I use an AMD GPU with torch.cuda?

No. CUDA is NVIDIA-only. AMD GPUs need ROCm builds of PyTorch and are checked differently.

What about Apple silicon Macs?

They do not use CUDA. Use the MPS backend instead and check torch.backends.mps.is_available().

Will reinstalling PyTorch delete my project files?

No. Uninstalling and reinstalling the package only affects the installed libraries in that environment, not your code or data.