1. Running the code shows that CUDA is currently unavailable.
import torch
print(torch.cuda.is_available()) # False
2. Open power shell or cmd and enter the nvidia-smi command to check the current NVIDIA graphics card information.
It can be seen that the current driver version is 512.78, the highest supported cuda version is 11.6, and pytorch 2.0.0 requires cuda version 11.7 or 11.8.
3. Download the latest version of GeForce (non-latest version drivers will fail to update), install, and update the driver inside: NVIDIA GeForce Driver - N Card Driver | NVIDIA
The current driver version has been updated to 535.98, and the highest supported cuda version has been changed to 12.2.
4. Next update cuda
Running nvcc -V shows that the current cuda version is 11.1.
5. Download cuda11.8 : CUDA Toolkit Archive | NVIDIA Developer
Choose custom installation
If C drive resources are tight, you can change the path to a non-C drive. (Even so, the C drive will occupy 5~6 G after installation)
After installation, add the CUDA path in Environment Variables->System Variables->Path.
6. Run nvcc -V. It can be seen that the current cuda version has been updated to 11.8.
7. Next install cudnn
Download cudnn: cuDNN Archive | NVIDIA Developer
You need to register your information before downloading, it’s not particularly troublesome, just check a few √’s.
Choose any version in for CUDA 11.x. I chose the latest version.
After the download is completed, unzip the compressed package and copy bin
the , include
, and lib 3个
folders to the cuda installation directory v11.8.
8. Install pytorch2.0
Enter the pytorch official website: PyTorch
conda create -n pytorch2.0 python==3.9
conda activate pytorch2.0
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
To make it easier for everyone to copy, here are three sections of code. (My personal habit is to name the environment of pytorch2.0 as pt2.0)
conda create -n pt2.0 python==3.9
conda activate pt2.0
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
I created a virtual environment on conda here, but it is more convenient to use the pip command to install it.
(If you want to download it yourself, you can visit: https://download.pytorch.org/whl/torch/ )
If pip installation is too slow, you can use:
pip install -i https://mirrors.aliyun.com/pypi/simple/ 库名
9. Check whether cuda is available
import torch
print(torch.cuda.is_available()) # True
Finally succeeded! The main reason is that it takes time to download and install. There is no technical difficulty in the step-by-step operation, and no difficult problems are encountered.
To sum up the following experience: after switching versions of CUDA, the pytorch2.0 environment needs to be re-established. Because my previous pytorch2.0.1 couldn't be used, I rebuilt the conda virtual environment and installed pytorch2.0.1 and it worked.