unfold can be used to get patches on your input tensor.
Here is a small example:
x = torch.randn(1, 3, 12, 12)  # batch, c, h, w
kh, kw = 3, 3  # kernel size
dh, dw = 3, 3  # stride
patches = x.unfold(2, kh, dh).unfold(3, kw, dw)
print(patches.size())
> torch.Size([1, 3, 4, 4, 3, 3])
patches = patches.contiguous().view(
    patches.size(0), patches.size(1), -1, kh, kw)
print(patches.shape)
> torch.Size([1, 3, 16, 3, 3])

This code will create 16 3-by-3 patches, which can be used for further calculation.
Note that you can adjust the kernel size and stride for your use case.