I made this change to the code because I realized that at the last iteration ‘start = tensor (1054) and end = tensor (1028)’, but I would probably lose data.
Do you have any better ideas?
class MySampler(torch.utils.data.Sampler):
    def __init__(self, end_idx, seq_length):
        indices = []
        for i in range(len(end_idx) - 1):
            start = end_idx[i]
            end = end_idx[i + 1] - seq_length
            if start > end:
                pass
            else:
                indices.append(torch.arange(start, end))
        indices = torch.cat(indices)
        self.indices = indices