torch.cuda.is_available() 解决方

本人使用的显卡如下,打开任务管理器查看

Anaconda下载哪个版本都可以

使用命令conda create -n pytorch python=3.6创建一个名为pytorch的环境,解释器使用3.6的

使用命令conda activate pytorch进入该环境

进入pytorch官网,选择下列选项

复制上面的命令,在pytorch环境下载

conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia

进入python,导入 torch 包,检查 GPU 启动失败

(pytorch) C:\Users\ml>python
Python 3.6.13 |Anaconda, Inc.| (default, Mar 16 2021, 11:37:27) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.cuda.is_available()
False

在pytorch下使用 conda list 命令查看pytorch是 CPU 版本的

使用命令conda uninstall pytorch卸载 CPU 的版本

选择 pip 方式下载,会下载 GPU 版本

复制命令到pytorch环境下载

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu117

没有找到匹配的版本,所以是11.7的版本太高,修改为 11.3版本,继续下载,这个过程很慢,需要耐心等待

最后检验,安装成功

或者直接运行这个命令

pip install torch==1.9.1+cu111 torchvision==0.10.1+cu111 torchaudio==0.9.1 -f https://download.pytorch.org/whl/torch_stable.html

或者

pip install torch==1.9.1+cu111 torchvision==0.10.1+cu111 torchaudio==0.9.1 -f 国内镜像源

或者

pip3 install torch==1.8.2 torchvision==0.9.2 torchaudio==0.8.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cu111
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
这个错误提示是因为你的torch.cuda模块没有is_available属性。根据引用,这个问题可以通过更新PyTorch版本来解决。根据引用,你可以尝试将PyTorch更新到1.7版本。你可以使用以下代码来确认你当前的PyTorch版本和CUDA版本: ``` import torch print(torch.__version__) print(torch.version.cuda) ``` 然后,根据引用,你可以使用以下命令来安装PyTorch 1.7.1版本: ``` conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=10.1 -c pytorch ``` 确保你根据你的CUDA版本选择适当的安装命令。通过更新PyTorch版本,你应该能够解决AttributeError: module 'torch.cuda' has no attribute 'is_available'的问题。123 #### 引用[.reference_title] - *1* *3* [AttributeError: module ‘torch.cuda‘ has no attribtue ‘amp‘ 问题解决](https://blog.csdn.net/qq_34211771/article/details/120625282)[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^v92^chatsearchT0_1"}} ] [.reference_item] - *2* [AttributeError: module ‘torch.cuda.amp‘ has no attribute ‘autocast](https://blog.csdn.net/fanre/article/details/115510919)[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^v92^chatsearchT0_1"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Q渡劫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值