更换 conda 源为清华源
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| channels: - defaults show_channel_urls: true default_channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2 custom_channels: conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
|
安装 CUDA 和 CUDNN
CUDA 下载页面
https://developer.nvidia.com/cuda-downloads
nvcc -V
查看安装是否成功
cuDNN 下载页面:https://developer.nvidia.com/rdp/cudnn-download
打开 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7
将 cuDNN 里的 bin、include、lib 复制到对应 bin、include、lib
Pytorch
下载 pytorch GPU 版
在此下载:
https://download.pytorch.org/whl/torch_stable.html
找到对应的 CUDA 版本和 python 版本
例如 torch-1.12.1+cu116-cp39-cp39-win_amd64.whl 对应 CUDA 1.16 python3.9
还需要对应 pytorch 官网下载 torchaudio torchvision。
安装 pytorch
进入下载目录
pip install ./torch-1.12.1+cu116-cp39-cp39-win_amd64.whl
验证
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| import torch
x = torch.rand(5, 3) print(x)
print("torch version ", torch.__version__)
print("torch.cuda.is_available()", torch.cuda.is_available())
output: tensor([[0.4556, 0.2505, 0.7284], [0.4068, 0.0266, 0.3300], [0.7225, 0.0090, 0.7773], [0.2523, 0.9489, 0.8674], [0.4931, 0.7107, 0.3855]]) torch version 1.12.1+cu116 torch.cuda.is_available() True
|