You could run a quick test and check, if the gradients are calculated:
squeeze = Squeeze(dim=2)
x = torch.randn(18, 18, 1, 512, requires_grad=True)
out = squeeze(x)
out.backward(torch.ones_like(out))
print(x.grad)
tensor([[[[1., 1., 1.,  ..., 1., 1., 1.]],

         [[1., 1., 1.,  ..., 1., 1., 1.]],

         [[1., 1., 1.,  ..., 1., 1., 1.]],

         ...,