1. Preparation work:
Check the torch version: enter the python interactive environment:
>>>import torch
>>>torch.__version__
Check cuda version: CMD window
nvcc --version
If the version is inconsistent, you need to uninstall and reinstall.
2. Installation
Install CUDA/cuDNN on Windows - Zhihu medium - Install CUDA On Windows: The Definitive Guidemedium - Installing CUDA and cuDNN on windows 10 Windows installs and configures the relationship between cudn and cudnn versions ... https://zhuanlan.zhihu.com/p/99880204 View the correspondence between CUDA and Pytorch:
Previous PyTorch Versions | PyTorch An open source machine learning framework that accelerates the path from research prototyping to production deployment. https://pytorch.org/get-started/previous-versions/ This machine is CUDA11.8, so the installation command is the first three:
# ROCM 5.4.2 (Linux only)
pip install torch==2.0.0+rocm5.4.2 torchvision==0.15.1+rocm5.4.2 torchaudio==2.0.1 --index-url https://download.pytorch.org/whl/rocm5.4.2
# CUDA 11.7
pip install torch==2.0.0+cu117 torchvision==0.15.1+cu117 torchaudio==2.0.1 --index-url https://download.pytorch.org/whl/cu117
# CUDA 11.8
pip install torch==2.0.0+cu118 torchvision==0.15.1+cu118 torchaudio==2.0.1 --index-url https://download.pytorch.org/whl/cu118
# CPU only
pip install torch==2.0.0+cpu torchvision==0.15.1+cpu torchaudio==2.0.1 --index-url https://download.pytorch.org/whl/cpu
3. Verification
View the cuda version corresponding to pytorch
python
>>>import torch
>>>torch.version.cuda
Verify that the GPU is available
import torch
import torchvision
print(torch.cuda.is_available())