class_docstr: Manages a PyTorch model for training.
class_docstr_tok: ["Manages","a","PyTorch","model","for","training","."]
docstr: Runs a training epoch and updates the model parameters.
docstr_tok: ["Runs","a","training","epoch","and","updates","the","model","parameters","."]
code: def train_epoch(
      self,
      data_loader,
      profile=False,
      callbacks=None,
      val_loader=None,
      val_steps=None,
  ):
      """Runs a training epoch and updates the model parameters."""
      if hasattr(data_loader, "sampler") and hasattr(
          data_loader.sampler, "set_epoch"
      ):
          data_loader.sampler.set_epoch(self.epochs)
      self.logger.debug(
          "Begin Training Step {}".format(self.epochs + 1)
      )
  
      if not self.models:
          invalidInputError(
              False, "You must provide a model for train and evaluate."
          )
  
      if not self.optimizers:
          invalidInputError(
              False, "You must provide the optimizer for train."
          )
  
      self._toggle_profiling(profile=profile)
  
      with self.timers.record("train_epoch"):
          data_loader = iter(data_loader)
          train_stats = self._train_epoch(data_loader, callbacks)
  
      if val_loader:
          with self.timers.record("validation"):
              validation_results = self._validate(
                  val_loader,
                  metrics=self.metrics,
                  num_steps=val_steps,
                  callbacks=callbacks,
              )
              # add prefix of "val_" for validation_stats
              validation_stats = {}
              for name, value in validation_results.items():
                  if not name.startswith("val_"):
                      name = "val_" + name.lower()
                  validation_stats[name] = value
  
      else:
          validation_stats = {}
  
      self.epochs += 1
      # This is so that `epochs` is first in ordering.
      stats = dict(epoch=self.epochs, **train_stats, **validation_stats)
  
      if profile:
          stats.update(profile=self.timers.stats())
  
      return stats
  
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 8 for calling the TorchRunner obj's underlying member method code with example usage: obj.train_epoch(data_loader, profile, callbacks, val_loader, val_steps) and returns: stats