What does calling self within a class do?
I noticed in the documentation for Pytorch Lightning, it was mentioned you can call the forward method from another method in the same class just by calling self(x). I haven't been able to find any info about how this works. I always thought you would call the method using self.forward
Evidently, it calls the forward method but how? Is there any python documentation about what's going on?
I found this at the following URL:
https://pytorch-lightning.readthedocs.io/en/stable/new-project.html
The specific code fragment is this:
def training_step(self, batch, batch_idx):
    ...
    z = self(x)


Generally speaking, in python, when &quot;calling&quot; an object, you are invoking its __call__ method. That is,
  self(x)

is equivalent to
  self.__call__(x)

For pytorch nn.Module (and all derivative classes) __call__ wraps around the module's forward function, therefore, from your perspective self(x) is basically forwarding x through the module self.
