学习记录:AttributeError: module ‘torch._C‘ has no attribute ‘_cuda_setDevice‘

运行main.py时报错如下:

AttributeError: module 'torch._C' has no attribute '_cuda_setDevice'

网上查询原因:说我安装的torch是适合CPU的,而不是适合GPU的。于是我查询pytorch

>python
Python 3.8.0 (default, Nov 6 2019, 16:00:48) [MSC v.1912 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>import torch
>>>torch.cuda.is_available()
False

显而易见,环境使用的是CPU版本的torch,但是我仔细检查了一下我安装的命令,如下

conda install pytorch==1.10.0 torchvision==0.11.0 torchaudio==0.10.0 cudatoolkit=11.3 -c pytorch -c conda-forge

发现并没有什么问题,查询才知道,windows系统会默认安装适合cpu版本的,于是我去

https://download.pytorch.org/whl/torch_stable.html

下载三个安装包,适合GPU版本的

分别pip install 他们,这样就能够安装适合GPU版本的torch了

猜你喜欢

转载自blog.csdn.net/weixin_47247597/article/details/130113980