# tf.distribute.Server

<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/training/server_lib.py#L94-L239) |

An in-process TensorFlow server, for use in distributed training.

#### View aliases


**Compat aliases for migration**

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

[`tf.compat.v1.distribute.Server`](https://www.tensorflow.org/api_docs/python/tf/distribute/Server), [`tf.compat.v1.train.Server`](https://www.tensorflow.org/api_docs/python/tf/distribute/Server)

<br />

    tf.distribute.Server(
        server_or_cluster_def,
        job_name=None,
        task_index=None,
        protocol=None,
        config=None,
        start=True
    )

A [`tf.distribute.Server`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/distribute/Server) instance encapsulates a set of devices and a
[`tf.compat.v1.Session`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat/v1/Session) target that
can participate in distributed training. A server belongs to a
cluster (specified by a [`tf.train.ClusterSpec`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/train/ClusterSpec)), and
corresponds to a particular task in a named job. The server can
communicate with any other server in the same cluster.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `server_or_cluster_def` | A [`tf.train.ServerDef`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/train/ServerDef) or [`tf.train.ClusterDef`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/train/ClusterDef) protocol buffer, or a [`tf.train.ClusterSpec`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/train/ClusterSpec) object, describing the server to be created and/or the cluster of which it is a member. |
| `job_name` | (Optional.) Specifies the name of the job of which the server is a member. Defaults to the value in `server_or_cluster_def`, if specified. |
| `task_index` | (Optional.) Specifies the task index of the server in its job. Defaults to the value in `server_or_cluster_def`, if specified. Otherwise defaults to 0 if the server's job has only one task. |
| `protocol` | (Optional.) Specifies the protocol to be used by the server. Acceptable values include `"grpc", "grpc+verbs"`. Defaults to the value in `server_or_cluster_def`, if specified. Otherwise defaults to `"grpc"`. |
| `config` | (Options.) A [`tf.compat.v1.ConfigProto`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat/v1/ConfigProto) that specifies default configuration options for all sessions that run on this server. |
| `start` | (Optional.) Boolean, indicating whether to start the server after creating it. Defaults to `True`. |

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| [`tf.errors.OpError`](https://www.tensorflow.org/api_docs/python/tf/errors/OpError) | Or one of its subclasses if an error occurs while creating the TensorFlow server. |

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `server_def` | Returns the [`tf.train.ServerDef`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/train/ServerDef) for this server. |
| `target` | Returns the target for a [`tf.compat.v1.Session`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat/v1/Session) to connect to this server. <br /> To create a [`tf.compat.v1.Session`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat/v1/Session) that connects to this server, use the following snippet: server = tf.distribute.Server(...) with tf.compat.v1.Session(server.target): # ... <br /> |

<br />

## Methods

### `create_local_server`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/training/server_lib.py#L216-L239)

    @staticmethod
    create_local_server(
        config=None, start=True
    )

Creates a new single-process cluster running on the local host.

This method is a convenience wrapper for creating a
[`tf.distribute.Server`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/distribute/Server) with a [`tf.train.ServerDef`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/train/ServerDef) that specifies a
single-process cluster containing a single task in a job called
`"local"`.

<br />

<br />

<br />

| Args ||
|---|---|
| `config` | (Options.) A [`tf.compat.v1.ConfigProto`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat/v1/ConfigProto) that specifies default configuration options for all sessions that run on this server. |
| `start` | (Optional.) Boolean, indicating whether to start the server after creating it. Defaults to `True`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A local [`tf.distribute.Server`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/distribute/Server). ||

<br />

### `join`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/training/server_lib.py#L176-L185)

    join()

Blocks until the server has shut down.

This method currently blocks forever.

<br />

<br />

<br />

| Raises ||
|---|---|
| [`tf.errors.OpError`](https://www.tensorflow.org/api_docs/python/tf/errors/OpError) | Or one of its subclasses if an error occurs while joining the TensorFlow server. |

<br />

### `start`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/training/server_lib.py#L167-L174)

    start()

Starts this server.

<br />

<br />

<br />

| Raises ||
|---|---|
| [`tf.errors.OpError`](https://www.tensorflow.org/api_docs/python/tf/errors/OpError) | Or one of its subclasses if an error occurs while starting the TensorFlow server. |

<br />