class_docstr: Manages a PyTorch model for training.
class_docstr_tok: ["Manages","a","PyTorch","model","for","training","."]
docstr: Runs one standard validation pass over the val_iterator.
  
  This will call ``model.eval()`` and ``torch.no_grad`` when iterating
  over the validation dataloader.
  
  If overriding this method, you can access model, criterion via
  ``self.model`` and ``self.criterion``. You also do not need to call
  ``validate_batch`` if overriding this method.
  
  Args:
      val_iterator (iter): Iterable constructed from the
          validation dataloader.
  
  Returns:
      A dict of metrics from the evaluation.
          By default, returns "val_accuracy" and "val_loss"
          which is computed by aggregating "loss" and "correct" values
          from ``validate_batch`` and dividing it by the sum of
          ``num_samples`` from all calls to ``self.validate_batch``.
docstr_tok: ["Runs","one","standard","validation","pass","over","the","val_iterator",".","This","will","call","``","model.eval","(",")","``","and","``","torch.no_grad","``","when","iterating","over","the","validation","dataloader",".","If","overriding","this","method",",","you","can","access","model",",","criterion","via","``","self.model","``","and","``","self.criterion","``",".","You","also","do","not","need","to","call","``","validate_batch","``","if","overriding","this","method",".","Args",":","val_iterator","(","iter",")",":","Iterable","constructed","from","the","validation","dataloader",".","Returns",":","A","dict","of","metrics","from","the","evaluation",".","By","default",",","returns","``","val_accuracy","''","and","``","val_loss","''","which","is","computed","by","aggregating","``","loss","''","and","``","correct","''","values","from","``","validate_batch","``","and","dividing","it","by","the","sum","of","``","num_samples","``","from","all","calls","to","``","self.validate_batch","``","."]
code: def _validate(
      self, val_iterator, metrics, num_steps=None, callbacks=None
  ):
      """Runs one standard validation pass over the val_iterator.
  
      This will call ``model.eval()`` and ``torch.no_grad`` when iterating
      over the validation dataloader.
  
      If overriding this method, you can access model, criterion via
      ``self.model`` and ``self.criterion``. You also do not need to call
      ``validate_batch`` if overriding this method.
  
      Args:
          val_iterator (iter): Iterable constructed from the
              validation dataloader.
  
      Returns:
          A dict of metrics from the evaluation.
              By default, returns "val_accuracy" and "val_loss"
              which is computed by aggregating "loss" and "correct" values
              from ``validate_batch`` and dividing it by the sum of
              ``num_samples`` from all calls to ``self.validate_batch``.
      """
      # switch to evaluate mode
      self._mode = "val"
      self.model.eval()
      metrics = Metric.convert_metrics_dict(metrics, backend="pytorch")
      losses = []
      total_samples = 0
      with torch.no_grad():
          self.call_hook(
              callbacks=callbacks, fn_name="before_val_epoch"
          )
          for batch_idx, batch in enumerate(val_iterator):
              self.batch_idx = batch_idx
              if num_steps and batch_idx == num_steps:
                  break
              output, target, loss = self.forward_batch(
                  batch, callbacks
              )
              num_samples = get_batchsize(output)
              total_samples += num_samples
              losses.append(loss.item() * num_samples)
              for metric in metrics.values():
                  metric(output, target)
  
              del self.batch_idx
  
      result = {
          name: metric.compute() for name, metric in metrics.items()
      }
  
      result["val_loss"] = sum(losses) / total_samples
  
      result["num_samples"] = total_samples
  
      self.call_hook(callbacks=callbacks, fn_name="after_val_epoch")
      return result
  
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 13 for calling the TorchRunner obj's underlying member method code with example usage: obj._validate(val_iterator, metrics, num_steps, callbacks) and returns: result