Why do we need to define a function to call another function?

In the implementation of ResNet architecture in Pytorch I encountered the code below which is from line 264 til 283:

def _forward_impl(self, x: Tensor) -> Tensor:
    # See note [TorchScript super()]
    x = self.conv1(x)
    x = self.bn1(x)
    x = self.relu(x)
    x = self.maxpool(x)

    x = self.layer1(x)
    x = self.layer2(x)
    x = self.layer3(x)
    x = self.layer4(x)

    x = self.avgpool(x)
    x = torch.flatten(x, 1)
    x = self.fc(x)

    return x

def forward(self, x: Tensor) -> Tensor:
    return self._forward_impl(x)

What is the purpose of _forward_impl? Why didn't the coder bring what is happening inside _forward_impl into forward itself and getting ride of _forward_impl? I see _forward_impl looks like a private method, since it has underscore at the start of its name, however, I cannot yet see what the purpose of _forward_impl is.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum