Preface
tensorflow的默认调度策略是吃满显存,如果我们模型较小、显存较大、占用率不足40%(自己估计的)时,是可以利用GPU同时训练两个模型的。
tensorflow 1
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
sess = tf.Session(config=config)
tensorflow 2
gpus = tf.config.list_physical_devices(device_type='GPU')
for gpu in gpus:
tf.config.experimental.set_memory_growth(gpu, True)