class_docstr: The standard training loop in Chainer.
  
  Trainer is an implementation of a training loop. Users can invoke the
  training by calling the :meth:`run` method.
  
  Each iteration of the training loop proceeds as follows.
  
  - Update of the parameters. It includes the mini-batch loading, forward
    and backward computations, and an execution of the update formula.
    These are all done by the update object held by the trainer.
  - Invocation of trainer extensions in the descending order of their
    priorities. A trigger object is attached to each extension, and it
    decides at each iteration whether the extension should be executed.
    Trigger objects are callable objects that take the trainer object as the
    argument and return a boolean value indicating whether the extension
    should be called or not.
  
  Extensions are callable objects that take the trainer object as the
  argument. There are three ways to define custom extensions: inheriting the
  :class:`Extension` class, decorating functions by :func:`make_extension`,
  and defining any callable including lambda functions. See
  :class:`Extension` for more details on custom extensions and how to
  configure them.
  
  Users can register extensions to the trainer by calling the :meth:`extend`
  method, where some configurations can be added.
  
  - Trigger object, which is also explained above. In most cases,
    :class:`IntervalTrigger` is used, in which case users can simply specify
    a tuple of the interval length and its unit, like
    ``(1000, 'iteration')`` or ``(1, 'epoch')``.
  - The order of execution of extensions is determined by their priorities.
    Extensions of higher priorities are invoked earlier. There are three
    standard values for the priorities:
  
    - ``PRIORITY_WRITER``. This is the priority for extensions that write
      some records to the :attr:`observation` dictionary. It includes cases
      that the extension directly adds values to the observation dictionary,
      or the extension uses the :func:`chainer.report` function to report
      values to the observation dictionary.
    - ``PRIORITY_EDITOR``. This is the priority for extensions that edit the
      :attr:`observation` dictionary based on already reported values.
    - ``PRIORITY_READER``. This is the priority for extensions that only read
      records from the :attr:`observation` dictionary. This is also suitable
      for extensions that do not use the :attr:`observation` dictionary at
      all.
  
  The current state of the trainer object and objects handled by the trainer
  can be serialized through the standard serialization protocol of Chainer.
  It enables us to easily suspend and resume the training loop.
  
  .. code-block:: python
  
      >>> serializers.save_npz('my.trainer', trainer)  # To suspend and save
      >>> serializers.load_npz('my.trainer', trainer)  # To load and resume
  
  The :meth:`~chainer.training.extensions.snapshot` method makes regular
  snapshots of the :class:`~chainer.training.Trainer` object during training.
  
  .. note::
     The serialization does not recover everything of the training loop. It
     only recovers the states which change over the training (e.g.
     parameters, optimizer states, the batch iterator state, extension
     states, etc.). You must initialize the objects correctly before
     deserializing the states.
  
     On the other hand, it means that users can change the settings on
     deserialization. For example, the exit condition can be changed on the
     deserialization, so users can train the model for some iterations,
     suspend it, and then resume it with larger number of total iterations.
  
  During the training, it also creates a :class:`~chainer.Reporter` object to
  store observed values on each update. For each iteration, it creates a
  fresh observation dictionary and stores it in the :attr:`observation`
  attribute.
  
  Links of the target model of each optimizer are registered to the reporter
  object as observers, where the name of each observer is constructed as the
  format ``<optimizer name><link name>``. The link name is given by the
  :meth:`chainer.Link.namedlink` method, which represents the path to each
  link in the hierarchy. Other observers can be registered by accessing the
  reporter object via the :attr:`reporter` attribute.
  
  The default trainer is `plain`, i.e., it does not contain any extensions.
  
  Args:
      updater (~chainer.training.Updater): Updater object. It defines how to
          update the models.
      stop_trigger: Trigger that determines when to stop the training loop.
          If it is not callable, it is passed to :class:`IntervalTrigger`.
      out: Output directory.
      extensions: Extensions registered to the trainer.
  
  Attributes:
      updater: The updater object for this trainer.
      stop_trigger: Trigger that determines when to stop the training loop.
          The training loop stops at the iteration on which this trigger
          returns ``True``.
      observation: Observation of values made at the last update. See the
          :class:`Reporter` class for details.
      out: Output directory.
      reporter: Reporter object to report observed values.
docstr: Returns the extension of a given name.
  
  Args:
      name (str): Name of the extension.
  
  Returns:
      Extension.
docstr_tok: ["Returns","the","extension","of","a","given","name",".","Args",":","name","(","str",")",":","Name","of","the","extension",".","Returns",":","Extension","."]
code: def get_extension(self, name):
      """Returns the extension of a given name.
  
      Args:
          name (str): Name of the extension.
  
      Returns:
          Extension.
  
      """
      extensions = self._extensions
      if name in extensions:
          return extensions[name].extension
      else:
          raise ValueError("extension %s not found" % name)
  
imports: import collections
  import os
  import sys
  import time
  import traceback
  import six
  from chainer import reporter
  from chainer import serializer
  from chainer.training import extension
  from chainer.training import trigger
  from chainer.utils import argument
label_desc: Use image node_id 5 for calling the Trainer obj's underlying member method code with example usage: obj.get_extension(name) and returns: extensions