How Forward method is being called

Hello Guys,
I’ve some knowledge of python and I’m trying to figure out one thing . I need some help here

Just like in file we have a class << class ConvLearner(Learner): >>. To use this class’s method (for e.g def pretrained() ), we are writing statements like

Similarly I see a lot of forward function which plays a crucial role , but I didnt see anywhere we calling a forward function . Can anyone point out to me how forward function is being called?

Thanks ,

When you have something inherited from nn.Module class it overloads the call operator with forward. So say you have a vgg model, and you create an object say vggmod = VggModel(). Now doing vggmod(x) is equivalent to doing vggmod.forward(x).

Hope that makes it clear. Cheers

1 Like

Look in the file in the Stepper class’s step method. The second line is

output = self.m(*xs)

It’s the job of the model stepper to call the module which Arka has already stated calls the forward method along with any registered hooks. Also, step method calculates the loss, zero’s the gradients and calls backward along with other things. The fit method from that same file calls the model stepper’s step method.