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: Calculates the loss and accuracy over a given batch.
  
  You can override this method to provide arbitrary metrics.
  
  Same as ``train_batch``, this method implementation assumes that
  batches are in (\*features, labels) format by default. So we also
  support multiple inputs model.
  
  Args:
      batch: One item of the validation iterator.
      batch_info (dict): Contains information per batch from
          ``validate()``.
  
  Returns:
      A dict of metrics.
          By default, returns "val_loss", "val_accuracy", and
          "num_samples". When overriding, consider returning
          "num_samples" in the metrics because
          by default, ``validate`` uses "num_samples" to
          calculate averages.
docstr_tok: ["Calculates","the","loss","and","accuracy","over","a","given","batch",".","You","can","override","this","method","to","provide","arbitrary","metrics",".","Same","as","``","train_batch","``",",","this","method","implementation","assumes","that","batches","are","in","(","\\","*","features",",","labels",")","format","by","default",".","So","we","also","support","multiple","inputs","model",".","Args",":","batch",":","One","item","of","the","validation","iterator",".","batch_info","(","dict",")",":","Contains","information","per","batch","from","``","validate","(",")","``",".","Returns",":","A","dict","of","metrics",".","By","default",",","returns","``","val_loss","''",",","``","val_accuracy","''",",","and","``","num_samples","''",".","When","overriding",",","consider","returning","``","num_samples","''","in","the","metrics","because","by","default",",","``","validate","``","uses","``","num_samples","''","to","calculate","averages","."]
code: def forward_batch(self, batch, batch_info):
      """Calculates the loss and accuracy over a given batch.
  
      You can override this method to provide arbitrary metrics.
  
      Same as ``train_batch``, this method implementation assumes that
      batches are in (\*features, labels) format by default. So we also
      support multiple inputs model.
  
      Args:
          batch: One item of the validation iterator.
          batch_info (dict): Contains information per batch from
              ``validate()``.
  
      Returns:
          A dict of metrics.
              By default, returns "val_loss", "val_accuracy", and
              "num_samples". When overriding, consider returning
              "num_samples" in the metrics because
              by default, ``validate`` uses "num_samples" to
              calculate averages.
      """
      # unpack features into list to support multiple inputs model
      *features, target = batch
      # If features is already a tuple, we don't give it an extra list dimension.
      already_list = isinstance(features[0], tuple) or isinstance(
          features[0], list
      )
      if len(features) == 1 and already_list:
          features = features[0]
  
      # compute output
      with self.timers.record("eval_fwd"):
          output = self.model(*features)
          loss = self.criterion(output, target)
  
      return output, target, loss
  
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 10 for calling the TrainingOperator obj's underlying member method code with example usage: obj.forward_batch(batch, batch_info) and returns: output,  target,  loss