<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.21.0/tensorflow/python/training/server_lib.py#L495-L574) |

Represent a collection of device filters for the remote workers in cluster.

#### View aliases


**Compat aliases for migration**

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

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

<br />

    tf.config.experimental.ClusterDeviceFilters()

> [!NOTE]
> **Note:** this is an experimental API and subject to changes.

Set device filters for selective jobs and tasks. For each remote worker, the
device filters are a list of strings. When any filters are present, the remote
worker will ignore all devices which do not match any of its filters. Each
filter can be partially specified, e.g. "/job:ps", "/job:worker/replica:3",
etc. Note that a device is always visible to the worker it is located on.

For example, to set the device filters for a parameter server cluster:

    cdf = tf.config.experimental.ClusterDeviceFilters()
    for i in range(num_workers):
      cdf.set_device_filters('worker', i, ['/job:ps'])
    for i in range(num_ps):
      cdf.set_device_filters('ps', i, ['/job:worker'])

    tf.config.experimental_connect_to_cluster(cluster_def,
                                              cluster_device_filters=cdf)

The device filters can be partically specified. For remote tasks that do not
have device filters specified, all devices will be visible to them.

## Methods

### `set_device_filters`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.21.0/tensorflow/python/training/server_lib.py#L533-L539)

    set_device_filters(
        job_name, task_index, device_filters
    )

Set the device filters for given job name and task id.