pytorch中的钩子(Hook):
- torch.autograd.Variable.register_hook
- torch.nn.Module.register_backward_hook
- torch.nn.Module.register_forward_hook
第一个是register_hook,是针对Variable对象的,后面的两个:register_backward_hook和register_forward_hook是针对nn.Module这个对象的。
就是反向传播过程中,可以把中间量的梯度弄出来搞点什么,还能改变这个梯度,但是不会改变输入输出值。
- https://pytorch.org/docs/stable/nn.html
- https://pytorch.org/docs/stable/autograd.html
- https://pytorch.org/docs/stable/nn.html