How to check if pytorch is using the GPU?
Query
Command




Does PyTorch see any GPUs?
torch.cuda.is_available()


Are tensors stored on GPU by default?
torch.rand(10).device


Set default tensor type to CUDA:
torch.set_default_tensor_type(torch.cuda.FloatTensor)


Is this tensor a GPU tensor?
my_tensor.is_cuda


Is this model stored on the GPU?
all(p.is_cuda for p in my_model.parameters())
How do I check if pytorch is using the GPU? It's possible to detect with nvidia-smi if there is any activity from the GPU during the process, but I want something written in a python script.