Solved by vadimkantorov in post #3 
              
              
                I’ve tried  the following: 
def ctc_alignment_targets(logits, targets, input_lengths, target_lengths, blank, dim = 1):
    with torch.enable_grad():
        logits = logits.detach().requires_grad_()
        log_probs = F.log_softmax(logits, dim = dim)
        ctc_loss = F.ctc_loss(log_probs.permute(…