# tf.config.set_visible_devices

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/config.py#L516-L549) |

Set the list of visible devices.

#### View aliases


**Main aliases**

[`tf.config.experimental.set_visible_devices`](https://www.tensorflow.org/api_docs/python/tf/config/set_visible_devices)
**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.config.experimental.set_visible_devices`](https://www.tensorflow.org/api_docs/python/tf/config/set_visible_devices), [`tf.compat.v1.config.set_visible_devices`](https://www.tensorflow.org/api_docs/python/tf/config/set_visible_devices)

<br />

    tf.config.set_visible_devices(
        devices, device_type=None
    )

Specifies which `PhysicalDevice` objects are visible to the runtime.
TensorFlow will only allocate memory and place operations on visible
physical devices, as otherwise no `LogicalDevice` will be created on them.
By default all discovered devices are marked as visible.

The following example demonstrates disabling the first GPU on the machine.

    physical_devices = tf.config.list_physical_devices('GPU')
    try:
      # Disable first GPU
      tf.config.set_visible_devices(physical_devices[1:], 'GPU')
      logical_devices = tf.config.list_logical_devices('GPU')
      # Logical device was not created for first GPU
      assert len(logical_devices) == len(physical_devices) - 1
    except:
      # Invalid device or cannot modify virtual devices once initialized.
      pass

<br />

<br />

<br />

| ## Args ||
|---|---|
| `devices` | List of `PhysicalDevice`s to make visible |
| `device_type` | (optional) Only configure devices matching this device type. For example "CPU" or "GPU". Other devices will be left unaltered. |

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If argument validation fails. |
| `RuntimeError` | Runtime is already initialized. |

<br />