The solution when torch.cuda.is_available() displays Flese

1. Go to the official website to update the graphics card driver

https://www.nvidia.cn/Download/index.aspx?lang=cn#

After downloading, click to install

2.WIN+R , cmd, enter nvidia-smi  to obtain driver information and CUDA version information

I originally used 11.2, but now I have updated it to 11.7 ( Additional: The 11.7 here seems to be the highest version that supports CUDA, not the current CUDA installation version. I installed 11.3, which will be mentioned later )

3. Enter the virtual environment of PyTorch, and then delete and uninstall the existing Pytorch. (I originally created a virtual environment of Pytorch. At this time, enter the virtual environment and enter the following command)

# 使用conda卸载Pytorch:
   conda uninstall pytorch     # 我使用的这种
   conda uninstall libtorch

# 使用pip卸载Pytorch:     
   pip uninstall torch

4. After the uninstallation is completed, then replace the Tsinghua download source in the PyTorch virtual environment (I did not delete the virtual environment, I still use the original virtual environment)

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes

5. Enter the official website and select CUDA11.3 version to download: Pytorch

conda install pytorch torchvision torchaudio cudatoolkit=11.3

Copy the above code into the Anaconda Prompt window

Wait for the installation to complete and a line similar to three will appear.

*******done

*******done

*******done

The installation is complete

Appendix : Check whether the GPU is available:

First, enter the Pytorch virtual environment, then enter Python to enter the interactive state, and then enter the following code. If True appears, it means that the installed cuda and torch version numbers match, and the GPU can be used.

import torch  #进入torch
torch.__version__   # 查询torch版本号
torch.cuda.is_available() #查询cuda和torch是否匹配
torch.cuda.device_count() #查询cuda个数
torch.version.cuda        #查询cuda版本

This is my first time covering these, so if there are any mistakes, please correct me!

Guess you like

Origin blog.csdn.net/ggbb_4/article/details/127184096