Skip to content

Instantly share code, notes, and snippets.

@innat
Created June 21, 2022 08:01
Show Gist options
  • Save innat/b38ca9af2b3df7edb56fd196e89ac348 to your computer and use it in GitHub Desktop.
Save innat/b38ca9af2b3df7edb56fd196e89ac348 to your computer and use it in GitHub Desktop.
# RESTRICT TENSORFLOW TO 2GB OF GPU RAM
# SO THAT WE HAVE 14GB RAM free
LIMIT = 2.0
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')
#print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs")
except RuntimeError as e:
print(e)
print('We will restrict TensorFlow to max %iGB GPU RAM'%LIMIT)
print('RAM Free %iGB GPU RAM'%(16-LIMIT))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment