如何检查 Pytorch 中的张量是否在 cuda 上?

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

我有张量

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

如何查看是否在gpu上?

From the pytorch forum

使用t.is_cuda

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