Difference between mean() method and AvgPooling

In the code snippet below, would there be any difference in backpropagation between the mean() method and AvgPooling2d() functional? I see only the tensor size is changing

x = torch.autograd.Variable(torch.rand(1,1,2,2));
avgpool = nn.AvgPool2d(2,2);

------- option 1 --------

x = x.mean();

------ option 2 ----------

x = avgpool(x);

other codes and finally loss


loss = ***
loss.backward();

The gradient should be the same:

x = Variable(torch.rand(1,1,2,2), requires_grad=True)
avgpool = nn.AvgPool2d(2,2)

y = x.mean()
y.backward()
print(x.grad)
x.grad.zero_()
z = avgpool(x)
z.backward()
print(x.grad)

Is there any difference in terms of efficiency or something else?