Restrict TensorFlow GPU Memory Usage for RAPIDS
Using TensorFlow version 2.4.1 We will restrict TensorFlow to max 8GB GPU RAM then RAPIDS can use 8GB GPU RAM
import os
os.environ['CUDA_VISIBLE_DEVICES']='0'
import tensorflow as tf
import tensorflow.keras.backend as K
print('Using TensorFlow version',tf.__version__)
# RESTRICT TENSORFLOW TO 8GB OF GPU RAM
# SO THAT WE HAVE 8GB RAM FOR RAPIDS
LIMIT = 8
gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
try:
tf.config.experimental.set_virtual_device_configuration(
gpus[0],
[tf.config.experimental.VirtualDeviceConfiguration(memory_limit=1024*LIMIT)])
logical_gpus = tf.config.experimental.list_logical_devices('GPU')
except RuntimeError as e:
print(e)
print('We will restrict TensorFlow to max %iGB GPU RAM'%LIMIT)
print('then RAPIDS can use %iGB GPU RAM'%(16-LIMIT))
原文地址: http://www.cveoy.top/t/topic/oFS8 著作权归作者所有。请勿转载和采集!