docstr: RNN-T Loss function based on https://github.com/HawkAaron/warp-transducer.
  Optionally, can utilize a numba implementation of the same loss without having to compile the loss,
  albiet there is a small speed penalty for JIT numba compile.
  
  Note:
      Requires Numba 0.53.0 or later to be installed to use this loss function.
  
  Losses can be selected via the config, and optionally be passed keyword arguments as follows.
  
  Examples:
      .. code-block:: yaml
  
          model:  # RNNT Model config
              ...
              loss:
                  loss_name: "warprnnt_numba"
                  warprnnt_numba_kwargs:
                      fastemit_lambda: 0.0
  
  Warning:
      In the case that GPU memory is exhausted in order to compute RNNTLoss, it might cause
      a core dump at the cuda level with the following error message.
  
      ```
          ...
          costs = costs.to(acts.device)
      RuntimeError: CUDA error: an illegal memory access was encountered
      terminate called after throwing an instance of 'c10::Error'
      ```
  
      Please kill all remaining python processes after this point, and use a smaller batch size
      for train, validation and test sets so that CUDA memory is not exhausted.
  
  Args:
      num_classes: Number of target classes for the joint network to predict.
          In all cases (conventional RNNT, multi-blank RNNT, and TDT model), this equals the token-id
          for the standard "blank" symbol. In particular, say V is the number of non-blank tokens in
          the vocabulary, then in the case of,
          standard RNNT: num_classes = V
          multiblank RNNT: num_classes = V + number-big-blanks (since we store big-blanks before
                           standard blank, and the standard blank is the last symbol in the vocab)
          TDT: num_classes = V. Note, V here does not include any of the "duration outputs".
  
      reduction: Type of reduction to perform on loss. Possible values are 
          `mean_batch`, 'mean_volume`, `mean`, `sum` or None.
          `None` will return a torch vector comprising the individual loss values of the batch.
          `mean_batch` will average the losses in the batch
          `mean` will divide each loss by the target length and then average
          `mean_volume` will add up all the losses and divide by sum of target lengths
  
      loss_name: String that is resolved into an RNNT loss function. Available list of losses
          is ininitialized in `RNNT_LOSS_RESOLVER` dictionary.
  
      loss_kwargs: Optional Dict of (str, value) pairs that are passed to the instantiated loss
          function.
docstr_tok: ["RNN-T","Loss","function","based","on","https",":","\/\/github.com\/HawkAaron\/warp-transducer",".","Optionally",",","can","utilize","a","numba","implementation","of","the","same","loss","without","having","to","compile","the","loss",",","albiet","there","is","a","small","speed","penalty","for","JIT","numba","compile",".","Note",":","Requires","Numba","0.53.0","or","later","to","be","installed","to","use","this","loss","function",".","Losses","can","be","selected","via","the","config",",","and","optionally","be","passed","keyword","arguments","as","follows",".","Examples",":","..","code-block",":",":","yaml","model",":","#","RNNT","Model","config","...","loss",":","loss_name",":","``","warprnnt_numba","''","warprnnt_numba_kwargs",":","fastemit_lambda",":","0.0","Warning",":","In","the","case","that","GPU","memory","is","exhausted","in","order","to","compute","RNNTLoss",",","it","might","cause","a","core","dump","at","the","cuda","level","with","the","following","error","message",".","``","`","...","costs","=","costs.to","(","acts.device",")","RuntimeError",":","CUDA","error",":","an","illegal","memory","access","was","encountered","terminate","called","after","throwing","an","instance","of","'c10",":",":Error'","``","`","Please","kill","all","remaining","python","processes","after","this","point",",","and","use","a","smaller","batch","size","for","train",",","validation","and","test","sets","so","that","CUDA","memory","is","not","exhausted",".","Args",":","num_classes",":","Number","of","target","classes","for","the","joint","network","to","predict",".","In","all","cases","(","conventional","RNNT",",","multi-blank","RNNT",",","and","TDT","model",")",",","this","equals","the","token-id","for","the","standard","``","blank","''","symbol",".","In","particular",",","say","V","is","the","number","of","non-blank","tokens","in","the","vocabulary",",","then","in","the","case","of",",","standard","RNNT",":","num_classes","=","V","multiblank","RNNT",":","num_classes","=","V","+","number-big-blanks","(","since","we","store","big-blanks","before","standard","blank",",","and","the","standard","blank","is","the","last","symbol","in","the","vocab",")","TDT",":","num_classes","=","V.","Note",",","V","here","does","not","include","any","of","the","``","duration","outputs","''",".","reduction",":","Type","of","reduction","to","perform","on","loss",".","Possible","values","are","`","mean_batch","`",",","'mean_volume","`",",","`","mean","`",",","`","sum","`","or","None",".","`","None","`","will","return","a","torch","vector","comprising","the","individual","loss","values","of","the","batch",".","`","mean_batch","`","will","average","the","losses","in","the","batch","`","mean","`","will","divide","each","loss","by","the","target","length","and","then","average","`","mean_volume","`","will","add","up","all","the","losses","and","divide","by","sum","of","target","lengths","loss_name",":","String","that","is","resolved","into","an","RNNT","loss","function",".","Available","list","of","losses","is","ininitialized","in","`","RNNT_LOSS_RESOLVER","`","dictionary",".","loss_kwargs",":","Optional","Dict","of","(","str",",","value",")","pairs","that","are","passed","to","the","instantiated","loss","function","."]
code: def __init__(
      self,
      num_classes,
      reduction: str = "mean_batch",
      loss_name: str = "default",
      loss_kwargs=None,
  ):
      """
      RNN-T Loss function based on https://github.com/HawkAaron/warp-transducer.
      Optionally, can utilize a numba implementation of the same loss without having to compile the loss,
      albiet there is a small speed penalty for JIT numba compile.
  
      Note:
          Requires Numba 0.53.0 or later to be installed to use this loss function.
  
      Losses can be selected via the config, and optionally be passed keyword arguments as follows.
  
      Examples:
          .. code-block:: yaml
  
              model:  # RNNT Model config
                  ...
                  loss:
                      loss_name: "warprnnt_numba"
                      warprnnt_numba_kwargs:
                          fastemit_lambda: 0.0
  
      Warning:
          In the case that GPU memory is exhausted in order to compute RNNTLoss, it might cause
          a core dump at the cuda level with the following error message.
  
          ```
              ...
              costs = costs.to(acts.device)
          RuntimeError: CUDA error: an illegal memory access was encountered
          terminate called after throwing an instance of 'c10::Error'
          ```
  
          Please kill all remaining python processes after this point, and use a smaller batch size
          for train, validation and test sets so that CUDA memory is not exhausted.
  
      Args:
          num_classes: Number of target classes for the joint network to predict.
              In all cases (conventional RNNT, multi-blank RNNT, and TDT model), this equals the token-id
              for the standard "blank" symbol. In particular, say V is the number of non-blank tokens in
              the vocabulary, then in the case of,
              standard RNNT: num_classes = V
              multiblank RNNT: num_classes = V + number-big-blanks (since we store big-blanks before
                               standard blank, and the standard blank is the last symbol in the vocab)
              TDT: num_classes = V. Note, V here does not include any of the "duration outputs".
  
          reduction: Type of reduction to perform on loss. Possible values are
              `mean_batch`, 'mean_volume`, `mean`, `sum` or None.
              `None` will return a torch vector comprising the individual loss values of the batch.
              `mean_batch` will average the losses in the batch
              `mean` will divide each loss by the target length and then average
              `mean_volume` will add up all the losses and divide by sum of target lengths
  
          loss_name: String that is resolved into an RNNT loss function. Available list of losses
              is ininitialized in `RNNT_LOSS_RESOLVER` dictionary.
  
          loss_kwargs: Optional Dict of (str, value) pairs that are passed to the instantiated loss
              function.
      """
      super(RNNTLoss, self).__init__()
  
      if reduction not in [
          None,
          "mean",
          "sum",
          "mean_batch",
          "mean_volume",
      ]:
          raise ValueError(
              "`reduction` must be one of [mean, sum, mean_batch, mean_volume]"
          )
  
      self._blank = num_classes
      self.reduction = reduction
      self._loss = resolve_rnnt_loss(
          loss_name, blank_idx=self._blank, loss_kwargs=loss_kwargs
      )
      self._force_float32 = RNNT_LOSS_RESOLVER[loss_name].force_float32
      self._fp16_compat_checked = False
  
imports: import inspect
  import operator
  from dataclasses import dataclass
  from typing import Any, Callable, Dict, List, Optional, Set
  import torch
  from omegaconf import DictConfig, OmegaConf
  from nemo.collections.asr.losses.rnnt_pytorch import MultiblankRNNTLossPytorch, RNNTLossPytorch, TDTLossPytorch
  from nemo.core.classes import Loss, typecheck
  from nemo.core.neural_types import LabelsType, LengthsType, LogprobsType, LossType, NeuralType
  from nemo.core.utils import numba_utils
  from nemo.core.utils.k2_utils import K2_INSTALLATION_MESSAGE
  from nemo.core.utils.numba_utils import NUMBA_INSTALLATION_MESSAGE
  from nemo.utils import logging, logging_mode, model_utils
label_desc: Use image node_id 3 to create a new RNNTLoss object from inherited base classes: Loss with example: obj = RNNTLoss(num_classes, reduction, loss_name, loss_kwargs)