docstr: A trainer that implements a DDP training algorithm using a simple hook that performs allreduce
  using the process_group implementation.
  Args:
      process_group (ProcessGroup): distributed process group
      use_cuda_rpc (bool): indicator for CUDA RPC
      server_rref (RRef): remote reference to the server
      backend (str): distributed communication backend
      epochs (int): epoch count for training
      preprocess_data (function): preprocesses data passed
          to the trainer before starting training
      create_criterion (function): creates a criterion to calculate loss
      create_ddp_model (function): creates a ddp model for the trainer
      hook_state_class (class): class that will be used to keep tracking of state
          during training.
      hook (function): ddp communication hook
      iteration_step (function): will perform 1 step of training
docstr_tok: ["A","trainer","that","implements","a","DDP","training","algorithm","using","a","simple","hook","that","performs","allreduce","using","the","process_group","implementation",".","Args",":","process_group","(","ProcessGroup",")",":","distributed","process","group","use_cuda_rpc","(","bool",")",":","indicator","for","CUDA","RPC","server_rref","(","RRef",")",":","remote","reference","to","the","server","backend","(","str",")",":","distributed","communication","backend","epochs","(","int",")",":","epoch","count","for","training","preprocess_data","(","function",")",":","preprocesses","data","passed","to","the","trainer","before","starting","training","create_criterion","(","function",")",":","creates","a","criterion","to","calculate","loss","create_ddp_model","(","function",")",":","creates","a","ddp","model","for","the","trainer","hook_state_class","(","class",")",":","class","that","will","be","used","to","keep","tracking","of","state","during","training",".","hook","(","function",")",":","ddp","communication","hook","iteration_step","(","function",")",":","will","perform","1","step","of","training"]
code: def __init__(
      self,
      process_group,
      use_cuda_rpc,
      server_rref,
      backend,
      epochs,
      preprocess_data,
      create_criterion,
      create_ddp_model,
      hook_state_class,
      hook,
      iteration_step,
  ):
      r"""
      A trainer that implements a DDP training algorithm using a simple hook that performs allreduce
      using the process_group implementation.
      Args:
          process_group (ProcessGroup): distributed process group
          use_cuda_rpc (bool): indicator for CUDA RPC
          server_rref (RRef): remote reference to the server
          backend (str): distributed communication backend
          epochs (int): epoch count for training
          preprocess_data (function): preprocesses data passed
              to the trainer before starting training
          create_criterion (function): creates a criterion to calculate loss
          create_ddp_model (function): creates a ddp model for the trainer
          hook_state_class (class): class that will be used to keep tracking of state
              during training.
          hook (function): ddp communication hook
          iteration_step (function): will perform 1 step of training
      """
      super().__init__(process_group.rank())
      self.process_group = process_group
      self.use_cuda_rpc = use_cuda_rpc
      self.server_rref = server_rref
      self.backend = backend
      self.epochs = epochs
      self.preprocess_data = preprocess_data
      self.create_criterion = create_criterion
      self.create_ddp_model = create_ddp_model
      self.hook_state_class = hook_state_class
      self.hook = hook
      self.iteration_step = iteration_step
  
      self.rank = process_group.rank()
      self.trainer_count = process_group.size()
  
imports: import functools
  import time
  from abc import ABC, abstractmethod
  import torch
  from metrics.MetricsLogger import MetricsLogger
label_desc: Use image node_id 1 to create a new DdpTrainer object from inherited base classes: TrainerBase with example: obj = DdpTrainer(process_group, use_cuda_rpc, server_rref, backend, epochs, preprocess_data, create_criterion, create_ddp_model, hook_state_class, hook, iteration_step)