code: def _initialize_distributed_backend() -> (
      Optional[core.DistributedContext]
  ):
      info = det.get_cluster_info()
  
      distributed_backend = det._DistributedBackend()
      if distributed_backend.use_horovod():
          hvd.require_horovod_type("torch", "PyTorchTrial is in use.")
          hvd.init()
          return core.DistributedContext.from_horovod(horovod.hvd)
      elif distributed_backend.use_torch():
          if torch.cuda.is_available():
              dist.init_process_group(backend="nccl")  # type: ignore
          else:
              dist.init_process_group(backend="gloo")  # type: ignore
          return core.DistributedContext.from_torch_distributed()
      elif info and (
          len(info.container_addrs) > 1 or len(info.slot_ids) > 1
      ):
          raise ValueError(
              "In multi-slot managed cluster training, you must wrap your training script with a "
              "distributed launch layer such as determined.launch.torch_distributed or "
              "determined.launch.horovod."
          )
      return None
  
file_path: determined/harness/determined/pytorch/_trainer.py
imports: import contextlib
  import logging
  import random
  import sys
  from typing import Any, Dict, Iterator, Optional
  import numpy
  import torch
  import torch.distributed
  import determined
  from determined import core, gpu, horovod, profiler, pytorch
  from determined.horovod import hvd
label_desc: Use image node_id 1 for calling a global function with example usage: _initialize_distributed_backend() and returns: None, core, core