class_docstr: CTC-attention hybrid Encoder-Decoder model
class_docstr_tok: ["CTC-attention","hybrid","Encoder-Decoder","model"]
docstr: Compute negative log likelihood(nll) from transformer-decoder
  
  To avoid OOM, this fuction seperate the input into batches.
  Then call nll for each batch and combine and return results.
  Args:
      encoder_out: (Batch, Length, Dim)
      encoder_out_lens: (Batch,)
      ys_pad: (Batch, Length)
      ys_pad_lens: (Batch,)
      batch_size: int, samples each batch contain when computing nll,
                  you may change this to avoid OOM or increase
                  GPU memory usage
docstr_tok: ["Compute","negative","log","likelihood","(","nll",")","from","transformer-decoder","To","avoid","OOM",",","this","fuction","seperate","the","input","into","batches",".","Then","call","nll","for","each","batch","and","combine","and","return","results",".","Args",":","encoder_out",":","(","Batch",",","Length",",","Dim",")","encoder_out_lens",":","(","Batch",",",")","ys_pad",":","(","Batch",",","Length",")","ys_pad_lens",":","(","Batch",",",")","batch_size",":","int",",","samples","each","batch","contain","when","computing","nll",",","you","may","change","this","to","avoid","OOM","or","increase","GPU","memory","usage"]
code: def batchify_nll(
      self,
      encoder_out: torch.Tensor,
      encoder_out_lens: torch.Tensor,
      ys_pad: torch.Tensor,
      ys_pad_lens: torch.Tensor,
      batch_size: int = 100,
  ):
      """Compute negative log likelihood(nll) from transformer-decoder
  
      To avoid OOM, this fuction seperate the input into batches.
      Then call nll for each batch and combine and return results.
      Args:
          encoder_out: (Batch, Length, Dim)
          encoder_out_lens: (Batch,)
          ys_pad: (Batch, Length)
          ys_pad_lens: (Batch,)
          batch_size: int, samples each batch contain when computing nll,
                      you may change this to avoid OOM or increase
                      GPU memory usage
      """
      total_num = encoder_out.size(0)
      if total_num <= batch_size:
          nll = self.nll(
              encoder_out, encoder_out_lens, ys_pad, ys_pad_lens
          )
      else:
          nll = []
          start_idx = 0
          while True:
              end_idx = min(start_idx + batch_size, total_num)
              batch_encoder_out = encoder_out[start_idx:end_idx, :, :]
              batch_encoder_out_lens = encoder_out_lens[
                  start_idx:end_idx
              ]
              batch_ys_pad = ys_pad[start_idx:end_idx, :]
              batch_ys_pad_lens = ys_pad_lens[start_idx:end_idx]
              batch_nll = self.nll(
                  batch_encoder_out,
                  batch_encoder_out_lens,
                  batch_ys_pad,
                  batch_ys_pad_lens,
              )
              nll.append(batch_nll)
              start_idx = end_idx
              if start_idx == total_num:
                  break
          nll = torch.cat(nll)
      assert nll.size(0) == total_num
      return nll
  
imports: import logging
  from contextlib import contextmanager
  from typing import Dict, List, Optional, Tuple, Union
  import torch
  from packaging.version import parse
  from typeguard import check_argument_types
  from espnet2.asr.ctc import CTC
  from espnet2.asr.decoder.abs_decoder import AbsDecoder
  from espnet2.asr.encoder.abs_encoder import AbsEncoder
  from espnet2.asr.frontend.abs_frontend import AbsFrontend
  from espnet2.asr.postencoder.abs_postencoder import AbsPostEncoder
  from espnet2.asr.preencoder.abs_preencoder import AbsPreEncoder
  from espnet2.asr.specaug.abs_specaug import AbsSpecAug
  from espnet2.asr.transducer.error_calculator import ErrorCalculatorTransducer
  from espnet2.asr_transducer.utils import get_transducer_task_io
  from espnet2.layers.abs_normalize import AbsNormalize
  from espnet2.torch_utils.device_funcs import force_gatherable
  from espnet2.train.abs_espnet_model import AbsESPnetModel
  from espnet.nets.e2e_asr_common import ErrorCalculator
  from espnet.nets.pytorch_backend.nets_utils import th_accuracy
  from espnet.nets.pytorch_backend.transformer.add_sos_eos import add_sos_eos
  from espnet.nets.pytorch_backend.transformer.label_smoothing_loss import LabelSmoothingLoss
label_desc: Use image node_id 7 for calling the ESPnetASRModel obj's underlying member method code with example usage: obj.batchify_nll(encoder_out, encoder_out_lens, ys_pad, ys_pad_lens, batch_size) and returns: nll