I think I could solve it. For who has the same problem, here is the code:
a = torch.tensor([[[[ 1.,  2.,  3., 4., 5., 6., 7., 8.]]],
        [[[9., 10., 11., 12., 13., 14., 15., 16.]]]])
print(a)
b = a.view(2,1,2,4)
print(b)
c = b.unfold(2, 2, 2).unfold(3, 2, 2).contiguous().view(2, 2, 2, 2)
print(c)
d= c.sum(2, keepdim=True).sum(3, keepdim=True)
print(d)

Regards