How to fix torch.cuda.is_available() false?
Before installation, You need to check the graphic card you have. Mine is NVIDIA Geforce RTX 3070. The value of true was returned when I set the environment like below.
- Graphic Driver 470.199.02
- CUDA 11.4
- PyTorch 1.12.1
1. Check Compatible Version for Specific Graphic Card
1.1 CUDA version
For RTX 3070, The compatible CUDA version is 11.4.
1.2 Graphic Driver version
Check compatible graphic driver version
1.3 PyTorch version
Check compatible PyTorch version
2. Install Compatible Version
2.1 Install NVIDIA Driver
$ sudo apt install nvidia-driver-470
2.2 Install CUDA
Ref) CUDA Toolkit 11.4 Update 1 Downloads
$ wget https://developer.download.nvidia.com/compute/cuda/11.4.0/local_installers/cuda_11.4.0_470.42.01_linux.run
$ sudo sh cuda_11.4.0_470.42.01_linux.run
2.3 Install cuDNN
$ tar -xvf cudnn-linux-x86_64-8.9.3.28_cuda11-archive.tar.xz
$ sudo cp cudnn-*-archive/include/cudnn*.h /usr/local/cuda/include $ sudo cp -P cudnn-*-archive/lib/libcudnn* /usr/local/cuda/lib64 $ sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*
2.4 activate conda (optional)
$ conda create -n <env_name> python=3.8
$ conda activate <env_name>
2.4.1 Install PyTorch (for 11.3)
There was no torch for 11.4, therefore I installed torch for 11.3 instead.
$conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 -c pytorch
Finally, I could get returned value from ‘torch.cuda.is_available()’.