AttributeError: module 'torch.cpu' has no attribute 'set_device' 是哪里出了问题怎么解决
可能是版本更新导致的 方法缺失 建议查询源代码 所用torch 版本 或者 寻找set_device的替代方法
模块“torch.cpu”没有属性“set_device”,升级 一下pytorch
【相关推荐】
原因是torch版本太老了,要升级torch,但是还不能升级到最高版,因为cuda跟不上
为解决这个问题,torch至少要升级到0.4version以上,建议1.0以上吧,要不然还有其他的问题。
在
https://pytorch.org/get-started/previous-versions/可以找到各个版本的torch我选择cuda90:https://download.pytorch.org/whl/cu90/torch_stable.html找到自己需要的版本使用wget 下载
wget [torch url]
pip install --upgrade [download file]
再用
import torch
print(torch.__version__)
查看torch版本,变成了1.1.0,在运行程序就不会找不到device了,搞定!