gpt4 book ai didi

python-3.x - pytorch 运行 : RuntimeError: Expected all tensors to be on the same device, 但至少找到两个设备,cuda:0 和 cpu

转载 作者:行者123 更新时间:2023-12-04 17:23:23 24 4
gpt4 key购买 nike

当我运行 python 代码时,第 44 行出现运行时错误:RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and 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))

谁知道原因可以帮我解决一下吗!谢谢!

最佳答案

张量 torch.eye(...) 似乎在 CPU 上。您需要将其传递为 -

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

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

关于python-3.x - pytorch 运行 : RuntimeError: Expected all tensors to be on the same device, 但至少找到两个设备,cuda:0 和 cpu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64929665/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com