That part is not working as intended:



 Danielr13:

        for i, (data, target) in enumerate(loader):
            data, target = data.cuda(), target.cuda()
            if batch == 3:
                data = torch.reshape(data, (batch, sequence_length, input_size))
            else:
                data = torch.reshape(data, (4, sequence_length, input_size))
   



From the loader, you get a single (data, target)-pair – at least I assume given the error. You then forcefully reshape the single data item into some kind of batch, where I’m pretty sure you mess up your data. Anyway, you don’t reshape target the same way, so it’s still of size 1.