class_docstr: Implementation of a ClusterResolver which reads the Sagemaker EnvVars. This is an implementation of cluster resolvers when running in a SageMaker environment to set information about the cluster.
  
  The cluster spec returned will be initialized from the SageMaker
  environment variables.
  Currently this Cluster Resolver only supports Multi-Worker Mirrored Strategy.
  It assumes all nodes in a SageMaker Cluster are workers.
class_docstr_tok: ["Implementation","of","a","ClusterResolver","which","reads","the","Sagemaker","EnvVars",".","This","is","an","implementation","of","cluster","resolvers","when","running","in","a","SageMaker","environment","to","set","information","about","the","cluster",".","The","cluster","spec","returned","will","be","initialized","from","the","SageMaker","environment","variables",".","Currently","this","Cluster","Resolver","only","supports","Multi-Worker","Mirrored","Strategy",".","It","assumes","all","nodes","in","a","SageMaker","Cluster","are","workers","."]
docstr: Returns the master address to use when creating a TensorFlow session.
  
  Note: this is only useful for TensorFlow 1.x.
  
  Args:
    task_type: (String, optional) Overrides and sets the task_type of the
      master.
    task_id: (Integer, optional) Overrides and sets the task id of the master.
    rpc_layer: (String, optional) Overrides and sets the protocol over which
      TensorFlow nodes communicate with each other.
  
  Returns:
    The address of the master.
  
  Raises:
    RuntimeError: If the task_type or task_id is not specified and the
      SageMaker environment variables does not contain a task section.
docstr_tok: ["Returns","the","master","address","to","use","when","creating","a","TensorFlow","session",".","Note",":","this","is","only","useful","for","TensorFlow","1.x",".","Args",":","task_type",":","(","String",",","optional",")","Overrides","and","sets","the","task_type","of","the","master",".","task_id",":","(","Integer",",","optional",")","Overrides","and","sets","the","task","id","of","the","master",".","rpc_layer",":","(","String",",","optional",")","Overrides","and","sets","the","protocol","over","which","TensorFlow","nodes","communicate","with","each","other",".","Returns",":","The","address","of","the","master",".","Raises",":","RuntimeError",":","If","the","task_type","or","task_id","is","not","specified","and","the","SageMaker","environment","variables","does","not","contain","a","task","section","."]
code: def master(self, task_type=None, task_id=None, rpc_layer=None):
      """Returns the master address to use when creating a TensorFlow session.
  
      Note: this is only useful for TensorFlow 1.x.
  
      Args:
        task_type: (String, optional) Overrides and sets the task_type of the
          master.
        task_id: (Integer, optional) Overrides and sets the task id of the master.
        rpc_layer: (String, optional) Overrides and sets the protocol over which
          TensorFlow nodes communicate with each other.
  
      Returns:
        The address of the master.
  
      Raises:
        RuntimeError: If the task_type or task_id is not specified and the
          SageMaker environment variables does not contain a task section.
      """
  
      # If `session_master` is set, just use that.
      session_master = _get_value_in_tfconfig(
          _SESSION_MASTER_KEY, self._port
      )
      if session_master is not None:
          return session_master
  
      # Return an empty string if we are the only job in the ClusterSpec.
      cluster_spec = self.cluster_spec()
      if not cluster_spec.jobs or (
          len(cluster_spec.jobs) == 1
          and len(cluster_spec.job_tasks(cluster_spec.jobs[0])) == 1
      ):
          return ""
  
      # We try to auto-detect the task type and id, but uses the user-supplied one
      # where available
      task_type = task_type if task_type is not None else self.task_type
      task_id = task_id if task_id is not None else self.task_id
      rpc_layer = rpc_layer if rpc_layer is not None else self.rpc_layer
  
      return format_master_url(
          cluster_spec.task_address(task_type, task_id), rpc_layer
      )
  
file_path: tensorflow-upstream/tensorflow/python/distribute/cluster_resolver/sagemaker_cluster_resolver.py
imports: import json
  import os
  from tensorflow.python.distribute.cluster_resolver.cluster_resolver import ClusterResolver
  from tensorflow.python.training.server_lib import ClusterSpec
label_desc: Use image node_id 11 for calling the SageMakerClusterResolver obj's underlying member method code with example usage: obj.master(task_type, task_id, rpc_layer) and returns: format_master_url, session_master, str