That is not quite what I am looking for. Here is an example via loop:

A=torch.arange(start=1, end=101)
def stack_sequence(sequence, window_size):
thread_range=sequence.size(-1)-window_size+1
out=torch.empty(0,window_size)
for i in range(thread_range):
out=torch.cat([out,sequence[i:i+window_size].unsqueeze(0)])
return out
B = stack_sequence(A,10)
print(B)

What I am looking for is a more efficient solution, if one exists.

Thanks @anantguptadbl . That works much faster than the loop.

import torch
import time
def stack_sequence(sequence, window_size):
thread_range=sequence.size(-1)-window_size+1
out=torch.empty(0,window_size)
for i in range(thread_range):
out=torch.cat([out,sequence[i:i+window_size].unsqueeze(0)])
return out
def stack_sequence2(sequence, window_size):
return torch.stack([sequence[x:x+window_size] for x in range(sequence.size()[-1]-window_size+1)])
A=torch.arange(start=1, end=100001)
now=time.time()
stack_sequence(A, 10)
print(time.time()-now)
now=time.time()
stack_sequence2(A,10)
print(time.time()-now)