look at torch.unfold (it is an autograd supported operation).
You can extract patches from an image using that, and then convolve on the extracted patches.
In the backward, it automatically computes the correct gradients.
For example see https://github.com/pytorch/pytorch/pull/1523#issue-227526015 100