def compute_loss(params: AttributeDict, model: nn.Module, batch: dict, graph_compiler: CtcTrainingGraphCompiler, is_training: bool) -> Tuple[(Tensor, MetricsTracker)]:
    '\n    Compute CTC loss given the model and its inputs.\n\n    Args:\n      params:\n        Parameters for training. See :func:`get_params`.\n      model:\n        The model for training. It is an instance of TdnnLstm in our case.\n      batch:\n        A batch of data. See `lhotse.dataset.K2SpeechRecognitionDataset()`\n        for the content in it.\n      graph_compiler:\n        It is used to build a decoding graph from a ctc topo and training\n        transcript. The training transcript is contained in the given `batch`,\n        while the ctc topo is built when this compiler is instantiated.\n      is_training:\n        True for training. False for validation. When it is True, this\n        function enables autograd during computation; when it is False, it\n        disables autograd.\n    '
    device = graph_compiler.device
    feature = batch['inputs']
    feature = feature.permute(0, 2, 1)
    assert (feature.ndim == 3)
    feature = feature.to(device)
    with torch.set_grad_enabled(is_training):
        nnet_output = model(feature)
    supervisions = batch['supervisions']
    (supervision_segments, texts) = encode_supervisions(supervisions, subsampling_factor=params.subsampling_factor)
    decoding_graph = graph_compiler.compile(texts)
    dense_fsa_vec = k2.DenseFsaVec(nnet_output, supervision_segments, allow_truncate=(params.subsampling_factor - 1))
    loss = k2.ctc_loss(decoding_graph=decoding_graph, dense_fsa_vec=dense_fsa_vec, output_beam=params.beam_size, reduction=params.reduction, use_double_scores=params.use_double_scores)
    assert (loss.requires_grad == is_training)
    info = MetricsTracker()
    info['frames'] = supervision_segments[:, 2].sum().item()
    info['loss'] = loss.detach().cpu().item()
    return (loss, info)
Compute CTC loss given the model and its inputs.

Args:
  params:
    Parameters for training. See :func:`get_params`.
  model:
    The model for training. It is an instance of TdnnLstm in our case.
  batch:
    A batch of data. See `lhotse.dataset.K2SpeechRecognitionDataset()`
    for the content in it.
  graph_compiler:
    It is used to build a decoding graph from a ctc topo and training
    transcript. The training transcript is contained in the given `batch`,
    while the ctc topo is built when this compiler is instantiated.
  is_training:
    True for training. False for validation. When it is True, this
    function enables autograd during computation; when it is False, it
    disables autograd.
def compute_loss(params: AttributeDict, model: nn.Module, batch: dict, graph_compiler: CtcTrainingGraphCompiler, is_training: bool) -> Tuple[(Tensor, MetricsTracker)]:
    '\n    Compute CTC loss given the model and its inputs.\n\n    Args:\n      params:\n        Parameters for training. See :func:`get_params`.\n      model:\n        The model for training. It is an instance of TdnnLstm in our case.\n      batch:\n        A batch of data. See `lhotse.dataset.K2SpeechRecognitionDataset()`\n        for the content in it.\n      graph_compiler:\n        It is used to build a decoding graph from a ctc topo and training\n        transcript. The training transcript is contained in the given `batch`,\n        while the ctc topo is built when this compiler is instantiated.\n      is_training:\n        True for training. False for validation. When it is True, this\n        function enables autograd during computation; when it is False, it\n        disables autograd.\n    '
    device = graph_compiler.device
    feature = batch['inputs']
    feature = feature.permute(0, 2, 1)
    assert (feature.ndim == 3)
    feature = feature.to(device)
    with torch.set_grad_enabled(is_training):
        nnet_output = model(feature)
    supervisions = batch['supervisions']
    (supervision_segments, texts) = encode_supervisions(supervisions, subsampling_factor=params.subsampling_factor)
    decoding_graph = graph_compiler.compile(texts)
    dense_fsa_vec = k2.DenseFsaVec(nnet_output, supervision_segments, allow_truncate=(params.subsampling_factor - 1))
    loss = k2.ctc_loss(decoding_graph=decoding_graph, dense_fsa_vec=dense_fsa_vec, output_beam=params.beam_size, reduction=params.reduction, use_double_scores=params.use_double_scores)
    assert (loss.requires_grad == is_training)
    info = MetricsTracker()
    info['frames'] = supervision_segments[:, 2].sum().item()
    info['loss'] = loss.detach().cpu().item()
    return (loss, info)