热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

RTX3090与pytorch版本对应关系

在RTX3090上判断,当前版本的的torch版本是否可以用,一般需要通过如下方式:condaactivatetorch1.8.1(激活

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

  1. conda activate torch1.8.1 ( 激活相关的虚拟环境)
  2. python 进入python 环境, import torch 导入torch 安装包;
  3. 测试 torch.cuda.is_available(),
  4. 测试 torch.zeros(1).cuda()

直到,第四步骤完成,才能说明当前版本的cuda 可以调用当前版本的pytorch;

问题的关键点:

  1. 安装pytorch 过程中, 需要两个注意点, 一个是当前安装的pytorch 版本, 该pytroch 版本官网指定包含了哪几个cuda 版本;
  2. 使用pip install torch==1.8.1 的方式安装,默认的是torch 版本+ 当前主机上的cuda 版本
  3. 可能出现的问题, 当前主机的cuda 版本 不兼容该torch版本中官方发布的几个cuda 版本;


1. 问题现象

>>> 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.1 问题分析

表明当前的安装的pytorch 版本没有匹配上合适的cuda,  即当前pytorch 版本的 cuda 版本没有对应到自己主机上,安装的cuda 版本,

pytorch 环境中安装的cuda 版本, 需要满足以下两个条件:

  1. 当前pytorch版本的算力支持 当前机器上显卡的算力;
  2. pytorch  中的 cuda 版本 不能高于当前机器上已经安装的 cuda 版本;

具体讲来, 同一个pytorch 版本,比如 pytorch 1.8.1 会对应到不同版本的 cuda

# ROCM 4.0.1 (Linux only)
pip install torch==1.8.1+rocm4.0.1 torchvision==0.9.1+rocm4.0.1 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html# ROCM 3.10 (Linux only)
pip install torch==1.8.1+rocm3.10 torchvision==0.9.1+rocm3.10 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html# CUDA 11.1
pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html# CUDA 10.2
pip install torch==1.8.1+cu102 torchvision==0.9.1+cu102 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html# CUDA 10.1
pip install torch==1.8.1+cu101 torchvision==0.9.1+cu101 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html# CPU only
pip install torch==1.8.1+cpu torchvision==0.9.1+cpu torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

1.2 解决问题

pytorch 环境中安装的cuda 版本, 需要满足以下两个条件:

  1. 当前pytorch版本的算力支持 当前机器上显卡的算力;
  2. pytorch 中的 cuda 版本不能高于当前机器上已经安装的 cuda 版本;

知道了问题的原因之后, 我们便可以解决了:

  1. RTX3090 至少需要cuda 11.1 版本,才能够驱动该设备, 故我们可以安装cuda11.1 以上版本
  2. 所以在想要安装的 pytorch 版本中&#xff0c;找到大于  cuda11.1 <&#61; pytorch-cuda --version <&#61;  当前机器上安装的 cuda --version

由于笔者机器上安装的是 cuda11.2 &#xff0c; 而3090对应的cuda 版本必须大于等于cuda11.1,
故安装pytorch 1.8.1 中的 cuda11.1 版本&#xff0c;  卸载重新安装对应版本&#xff1b;

pip install -i https://pypi.douban.com/simple torch-1.8.1&#43;cu111-cp37-cp37m-linux_x86_64.whl
Looking in indexes: https://pypi.douban.com/simple
Processing ./torch-1.8.1&#43;cu111-cp37-cp37m-linux_x86_64.whl
Requirement already satisfied: numpy in /home/respecting/anaconda3/envs/torch1.8.1/lib/python3.7/site-packages (from torch&#61;&#61;1.8.1&#43;cu111) (1.21.6)
Requirement already satisfied: typing-extensions in /home/respecting/anaconda3/envs/torch1.8.1/lib/python3.7/site-packages (from torch&#61;&#61;1.8.1&#43;cu111) (4.2.0)
Installing collected packages: torchAttempting uninstall: torchFound existing installation: torch 1.8.1Uninstalling torch-1.8.1:Successfully uninstalled torch-1.8.1
Successfully installed torch-1.8.1&#43;cu111

torchvision install

(torch1.8.1) respecting&#64;respecting-B360M-GAMING-HD:/media/respecting/Ubuntu 18.0/June18$ pip install -i https://pypi.douban.com/simple torch-1.8.1&#43;cu111-cp37-cp37m-linux_x86_64.whl
Looking in indexes: https://pypi.douban.com/simple
Processing ./torch-1.8.1&#43;cu111-cp37-cp37m-linux_x86_64.whl
Requirement already satisfied: numpy in /home/respecting/anaconda3/envs/torch1.8.1/lib/python3.7/site-packages (from torch&#61;&#61;1.8.1&#43;cu111) (1.21.6)
Requirement already satisfied: typing-extensions in /home/respecting/anaconda3/envs/torch1.8.1/lib/python3.7/site-packages (from torch&#61;&#61;1.8.1&#43;cu111) (4.2.0)
Installing collected packages: torchAttempting uninstall: torchFound existing installation: torch 1.8.1Uninstalling torch-1.8.1:Successfully uninstalled torch-1.8.1
Successfully installed torch-1.8.1&#43;cu111

2. 重新测试

(torch1.8.1) respecting&#64;respecting-B360M-GAMING-HD:~$ python
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&#61;&#39;cuda:0&#39;)
>>>

3090Ti 系列

3.1 nvidia 显卡驱动

Version: 515.57
Release Date: 2022.6.28
Operating System: Linux 64-bit
Language: English (US)
File Size: 346.53 MB


推荐阅读
author-avatar
zhousulian
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有