cuda+anaconda+pytorch按照教程

首先安装显卡对应的CUDA版本,关键点在于区别显卡支持的CUDA最高版本和运行版本

1、查看当前显卡支持的最高版本,有两种方式:

1)NVIDIA控制面板--->帮助--->系统信息--->组件--->NVCUDA.dll对应版本

请注意,12.2为本机CUDA支持的最高版本

python 复制代码
nvidia-smi

nvidia-smi显示的同上,也表示cuda支持的最高版本

安装对应CUDA版本并查看

按照CUDA时需要对应torch的版本,官方推荐的cuda版本为10.2和11.3,这两种 cuda 支持大多数的 pytorch 版本。

1、以下是Pytorch和CUDA对应的版本

2、以下是Pytorch和Python对应的版本

3、安装CUDA 11.3版本

1)CUDA 安装包官网

下载对应安装包并默认按照即可,安装效果如下:
上述11.3即对应的cuda版本

python 复制代码
ncvv -V  #查看并检查电脑对应cuda版本

接着创建anaconda环境并按照gpu版本的pytorch

1、首先创建环境

python 复制代码
conda create -n pytorch python=3.7

2、接着在安装torch时,先配置好anaconda的镜像源。由于刚开始c盘并没有配置镜像源的文件,《C:\Users\Admin.condarc》,安装anaconda时关于windows系统没有.condarc文件的处理

python 复制代码
conda config --set show_channel_urls yes

同时配置清华镜像源

python 复制代码
show_channel_urls: true
ssl_verify: true
remote_read_timeout_secs: 100000.0
channels:
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - defaults
  - conda-forge
report_errors: true

3、安装gpu版本的torch有以下教程,最简单的是直接使用下面这条命令

python 复制代码
conda install pytorch torchvision torchaudio cudatoolkit=11.3

但是,安装的总是cpu版本的torch,主要是因为不能同时匹配cuda对用的gpu版torch,conda按照总是体术pytorch对应的cpu版本,如下图:

conda安装GPU版pytorch,结果却是cpu版本[找到问题根源,从容解决。

上述解决方法从根本上解决版本不对应问题,主要通过先查看清华镜像源的方式。

1)先看清华镜像源cuda对应的安装包版本,清华镜像源

以cuda 11.3为例,其对应的torch==1.10.0,cudnn=8.0,进一步需查看torch对应的torchvision版本,链接详情如下:

至此,准备工作结束!

4、使用以下命令先安装cudatoolkit,接着cudnn,最后pytorch、torchvision。

1)安装 cudatoolkit,其实环境里面的

python 复制代码
conda install cudatoolkit=11.3 # 安装 cuda

2)安装 cudnn

python 复制代码
conda install cudnn=8.0 # 安装cudnn

3)安装 pytorch

python 复制代码
conda install pytorch==1.10.0 torchvision==0.11.1 cudatoolkit=11.3
  1. 检查
  2. 测试
python 复制代码
import torch
print(torch.__version__)  #注意是双下划线
print(torch.version.cuda)
print(torch.cuda.is_available())
print(torch.cuda.get_device_name())
相关推荐
火山引擎开发者社区10 小时前
火山AgentPlan/CodingPlan同步上线GLM-5.2
人工智能
冬奇Lab11 小时前
Skill 系列(05):Skill 工作流串联——4 种模式实测,并发加速 1.5x
人工智能·开源
冬奇Lab11 小时前
每日一个开源项目(第141篇):hiring-agent - HackerRank 开源了他们的简历评分系统,你的简历能得几分?
人工智能·面试·开源
甲维斯12 小时前
又升级咯!坦克大战2026,科技与复古并存!
前端·人工智能·游戏开发
姗姗来迟了14 小时前
用React Hook封装AI对话状态
人工智能
Goodbye14 小时前
从 Token 到 Embedding:LLM 核心基础深度解析
javascript·人工智能
阿瑞IT14 小时前
AI Agent 在甘特计划变更场景中的动态响应工程实践
人工智能
用户9385156350714 小时前
工具调用背后:LLM 如何突破“缸中大脑”,操控真实世界?
javascript·人工智能