Ops, I found this in the CTC docs:

In order to use CuDNN, the following must be satisfied: targets must be in concatenated format, all input_lengths must be T. blank=0, target_lengths ≤256, the integer arguments must be of dtype torch.int32.
The regular implementation uses the (more common in PyTorch) torch.long dtype.

So I guess I cannot use different values for input_lengths in CUDA, I will try on CPU. Anyway even with fixed lengths I was using LongTensor instead of torch.int32 and no errors were raised. I don’t know if the result is still correct in this case.