Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share GPU memory for different users in keras and tensorflow

We had only one GPU installed with CUDA drivers and whenever one user runs the code, the whole memory is assigned to that user. And the other users are unable to use the GPU. Is there a way to get rid of this behavior?

like image 714
Rajesh Avatar asked Mar 08 '23 04:03

Rajesh


1 Answers

If you are using keras, add this at the beginning of your script:

from keras import backend as K

config = tf.ConfigProto()
config.gpu_options.allow_growth=True
sess = tf.Session(config=config)
K.set_session(sess)

This will prevent tensorflow to take all the memory as can be seen here.

If you are using tensorflow without keras, add this:

config = tf.ConfigProto()
config.gpu_options.allow_growth = True
session = tf.Session(config=config, ...)

As shown here.

like image 54
vinzee Avatar answered Apr 28 '23 11:04

vinzee