How do I check if PyTorch is using the GPU?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In PyTorch, "GPU available" and "your code is actually using the GPU" are not the same thing. The correct check is usually a combination of three things: CUDA availability, the device of your tensors and model, and whether the operations you care about are happening on that device.
Check Whether CUDA Is Available
The first check is whether the installed PyTorch build can see a CUDA-capable device at all.
If torch.cuda.is_available() is False, your code is not going to use the NVIDIA GPU through CUDA, no matter how the rest of the script is written.
This check confirms that PyTorch can detect the GPU. It does not confirm that your tensors or model are actually running there.
Check the Device of a Tensor or Model
The next step is to inspect the device of the objects doing the work.
For a tensor:
For a model:
If the model parameters are still on cpu, then the forward pass is not running on the GPU even if CUDA is installed.
Make Sure Inputs and Model Match
A very common mistake is moving the model to CUDA but leaving the input tensors on the CPU, or the reverse. PyTorch expects them to be on compatible devices.
If both model and inputs are on cuda, the output should also report a CUDA device.
That is often the most practical runtime confirmation: inspect the device of the tensors involved in the actual computation you care about.
A Minimal End-to-End Check
A small working script is often the fastest sanity check:
If all three print a CUDA device, then the computation is actually happening on the GPU.
Use Monitoring When You Need Extra Confirmation
If you want confirmation outside Python, use nvidia-smi while the program is running:
That can show GPU memory usage and active processes. It is useful when debugging whether a training job really moved to the GPU or is just sitting on the CPU.
Still, nvidia-smi is a secondary check. In code, the most reliable test is still the device of the tensors and parameters involved in the computation.
Common Pitfalls
- Checking only
torch.cuda.is_available()and assuming that means the model is already using the GPU. - Moving the model to CUDA but forgetting to move the inputs.
- Moving inputs to CUDA but leaving the model on the CPU.
- Running on Apple Silicon or another non-CUDA backend and expecting
torch.cudachecks to apply. - Looking at the device too early, before the tensors or model have actually been moved.
Summary
- First check whether CUDA is available with
torch.cuda.is_available(). - Then inspect the device of the actual tensors and model parameters.
- Model, inputs, and outputs should all report a CUDA device if the computation is on the GPU.
- A small end-to-end forward pass is the best practical sanity check.
- '
nvidia-smiis useful as an extra confirmation, but the code-level device checks matter most.'

