Solved by PersiQ in post #3 
              
              
                hey sorry for the late response and thank you for your reply. 
I tried using use reduction=‘mean’ and zero_infinity=“True” but they didn’t work. 
It seems that by doing this : loss = ctc_loss(output, y.cpu(), x_lengths.cpu(), y_lengths.cpu()) and updating Pytorch, it made it work perfectly now.