Your code is unfortunately not executable, so I can just make a few suggestions.
I assume this line of code is wrong:
patches = patches.contiguous().view(-1, in_channels,k, k)

patches should have the shape [2, 6, 8, 256, 256] ([channels, patch_h, patch_w, h, w]), so the view call would interleave the data.
Probably patches.permute(1, 2, 0, 3, 4).view(-1, in_channels, k, k) would work.