关于AttributeError: module ‘torch._C‘ has no attribute ‘_cuda_setDevice‘问题的解决

1.该问题错误情况如下

  File "E:\PythonCode\STANet-master\options\base_options.py", line 140, in parse
    torch.cuda.set_device(opt.gpu_ids[0])
  File "E:\Python\lib\site-packages\torch\cuda\__init__.py", line 281, in set_device
    torch._C._cuda_setDevice(device)
AttributeError: module 'torch._C' has no attribute '_cuda_setDevice'

2.解决方法

1)修改执行命令

由于我的pytorch装的是CPU版本的,因此需要在python执行命令后面加上 --gpu_ids -1

E:\PythonCode\Net>python train.py --gpu_ids -1

这样运行就没有出错了,不过,还可以用另一种方式解决~

2)修改"base_options.py"文件

这个文件在错误信息里面可以找到。

    def initialize(self, parser):
        """Define the common options that are used in both training and test."""
        # basic param
  • 7
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
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: moduletorch._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: moduletorch._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 ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值