module 'torch._c' has no attribute '_cuda_setdevice'
时间: 2023-04-28 14:06:16 浏览: 2485
这个错误的意思是,torch._c模块中没有_cuda_setdevice属性。这可能是由于您使用了过时的PyTorch版本或者使用了错误的导入方式导致的。建议检查您的PyTorch版本是否是最新的,并检查您的代码中的导入语句是否正确。
相关问题
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 ]