Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Tensorflow not recognizing my GPU after conda install?

I am new to deep learning and I have been trying to install tensorflow-gpu version in my pc in vain for the last 2 days. I avoided installing CUDA and cuDNN drivers since several forums online don't recommend it due to numerous compatibility issues. Since I was already using the conda distribution of python before, I went for the conda install -c anaconda tensorflow-gpu as written in their official website here: https://anaconda.org/anaconda/tensorflow-gpu .

However even after installing the gpu version in a fresh virtual environment (to avoid potential conflicts with pip installed libraries in the base env), tensorflow doesn't seem to even recognize my GPU for some mysterious reason.

Some of the code snippets I ran(in anaconda prompt) to understand that it wasn't recognizing my GPU:-

1.

>>>from tensorflow.python.client import device_lib
        >>>print(device_lib.list_local_devices())
                    [name: "/device:CPU:0"
                device_type: "CPU"
                memory_limit: 268435456
                locality {
                }
                incarnation: 7692219132769779763
                ]

As you can see it completely ignores the GPU.

2.

>>>tf.debugging.set_log_device_placement(True)
    >>>a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
2020-12-13 10:11:30.902956: I tensorflow/core/platform/cpu_feature_guard.cc:142] This 
TensorFlow 
binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU 
instructions in performance-critical operations:  AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
>>>b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
>>>c = tf.matmul(a, b)
>>>print(c)
tf.Tensor(
[[22. 28.]
[49. 64.]], shape=(2, 2), dtype=float32)

Here, it was supposed to indicate that it ran with a GPU by showing Executing op MatMul in device /job:localhost/replica:0/task:0/device:GPU:0 (as written here: https://www.tensorflow.org/guide/gpu) but nothing like that is present. Also I am not sure what the message after the 2nd line means.

I have also searched for several solutions online including here but almost all of the issues are related to the first manual installation method which I haven't tried yet since everyone recommended this approach.

I don't use cmd anymore since the environment variables somehow got messed up after uninstalling tensorflow-cpu from the base env and on re-installing, it worked perfectly with anaconda prompt but not cmd. This is a separate issue (and widespread also) but I mentioned it in case that has a role to play here. I installed the gpu version in a fresh virtual environment to ensure a clean installation and as far as I understand path variables need to be set up only for manual installation of CUDA and cuDNN libraries.

The card which I use:-(which is CUDA enabled)

C:\WINDOWS\system32>wmic path win32_VideoController get name
Name
NVIDIA GeForce 940MX
Intel(R) HD Graphics 620

Tensorflow and python version I am using currently:-

>>> import tensorflow as tf
>>> tf.__version__
'2.3.0'

Python 3.8.5 (default, Sep  3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.

System information: Windows 10 Home, 64-bit operating system, x64-based processor.

Any help would be really appreciated. Thanks in advance.

like image 442
Sarosij Bose Avatar asked Dec 13 '20 06:12

Sarosij Bose


People also ask

Why is TensorFlow not detecting my GPU?

This is most likely because the CUDA and CuDNN drivers are not being correctly detected in your system. In both cases, Tensorflow is not detecting your Nvidia GPU. This can be for a variety of reasons: Nvidia Driver not installed.


Video Answer


4 Answers

August 2021 Conda install may be working now, as according to @ComputerScientist in the comments below, conda install tensorflow-gpu==2.4.1 will give cudatoolkit-10.1.243 and cudnn-7.6.5

The following was written in Jan 2021 and is out of date

Currently conda install tensorflow-gpu installs tensorflow v2.3.0 and does NOT install the conda cudnn or cudatoolkit packages. Installing them manually (e.g. with conda install cudatoolkit=10.1) does not seem to fix the problem either.

A solution is to install an earlier version of tensorflow, which does install cudnn and cudatoolkit, then upgrade with pip

conda install tensorflow-gpu=2.1
pip install tensorflow-gpu==2.3.1

(2.4.0 uses cuda 11.0 and cudnn 8.0, however cudnn 8.0 is not in anaconda as of 16/12/2020)

Edit: please also see @GZ0's answer, which links to a github discussion with a one-line solution

like image 101
geometrikal Avatar answered Oct 14 '22 03:10

geometrikal


The tensorflow build automatically selected by Anaconda on Windows 10 during the installation of tensorflow-gpu 2.3 seems to be faulty. Please find a workaround here (consider upvoting the GitHub answer if you have a GitHub account).

Windows only: Python 3.7: conda install tensorflow-gpu=2.3 tensorflow=2.3=mkl_py37h936c3e2_0

Python 3.8: conda install tensorflow-gpu=2.3 tensorflow=2.3=mkl_py38h1fcfbd6_0

like image 29
GZ0 Avatar answered Oct 14 '22 03:10

GZ0


@geometrikal solution almost worked for me. But in between installing tensorflow-gpu with conda and installing tensorflow 2.3 with pip, I needed to uninstall the tensorflow parts of the package tensorflow-gpu to avoid conistency warnings by pip. Conda would have uninstalled the whole package. I know Conda does not recommend mixing pip with conda but this is the solution worked that worked and I am tired of spending another day with this issue.

conda create -n tfgpu python=3.7
conda activate tfgpu
conda install tensorflow-gpu=2.1

pip uninstall tensorflow
pip uninstall tensorflow-estimator
pip uninstall tensorboard 
pip uninstall tensorboard-plugin-wit
pip install tensorflow==2.3
pip check
like image 44
tobi.tobt Avatar answered Oct 14 '22 01:10

tobi.tobt


I also have been unable (yet) to get TF 2.3.0 to recognize my Nvidia Quadro Pro 620 GPU.

Note: I have 2 other 'environments' on this PC (windows Pro) All installed via Anaconda:

  1. Python 3.7.8 TF 2.0.0... recognizes (and uses) the Nvidia GPU
  2. Python 3.6.9 TF 2.1.0... recognizes (and uses) the Nvidia GPU
  3. Python 3.8.6 TF 2.3.0... does NOT see the GPU

My Machine has Cuda 11.1; cuDNN 8.0.5

My next thought is to consider downgrading Python from 3.8.6 to 3.7.8 in the 3rd configuration where TF = 2.3.0

Steve

like image 25
steve Schneider Avatar answered Oct 14 '22 02:10

steve Schneider