MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / set_visible_devices

Function set_visible_devices

tensorflow/python/framework/config.py:447–473  ·  view source on GitHub ↗

Set the list of visible devices. Sets the list of PhysicalDevices to be marked as visible to the runtime. Any devices that are not marked as visible means TensorFlow will not allocate memory on it and will not be able to place any operations on it as no LogicalDevice will be created on it.

(devices, device_type=None)

Source from the content-addressed store, hash-verified

445
446@tf_export('config.experimental.set_visible_devices')
447def set_visible_devices(devices, device_type=None):
448 """Set the list of visible devices.
449
450 Sets the list of PhysicalDevices to be marked as visible to the runtime. Any
451 devices that are not marked as visible means TensorFlow will not allocate
452 memory on it and will not be able to place any operations on it as no
453 LogicalDevice will be created on it. By default all discovered devices are
454 marked as visible.
455
456 The following example demonstrates disabling the first GPU on the machine.
457
458 ```python
459 physical_devices = config.experimental.list_physical_devices('GPU')
460 assert len(physical_devices) > 0, "Not enough GPU hardware devices available"
461 # Disable first GPU
462 tf.config.experimental.set_visible_devices(physical_devices[1:], 'GPU')
463 logical_devices = config.experimental.list_logical_devices('GPU')
464 # Logical device was not created for first GPU
465 assert len(logical_devices) == len(physical_devices) - 1
466 ```
467
468 Args:
469 devices: (optional) List of PhysicalDevice objects to make visible
470 device_type: (optional) Device types to limit visibility configuration to.
471 Other device types will be left unaltered.
472 """
473 context.context().set_visible_devices(devices, device_type)
474
475
476@tf_export('config.experimental.get_memory_growth')

Callers 1

initMethod · 0.85

Calls 2

set_visible_devicesMethod · 0.45
contextMethod · 0.45

Tested by

no test coverage detected