tf.distribute.cluster_resolver.UnionResolver

Performs a union on underlying ClusterResolvers.

Inherits From: ClusterResolver

This class performs a union given two or more existing ClusterResolvers. It merges the underlying ClusterResolvers, and returns one unified ClusterSpec when cluster_spec is called. The details of the merge function is documented in the cluster_spec function.

For additional ClusterResolver properties such as task type, task index, rpc layer, environment, etc..., we will return the value from the first ClusterResolver in the union.

An example to combine two cluster resolvers:

cluster_0 = tf.train.ClusterSpec({"worker": ["worker0.example.com:2222",
                                             "worker1.example.com:2222"]})
cluster_resolver_0 = SimpleClusterResolver(cluster, task_type="worker",
                                           task_id=0,
                                           rpc_layer="grpc")

cluster_1 = tf.train.ClusterSpec({"ps": ["ps0.example.com:2222",
                                         "ps1.example.com:2222"]})
cluster_resolver_1 = SimpleClusterResolver(cluster, task_type="ps",
                                           task_id=0,
                                           rpc_layer="grpc")

# Its task type would be "worker".
cluster_resolver = UnionClusterResolver(cluster_resolver_0,
                                        cluster_resolver_1)

An example to override the number of GPUs in a TFConfigClusterResolver instance:

tf_config = TFConfigClusterResolver()
gpu_override = SimpleClusterResolver(tf_config.cluster_spec(),
                                     num_accelerators={"GPU": 1})
cluster_resolver = UnionResolver(gpu_override, tf_config)

*args ClusterResolver objects to be unionized.
**kwargs rpc_layer - (Optional) Override value for the RPC layer used by TensorFlow. task_type - (Optional) Override value for the current task type. task_id - (Optional) Override value for the current task index.

TypeError If any argument is not a subclass of ClusterResolvers.
ValueError If there are no arguments passed.