class, filename='', variable_style=None, function_style=None)[source]

Trainer extension to dump a computational graph.

This extension dumps a computational graph. The graph is output in DOT language. If graphviz is available, this also renders and saves the image of the computational graph.

It only dumps a graph at the first invocation.


The computational graph is not kept by default. This extension changes this behavior until the first invocation. It is strongly recommended that you use it with the default trigger setting.

The detailed behavior of this extension is as follows.

  1. In its initializer, it turns on the chainer.config.keep_graph_on_report flag.

  2. At the first iteration, it dumps the graph using the graph held by the reported variable.

  3. After dumping the graph, it turns off the flag (if it was originally turned off) so that any variable reported afterward does not hold a computational graph.

When the keep_graph_on_report flag is turned on, the computational graph created by the updater is kept during the invocation of extensions. It will cause an unnecessarily large memory consumption when an extension also uses a large amount of memory, e.g. Evaluator.

With the default setting, the DumpGraph extension is called at the first iteration. Since Evaluator is not called at the first iteration in most cases, it does not cause any memory problem.

  • root_name (str) – Name of the root of the computational graph. The root variable is retrieved by this name from the observation dictionary of the trainer.

  • filename (str) – Output file name. For historical reasons out_name is also accepted as an alias of this argument.

  • variable_style (dict) – Dot node style for variables. Each variable is rendered by an octagon by default.

  • function_style (dict) – Dot node style for functions. Each function is rendered by a rectangular by default.

See also

See build_computational_graph() for the variable_style and function_style arguments.



Invokes the extension.

Implementations should override this operator. This method is called at iterations which the corresponding trigger accepts.


trainer (Trainer) – Trainer object that calls this operator.


Finalizes the extension.

This method is called at the end of the training loop.


Initializes up the trainer state.

This method is called before entering the training loop. An extension that modifies the state of Trainer can override this method to initialize it.

When the trainer has been restored from a snapshot, this method has to recover an appropriate part of the state of the trainer.

For example, ExponentialShift extension changes the optimizer’s hyperparameter at each invocation. Note that the hyperparameter is not saved to the snapshot; it is the responsibility of the extension to recover the hyperparameter. The ExponentialShift extension recovers it in its initialize method if it has been loaded from a snapshot, or just setting the initial value otherwise.


trainer (Trainer) – Trainer object that runs the training loop.

on_error(trainer, exc, tb)[source]

Handles the error raised during training before finalization.

This method is called when an exception is thrown during the training loop, before finalize. An extension that needs different error handling from finalize, can override this method to handle errors.

  • trainer (Trainer) – Trainer object that runs the training loop.

  • exc (Exception) – arbitrary exception thrown during update loop.

  • tb (traceback) – traceback object of the exception


Serializes the extension state.

It is called when a trainer that owns this extension is serialized. It serializes nothing by default.


Built-in immutable sequence.

If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable’s items.

If the argument is a tuple, the return value is the same object.

__eq__(value, /)

Return self==value.

__ne__(value, /)

Return self!=value.

__lt__(value, /)

Return self<value.

__le__(value, /)

Return self<=value.

__gt__(value, /)

Return self>value.

__ge__(value, /)

Return self>=value.


default_name = 'dump_graph'
name = None
priority = 100