New Tensorflow 2.4 GPU issues - python

Question
Tensorflow 2.4.1 doesn't recognize my GPU, even though I followed the official instructions from Tensorflow as well as the ones from NVIDIA for CUDA and NVIDIA for cuDNN to install it in my computer. I also installed it in conda (which I'm not sure if it is needed?).
When I try the official way to check if TF is using GPUs, I get 0:
import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.list_physical_devices('GPU')))
Num GPUs Available: 0
Specifications
Hardware:
My NVIDIA fulfills the requirements specified by Tensorflow.
Software
I installed CUDA (with CUPTI) and cuDNN as mentioned above, so I got:
ubuntu 20.04 LTS
NVIDIA driver = 460.39
CUDA (+CUPTI) = 11.2
cuDNN = 8.1.1
In a conda environment I have:
python = 3.8
tensorflow = 2.4.1 (which I understand is the new way of having the GPU support)
and I installed extra the cudatoolkit==11.0 and cudnn==8.0 for conda as mentioned here.
Procedure followed:
It did not work when I didn't have the conda extra packages, and it still doesn't work even though I installed those extra packages.

After quite a bit of extensive research, it finally works on my computer: the latest versions of the components (i.e. CUDA 11.2, cuDNN 8.1.0) are not tested and not ensure a working result in TF 2.4.1. Therefore, this is my final configuration:
nvidia-drivers-460.39 have CUDA 11.2 drivers. However, you can still install CUDA 11.0 runtime and get it from the official NVIDIA archive for CUDA. Following the installing instructions is still mandatory (i.e. adding the path variables and so on).
cuDNN library needs to be on the version 8.0.4. You can get it also from the official NVIDIA archive for cuDNN
After installing both components on these specific versions, I successfully get:
import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.list_physical_devices('GPU')))
Num GPUs Available: 1
with a few debut messages indicating that the GPU libraries were correctly imported.
EDIT:
By the way! For the folks out there who use Pycharm, either you include the environment variables also in PyCharm, or make them system-wide. Otherwise you won't still get your TF to get the GPUs.

Related

Tensorflow crashes when ask it to fit model

Tensorflow on gpu new to me, first naive question is, am I correct in assuming that I can use a gpu (nv gtx 1660ti) to run tensorflow ml operations, while it simultaneously runs my monitor? Only have one gpu card in my pc, assume it can do both at the same time or do I require a dedicated gpu for tensorflow only, that is not connected to any monitor?
All on ubuntu 21.10, have set up nvidia-toolkit, cudnn, tensorflow, tensorflow-gpu in a conda env, all appears to work fine: 1 gpu visible, built with cudnn 11.6.r11.6, tf version 2.8.0, python version 3.7.10 all in conda env running on a jupyter notebook. All seems to run fine until I attempt to train a model and then I get this error message:
2022-03-19 04:42:48.005029: I tensorflow/stream_executor/cuda/cuda_dnn.cc:368] Loaded cuDNN version 8302
and then the kernel just locks up and crashes. BTW the code worked prior to installing gpu, when it simply used cpu. Is this simply a version mismatch somewhere between python, tensorflow, tensorflow-gpu, cudnn versions or something more sinister? Thx. J.
am I correct in assuming that I can use a GPU (nv gtx 1660ti) to run
tensorflow ml operations, while it simultaneously runs my monitor?
Yes, you can check with nvidia-smi on ubuntu to see how much free memory you have or which processes are using GPU.
Only have one GPU card in my pc, assume it can do both at the same?
time
Yes, It can. Most people do the same, a training process on GPU is just similar to running a game, (but more memory hungry)
About the problem:
install based on this version table.
check your driver version with nvidia-smi But, for true Cuda version check this nvcc -V ( the Cuda version in nvidia-smi is actually max supported Cuda version. )
just install pip install tensorflow-gpu this will also install keras for you.
check if tensorflow has access to GPU as follow:
import tensorflow as tf
tf.test.is_gpu_available() #should return True
print("Num GPUs Available: ", len(tf.config.list_physical_devices('GPU')))
install based on this version table.
That was the key for me. Had the same issue , CPU worked fine, GPU would dump out during model fit with an exit code but no error. The matrix will show you that tensorflow 2.5 - 2.8 work with CUDA 11.2 and cudnn 8.1 , the 'latest' versions are 11.5 and 8.4 as of 05/2022. I rolled back both versions and everything is working fine.
The matrix will show you that tensorflow 2.5 - 2.8 work with CUDA 11.2 and cudnn 8.1
I believe the problem is that CUDA 11.2 is not available for Windows 11.

How to use tensorflow v2 with directml backend

