look at unfold: http://pytorch.org/docs/master/tensors.html?highlight=unfold#torch.Tensor.unfold 783
You can do what you want with two unfolds (first unfold in dimension 0 and second unfold in dimension 1)