code: def task_count(cluster_spec, task_type):
      try:
          return cluster_spec.num_tasks(task_type)
      except ValueError:
          return 0
  
file_path: tensorflow/tensorflow/python/distribute/multi_worker_util.py
imports: from tensorflow.core.protobuf import cluster_pb2
  from tensorflow.python.distribute import distribute_coordinator_context
  from tensorflow.python.training import server_lib
label_desc: Use image node_id 2 for calling a global function with example usage: task_count(cluster_spec, task_type) and returns: cluster_spec, int