Understanding backward hooks
I wrote this snippet below to try and understand what's going on with these hooks. class Model(nn.Module): def __init__(self): super(Model, self).__init__() self.fc1 = nn.Linear(10,5) self.fc2 = nn.Linear(5,1) self.fc1.register_forward_hook(self._forward_hook) self.fc1.register_backward_hook(self._backward_hook) def forward(self, inp): return self.fc2(self.fc1(inp)) def _forward_hook(self, module, input, output): print(type(input)) print(len(input)) print(type(output)) print(input[0].shape) print(output.shape) print() def _backward_hook(self, module, grad_input, grad_output): print(type(grad_i
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.