code: def get_strategy(tpu="", cluster_config=""):
      """Create a distribution strategy for running on accelerators.
  
      For CPU, single-GPU, or multi-GPU jobs on a single machine, call this function
      without args to return a MirroredStrategy.
  
      For TPU jobs, specify an address to the `tpu` argument.
  
      For multi-machine GPU jobs, specify a `cluster_config` argument of the cluster
      configuration.
  
      Args:
        tpu: Address of the TPU. No TPU if left blank.
        cluster_config: Should be specified only for multi-worker jobs.
          Task specific dictionary for cluster config dict in the TF_CONFIG format.
          https://www.tensorflow.org/guide/distributed_training#setting_up_tf_config_environment_variable
          If passed as a string, will be parsed to a dictionary. Two components
          should be specified: cluster and task. Cluster provides information about
          the training cluster, which is a dict consisting of different types of
          jobs such as chief and worker. Task is information about the current task.
          For example: "{"cluster": {"worker": ["host1:port", "host2:port"]},
                         "task": {"type": "worker", "index": 0}}"
  
      Returns:
        A distribution strategy. MirroredStrategy by default. TPUStrategy if `tpu`
        arg is specified. MultiWorkerMirroredStrategy if `cluster_config` arg is
        specified.
      """
      if tpu:
          logging.info("Use TPU at %s", tpu)
          resolver = tf.distribute.cluster_resolver.TPUClusterResolver(
              tpu=tpu
          )
          tf.config.experimental_connect_to_cluster(resolver)
          tf.tpu.experimental.initialize_tpu_system(resolver)
          strategy = tf.distribute.TPUStrategy(resolver)
      elif cluster_config:
          if not isinstance(cluster_config, dict):
              cluster_config = json.loads(cluster_config)
          cluster_spec = tf.train.ClusterSpec(cluster_config["cluster"])
          resolver = (
              tf.distribute.cluster_resolver.SimpleClusterResolver(
                  cluster_spec=cluster_spec,
                  task_type=cluster_config["task"]["type"],
                  task_id=cluster_config["task"]["index"],
                  num_accelerators={
                      "GPU": len(tf.config.list_physical_devices("GPU"))
                  },
                  rpc_layer="grpc",
              )
          )
          strategy = (
              tf.distribute.experimental.MultiWorkerMirroredStrategy(
                  cluster_resolver=resolver
              )
          )
      else:
          logging.info("Defaulting to MirroredStrategy")
          strategy = tf.distribute.MirroredStrategy()
      return strategy
  
file_path: ddsp/ddsp/training/train_util.py
imports: import json
  import os
  import time
  from absl import logging
  from ddsp.training import cloud
  import gin
  import tensorflow.compat.v2
label_desc: Use image node_id 1 for calling a global function with example usage: get_strategy(tpu, cluster_config) and returns: strategy