Update hook system
TODO
-
...
Specification
Hook is an object you can register to a node. We chose to register Hook in Node instead of Operator because node have access to key attributes such as parent and children Node and a name.
Hook define 4 methods the user can override:
-
call_pre_forward
: execute before forward pass -
call_forward
: execute after forward pass -
call_pre_backward
: execute before backward pass (added in case of inplace operator) -
call_backward
: execute after backward pass
Node need a method to remove all hook. Node register himself to the node
Code example
ugly_global_var = 0
class myHook(aidge_core.Hook):
def __init__(self, node):
aidge_core.Hook.__init__(self, node)
global ugly_global_var # You can use global var like in PyTorch
ugly_global_var += 1
def call_pre_hook(self):
pass
def call_hook(self):
pass
# in case of in place operator1
def call_pre_back_hook(self):
pass
def call_back_hook(self):
pass
# v1 proposition
hook_object = myHook(node)
del hook_object # hook destructor remove himself from node
hooks = []
for n in graph.get_node():
hooks.append(myHook(n))
Test to add:
Edited by Cyril Moineau