Would calling your custom function inside the forward
work?
E.g.
...
def forward(self, x):
l = self.loss(x)
return l
It’s a bit of nitpicking and if you are sure you won’t use hooks and always call the custom method, you could of course just go for it.
However, if other users would like to use your module in an nn.Sequential
or just use it as a standard nn.Module
, they will face a NotImplementedError
.
Hooks are used to e.g. get intermediate activations as explained here.