【torch.cuda.is_available()输出false】

一、报错与原因分析

报错:安装的是gpu版本,但是输出false

原因分析:就很奇怪,明明是输入的pytorch的官方命令,conda下载速度很慢,经常下载失败,为了下载速度快,删除了命令行后面的 -c pytorch使用清华源下载

添加清华源命令或者直接修改.condarc文件修改(这个文件我的是在C:\Users\用户名):

命令行:

conda config --addchannels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --addchannels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --addchannels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --addchannels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --addchannels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
conda config --addchannels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --addchannels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --addchannels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/peterjc123/
conda config --setshow_channel_urls yes

这样虽然很快,但是下载的是cpu版本,导致测试GPU时输出false,具体原因不明

二、我的解决方法

解决方法:后来我查看了自己的已经安装的cuda版本为11.0,去pytorch官网找到了对应cuda11.0的之前的pytorch版本1.7.1。由于我的最高可以安装的版本是11.7。

我最开始安装的是cuda11.6+ pytorch1.13但是即使没有删除 -c pytorch 完全按照官方命令也安装失败,猜想两个原因,一个是安装时间太长,一个是由于cuda11.6高于我安装的11.0版本,就算第一个原因没有问题,安装好了,猜想也会报错

pytorch官网cuda11.0 + pytorch1.7.1地址:Previous PyTorch Versions | PyTorch

命令如下:

pip install torch==1.7.1+cu110torchvision==0.8.2+cu110 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html

安装过程:(等待就行)

测试是否安装成功:

print(torch.cuda.device_count()) # 输出有的GPU数量

print(torch.cuda.get_device_name(0)) # 输出GPU名字

测试是否是GPU版本:

输出True,安装pytorch1.7.1GPU版本成功

最终我的安装配置是:cuda11.0+ pytorch1.7.1 + python3.7

最后的最后由于安装的是1.7.1的版本与环境名字不一样,为了防止以后误会再改一下名即可

  1. 重新复制一个新的环境,再删除原有环境

conda create -n conda-new --clone conda-old
conda remove -n conda-old --all

2.直接修改文件夹名字,但这样后面pip install包会出现问题

我这里是:

conda create -n pytorch1.7.1-gpu --clone pytorch1.13-gpu

conda remove -n pytorch1.13-gpu --all

再次测试

完美解决,可以愉快玩耍了!

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值