Since the current shape is not divisible by the kernel size and the stride without losing pixels, you would have to pad the input manually before applying unfold.
I’ve just used some values to increase the size to the next multiple of 128.
Then a permute with view will reconstruct the original input:
img = torch.randn(3, 5176, 3793)
img = F.pad(img, (23, 24, 36, 36))
patches = img.data.unfold(0, 3, 3).unfold(1, 128, 128).unfold(2, 128, 128)

re = patches.permute(0, 3, 1, 4, 2, 5).contiguous().view_as(img)
print((re == img).all())
> tensor(1, dtype=torch.uint8)