Debug mode

In debug mode, Chainer checks values of variables on runtime and shows more detailed error messages. It helps you to debug your programs. Instead it requires additional overhead time.

In debug mode, Chainer checks all results of forward and backward computation, and if it founds a NaN value, it raises RuntimeError. Some functions and links also check validity of input values.

As of v2.0.0, it is recommended to turn on the debug mode using chainer.config.debug. See Configuring Chainer for the way to use the config object. We leave the reference of the conventional ways (which have been available since Chainer v1) as follows.

chainer.is_debug()[source]

Get the debug mode.

Returns:Return True if Chainer is in debug mode.
Return type:bool
chainer.set_debug(debug)[source]

Set the debug mode.

Note

This method changes global state. When you use this method on multi-threading environment, it may affects other threads.

Parameters:debug (bool) – New debug mode.
class chainer.DebugMode(debug)[source]

Debug mode context.

This class provides a context manager for debug mode. When entering the context, it sets the debug mode to the value of debug parameter with memorizing its original value. When exiting the context, it sets the debug mode back to the original value.

Deprecated since version v2.0.0: DebugMode is deprecated. Use using_config('debug', debug) instead.

Parameters:debug (bool) – Debug mode used in the context.