Answer:
There is a parameter in F.avg_pool2d() to handle this (count_include_pad=True).
According to the documentation https://pytorch.org/docs/stable/nn.html#torch.nn.AvgPool2d 61, by default count_include_pad=True. But by default count_include_pad=False.
EIther the documentation has to be modified or default parameter has to be count_include_pad=True