PyTorch provide the powerful function unfold, through both torch.nn.functional.unfold and the builtin function for tensor torch.Tensor.unfold. It seems the latter is easier to use, and it is more general as it is not restricted to 4D tensor. However, the former implementation support dilation, while the latter does not.
Does anyone has method to augment the builtin function implementation to make it support dilation?
They are really doing different things. nn.Unfold gets the sliding window from image tensors. Tensor.unfold just unfolds along a single dimension. (You can think of the former as doing the latter along dim 2 and dim 3 at the same time). For Tensor.unfold, step arg is probably what you want.