code: def calc_bw_log(comm_op, size, duration):
      import deepspeed.comm as dist
  
      n = dist.get_world_size()
      tput = 0
      busbw = 0
      if comm_op == "all_to_all_single":
          tput = size / duration
          busbw = (size / duration) * ((n - 1) / n)
      elif (
          comm_op == "all_gather"
          or comm_op == "all_gather_base"
          or comm_op == "reduce_scatter"
          or comm_op == "reduce_scatter_base"
      ):
          size *= n
          tput = size / duration
          busbw = (size / duration) * ((n - 1) / n)
      elif comm_op == "all_reduce":
          tput = size * 2 / duration
          busbw = (size / duration) * (2 * (n - 1) / n)
      elif (
          comm_op == "send"
          or comm_op == "recv"
          or comm_op == "isend"
          or comm_op == "irecv"
          or comm_op == "broadcast"
          or comm_op == "reduce"
          or comm_op == "gather"
          or comm_op == "scatter"
          or comm_op == "barrier"
      ):
          tput = size / duration
          busbw = tput
      else:
          print_rank_0("wrong comm_op specified")  # noqa: F821
          exit(0)
  
      # convert to Gbps
      tput *= 8
      busbw *= 8
  
      tput /= 1e6
      busbw /= 1e6
  
      return tput, busbw
  
file_path: H2O/h2o_flexgen/benchmark/third_party/DeepSpeed/deepspeed/utils/comms_logging.py
imports: import math
  from deepspeed.utils import log_dist
label_desc: Use image node_id 3 for calling a global function with example usage: calc_bw_log(comm_op, size, duration) and returns: tput,  busbw