作为一个新手,我问的东西可能有点基础,但是确实没有在网上找到解决方案,请各位前辈包涵。
https://tangshusen.me/Dive-in...
https://tangshusen.me/Dive-in...
我在上面这个网址学习pytorch,跟着运行demo的时候出现了如下的报错预计。一行代码都没有改,却出现了这样的问题。
RuntimeError: Tensor for 'out' is on CPU, Tensor for argument #1 'self' is on CPU, but expected them to be on GPU (while checking arguments for addmm)
网上有些解决方法,但是目前知识不够,确实没法看懂。
tensor可以相互运算的前提是,它们处在同一个设备中,所以如果你无法确定tensor的位置的话,可以在运算之前统一移动到cpu上(
tensor = tensor.cpu()
)或统一移动到gpu上(tensor = tensor.to(torch.device("cuda:0"))
),再进行运算。