Python 3.x pytorch running:RuntimeError:预期所有张量都在同一个设备上,但至少找到两个设备:cuda:0和cpu

Python 3.x pytorch running:RuntimeError:预期所有张量都在同一个设备上,但至少找到两个设备:cuda:0和cpu,python-3.x,pytorch,Python 3.x,Pytorch,当我运行python代码时,第44行出现了一个runtimeError:runtimeError:预期所有张量都在同一个设备上,但至少发现了两个设备,cuda:0和cpu 42 feats = self.node_features[self.train_mask] 43 labels = self.node_labels[train_mask] 44 A = torch.mm(feats.t(), feats) + 1e-05 * torch.eye(feats.

当我运行python代码时,第44行出现了一个runtimeError:runtimeError:预期所有张量都在同一个设备上,但至少发现了两个设备,cuda:0和cpu

    42  feats = self.node_features[self.train_mask]
    43  labels = self.node_labels[train_mask]

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

    45  labels_one_hot = torch.zeros((feats.size(0), self.n_classes))

谁能知道原因并帮我解决它!谢谢

似乎张量火炬眼(…)在CPU上。 你需要把它作为-

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


看起来张量火炬眼(…)在CPU上。 你需要把它作为-

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


您试图求两个张量之和,一个在CPU上(您使用
torch.eye
定义的标识矩阵),另一个在GPU上(
feats
)。因此,在第44行中,将
添加到('cuda')
,如下所示:
火炬眼(feats.size(1)).to('cuda')
。您试图求两个张量之和,一个在CPU上(使用
火炬眼定义的身份矩阵),另一个在GPU上(
feats
)。因此,在第44行中,将
添加到('cuda')
如下:
火炬眼(专长大小(1))。添加到('cuda')