def __init__(self, cuda, word_dim, tag_dim, mem_dim, criterion):
.. # do something
model = MyModel()
Is there any different if I called
Because only when I call model.forward(input), IDE (in this case, Pycharm) suggest me argument for forward function.
You should avoid calling
The difference is that all the hooks are dispatched in the
__call__ function, so if you call
.forward and have hooks in your model, the hooks won’t have any effect
But who/what exactly calls the .forward() function? is it the init()? In my case I am being told in error that the .forward is not getting all the arguments it needs, but I am not able to figure out where in the control flow its getting lost.
As @fmassa said,
forward is called in the
.__call__ function. Have a look at the line of code.
What so you mean by the “hooks”?
Just avoiding using forward directly doesn’t really solve the issue that it breaks IDE support. One potential solution could be this Solution to different forward for train and inference + IDE support for forward args . Here I just wrapped nn.Module to allow a forward method with both hooks and IDE support is retained.
I haven’t use “hooks” yet, but it is like event trigger.