How to check if a tensor is on cuda in Pytorch?

Viewed 18423

I have a tensor

t = torch.zeros((4, 5, 6))

How to check if it is on gpu or not?

1 Answers

From the pytorch forum

use t.is_cuda

t = torch.randn(2,2)
t.is_cuda  # returns False
t = torch.randn(2,2).cuda()
t.is_cuda  # returns True
Related