Prevent TensorFlow from accessing the GPU?

Is there a way to run TensorFlow exclusively on CPU. All memory on my machine is started by a separate TensorFlow process. I tried setting per_process_memory_fraction to 0, unsuccessful.

+3


source to share


2 answers


Look at this question or this one.

To summarize, you can add this piece of code:

import os
os.environ["CUDA_VISIBLE_DEVICES"]="-1"    
import tensorflow as tf

      



EDIT: Quoting this comment , playing with an environment variable CUDA_VISIBLE_DEVICES

is one (if not) way to go when you have a GPU tensorflow and don't want to use your graphics card at all.

You want to either export CUDA_VISIBLE_DEVICES = or alternatively virtualenv with non-GPU TensorFlow. See also: # 2175 (comment)

+8


source


You can only use processors by opening a session with a GPU limit of 0:

sess = tf.Session(config=tf.ConfigProto(device_count={'GPU': 0}))

      

See https://www.tensorflow.org/api_docs/python/tf/ConfigProto for details .

Proof that it works for @Nicolas:

In Python, write:

import tensorflow as tf
sess_cpu = tf.Session(config=tf.ConfigProto(device_count={'GPU': 0}))

      

Then in the terminal:

nvidia-smi

      



You will see something like:

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID  Type  Process name                               Usage      |
|=============================================================================|
|    0     24869    C   /.../python                 99MiB                     |
+-----------------------------------------------------------------------------+

      

Then repeat the process: In Python, write:

import tensorflow as tf
sess_gpu = tf.Session()

      

Then in the terminal:

nvidia-smi

      



You will see something like:

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID  Type  Process name                               Usage      |
|=============================================================================|
|    0     25900    C   /.../python                                   5775MiB |
+-----------------------------------------------------------------------------+

      

0


source







All Articles