Skip to content Skip to sidebar Skip to footer

Pytorch Running: Runtimeerror: Expected All Tensors To Be On The Same Device, But Found At Least Two Devices, Cuda:0 And Cpu

When I running the python code, there is a runtimeError in line 44:RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!

Solution 1:

It seems that the tensor torch.eye(...) is on CPU. you need to pass it as -

44  A = torch.mm(feats.t(), feats) + 1e-05 * torch.eye(feats.size(1)).to(device='cuda')

or

44  A = torch.mm(feats.t(), feats) + 1e-05 * torch.eye(feats.size(1)).cuda()

Post a Comment for "Pytorch Running: Runtimeerror: Expected All Tensors To Be On The Same Device, But Found At Least Two Devices, Cuda:0 And Cpu"