GPU guide
torch.cuda.is_available() returns False: causes and fixes (Mac, PC without NVIDIA, Docker)
Updated on
Short answer
On a Mac or a PC without an NVIDIA card, CUDA does not exist: torch.cuda.is_available() always returns False and no setting changes that, so you need an NVIDIA GPU, for example rented by the hour at GPU Cloud from CA$0.67/h in Canada. On an NVIDIA machine, the usual causes are a PyTorch build without CUDA, a missing or outdated driver, or a container started without --gpus all.
The one-command diagnosis
Run this script: it tells you which system you are on, whether your PyTorch build targets CUDA, and whether a variable hides the GPU.
import os, platform
import torch
print("system :", platform.system(), platform.machine())
print("torch :", torch.__version__)
print("built for CUDA:", torch.version.cuda) # None = PyTorch without CUDA
print("cuda available:", torch.cuda.is_available())
print("CUDA_VISIBLE_DEVICES:", os.environ.get("CUDA_VISIBLE_DEVICES"))
if torch.cuda.is_available():
print("GPU:", torch.cuda.get_device_name(0))
elif torch.backends.mps.is_available():
print("Apple GPU (MPS): no CUDA on this machine")The causes and their fixes
| Cause | How to spot it | Fix |
|---|---|---|
| Mac (Apple silicon or Intel) | platform.system() is Darwin, nvidia-smi does not exist | CUDA does not exist on a Mac. Use mps for small tests, or an NVIDIA GPU server for CUDA code. |
| PC without an NVIDIA card (AMD, Intel) | nvidia-smi is not found | CUDA is NVIDIA only. You need an NVIDIA card, on your computer or rented by the hour. |
| PyTorch installed without CUDA | torch.version.cuda is None, or the version ends with +cpu | Reinstall the CUDA build of PyTorch (command below). |
| NVIDIA driver missing or too old | nvidia-smi fails, or shows a CUDA version older than the one PyTorch was built for | Install or update the NVIDIA driver, or pick a PyTorch build that matches your driver. |
| Docker container without GPU access | nvidia-smi works on the machine, not in the container | Start the container with --gpus all; the machine needs the NVIDIA Container Toolkit. |
| GPU hidden by a variable | CUDA_VISIBLE_DEVICES is empty or -1 | Remove the variable, or set the GPU index (0). |
| WSL2 on Windows | nvidia-smi fails inside Linux | Install the NVIDIA driver for Windows that supports WSL, and do not install a Linux driver inside WSL. |
Reinstall PyTorch with CUDA
If torch.version.cuda is None, you have the CPU build. Reinstall a CUDA build; the selector on pytorch.org gives the exact command for your system and driver.
pip uninstall -y torch torchvision torchaudio
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
python -c "import torch; print(torch.version.cuda, torch.cuda.is_available())"In Docker
A container does not see the GPU by default. You must ask for it at startup, and the host needs the NVIDIA driver and the NVIDIA Container Toolkit.
# The container only sees the GPU when you ask for it
docker run --rm --gpus all your-image nvidia-smiOn a Mac: MPS for tests, an NVIDIA GPU for CUDA
Macs have a GPU that PyTorch uses through mps, handy for small tests. But code that requires CUDA (CUDA kernels, bitsandbytes, vLLM, many training scripts) does not run on a Mac. Write your code so it picks its device: CUDA when present, then MPS, then the CPU.
import torch
if torch.cuda.is_available():
device = torch.device("cuda")
elif torch.backends.mps.is_available():
device = torch.device("mps")
else:
device = torch.device("cpu")
model = model.to(device)The fix without an NVIDIA card: a GPU by the hour
The GPU Cloud PyTorch (CUDA) template delivers an Ubuntu server with the NVIDIA driver, CUDA and PyTorch ready in /opt/pytorch, activated at SSH login. An RTX A6000 with 48 GB costs CA$0.67/h. The guide to run your script on a GPU shows every step, from copying the project to stopping the charges.
| GPU | Memory (VRAM) | On demand, per hour | Spot, per hour |
|---|---|---|---|
| NVIDIA RTX A6000 | 48 GB | $0.67 | $0.54 |
| NVIDIA L40 | 48 GB | $1.34 | $1.07 |
| NVIDIA A100 PCIe | 80 GB | $1.81 | $1.45 |
| NVIDIA RTX PRO 6000 | 96 GB | $2.48 | $1.98 |
| NVIDIA H100 PCIe | 80 GB | $3.35 | $2.68 |
Price of a 1-GPU server in Canadian dollars, taxes extra, read from the catalog when the page is built.
Good to know before you launch
- Billing is hourly, at the server’s hourly rate, from prepaid credit. There is no per-minute billing, and the first hour is charged when you deploy.
- A stopped server is still billed at the full hourly rate. To pay less, hibernate it ($0.02 per hour (about $14.60 per month), disk kept) or delete it. A Spot machine cannot be hibernated: delete it when you are done.
- The minimum top-up is CA$25.00, paid by credit card.
- Servers and their disks stay in Canada (region canada-montreal, in Montreal). Account information (identity, billing, e-mails) may be processed outside Quebec, as the privacy policy explains.
Frequently asked questions
Can PyTorch use CUDA on an M1, M2, M3 or M4 Mac?
No. CUDA is specific to NVIDIA cards, which Macs do not have. PyTorch uses the Apple GPU through mps, but code that requires CUDA needs an NVIDIA GPU.
Why does torch.cuda.is_available() return False in Docker?
Because the container was started without --gpus all, or because the host does not have the NVIDIA Container Toolkit. Check with docker run --rm --gpus all your-image nvidia-smi.
How do I know whether my PyTorch was built with CUDA?
torch.version.cuda gives the CUDA version it targets, or None for a CPU-only build.
Does the GPU Cloud server have CUDA?
Yes. The images are Ubuntu with the NVIDIA driver, CUDA and Docker, and the PyTorch (CUDA) template installs PyTorch in /opt/pytorch, activated at SSH login.
How much does an NVIDIA GPU cost per hour?
From CA$0.67/h for an RTX A6000 with 48 GB, in Canadian dollars, taxes extra, billed by the hour from prepaid credit.
Need GPUs? We’ve got you.
Launch an NVIDIA GPU server by the hour in Canada, paid in Canadian dollars by credit card, or reserve a GPU for a given date.
Other guides
- Your AI says you need a GPU? Run your Python script on a GPU in minutes
- CUDA out of memory: causes, fixes, and when to move to a GPU with more VRAM
- How much does a GPU cost per hour in Canada, in Canadian dollars?
- OpenAI API too expensive? Host your LLM on a GPU by the hour, in Canada
- Rent a GPU by the hour in Canada: prices, steps and billing
- GPU cloud in Montreal, Canada: NVIDIA GPU servers hosted in the country
- Rent an H100 in Canada: PCIe, NVLink or SXM, by the hour
- Which GPU to fine-tune an LLM? Memory, machine and cost
- Cheap GPU cloud: how to pay as little as possible for a GPU