class_docstr: Abstract class for custom training or validation loops.
  
  The scheduler will only be called at a batch or epoch frequency, depending
  on the user parameter. Be sure to set ``scheduler_step_freq`` in
  ``TorchTrainer`` to either "batch" or "epoch" to increment the scheduler
  correctly during training. If using a learning rate scheduler
  that depends on validation loss, you can use ``trainer.update_scheduler``.
  
  For both training and validation, there are two granularities that
  you can provide customization: per epoch or per batch.
  You do not need to override both.
  
  .. image:: raysgd-custom.jpg
      :scale: 80%
      :align: center
  
  Raises:
      ValueError if multiple models/optimizers/schedulers are provided.
          You are expected to subclass this class if you wish
          to train over multiple models/optimizers/schedulers.
docstr: Runs one standard training pass over the training dataloader.
  
  By default, this method will iterate over the given iterator and
  call ``self.train_batch`` over each batch. If ``scheduler_step_freq``
  is set, this default method will also step the scheduler accordingly.
  
  You do not need to call ``train_batch`` in this method if you plan
  to implement a custom optimization/training routine here.
  
  You may find ``ray.util.sgd.utils.AverageMeterCollection`` useful
  when overriding this method. See example below:
  
  .. code-block:: python
  
      def train_epoch(self, ...):
          meter_collection = AverageMeterCollection()
          self.model.train()
          for batch in iterator:
              # do some processing
              metrics = {"metric_1": 1, "metric_2": 3} # dict of metrics
  
              # This keeps track of all metrics across multiple batches
              meter_collection.update(metrics, n=len(batch))
  
          # Returns stats of the meters.
          stats = meter_collection.summary()
          return stats
  
  
  Args:
      iterator (iter): Iterator over the training data for the entire
          epoch. This iterator is expected to be entirely consumed.
      info (dict): Dictionary for information to be used for custom
          training operations.
  
  Returns:
      A dict of metrics from training.
docstr_tok: ["Runs","one","standard","training","pass","over","the","training","dataloader",".","By","default",",","this","method","will","iterate","over","the","given","iterator","and","call","``","self.train_batch","``","over","each","batch",".","If","``","scheduler_step_freq","``","is","set",",","this","default","method","will","also","step","the","scheduler","accordingly",".","You","do","not","need","to","call","``","train_batch","``","in","this","method","if","you","plan","to","implement","a","custom","optimization\/training","routine","here",".","You","may","find","``","ray.util.sgd.utils.AverageMeterCollection","``","useful","when","overriding","this","method",".","See","example","below",":","..","code-block",":",":","python","def","train_epoch","(","self",",","...",")",":","meter_collection","=","AverageMeterCollection","(",")","self.model.train","(",")","for","batch","in","iterator",":","#","do","some","processing","metrics","=","{","``","metric_1","''",":","1",",","``","metric_2","''",":","3","}","#","dict","of","metrics","#","This","keeps","track","of","all","metrics","across","multiple","batches","meter_collection.update","(","metrics",",","n=len","(","batch",")",")","#","Returns","stats","of","the","meters",".","stats","=","meter_collection.summary","(",")","return","stats","Args",":","iterator","(","iter",")",":","Iterator","over","the","training","data","for","the","entire","epoch",".","This","iterator","is","expected","to","be","entirely","consumed",".","info","(","dict",")",":","Dictionary","for","information","to","be","used","for","custom","training","operations",".","Returns",":","A","dict","of","metrics","from","training","."]
code: def train_epoch(self, iterator, info):
      """Runs one standard training pass over the training dataloader.
  
      By default, this method will iterate over the given iterator and
      call ``self.train_batch`` over each batch. If ``scheduler_step_freq``
      is set, this default method will also step the scheduler accordingly.
  
      You do not need to call ``train_batch`` in this method if you plan
      to implement a custom optimization/training routine here.
  
      You may find ``ray.util.sgd.utils.AverageMeterCollection`` useful
      when overriding this method. See example below:
  
      .. code-block:: python
  
          def train_epoch(self, ...):
              meter_collection = AverageMeterCollection()
              self.model.train()
              for batch in iterator:
                  # do some processing
                  metrics = {"metric_1": 1, "metric_2": 3} # dict of metrics
  
                  # This keeps track of all metrics across multiple batches
                  meter_collection.update(metrics, n=len(batch))
  
              # Returns stats of the meters.
              stats = meter_collection.summary()
              return stats
  
  
      Args:
          iterator (iter): Iterator over the training data for the entire
              epoch. This iterator is expected to be entirely consumed.
          info (dict): Dictionary for information to be used for custom
              training operations.
  
      Returns:
          A dict of metrics from training.
      """
      if self.use_tqdm and self.world_rank == 0:
          desc = ""
          if info is not None and "epoch_idx" in info:
              if "num_epochs" in info:
                  desc = "{}/{}e".format(
                      info["epoch_idx"] + 1, info["num_epochs"]
                  )
              else:
                  desc = "{}e".format(info["epoch_idx"] + 1)
          _progress_bar = tqdm(
              total=len(iterator), desc=desc, unit="batch", leave=False
          )
      else:
          _progress_bar = None
  
      metric_meters = AverageMeterCollection()
  
      self.model.train()
      if isinstance(self.model, DDP):
          with self.model.join():
              self._train_loop(
                  iterator, info, _progress_bar, metric_meters
              )
      else:
          self._train_loop(iterator, info, _progress_bar, metric_meters)
  
      if (
          self.scheduler
          and info.get(SCHEDULER_STEP) == SCHEDULER_STEP_EPOCH
      ):
          self.scheduler.step()
  
      return metric_meters.summary()
  
imports: import collections
  import torch
  import numpy
  from zoo.orca.learn.metrics import Metric
  from zoo.orca.learn.pytorch.utils import TimerCollection, AverageMeterCollection, NUM_SAMPLES
  from zoo.orca.learn.pytorch.constants import SCHEDULER_STEP_EPOCH, NUM_STEPS, SCHEDULER_STEP_BATCH, SCHEDULER_STEP
  from torch.nn.parallel import DistributedDataParallel
label_desc: Use image node_id 4 for calling the TrainingOperator obj's underlying member method code with example usage: obj.train_epoch(iterator, info) and returns: metric_meters