@@ -354,15 +354,15 @@ import tensorflow as tf
354
354
# For TensorFlow 2.x
355
355
gpus = tf.config.list_physical_devices(' GPU' )
356
356
if gpus:
357
- try :
358
- # Currently, memory growth needs to be the same across GPUs
359
- for gpu in gpus:
360
- tf.config.experimental.set_memory_growth(gpu, True )
361
- logical_gpus = tf.config.list_logical_devices(' GPU' )
362
- print (len (gpus), " Physical GPUs," , len (logical_gpus), " Logical GPUs" )
363
- except RuntimeError as e:
364
- # Memory growth must be set before GPUs have been initialized
365
- print (e)
357
+ try :
358
+ # Currently, memory growth needs to be the same across GPUs
359
+ for gpu in gpus:
360
+ tf.config.experimental.set_memory_growth(gpu, True )
361
+ logical_gpus = tf.config.list_logical_devices(' GPU' )
362
+ print (len (gpus), " Physical GPUs," , len (logical_gpus), " Logical GPUs" )
363
+ except RuntimeError as e:
364
+ # Memory growth must be set before GPUs have been initialized
365
+ print (e)
366
366
```
367
367
368
368
##### <a name =" reserve-fraction " />2. Reserve fixed fraction
@@ -377,16 +377,16 @@ import tensorflow as tf
377
377
# For TensorFlow 2.x
378
378
gpus = tf.config.list_physical_devices(' GPU' )
379
379
if gpus:
380
- # Restrict TensorFlow to only allocate 1GB of memory on the first GPU
381
- try :
382
- tf.config.set_logical_device_configuration(
383
- gpus[0 ],
384
- [tf.config.LogicalDeviceConfiguration(memory_limit = 1024 )])
385
- logical_gpus = tf.config.list_logical_devices(' GPU' )
386
- print (len (gpus), " Physical GPUs," , len (logical_gpus), " Logical GPUs" )
387
- except RuntimeError as e:
388
- # Virtual devices must be set before GPUs have been initialized
389
- print (e)
380
+ # Restrict TensorFlow to only allocate 1GB of memory on the first GPU
381
+ try :
382
+ tf.config.set_logical_device_configuration(
383
+ gpus[0 ],
384
+ [tf.config.LogicalDeviceConfiguration(memory_limit = 1024 )])
385
+ logical_gpus = tf.config.list_logical_devices(' GPU' )
386
+ print (len (gpus), " Physical GPUs," , len (logical_gpus), " Logical GPUs" )
387
+ except RuntimeError as e:
388
+ # Virtual devices must be set before GPUs have been initialized
389
+ print (e)
390
390
```
391
391
The ` per_process_gpu_memory_fraction ` acts as a hard upper bound on the amount of GPU memory
392
392
that will be used by the process on each GPU on the same machine.
0 commit comments