code: def _parse_dtensor_env_var_from_cluster_resolver(cluster_resolver):
      """Parse the env vars for Dtensor based on the cluster resolver.
  
      In the multi-client setting, each of the DTensor jobs need to aware of each
      other, and the interface to setup those values are via the envvars. The
      value used by dtensor are different from the existing
      `MultiWorkerMirroredStrategy`. This function will parse the value from
      cluster resolver, and populate the corresponding value for DTensor jobs in the
      `os.environ`.
  
      Args:
        cluster_resolver: A `tf.distribute.cluster_resolver.ClusterResolver`
          instance.
  
      Returns:
        A dict of {Str:Str} which contains all the env vars needed by DTensor jobs.
        The value is for verification purpose.
  
      Raises:
        The value parsed from existing cluster spec is not valid.
      """
      result = {}
  
      # Retrieve the number of host, cluster config from the resolver.
      cluster_spec = multi_worker_util.normalize_cluster_spec(
          cluster_resolver.cluster_spec()
      )
      # Export all the necessary envvars for dtensor
      # Get all the jobs from the cluster spec. Note that the in the normal
      # setting, it could be multiple worker devices without chief, and the
      # worker 0 will be the chief, or an explicit chief with multiple worker job.
      dtensor_jobs = []
      if "chief" in cluster_spec.jobs:
          dtensor_jobs.extend(cluster_spec.job_tasks("chief"))
      if "worker" in cluster_spec.jobs:
          dtensor_jobs.extend(cluster_spec.job_tasks("worker"))
  
      if None in dtensor_jobs:
          raise ValueError(
              "Unexpected dtensor job address from cluster spec: "
              f"{cluster_spec}"
          )
      result["DTENSOR_JOBS"] = ",".join(dtensor_jobs)
      result["DTENSOR_NUM_CLIENTS"] = str(len(dtensor_jobs))
  
      if cluster_resolver.task_type == "chief":
          dtensor_client_id = 0
      elif cluster_resolver.task_type == "worker":
          dtensor_client_id = cluster_resolver.task_id
          if "chief" in cluster_spec.jobs:
              dtensor_client_id += 1
      result["DTENSOR_CLIENT_ID"] = str(dtensor_client_id)
      result["DTENSOR_JOB_NAME"] = "worker"
  
      return result
  
file_path: tensorflow/tensorflow/python/distribute/experimental/multi_worker_mirrored_strategy.py
imports: import os
  from tensorflow.dtensor.python import config
  from tensorflow.dtensor.python import mesh_util
  from tensorflow.python.distribute import distribute_lib
  from tensorflow.python.distribute import multi_worker_util
  from tensorflow.python.distribute.cluster_resolver import tfconfig_cluster_resolver
  from tensorflow.python.distribute.experimental import dtensor_strategy_extended
  from tensorflow.python.distribute.experimental import dtensor_util
label_desc: Use image node_id 1 for calling a global function with example usage: _parse_dtensor_env_var_from_cluster_resolver(cluster_resolver) and returns: result