Pytorch GPU 环境搭建

之前⼀直使⽤ Tensorflow 训练模型,第⼀次训练Pytorch模型的时候,发现速度很慢,仔细观察,发现GPU 内存占⽤为0,基本没有使⽤GPU。

AssertionError: CUDA unavailable, invalid device 0 requested
cuda不可⽤报错,现实没有有效的驱动可使⽤

测试cuda是否配置正确

import torch
print(torch.cuda.is_available())

重新安装cuda

检测本地GPU CUDA版本 nvidia-smi

pip3 install torch1.9.0+cu101 torchvision0.10.0+cu101 torchaudio=0.9.0 -f
https://download.pytorch.org/whl/torch_stable.html

当前 torchvision0.10.0+cu101 版本必须是匹配的。如果版本不匹配,如上⾯的命令,则会出现错误

我们打开网站
https://download.pytorch.org/whl/torch_stable.html
查看所有版本

“cu101” 表示需要的CUDA版本

“torchvision-0.2.1” 可以看到我们可以适应的版本

其它字段信息,包含适配 python 版本,cpu 版本,或者是系统⽀持

conda install torch==1.8.1+cu101 torchvision==0.9.1+cu101
torchaudio===0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

如果安装还是报错的话

ERROR: Could not find a version that satisfies the requirement
torch1.8.1+cu101...

我们可以换下⾯这种安装⽅式

conda install -i https://pypi.tuna.tsinghua.edu.cn/simple torch===1.8.1
torchvision===0.9.1 -f https://download.pytorch.org/whl/torch_stable.html

终于安装成功,满⼼欢⼼重新测试:

还是不对,这⼀次报错说我们的 CUDA 驱动版本太低了,⽽是 Pytorch 的版本和 CUDA 不匹配。

查看我们的 CUDA Version 为 10.0.130

再看下我们当前环境的 torch 版本

发现1.8.0版本对应的CUDA最低为10.2 版本,确实⽐我们的要训练环境要高,重新调整我们本地虚拟环境版本,我们稍微降低⼀下版本,Torch官⽹的版本只提供了CUDA 9.2和CUDA 10.1的版本,我的CUDA是10.0的。所以这里版本不对应导致Torch.cuda加速无法运行。

这⾥支持10.0版本为1.2.0版本,感觉有点低,升级⼀下CUDA版本到10.1版本

更多技术文章

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值