How could I compute the local mean and variance

I am trying to use sliding window method the compute the local mean and variance withing the sliding window. Does pytorch provide the associated function to do that please?

You can use https://pytorch.org/docs/stable/nn.html#torch.nn.Fold to perform sliding window.