RTX3090 与pytorch对应版本的安装问题汇总

一、Linux查看CUDA版本以及cudnn版本号

1、查看CUDA版本
方法1: 查看文件

cat  /usr/local/cuda/version.txt

方法2: 命令

nvcc --version

2、查看cudnn版本

cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2

注意:如果系统本身没安装cuda和cudnn,无法进行查询;实际使用过程中,发现在创建虚拟环境后,安装特定cuda版本的pytorch时会自带cuda和cudnn,这点需要关注。

二、RTX3090 与pytorch版本对应关系

1、在RTX 3090 上判断,当前版本的的torch版本是否可以用,一般需要通过如下方式:

(1)python 进入python 环境, import torch 导入torch 安装包;
(2)测试 torch.cuda.is_available(),
(3)测试 torch.zeros(1).cuda()

才能说明当前版本的cuda 可以调用当前版本的pytorch
问题现象:

>>> torch.zeros(1).cuda()
/home/respecting/anaconda3/envs/torch1.8.1/lib/python3.7/site-packages/torch/cuda/__init__.py:104: UserWarning: 
NVIDIA GeForce RTX 3090 with CUDA capability sm_86 is not compatible with the current PyTorch installation.
The current PyTorch install supports CUDA capabilities sm_37 sm_50 sm_60 sm_70.
If you want to use the NVIDIA GeForce RTX 3090 GPU with PyTorch, please check the instructions at https://pytorch.org/get-started/locally/

问题分析:
(1)表明当前的安装的pytorch 版本没有匹配上合适的cuda, 即当前pytorch 版本的 cuda 版本没有对应到自己主机上安装的cuda版本,
(2)pytorch 环境中安装的cuda 版本,需要满足以下两个条件:
1、当前pytorch版本的算力支持当前机器上显卡的算力;
2、pytorch 中的 cuda 版本不能高于当前机器上已经安装的 cuda版本;

解决问题:
知道了问题的原因之后, 我们便可以解决了:
1、RTX3090 至少需要cuda 11.1 版本,才能够驱动该设备, 故我们可以安装cuda11.1 以上版本
所以在想要安装的 pytorch 版本中,找到大于cuda11.1 <= pytorch-cuda --version <= 当前机器上安装的 cuda --version
在这里插入图片描述
可以发现:本机当前支持的最高cuda为11.1,因此,这里最好安装cuda11.1的pytorch

三、安装匹配版本的pytorch

torch地址:
https://download.pytorch.org/whl/cu111/torch/
torchvision地址:
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud//pytorch/linux-64/
找到对应python版本的torch:
torch-1.10.2+cu111-cp37-cp37m-linux_x86_64.whl
找到对应版本的torchvision:
torchvision-0.11.1-py37_cu111.tar.bz2
分步安装torch和torchvision:
pip install torch-1.10.2+cu111-cp37-cp37m-linux_x86_64.whl
conda install torchvision-0.11.1-py37_cu111.tar.bz2
pip install numpy
pip install Pillow
验证:
Python 3.7.13 (default, Mar 29 2022, 02:18:16) 
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.zeros(1).cuda()
tensor([0.], device='cuda:0')
>>> 

出现这表示验证通过

四、查看PyTorch的版本及CUDA和cuDNN版本

检查PyTorch版本

torch.version # PyTorch version

torch.version.cuda # Corresponding CUDA version

torch.backends.cudnn.version() # Corresponding cuDNN version

torch.cuda.get_device_name(0) # GPU type
  • 4
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

荆楚狂人

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

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

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

打赏作者

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

抵扣说明:

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

余额充值