code: def train(config_files, job_dir, override_params):
      """
      Parse TF_CONFIG to cluster_spec and call run() function
      """
      # TF_CONFIG environment variable is available when running using gcloud
      # either locally or on cloud. It has all the information required to create
      # a ClusterSpec which is important for running distributed code.
      tf_config_val = os.environ.get("TF_CONFIG")
  
      if tf_config_val:
          tf_config = json.loads(tf_config_val)
      else:
          tf_config = {}
  
      cluster = tf_config.get("cluster")
      job_name = tf_config.get("task", {}).get("type")
      task_index = tf_config.get("task", {}).get("index")
      environment = tf_config.get("environment", "local")
  
      # Get the user config and the model type from it.
      try:
          config = get_config(
              config_files, override_params=override_params
          )
      except KeyError:
          # Without mode type defined we can't use the default config settings.
          raise KeyError(
              "model.type should be set on the custom config."
          )
  
      if job_dir:
          override_params += ("train.job_dir={}".format(job_dir),)
  
      # If cluster information is empty or TF_CONFIG is not available, run local
      if job_name is None or task_index is None:
          return run(config, environment=environment)
  
      cluster_spec = tf.train.ClusterSpec(cluster)
      server = tf.train.Server(
          cluster_spec, job_name=job_name, task_index=task_index
      )
  
      # Wait for incoming connections forever
      # Worker ships the graph to the ps server
      # The ps server manages the parameters of the model.
      if job_name == "ps":
          server.join()
          return
      elif job_name in ["master", "worker"]:
          is_chief = job_name == "master"
          return run(
              config,
              target=server.target,
              cluster_spec=cluster_spec,
              is_chief=is_chief,
              job_name=job_name,
              task_index=task_index,
              environment=environment,
          )
  
file_path: luminoth/luminoth/train.py
imports: import click
  import json
  import os
  import sys
  import tensorflow
  import time
  from tensorflow.python import debug
  from luminoth.datasets import get_dataset
  from luminoth.datasets.exceptions import InvalidDataDirectory
  from luminoth.models import get_model
  from luminoth.utils.config import get_config
  from luminoth.utils.hooks import ImageVisHook, VarVisHook
  from luminoth.utils.training import get_optimizer, clip_gradients_by_norm
  from luminoth.utils.experiments import save_run
label_desc: Use image node_id 2 for calling a global function with example usage: train(config_files, job_dir, override_params) and returns: run, run