code: def get_strategy(tpu, use_gpu):
      """Utility to create a `tf.DistributionStrategy` for TPU or GPU.
  
      If neither is being used a DefaultStrategy is returned which allows executing
      on CPU only.
  
      Args:
        tpu: BNS address of TPU to use. Note the flag and param are called TPU as
          that is what the xmanager utilities call.
        use_gpu: Whether a GPU should be used. This will create a MirroredStrategy.
  
      Raises:
        ValueError if both tpu and use_gpu are set.
      Returns:
        An instance of a `tf.DistributionStrategy`.
      """
      if tpu and use_gpu:
          raise ValueError(
              "Only one of tpu or use_gpu should be provided."
          )
      if tpu or use_gpu:
          logging.info(
              "Devices: \n%s", tf.config.list_logical_devices()
          )
          if 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)
          else:
              strategy = tf.distribute.MirroredStrategy()
          logging.info(
              "Devices after getting strategy:\n%s",
              tf.config.list_logical_devices(),
          )
      else:
          strategy = tf.distribute.get_strategy()
  
      return strategy
  
imports: from absl import flags
  from absl import logging
  import tensorflow.compat.v2
label_desc: Use image node_id 1 for calling a global function with example usage: get_strategy(tpu, use_gpu) and returns: strategy