I have a computer with the windows operating system with an amd gpu (rx 5600 xt), and I want to run tensorflow on the gpu.
I found "tensorflow-directml" which allows me to run tensorflow on my gpu, but it uses tensorflow 1.14.0.
Is there another version of "tensorflow-directml" that uses tensorflow v2, or is there another way to run tensorflow in my gpu?
Thanks, and sorry if I wrote something wrong or inaccurate
Microsoft has announced DirectML-plugin for tensorflow 2 in June this year. Check it out at this link: https://learn.microsoft.com/en-us/windows/ai/directml/gpu-tensorflow-plugin. However I believe for your particular GPU model DirectML-plugin may not be compatible as of yet.
Is there another version of "tensorflow-directml" that uses tensorflow
v2
No, According to pypi, latest release (i.e. on Sep 12, 2020) tensorflow-directml 1.15.3.dev200911 is available for public. For more details please refer this.
To run Tensorflow in GPU on windows
For TensorFlow 1.x (i.e. for releases 1.15 and older, CPU and GPU packages are separate)
pip install tensorflow-gpu==1.15 # GPU
For Tensorflow 2.x (i.e. V2) onwards, pip package includes GPU support for CUDA enabled cards
pip install tensorflow
For more information please refer this.

tensorflow gpu tests pass--but I don't have cuDNN installed

Windows10-pro, single RTX 2080 Ti. I am new to Tensorflow.
I just installed tensorflow-gpu, version 2.1.0, python 3.7.7. Cuda compilation tools, release 10.1, V10.1.105. Nothing self-compiled. And I have not installed cuDNN, nor have I registered. All installation is standard, nothing self-compiled.
The tensorflow.org documentation states that cuDNN is needed to use the GPU. But my tests for GPU-usage seem to pass. For example,
tf.config.experimental.list_physical_devices('GPU') returns [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')].
It may appear that I should just install cuDNN and not lose any more sleep. But I would still want to know if I were using the GPU so I would prefer a test that is capable of failing.
Is there a true test to see if an installation will use the GPU?
In NVIDIA GPU computing toolkit, one can verify the cuDNN installation,
On windows system,
Go to
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include\
open cudnn.h
To utilize the Tensorflow-GPU successfully, CUDA and cuDNN are required.
Some of the Tensorflow library such as tf.keras.layers.GRU(Keras GRU layers) employs the capability of cuDNN.
Check these examples provided in Tensorflow site for GPU utilization.

Tensorflow shows only "successfully opened CUDA library libcublas.so.10.0 locally" and nothing about cudnn

My tensorflow only prints out the line:
I tensorflow/stream_executor/dso_loader.cc:152] successfully opened CUDA library libcublas.so.10.0 locally when running.
Tensorflow logs on the net has lots of other libraries being loaded like libcudnn.
As I think my installation performance is not optimal, I am trying to find out if it is because of this. Any help will be appreciated!
my tf is 1.13.1
NVIDIA Driver Version: 418.67
CUDA Version: 10.1 (I have also 10.0 installed. can this be the problem?)
According to TensorFlow documentation, cuDNN is a requirement for tensorflow-gpu. If you don't have cuDNN installed, you wouldn't be able to install tensorflow-gpu since the dependency library would be missing.
So, if you have successfully installed tensorflow-gpu and are able to use it, e.g.
import tensorflow as tf
tf.Session()
you are fine.
EDIT
I just checker here and tensorflow_gpu-1.13.1 officially only supports CUDA 10.0. I would recommend to use it instead of CUDA 10.1.
Further, NVIDIA recommends using driver version 410.48 with CUDA 10.0. I would stick with it as well.
Actually i always rely on a stable setup. And i tried most of the tf - cuda - cudnn versions. But most stable was tf 1.9.0 , CUDA 9.0, Cudnn 7 for me. Used it for too long without a problem. You should give it a try if it suits you.

How to use Tensorflow GPU with CUDA 10 on RTX 2070?

in a few days I will setup my new computer with a RTX 2070.
I would like to user tensorflow GPU but I can't find compatible versions of CUDA and Tensorflow GPU.
As far as I know, I need CUDA 10 to benefit from the additional computing power of the RTX's Turing architecture. But regarding to the Tensorflow website the newest version of tf (tensorflow_gpu-1.12.0) only works with CUDA 9.
I would prefer to get it all working on windows 10 but if there is no other way, linux would work as well.
Somewhere on the internet I read about two rumors:
1. there is some way to compile an unpublished version of tf-gpu which works with CUDA 10
2. they will publish an official version of tf-gpu in january 2019 (which is almost over now) which will support CUDA 10.
Can someone confirm one of those rumors (with source would be the best) or tell me how I will be able to get it all working?
You're correct that you need cuda 10 and that tensorflow-gpu currently doesn't support it. What you need to do is compile tensorflow from source like your first rumor.
Installation steps:
Install CUDA 10 and cuDNN 7.3.1
Configure Tensorflow and compile it
Install the .whl package with pip
Here are some tutorials to compile tensorflow.
Windows:
https://www.pytorials.com/how-to-install-tensorflow-gpu-with-cuda-10-0-for-python-on-windows/2/
Ubuntu:
https://medium.com/#saitejadommeti/building-tensorflow-gpu-from-source-for-rtx-2080-96fed102fcca
https://towardsdatascience.com/how-to-make-tensorflow-work-on-rtx-20xx-series-73eb409bd3c0
Alternatively
you can find the pre-built tensorflow wheels here, thus skipping step 2:
https://github.com/fo40225/tensorflow-windows-wheel

Categories

Resources