A tf.train.ClusterSpec represents the set of processes that
participate in a distributed TensorFlow computation. Every
tf.distribute.Server is constructed in a particular cluster.
To create a cluster with two jobs and five tasks, you specify the
mapping from job names to lists of network addresses (typically
hostname-port pairs).
Each job may also be specified as a sparse mapping from task indices
to network addresses. This enables a server to be configured without
needing to know the identity of (for example) all other worker
tasks:
A dictionary mapping one or more job names to (i) a list of
network addresses, or (ii) a dictionary mapping integer task indices to
network addresses; or a tf.train.ClusterDef protocol buffer.
Raises
TypeError
If cluster is not a dictionary mapping strings to lists
of strings, and not a tf.train.ClusterDef protobuf.
Returns a dictionary from job names to their tasks.
For each job, if the task index space is dense, the corresponding
value will be a list of network addresses; otherwise it will be a
dictionary mapping (sparse) task indices to the corresponding
addresses.
Returns
A dictionary mapping job names to lists or dictionaries
describing the tasks in those jobs.
Returns a mapping from task ID to address in the given job.
Args
job_name
The string name of a job in this cluster.
Returns
A list of task addresses, where the index in the list
corresponds to the task index of each task. The list may contain
None if the job was defined with a sparse set of task indices.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.train.ClusterSpec\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/training/server_lib.py#L242-L492) |\n\nRepresents a cluster as a set of \"tasks\", organized into \"jobs\".\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.train.ClusterSpec`](https://www.tensorflow.org/api_docs/python/tf/train/ClusterSpec)\n\n\u003cbr /\u003e\n\n tf.train.ClusterSpec(\n cluster\n )\n\n### Used in the notebooks\n\n| Used in the tutorials |\n|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [Custom training loop with Keras and MultiWorkerMirroredStrategy](https://www.tensorflow.org/tutorials/distribute/multi_worker_with_ctl) - [Parameter server training with ParameterServerStrategy](https://www.tensorflow.org/tutorials/distribute/parameter_server_training) |\n\nA [`tf.train.ClusterSpec`](../../tf/train/ClusterSpec) represents the set of processes that\nparticipate in a distributed TensorFlow computation. Every\n[`tf.distribute.Server`](../../tf/distribute/Server) is constructed in a particular cluster.\n\nTo create a cluster with two jobs and five tasks, you specify the\nmapping from job names to lists of network addresses (typically\nhostname-port pairs). \n\n cluster = tf.train.ClusterSpec({\"worker\": [\"worker0.example.com:2222\",\n \"worker1.example.com:2222\",\n \"worker2.example.com:2222\"],\n \"ps\": [\"ps0.example.com:2222\",\n \"ps1.example.com:2222\"]})\n\nEach job may also be specified as a sparse mapping from task indices\nto network addresses. This enables a server to be configured without\nneeding to know the identity of (for example) all other worker\ntasks: \n\n cluster = tf.train.ClusterSpec({\"worker\": {1: \"worker1.example.com:2222\"},\n \"ps\": [\"ps0.example.com:2222\",\n \"ps1.example.com:2222\"]})\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `cluster` | A dictionary mapping one or more job names to (i) a list of network addresses, or (ii) a dictionary mapping integer task indices to network addresses; or a [`tf.train.ClusterDef`](../../tf/train/ClusterDef) protocol buffer. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|-------------|----------------------------------------------------------------------------------------------------------------------------------------------|\n| `TypeError` | If `cluster` is not a dictionary mapping strings to lists of strings, and not a [`tf.train.ClusterDef`](../../tf/train/ClusterDef) protobuf. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|--------|----------------------------------------------|\n| `jobs` | Returns a list of job names in this cluster. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `as_cluster_def`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/training/server_lib.py#L364-L366) \n\n as_cluster_def()\n\nReturns a [`tf.train.ClusterDef`](../../tf/train/ClusterDef) protocol buffer based on this cluster.\n\n### `as_dict`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/training/server_lib.py#L337-L362) \n\n as_dict()\n\nReturns a dictionary from job names to their tasks.\n\nFor each job, if the task index space is dense, the corresponding\nvalue will be a list of network addresses; otherwise it will be a\ndictionary mapping (sparse) task indices to the corresponding\naddresses.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A dictionary mapping job names to lists or dictionaries describing the tasks in those jobs. ||\n\n\u003cbr /\u003e\n\n### `job_tasks`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/training/server_lib.py#L438-L465) \n\n job_tasks(\n job_name\n )\n\nReturns a mapping from task ID to address in the given job.\n| **Note:** For backwards compatibility, this method returns a list. If the given job was defined with a sparse set of task indices, the length of this list may not reflect the number of tasks defined in this job. Use the [`tf.train.ClusterSpec.num_tasks`](../../tf/train/ClusterSpec#num_tasks) method to find the number of tasks defined in a particular job.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|------------|-------------------------------------------|\n| `job_name` | The string name of a job in this cluster. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A list of task addresses, where the index in the list corresponds to the task index of each task. The list may contain `None` if the job was defined with a sparse set of task indices. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|--------------|----------------------------------------------------|\n| `ValueError` | If `job_name` does not name a job in this cluster. |\n\n\u003cbr /\u003e\n\n### `num_tasks`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/training/server_lib.py#L377-L393) \n\n num_tasks(\n job_name\n )\n\nReturns the number of tasks defined in the given job.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|------------|-------------------------------------------|\n| `job_name` | The string name of a job in this cluster. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| The number of tasks defined in the given job. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|--------------|----------------------------------------------------|\n| `ValueError` | If `job_name` does not name a job in this cluster. |\n\n\u003cbr /\u003e\n\n### `task_address`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/training/server_lib.py#L414-L436) \n\n task_address(\n job_name, task_index\n )\n\nReturns the address of the given task in the given job.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|--------------|-------------------------------------------|\n| `job_name` | The string name of a job in this cluster. |\n| `task_index` | A non-negative integer. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| The address of the given task in the given job. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|--------------|---------------------------------------------------------------------------------------------------------------|\n| `ValueError` | If `job_name` does not name a job in this cluster, or no task with index `task_index` is defined in that job. |\n\n\u003cbr /\u003e\n\n### `task_indices`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/training/server_lib.py#L395-L412) \n\n task_indices(\n job_name\n )\n\nReturns a list of valid task indices in the given job.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|------------|-------------------------------------------|\n| `job_name` | The string name of a job in this cluster. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A list of valid task indices in the given job. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|--------------|---------------------------------------------------------------------------------------------------------------|\n| `ValueError` | If `job_name` does not name a job in this cluster, or no task with index `task_index` is defined in that job. |\n\n\u003cbr /\u003e\n\n### `__bool__`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/training/server_lib.py#L318-L319) \n\n __bool__()\n\n### `__eq__`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/training/server_lib.py#L324-L325) \n\n __eq__(\n other\n )\n\nReturn self==value.\n\n### `__ne__`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/training/server_lib.py#L327-L328) \n\n __ne__(\n other\n )\n\nReturn self!=value.\n\n### `__nonzero__`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/training/server_lib.py#L318-L319) \n\n __nonzero__()"]]