How is self() used in Pytorch to generate predictions?
class MNIST_model(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(input_size, num_classes)

    def forward(self, xb):
        xb = xb.reshape(-1, 28 * 28)
        out = self.linear(xb)
        return out
    
    def training_step(self, batch):
        images, labels = batch
        out = self(images)
        loss = F.cross_entropy(out, labels)
        return loss

I am following the Freecodecamp tutorial.
In the training_step method, the tutorial says
out = self(images) is used to Generate Predictions.
I am not able to understand how is self is being used to get the predictions.

This is actually nothing specific to PyTorch but rather to how Python works.
Using parenthesis on an object or directly on self inside that class will call a special Python function named __call__. This function is available to your class because you're inheriting from nn.Module which implemented it for you.
Here's a minimal example outside of PyTorch:
class A():
    def __call__(self):
        print('calling the object')

    def foo(self):
        self()

Then
&gt;&gt;&gt; x = A()
&gt;&gt;&gt; x.foo() # prints out &quot;calling the object&quot;

