Local LLMs

Fix pip install torch (CPU-only or CUDA mismatch)

3 min read

By default pip install torch pulls a CPU-only build on Windows, and on Linux it may not match your installed CUDA, so torch.cuda.is_available() returns False. The fix is to install from the PyTorch index URL that matches your CUDA version.

1. Check what you actually have

import torch
print(torch.__version__, torch.version.cuda, torch.cuda.is_available())

A version ending in +cpu, a None CUDA, or False means you have the CPU-only build.

2. Remove the CPU-only build

pip uninstall -y torch torchvision torchaudio

Uninstall first so pip does not keep the cached CPU wheel; the command is the same on every OS.

3. Install the build that matches your CUDA

Open the official selector, pick your OS and CUDA version, and copy the command it shows. It uses an --index-url like this:

pip install torch --index-url https://download.pytorch.org/whl/cu<version>

Replace cu<version> with the value from the selector, for example cu126 or cu130 today; do not guess it. On macOS there is no CUDA build, so the default pip install torch using Metal is correct.

4. Match the driver to the toolkit

The pip wheel bundles its own CUDA runtime, so you do not need the full CUDA Toolkit, only an NVIDIA driver new enough for that runtime.

nvidia-smi

The top-right CUDA version is the maximum your driver supports; pick a wheel at or below it.

5. Verify the GPU build

import torch
print(torch.cuda.is_available(), torch.cuda.get_device_name(0))

True plus your GPU name means torch can use CUDA. See how much RAM or VRAM a model needs, then run a model with the Transformers pipeline quickstart.

If it fails:

Open the full interactive version (with copy buttons) ↗

← All guides