-1

I am trying to use Linear class of Pytorch module.In this automatically forward method is called once I create an instance of the class.Can anyone explain me from basics (If I can get code of Linear class of pytorch that would be great)

from torch.nn mport Linear
model=Linear(in_features=1,out_features=1)
x=torch.tensor([1])
y=model(x)

I am not able to understand how model(x) displays the result.As per my understanding model.forward() should display the actual result It would be great if someone explain me from basics (Would be great if someone can share the link of code of Linear class in pytorch)

1 Answers1

0

In the source, you'll see that the __call__ method of any Module in turn calls the forward method, so calling model(x) in your case is kind of like calling model.forward(x), but not exactly, due to the reasons explained here.

If you're not familiar with the __call__ method, just know roughly that it makes an object of a class callable.

This same question is answered in this Pytorch forum post.

Proyag
  • 1,719
  • 12
  • 22