You can use the advanced indexing that has been used in master recently to do this:
import torch
from torch import nn
from torch.autograd import Variable

avgpool=nn.AvgPool2d(2,2)

a = Variable(torch.rand(10, 20, 50, 50))

# nn implementation
out_nn = avgpool(a)

# Manual implementation
out_man = (a[:,:,::2,::2] + a[:,:,1::2,::2] + a[:,:,::2,1::2] + a[:,:,1::2,1::2]) / 4

print((out_nn - out_man).abs().mean())