tf.config.experimental.set_visible_devices
Stay organized with collections
Save and categorize content based on your preferences.
Set the list of visible devices.
tf.config.experimental.set_visible_devices(
devices, device_type=None
)
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. By default all discovered devices are
marked as visible.
The following example demonstrates disabling the first GPU on the machine.
physical_devices = config.experimental.list_physical_devices('GPU')
assert len(physical_devices) > 0, "Not enough GPU hardware devices available"
# Disable first GPU
tf.config.experimental.set_visible_devices(physical_devices[1:], 'GPU')
logical_devices = config.experimental.list_logical_devices('GPU')
# Logical device was not created for first GPU
assert len(logical_devices) == len(physical_devices) - 1
Args |
devices
|
(optional) List of PhysicalDevice objects to make visible
|
device_type
|
(optional) Device types to limit visibility configuration to.
Other device types will be left unaltered.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.config.experimental.set_visible_devices\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/framework/config.py#L379-L406) |\n\nSet the list of visible devices.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.config.experimental.set_visible_devices`](/api_docs/python/tf/config/set_visible_devices), \\`tf.compat.v2.config.experimental.set_visible_devices\\`\n\n\u003cbr /\u003e\n\n tf.config.experimental.set_visible_devices(\n devices, device_type=None\n )\n\nSets the list of PhysicalDevices to be marked as visible to the runtime. Any\ndevices that are not marked as visible means TensorFlow will not allocate\nmemory on it and will not be able to place any operations on it as no\nLogicalDevice will be created on it. By default all discovered devices are\nmarked as visible.\n\nThe following example demonstrates disabling the first GPU on the machine. \n\n physical_devices = config.experimental.list_physical_devices('GPU')\n assert len(physical_devices) \u003e 0, \"Not enough GPU hardware devices available\"\n # Disable first GPU\n tf.config.experimental.set_visible_devices(physical_devices[1:], 'GPU')\n logical_devices = config.experimental.list_logical_devices('GPU')\n # Logical device was not created for first GPU\n assert len(logical_devices) == len(physical_devices) - 1\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------------|----------------------------------------------------------------------------------------------------------|\n| `devices` | (optional) List of PhysicalDevice objects to make visible |\n| `device_type` | (optional) Device types to limit visibility configuration to. Other device types will be left unaltered. |\n\n\u003cbr /\u003e"]]