code: def _load_tf_config(port):
      # Create a tf_config from SM Variables
      assert all(
          [x in os.environ for x in [_SM_CURRENT_HOST, _SM_HOSTS]]
      ), "Not a SageMaker Environment"
      hosts = (
          sorted(json.loads(os.environ[_SM_HOSTS]))
          if os.environ[_SM_HOSTS] != ""
          else []
      )
      current_host = os.environ[_SM_CURRENT_HOST]
  
      if current_host not in hosts:
          return {}
  
      host_index = hosts.index(current_host)
      # Assign ports
      hosts = ["%s:%s" % (host, port) for host in hosts]
  
      tf_config = {
          _CLUSTER_KEY: {_WORKER_KEY: hosts},
          _TASK_KEY: {_TYPE_KEY: _WORKER_KEY, _INDEX_KEY: host_index},
      }
      return tf_config
  
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 2 for calling a global function with example usage: _load_tf_config(port) and returns: tf_config, dict