I am using rtx2070s and Windows 11 I've tried so many things to use tensorflow2(keras) and pytorch in one virtual environment, but I failed. I tried to find CUDA and cuDNN compatible versions, but most of them failed. Even though I succeeded, if I proceed with the fit on the TF, the kernel dies.
Is there any tip or solution to this?
install / CUDA = 10.1, 10.2, 11.6 ... / cuDNN = compatible with CUDA ... tf 2.1~2.11 ..
CodePudding user response:
To make it straightforward I am not going to dive into non official wheels or compiling the libraries to make them use the same CUDA/CUDNN version.
So let's assume you want to install Tensorflow 2.10.1 and PyTorch 1.13.0 in the same virtual environment.
PyTorch requires either CUDA 11.6 or 11.7, we will be installing 11.6. Tensorflow 2.10 still uses CUDA 11.2 so we are going to install that one.
- Download and install 11.2 and CUDNN 8.6.0 for CUDA 11.X.
- Make sure the CUDA_PATH, CUDA_PATH_V11_2 are set correctly and that both bin and libnvvp are also set within path. I guess the most common path would be:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\libnvvp
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\bin
- Same process for CUDA 11.6 and 8.6.0 CUDNN for 11.X. Including setting the paths for libnvpp and bin.
- Now both versions should be visible and usable within Windows. The CUDA_PATH is going to be pointing to version 11.6 but that is fine.
- Next step is to install Tensorflow and PyTorch, so use
pip install tensorflow-gpu
for Tensorflow andpip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116
for PyTorch. - Last step should be checking if both libraries can see the GPU and were compiled to use CUDA. So let's call the Python interpreter of your virtual environment and inside it type:
For Tensorflow,
import tensorflow as tf
tf.test.is_built_with_cuda()
tf.config.list_physical_devices('GPU')
For PyTorch,
import torch
torch.cuda.is_available()
torch.cuda.get_device_name()
Hope this helps!