code: def _sync_durations(
      recorded_durations: Dict[str, List[float]],
      pg: Optional[dist.ProcessGroup],
  ) -> Dict[str, List[float]]:
      if not (dist.is_available() and dist.is_initialized()):
          return recorded_durations
  
      pg_wrapper = PGWrapper(pg)
      world_size = pg_wrapper.get_world_size()
      outputs = [None] * world_size
      pg_wrapper.all_gather_object(outputs, recorded_durations)
      ret = defaultdict(list)
      for output in outputs:
          # pyre-ignore [16]: `Optional` has no attribute `__getitem__`.
          for k, v in output.items():
              if k not in ret:
                  ret[k] = []
              ret[k].extend(v)
      return ret
  
imports: import datetime
  import logging
  import os
  from collections import defaultdict
  from contextlib import contextmanager
  from time import perf_counter
  from typing import Any, Dict, Generator, List, Optional, Protocol, runtime_checkable, Sequence, Tuple, TypeVar
  import numpy
  import torch
  import torch.distributed
  from tabulate import tabulate
  from torchtnt.utils.distributed import PGWrapper
label_desc: Use image node_id 8 for calling a global function with example usage: _sync_durations(recorded_durations, pg) and returns: ret, recorded_durations