2017-09-08 2 views
1

| Processus: Mémoire GPU | | GPU PID Type Nom du processus Utilisation
| 0 6944 C python3 11585MiB | | 1 6944 C python3 11587MiB | | 2 6944 C python3 10621MiB |Problèmes de gestion de mémoire GPU lors de l'utilisation de TensorFlow

La mémoire nvidia-smi n'est pas libérée après l'arrêt du tensorflow au milieu.

Essayé d'utiliser ce

config = tf.ConfigProto() 
config.gpu_options.allocator_type = 'BFC' 
config.gpu_options.per_process_gpu_memory_fraction = 0.90 
config.gpu_options.allow_growth = True 
sess = tf.Session(config=config) 

également

with tf.device('/gpu:0'): 
with tf.Graph().as_default(): 

après la réinitialisation du GPU sudo nvidia-smi --gpu-reset -i 0

La mémoire ne peut pas être libéré du tout.

Répondre

1

La solution a été obtenue à partir de Tensorflow set CUDA_VISIBLE_DEVICES within jupyter grâce à Yaroslav.

La plupart des informations ont été obtenues à partir de la documentation de Tensorflow Stackoverflow. Je ne suis pas autorisé à ne pas le poster pas sûr pourquoi.

Insérez ceci au début de votre code.

from tensorflow.python.client import device_lib 

# Set the environment variables 
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" 
os.environ["CUDA_VISIBLE_DEVICES"] = "0" 

# Double check that you have the correct devices visible to TF 
print("{0}\nThe available CPU/GPU devices on your system\n{0}".format('=' * 100)) 
print(device_lib.list_local_devices()) 

Different options to start with GPU or CPU. I am using the CPU. Can be changed from the below options 
with tf.device('/cpu:0'): 
# with tf.device('/gpu:0'): 
# with tf.Graph().as_default(): 

Utilisez les lignes suivantes dans la session:

config = tf.ConfigProto(device_count={'GPU': 1}, log_device_placement=False, 
         allow_soft_placement=True) 
# allocate only as much GPU memory based on runtime allocations 
config.gpu_options.allow_growth = True 
sess = tf.Session(config=config) 
# Session needs to be closed 
sess.close() 

La ligne ci-dessous résoudre le problème des ressources verrouillé par python

with tf.Session(config=config) as sess: 

Un autre article utile de comprendre l'importance de 'with' Veuillez vérifier le tf.Session() officiel de tensorflow.

explication des paramètres

To find out which devices your operations and tensors are assigned to, create the session with 
    log_device_placement configuration option set to True. 

    TensorFlow to automatically choose an existing and supported device to run the operations in case the specified 
    one doesn't exist, you can set allow_soft_placement=True in the configuration option when creating the session.