Tag Archives: #RuntimeError: Expected all tensors to be on the same device

[Solved] RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!

There are two types of data: numpy and torch

z = mean.clone().detach() + eps * torch.exp(logstd)

An error is reported in the source code, which is modified as follows

eps = eps.cuda()    
z = mean.cuda()+ eps * torch.exp(logstd).cuda()

It is to add CUDA() after numpy, such as reshape