chainer.function_hooks.TimerHook¶
- class chainer.function_hooks.TimerHook[source]¶
Function hook for measuring elapsed time of functions.
Example
Code example:
from chainer.function_hooks import TimerHook hook = TimerHook() with hook: trainer.run() hook.print_report()
Output example:
FunctionName ElapsedTime Occurrence LinearFunction 1.24sec 3900 ReLU 0.59sec 2600 SoftmaxCrossEntropy 0.82sec 1300 Accuracy 0.18sec 700
where FunctionName is the name of function that calls the hook, and ElapsedTime is the elapsed time the function consumed, and Occurrence is the number of calls.
- Variables
call_history – List of measurement results. It consists of pairs of the name of the function that calls this hook and the elapsed time the function consumes.
Methods
- added(function)[source]¶
Callback function invoked when the function hook is registered
- Parameters
function (FunctionNode) – Function object to which the function hook is added.
None
if the function hook is registered globally.
- backward_postprocess(function, in_data, out_grad)[source]¶
Callback function invoked after backward propagation.
- Parameters
function (FunctionNode) – Function object to which the function hook is registered.
in_data (tuple of N-dimensional array) – Input of forward propagation.
out_grad (tuple of N-dimensional array) – Gradient data of backward propagation.
- backward_preprocess(function, in_data, out_grad)[source]¶
Callback function invoked before backward propagation.
- Parameters
function (FunctionNode) – Function object to which the function hook is registered.
in_data (tuple of N-dimensional array) – Input data of forward propagation.
out_grad (tuple of N-dimensional array) – Gradient data of backward propagation.
- deleted(function)[source]¶
Callback function invoked when the function hook is unregistered
- Parameters
function (FunctionNode) – Function object from which the function hook is deleted.
None
if the function hook was registered globally.
- forward_postprocess(function, in_data)[source]¶
Callback function invoked after forward propagation.
- Parameters
function (FunctionNode) – Function object to which the function hook is registered.
in_data (tuple of N-dimensional array) – Input data of forward propagation.
- forward_preprocess(function, in_data)[source]¶
Callback function invoked before forward propagation.
- Parameters
function (FunctionNode) – Function object to which the function hook is registered.
in_data (tuple of N-dimensional array) – Input data of forward propagation.
- print_report(unit='auto', file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>)[source]¶
Prints a summary report of time profiling in functions.
- Parameters
unit (str) – Supplementary units used for computational times. sec, ms, us, ns, auto`(default) and `auto_foreach are supported. If auto, units of times are aligned to the largest, and if auto_foreach, units of times are adjusted for each element.
- summary()[source]¶
Returns a summary of time profiling in functions.
- Returns
A summarized dictionary whose keys are function names and values are dictionaries of elapsed_time and occurrence.
- __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.
Attributes
- name = 'TimerHook'¶
- table = {'ms': 1000, 'ns': 1000000000, 'sec': 1, 'us': 1000000}¶