Hmm. I see I completely missed the point (probably because I am playing lstms atm haha).
I don’t see any easy solution, unfortunately. One way could be first sort your data in order of length. Make shuffle=False in the Dataloader. Say for the first 100 indices you only have sequences of length max 4, so you can adjust your Dataset output accordingly. Not sure if there are any easier or better approaches available.