Understanding Pytorch filter function
I was going through the documentation of PyTorch framework and found lots of instances where a variable is assigned a function but when it calls the function the parameters change. Not sure on how this works, any pointers would be helpful.
What I do understand -
def func1(word):
    print(&quot;hello&quot;, word)
var1 = func1

Now in this scenario, var1(&quot;world&quot;) would print the string hello world.
But what I dont understand is some lines from PyTorch like:
def __init__(self, input_size, num_classes): 
    super(NN,self).__init__()
    self.fc1 = nn.Linear(input_size, 50)  
    self.fc2 = nn.Linear(50, num_classes)  
def forward(self,x):
    x = F.relu(self.fc1(x))
    x = self.fc2(x)
    return x

How do we know that only 1 param should be passed to self.fc2. It seems to be independent of the number of params defined in nn.Linear
Does nn.Linear return a function like func1 that we store in var1 from the earlier example? If so is there any documentation on what is being returned?
I do find the usage for each function in the nn module but is there something that gives more details on how exactly this works?

nn.Linear is not a function (and neither are all the other layers, like the convolution layers, batchnorms...), but a functor, which means it is a class which implements the __call__ method/operator which is called when you write something like self.fc2(x).
The __call__ operator is implemented in the nn.Module base class, and it's a call to another method _call_impl which itself calls (basically) the forward method. Therefore, thanks to inheritance magic, when you make a class derive from nn.Module, you only need to implement the forward method.
The signature of this method is kinda up to you, but in most cases it will take a tensor as input and return another tensor.
In summary  :
# calls the constructor of nn.Linear. self.fc1 is now a functor
self.fc1 = nn.Linear(20, 10)
# calls the fc1 functor on an input 
y = self.fc1(torch.randn(2, 10))
# which is basically doing
y = self.fc1.forward(torch.randn(2, 10))

