class_docstr: Custom updater.
class_docstr_tok: ["Custom","updater","."]
docstr: Update model one step.
docstr_tok: ["Update","model","one","step","."]
code: def update_core(self):
      """Update model one step."""
      # When we pass one iterator and optimizer to StandardUpdater.__init__,
      # they are automatically named 'main'.
      train_iter = self.get_iterator("main")
      optimizer = self.get_optimizer("main")
  
      # Get the next batch (a list of json files)
      batch = train_iter.next()
      if isinstance(batch, tuple):
          x = tuple(arr.to(self.device) for arr in batch)
      else:
          x = batch
          for key in x.keys():
              x[key] = x[key].to(self.device)
  
      # compute loss and gradient
      if isinstance(x, tuple):
          loss = self.model(*x).mean() / self.accum_grad
      else:
          loss = self.model(**x).mean() / self.accum_grad
      loss.backward()
  
      # update parameters
      self.forward_count += 1
      if self.forward_count != self.accum_grad:
          return
      self.forward_count = 0
  
      # compute the gradient norm to check if it is normal or not
      grad_norm = self.clip_grad_norm(
          self.model.parameters(), self.grad_clip
      )
      logging.debug("grad norm={}".format(grad_norm))
      if math.isnan(grad_norm):
          logging.warning("grad norm is nan. Do not update model.")
      else:
          optimizer.step()
      optimizer.zero_grad()
  
imports: import copy
  import json
  import logging
  import math
  import os
  import time
  import chainer
  import kaldiio
  import numpy
  import torch
  from chainer import training
  from chainer.training import extensions
  from espnet.asr.asr_utils import get_model_conf, snapshot_object, torch_load, torch_resume, torch_snapshot
  from espnet.asr.pytorch_backend.asr_init import load_trained_modules
  from espnet.nets.pytorch_backend.nets_utils import pad_list
  from espnet.nets.tts_interface import TTSInterface
  from espnet.utils.dataset import ChainerDataLoader, TransformDataset
  from espnet.utils.deterministic_utils import set_deterministic_pytorch
  from espnet.utils.dynamic_import import dynamic_import
  from espnet.utils.io_utils import LoadInputsAndTargets
  from espnet.utils.training.batchfy import make_batchset
  from espnet.utils.training.evaluator import BaseEvaluator
  from espnet.utils.training.iterators import ShufflingEnabler
  from espnet.utils.training.tensorboard_logger import TensorboardLogger
  from espnet.utils.training.train_utils import check_early_stop, set_early_stop
label_desc: Use image node_id 2 for calling the CustomUpdater obj's underlying member method code with example usage: obj.update_core() without return types