Splitting tensor into sub-tensors in overlapping fashion

Is there any way to Splitting tensor into sub-tensors in overlapping fashion? My input is video frames B x T x C x H x W. I want to split it become sub-tensors for example, frame1~5, frame 2~6, frame 3~7,… . Is there any built-in pytorch function to do that?

Yes, you can use tensor.unfold:

x = torch.arange(10)
y = x.unfold(dimension=0, size=5, step=1)
print(y)
> tensor([[0, 1, 2, 3, 4],
          [1, 2, 3, 4, 5],
          [2, 3, 4, 5, 6],
          [3, 4, 5, 6, 7],
          [4, 5, 6, 7, 8],
          [5, 6, 7, 8, 9]])