Tech & GPU October 24, 2026
Global Edition

PyTorch: How to Check if GPU Is Available (CUDA)

• •
3 min read
PyTorch: How to Check if GPU Is Available (CUDA)

Last updated:

To check if a GPU is available in PyTorch, run torch.cuda.is_available(). It returns True when PyTorch can use an NVIDIA CUDA GPU (or an AMD GPU with the ROCm build), and False when it cannot.

How do you check if PyTorch can use the GPU?

You check if PyTorch can use the GPU with 4 commands:

  • torch.cuda.is_available() returns True or False.
  • torch.cuda.device_count() returns the number of GPUs.
  • torch.cuda.get_device_name(0) returns the GPU name, such as “NVIDIA GeForce RTX 5070”.
  • torch.version.cuda returns the CUDA version PyTorch was built with (None means a CPU-only build).

A complete check in Python:

import torch; print(torch.cuda.is_available(), torch.cuda.device_count(), torch.cuda.get_device_name(0) if torch.cuda.is_available() else "no GPU")

How do you run a model on the GPU in PyTorch?

You run a model on the GPU by creating a device and moving the model and tensors to it:

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

Then call model.to(device) and tensor.to(device). Both the model and its input data must be on the same device.

Why does torch.cuda.is_available() return False?

torch.cuda.is_available() returns False for one of 5 reasons:

  1. CPU-only PyTorch is installed: pip installed the CPU build. Reinstall with the CUDA command from pytorch.org.
  2. No NVIDIA driver or an outdated driver; see how to update GPU drivers.
  3. No supported GPU: the PC has only integrated graphics; see how to see what graphics card you have.
  4. Driver too old for the CUDA version: new PyTorch CUDA builds need a recent driver. RTX 50 (Blackwell) cards need PyTorch builds with CUDA 12.8 or newer.
  5. Wrong environment: the Jupyter kernel or IDE uses a different Python environment.

How do you check the GPU from the command line?

You check the GPU from the command line with nvidia-smi, which shows the GPU name, driver version, maximum supported CUDA version, temperature, usage and memory. If nvidia-smi fails, the NVIDIA driver is not installed correctly.

How do you check for Apple Silicon (MPS) in PyTorch?

You check for Apple Silicon GPUs with torch.backends.mps.is_available(). Use torch.device("mps") to run models on M-series Macs.

Does PyTorch work with AMD GPUs?

Yes. PyTorch works with AMD Radeon and Instinct GPUs through the ROCm build on Linux. With ROCm, torch.cuda.is_available() also returns True, because PyTorch uses the same CUDA API names.

What if you do not have a GPU for PyTorch?

If you do not have a GPU, you can rent one in the cloud by the hour; see GPU rental. Read NPU vs GPU to understand why GPUs are used for AI.

FAQ

How do I know PyTorch is using my GPU?

Check that tensors show device=’cuda:0′ and watch GPU usage in nvidia-smi or Task Manager.

Do I need to install CUDA separately for PyTorch?

No. PyTorch wheels include the CUDA runtime; you need only the NVIDIA driver.

How do I select a specific GPU in PyTorch?

Use torch.device(“cuda:1”) or set the CUDA_VISIBLE_DEVICES environment variable.

Related guides

Related reading: see our guide on how to fix “error occurred on GPU ID 100”.

Walker
Written by

Walker is a GPU expert with 10 years of hands-on experience in graphics cards, PC hardware, gaming performance, and GPU troubleshooting. He writes simple and helpful content about GPUs, FPS optimization, cooling, drivers, and PC builds. His goal is to help gamers, creators, and PC users understand GPU technology in an easy way.

Leave a Reply

Your email address will not be published. Required fields are marked *