class_docstr: Cluster Resolver for Google Cloud TPUs.
  
  This is an implementation of cluster resolvers for the Google Cloud TPU
  service.
  
  TPUClusterResolver supports the following distinct environments:
  Google Compute Engine
  Google Kubernetes Engine
  Google internal
  
  It can be passed into `tf.distribute.TPUStrategy` to support TF2 training on
  Cloud TPUs.
docstr: Get the Master string to be used for the session.
  
  In the normal case, this returns the grpc path (grpc://1.2.3.4:8470) of
  first instance in the ClusterSpec returned by the cluster_spec function.
  
  If a non-TPU name is used when constructing a TPUClusterResolver, that will
  be returned instead (e.g. If the tpus argument's value when constructing
  this TPUClusterResolver was 'grpc://10.240.1.2:8470',
  'grpc://10.240.1.2:8470' will be returned).
  
  Args:
    task_type: (Optional, string) The type of the TensorFlow task of the
      master.
    task_id: (Optional, integer) The index of the TensorFlow task of the
      master.
    rpc_layer: (Optional, string) The RPC protocol TensorFlow should use to
      communicate with TPUs.
  
  Returns:
    string, the connection string to use when creating a session.
  
  Raises:
    ValueError: If none of the TPUs specified exists.
code: def master(self, task_type=None, task_id=None, rpc_layer=None):
      """Get the Master string to be used for the session.
  
      In the normal case, this returns the grpc path (grpc://1.2.3.4:8470) of
      first instance in the ClusterSpec returned by the cluster_spec function.
  
      If a non-TPU name is used when constructing a TPUClusterResolver, that will
      be returned instead (e.g. If the tpus argument's value when constructing
      this TPUClusterResolver was 'grpc://10.240.1.2:8470',
      'grpc://10.240.1.2:8470' will be returned).
  
      Args:
        task_type: (Optional, string) The type of the TensorFlow task of the
          master.
        task_id: (Optional, integer) The index of the TensorFlow task of the
          master.
        rpc_layer: (Optional, string) The RPC protocol TensorFlow should use to
          communicate with TPUs.
  
      Returns:
        string, the connection string to use when creating a session.
  
      Raises:
        ValueError: If none of the TPUs specified exists.
      """
  
      if self._tpu != "local":
          cluster_spec = self.cluster_spec()
          if task_type is not None and task_id is not None:
              # task_type and task_id is from the function parameter
              master = cluster_spec.task_address(task_type, task_id)
          elif self.task_type is not None and self.task_id is not None:
              # task_type and task_id is from the object
              master = cluster_spec.task_address(
                  self.task_type, self.task_id
              )
          else:
              # by default we take the first item in the cluster with the right name
              job_tasks = cluster_spec.job_tasks(self.task_type)
              if not job_tasks:
                  raise ValueError(
                      "No TPUs with the specified names exist."
                  )
              master = job_tasks[0]
          return cluster_resolver_lib.format_master_url(master, "grpc")
      else:
          return ""
  
imports: import collections
  import re
  from tensorflow.core.protobuf.tpu import topology_pb2
  from tensorflow.python.distribute.cluster_resolver import cluster_resolver
  from tensorflow.python.eager import remote
  from tensorflow.python.framework import config
  from tensorflow.python.framework import errors
  from tensorflow.python.platform import tf_logging
  from tensorflow.python.tpu import tpu_strategy_util
  from tensorflow.python.tpu import tpu_system_metadata
  from tensorflow.python.training import server_lib
  from tensorflow.python.util import compat
label_desc: Use image node_id 7 for calling the TPUClusterResolver obj's underlying member method code with example usage: obj.master(task_type, task_id, rpc_layer) and returns: cluster_resolver_lib, str