You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

PyTorch 安装

1、查看本机的CUDA版本

cmd命令行输入nvidia-smi在第一行最右边可以看到CUDA的版本号我的版本是12.4

2、安装Pytroch

(1)、官网:https://pytorch.org/

然后选择Get Started就是如下界面

(2)、这里进行Pytorch版本的选择,首先我选择的是Stable稳定版,然后OSWindows系统,Package包就使用CondaLanguage肯定选Python,最后的Compute Platform 选择 CUDA12.1

conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia

3、安装下Anaconda并创建一个Python环境,安装的是python3.9

conda activate py39

4、关闭掉VPN,然后执行:

# 解决一些环境变量问题
G:
cd G:\anaconda3
copy Library\bin\libcrypto-1_1-x64.dll DLLs\.
copy Library\bin\libssl-1_1-x64.dll DLLs\.

#开始安装 
conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia

注:如果环境变量不对了,需要重置一下环境:

conda config --remove-key channels

5、可以看到将要安装的包里面有pytorchcudatoolkit,输入y确认,然后回车

6、下面就等待这些package安装成功,可以看到Pytorch还是比较大的,所以耐心等待一下。如果下载过程中卡住的同学,直接到torch镜像源下载安装包进行安装,效果相同。

7、安装完成后会提示信息done

8、输入pip list,查看我们的包是否被安装,这里可以看到torch相关的包都安装了。

9、我们输入python进入下 Python 环境,然后输入`

import torch

如果没有报错说明可以导入成功。

10、输入

torch.cuda.is_available()

查看torch是否可以使用显卡,True就代表可以!