3

My computer has the following software installed: Anaconda (3), TensorFlow (GPU), and Keras. There are two Anaconda virtual environments - one with TensorFlow for Python 2.7 and one for 3.5, both GPU version, installed according to the TF instructions. (I had a CPU version of TensorFlow installed previously in a separate environment, but I've deleted it.)

When I run the following:

source activate tensorflow-gpu-3.5
python code.py

and check nvidia-smi it shows only 3MiB GPU Memory Usage by Python, so it looks like GPU is not used for calculations. (code.py is a simple deep Q-learning algorithm implemented with Keras)

Any ideas what can be going wrong?

Juan Leni
  • 6,982
  • 5
  • 55
  • 87
Massyanya
  • 2,844
  • 8
  • 28
  • 37

4 Answers4

4

A good way to debug these problems is to check which operations have been allocated to which devices.

You can check this by passing a configuration parameter to the session:

session = tf.Session(config=tf.ConfigProto(log_device_placement=True))

When you run your app, you will see some output indicating which devices are being used.

You can find more information here: https://www.tensorflow.org/tutorials/using_gpu

Juan Leni
  • 6,982
  • 5
  • 55
  • 87
4

TensorFlow on Windows

It took me hours to fix TensorFlow installation issues on windows, so here is summary:

To Check if TensorFlow-gpu is working or not (use this code):

with tf.device('/gpu:0'):
    a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
    b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
    c = tf.matmul(a, b)
with tf.Session() as sess:
    print(sess.run(c))

To Check list of available CPUs or GPUs (use this code):

from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())

if tf.test.gpu_device_name():
    print('Default GPU Device: {}'.format(tf.test.gpu_device_name()))
else:
    print("Please install GPU version of TF")

Install Tensorflow GPU on Windows using CUDA and cuDNN

Guide Overview

  • Install Nvidia's card on your computer along with drivers
  • Download & Install CUDA
  • Download & "Install" cuDNN
  • Uninstall Tensorflow, Install Tensorflow GPU
  • Update the %PATH% on the system
  • Verify installation

Guide Complete details

Make Sure

  • You have uninstalled tensorflow and you have installed just tensorflow-gpu in order to get things done.
  • Uninstall tensorflow from pip and conda environement depending upon your project settings and install just tensorflow-gpu
  • After settings PATH variable make sure to logout or reboot your system.

Hope thats helpful :))

Aqib Mumtaz
  • 4,936
  • 1
  • 36
  • 33
3

The reason my GPU wasn't running was because of a broken installation of the CuDNN, more precisely libraries and source came from different versions of CuDNN.

It was fixed with the following piece of advice.

Massyanya
  • 2,844
  • 8
  • 28
  • 37
0

This is a slippery problem and it's almost as if the computer will use any possible excuse to revert back to CPU. To ensure tensoflow, keras and pytorch are currently being used, see https://stackoverflow.com/a/53244520/420400

Paul Williams
  • 3,099
  • 38
  • 34