class_docstr: Manages a PyTorch model for training.
class_docstr_tok: ["Manages","a","PyTorch","model","for","training","."]
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.
  
  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",".","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, callbacks=None):
      """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.
  
      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
      # and restore batch to what it should be.
      self.batch = batch
      self.call_hook(callbacks=callbacks, fn_name="before_val_iter")
  
      # compute output
      with self.timers.record("eval_fwd"):
          self.call_hook(callbacks=callbacks, fn_name="on_val_forward")
  
      self.call_hook(callbacks=callbacks, fn_name="after_val_iter")
  
      output, target, loss = None, None, None
  
      if hasattr(self, "output"):
          output = self.output
          del self.output
  
      # User should not see batch from last iteration
      if hasattr(self, "target"):
          target = self.target
          del self.target
      del self.batch
  
      if hasattr(self, "loss"):
          loss = self.loss
          del self.loss
  
      return output, target, loss
  
imports: from filelock import FileLock
  import logging
  import os
  import copy
  import tempfile
  import math
  import torch
  import torch.nn
  import numpy
  from torch.utils.data import DataLoader, IterableDataset
  from bigdl.orca.learn.metrics import Metric
  from bigdl.orca import OrcaContext
  from bigdl.orca.learn.pytorch import utils
  from bigdl.orca.learn.pytorch.utils import AverageMeterCollection, NUM_SAMPLES, get_batchsize, index_concatenate, split_predict_cols
  from bigdl.orca.learn.pytorch.core import BaseRunner
  from bigdl.dllib.utils.log4Error import invalidInputError
label_desc: Use image node_id 14 for calling the TorchRunner obj's underlying member method code with example usage: obj.forward_batch(batch, callbacks) and returns: output,  target,  loss