已经安装了anaconda
核实是否为英伟达显卡,我电脑是入门级1030,在英伟达算力表上没有,但是也可以装。
nvidia-smi
1.安装CUDA
CUDA Toolkit Archive | NVIDIA Developer
CUDA 版本根据系统来,不用安装最新版,根据pytorch 支持的来选择。
文件很大,不要安装错了。
新增环境变量,将nvcc.exe所在目录添加至环境变量。
核实是否完成 cmd
nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Fri_Dec_17_18:28:54_Pacific_Standard_Time_2021
Cuda compilation tools, release 11.6, V11.6.55
Build cuda_11.6.r11.6/compiler.30794723_0
2.安装 cuDNN
cuDNN Archive | NVIDIA Developer
需要账号,注册就好
将文件复制到CUDA中,插入式组件,为了加速GPU的计算。
3.安装pytorch
在pytorch管网找到对应的pytorch地址
打开anaconda PowerShell prompt
创建pytorch 环境
conda info -e
# 查看已有的环境
conda create -n pytorch
# 注意不要开vpn
根据自己电脑情况输入pytorch 安装代码,文件有点大,我用的pip ,conda安装太慢。
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116
4.检查是否安装成功
import torch
print("hello {}".format(torch.__version__))
print(torch.cuda.is_available())