Pytorch关于参数在CPU和GPU的问题

作为一个新手,我问的东西可能有点基础,但是确实没有在网上找到解决方案,请各位前辈包涵。

https://tangshusen.me/Dive-into-DL-PyTorch/#/chapter03_DL-basics/3.7_softmax-regression-pytorch

https://tangshusen.me/Dive-into-DL-PyTorch/#/chapter03_DL-basics/3.10_mlp-pytorch

我在上面这个网址学习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 都是在CPU 上,或者都是在GPU 上: https://blog.csdn.net/On_theway10/article/details/97789861