- class chainer.training.extensions.DumpGraph(root_name, filename='cg.dot', variable_style=None, function_style=None)¶
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.
In its initializer, it turns on the
At the first iteration, it dumps the graph using the graph held by the reported variable.
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.
keep_graph_on_reportflag 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.
With the default setting, the
DumpGraphextension is called at the first iteration. Since
Evaluatoris 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_nameis 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.
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
Trainercan 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.
ExponentialShiftextension 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
ExponentialShiftextension recovers it in its
initializemethod 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)¶
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.
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, /)¶
- __ne__(value, /)¶
- __lt__(value, /)¶
- __le__(value, /)¶
- __gt__(value, /)¶
- __ge__(value, /)¶
- default_name = 'dump_graph'¶
- name = None¶
- priority = 100¶