# chainer.training.extensions.DumpGraph¶

class chainer.training.extensions.DumpGraph(root_name, filename='cg.dot', 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.

Note

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.

Parameters
• 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 build_computational_graph() for the variable_style and function_style arguments.

Methods

__call__(trainer)[source]

Invokes the extension.

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

Parameters

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

finalize()[source]

Finalizes the extension.

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

initialize(trainer)[source]

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.

Parameters

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.

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

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

• tb (traceback) – traceback object of the exception

serialize(serializer)[source]

Serializes the extension state.

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

trigger(trainer)[source]

tuple() -> empty tuple tuple(iterable) -> tuple initialized from iterable’s items

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

__eq__()

Return self==value.

__ne__()

Return self!=value.

__lt__()

Return self<value.

__le__()

Return self<=value.

__gt__()

Return self>value.

__ge__()

Return self>=value.

Attributes

default_name = 'dump_graph'
name = None
priority = 100