How to prevent tensorflow from allocating the totality of a GPU memory?

前端 未结 16 2227
南旧
南旧 2020-11-22 04:26

I work in an environment in which computational resources are shared, i.e., we have a few server machines equipped with a few Nvidia Titan X GPUs each.

For small to m

16条回答
  •  误落风尘
    2020-11-22 04:52

    For Tensorflow version 2.0 and 2.1 use the following snippet:

     import tensorflow as tf
     gpu_devices = tf.config.experimental.list_physical_devices('GPU')
     tf.config.experimental.set_memory_growth(gpu_devices[0], True)
    

    For prior versions , following snippet used to work for me:

    import tensorflow as tf
    tf_config=tf.ConfigProto()
    tf_config.gpu_options.allow_growth=True
    sess = tf.Session(config=tf_config)
    

提交回复
热议问题