'torch._C' has no attribute '_cuda_setDevice'
时间: 2023-10-13 10:07:13 浏览: 67
这个错误通常是因为你的PyTorch版本太老了,不支持你的CUDA版本。你可以尝试更新PyTorch版本,或者降低CUDA的版本。你也可以使用CPU版本的PyTorch,但是速度可能会慢一些。如果你确定你的PyTorch版本和CUDA版本是兼容的,那么可能是你的环境配置有问题,可以检查一下CUDA和cuDNN的安装路径是否正确配置,并且环境变量是否设置正确。
相关问题
module 'torch._C' has no attribute '_cuda_setDevice'
根据提供的引用内容,当出现 "module 'torch._C' has no attribute '_cuda_setDevice'" 这个错误时,可能是由于使用了过时的方法来设置GPU设备。你可以尝试使用新的方法来设置GPU设备。例如,在你的Python文件中,可以使用以下代码来设置GPU设备:
torch.cuda.set_device(-1)
如果你是通过命令行执行Python文件,可以在最后添加以下命令来设置GPU设备:
python train.py --你的GPU的设置对应形参 -1
请注意,你需要将上述代码中的-1更改为你要使用的GPU设备的编号。此外,还要确保你的GPU版本已经正确安装并可用。
AttributeError: module 'torch._C' has no attribute '_cuda_setDevice'
AttributeError: module 'torch._C' has no attribute '_cuda_setDevice' 是由于torch模块中没有_cuda_setDevice属性而导致的错误。
这个错误通常是由于安装的torch版本不兼容或者不支持GPU而引起的。根据查询结果可以看出,您安装的torch是适用于CPU的版本,而不是适用于GPU的版本。
解决这个问题的方法是安装适用于GPU的torch版本。您可以通过在命令行中运行以下命令来安装适用于GPU的torch版本:
```
pip install torch==<your desired torch version> # 例如:pip install torch==1.8.0
```
安装完适用于GPU的torch版本后,再次运行main.py应该就不会再出现该错误了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [学习记录:AttributeError: module ‘torch._C‘ has no attribute ‘_cuda_setDevice](https://blog.csdn.net/weixin_47247597/article/details/130113980)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [关于AttributeError: module ‘torch._C‘ has no attribute ‘_cuda_setDevice‘问题的解决](https://blog.csdn.net/qq_39578356/article/details/108575978)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]