请问这个地方的代码为什么一直报错?
报错位置第三行
错误:RuntimeError: All input tensors must be on the same device. Received cuda:0 and cpu
已知:x_c,x_p和y存储位置均为cuda:0
from inspect import Parameter
n = x_c.shape[0]
A = torch.cat([x_c,torch.ones(n, 1)], dim=1)
B = torch.cat([x_p,torch.ones(n, 1)], dim=1)
C = torch.cat([y,torch.ones(n, 1)], dim=1)
因为cat的两个变量一个在gpu一个在cpu,所以无法cat,将两个都移到gpu就行了。加上:
device = torch.device(‘cuda:0’)
在cpu变量后加个to(device)
如torch.ones(n, 1).to(device) 即A = torch.cat([x_c,torch.ones(n, 1).to(device)], dim=1)