class_docstr: ESPnet2ASRTransducerModel module definition.
  
  Args:
      vocab_size: Size of complete vocabulary (w/ SOS/EOS and blank included).
      token_list: List of tokens in vocabulary (minus reserved tokens).
      frontend: Frontend module.
      specaug: SpecAugment module.
      normalize: Normalization module.
      encoder: Encoder module.
      decoder: Decoder module.
      joint_network: Joint Network module.
      transducer_weight: Weight of the Transducer loss.
      use_k2_pruned_loss: Whether to use k2 pruned Transducer loss.
      k2_pruned_loss_args: Arguments of the k2 loss pruned Transducer loss.
      warmup_steps: Number of steps in warmup, used for pruned loss scaling.
      validation_nstep: Maximum number of symbol expansions at each time step
                        when reporting CER or/and WER using mAES.
      fastemit_lambda: FastEmit lambda value.
      auxiliary_ctc_weight: Weight of auxiliary CTC loss.
      auxiliary_ctc_dropout_rate: Dropout rate for auxiliary CTC loss inputs.
      auxiliary_lm_loss_weight: Weight of auxiliary LM loss.
      auxiliary_lm_loss_smoothing: Smoothing rate for LM loss' label smoothing.
      ignore_id: Initial padding ID.
      sym_space: Space symbol.
      sym_blank: Blank Symbol.
      report_cer: Whether to report Character Error Rate during validation.
      report_wer: Whether to report Word Error Rate during validation.
      extract_feats_in_collect_stats: Whether to use extract_feats stats collection.
class_docstr_tok: ["ESPnet2ASRTransducerModel","module","definition",".","Args",":","vocab_size",":","Size","of","complete","vocabulary","(","w\/","SOS\/EOS","and","blank","included",")",".","token_list",":","List","of","tokens","in","vocabulary","(","minus","reserved","tokens",")",".","frontend",":","Frontend","module",".","specaug",":","SpecAugment","module",".","normalize",":","Normalization","module",".","encoder",":","Encoder","module",".","decoder",":","Decoder","module",".","joint_network",":","Joint","Network","module",".","transducer_weight",":","Weight","of","the","Transducer","loss",".","use_k2_pruned_loss",":","Whether","to","use","k2","pruned","Transducer","loss",".","k2_pruned_loss_args",":","Arguments","of","the","k2","loss","pruned","Transducer","loss",".","warmup_steps",":","Number","of","steps","in","warmup",",","used","for","pruned","loss","scaling",".","validation_nstep",":","Maximum","number","of","symbol","expansions","at","each","time","step","when","reporting","CER","or\/and","WER","using","mAES",".","fastemit_lambda",":","FastEmit","lambda","value",".","auxiliary_ctc_weight",":","Weight","of","auxiliary","CTC","loss",".","auxiliary_ctc_dropout_rate",":","Dropout","rate","for","auxiliary","CTC","loss","inputs",".","auxiliary_lm_loss_weight",":","Weight","of","auxiliary","LM","loss",".","auxiliary_lm_loss_smoothing",":","Smoothing","rate","for","LM","loss","'","label","smoothing",".","ignore_id",":","Initial","padding","ID",".","sym_space",":","Space","symbol",".","sym_blank",":","Blank","Symbol",".","report_cer",":","Whether","to","report","Character","Error","Rate","during","validation",".","report_wer",":","Whether","to","report","Word","Error","Rate","during","validation",".","extract_feats_in_collect_stats",":","Whether","to","use","extract_feats","stats","collection","."]
docstr: Compute k2 pruned Transducer loss.
  
  Args:
      encoder_out: Encoder output sequences. (B, T, D_enc)
      decoder_out: Decoder output sequences. (B, T, D_dec)
      labels: Label ID sequences. (B, L)
      encoder_out_len: Encoder output sequences lengths. (B,)
      decoder_out_len: Target label ID sequences lengths. (B,)
      prune_range: How many tokens by frame are used compute the pruned loss.
      simple_loss_scaling: The weight to scale the simple loss after warm-up.
      lm_scale: The scale factor to smooth the LM part.
      am_scale: The scale factor to smooth the AM part.
      loss_type: Define the type of path to take for loss computation.
                   (Either 'regular', 'smoothed' or 'constrained')
      padding_idx: SOS/EOS + Padding index.
  
  Return:
      loss_transducer: Transducer loss value.
docstr_tok: ["Compute","k2","pruned","Transducer","loss",".","Args",":","encoder_out",":","Encoder","output","sequences",".","(","B",",","T",",","D_enc",")","decoder_out",":","Decoder","output","sequences",".","(","B",",","T",",","D_dec",")","labels",":","Label","ID","sequences",".","(","B",",","L",")","encoder_out_len",":","Encoder","output","sequences","lengths",".","(","B",",",")","decoder_out_len",":","Target","label","ID","sequences","lengths",".","(","B",",",")","prune_range",":","How","many","tokens","by","frame","are","used","compute","the","pruned","loss",".","simple_loss_scaling",":","The","weight","to","scale","the","simple","loss","after","warm-up",".","lm_scale",":","The","scale","factor","to","smooth","the","LM","part",".","am_scale",":","The","scale","factor","to","smooth","the","AM","part",".","loss_type",":","Define","the","type","of","path","to","take","for","loss","computation",".","(","Either","'regular","'",",","'smoothed","'","or","'constrained","'",")","padding_idx",":","SOS\/EOS","+","Padding","index",".","Return",":","loss_transducer",":","Transducer","loss","value","."]
code: def _calc_k2_transducer_pruned_loss(
      self,
      encoder_out: torch.Tensor,
      decoder_out: torch.Tensor,
      labels: torch.Tensor,
      encoder_out_len: torch.Tensor,
      decoder_out_len: torch.Tensor,
      prune_range: int = 5,
      simple_loss_scaling: float = 0.5,
      lm_scale: float = 0.0,
      am_scale: float = 0.0,
      loss_type: str = "regular",
      reduction: str = "mean",
      padding_idx: int = 0,
  ) -> torch.Tensor:
      """Compute k2 pruned Transducer loss.
  
      Args:
          encoder_out: Encoder output sequences. (B, T, D_enc)
          decoder_out: Decoder output sequences. (B, T, D_dec)
          labels: Label ID sequences. (B, L)
          encoder_out_len: Encoder output sequences lengths. (B,)
          decoder_out_len: Target label ID sequences lengths. (B,)
          prune_range: How many tokens by frame are used compute the pruned loss.
          simple_loss_scaling: The weight to scale the simple loss after warm-up.
          lm_scale: The scale factor to smooth the LM part.
          am_scale: The scale factor to smooth the AM part.
          loss_type: Define the type of path to take for loss computation.
                       (Either 'regular', 'smoothed' or 'constrained')
          padding_idx: SOS/EOS + Padding index.
  
      Return:
          loss_transducer: Transducer loss value.
  
      """
      try:
          import k2
  
          if self.fastemit_lambda > 0.0:
              logging.info(
                  "Disabling FastEmit, it is not available with k2 Transducer loss. "
                  "Please see delay_penalty option instead."
              )
      except ImportError:
          logging.error(
              "k2 was not installed. Please consult the installation documentation."
          )
          exit(1)
  
      # Note (b-flo): We use a dummy scaling scheme until the training parts are
      # revised (in a short future).
      self.steps_num += 1
  
      if self.steps_num < self.warmup_steps:
          pruned_loss_scaling = 0.1 + 0.9 * (
              self.steps_num / self.warmup_steps
          )
          simple_loss_scaling = 1.0 - (
              (self.steps_num / self.warmup_steps)
              * (1.0 - simple_loss_scaling)
          )
      else:
          pruned_loss_scaling = 1.0
  
      labels_unpad = [y[y != self.ignore_id].tolist() for y in labels]
  
      target = k2.RaggedTensor(labels_unpad).to(decoder_out.device)
      target_padded = target.pad(
          mode="constant", padding_value=padding_idx
      )
      target_padded = target_padded.to(torch.int64)
  
      boundary = torch.zeros(
          (encoder_out.size(0), 4),
          dtype=torch.int64,
          device=encoder_out.device,
      )
      boundary[:, 2] = decoder_out_len
      boundary[:, 3] = encoder_out_len
  
      lm = self.lm_proj(decoder_out)
      am = self.am_proj(encoder_out)
  
      with autocast(False):
          simple_loss, (px_grad, py_grad) = k2.rnnt_loss_smoothed(
              lm.float(),
              am.float(),
              target_padded,
              padding_idx,
              lm_only_scale=lm_scale,
              am_only_scale=am_scale,
              boundary=boundary,
              rnnt_type=loss_type,
              reduction=reduction,
              return_grad=True,
          )
  
      ranges = k2.get_rnnt_prune_ranges(
          px_grad,
          py_grad,
          boundary,
          prune_range,
      )
  
      am_pruned, lm_pruned = k2.do_rnnt_pruning(
          self.joint_network.lin_enc(encoder_out),
          self.joint_network.lin_dec(decoder_out),
          ranges,
      )
  
      joint_out = self.joint_network(
          am_pruned, lm_pruned, no_projection=True
      )
  
      with autocast(False):
          pruned_loss = k2.rnnt_loss_pruned(
              joint_out.float(),
              target_padded,
              ranges,
              padding_idx,
              boundary,
              rnnt_type=loss_type,
              reduction=reduction,
          )
  
      loss_transducer = (
          simple_loss_scaling * simple_loss
          + pruned_loss_scaling * pruned_loss
      )
  
      return loss_transducer
  
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.frontend.abs_frontend import AbsFrontend
  from espnet2.asr.specaug.abs_specaug import AbsSpecAug
  from espnet2.asr_transducer.decoder.abs_decoder import AbsDecoder
  from espnet2.asr_transducer.encoder.encoder import Encoder
  from espnet2.asr_transducer.joint_network import JointNetwork
  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
label_desc: Use image node_id 7 for calling the ESPnetASRTransducerModel obj's underlying member method code with example usage: obj._calc_k2_transducer_pruned_loss(encoder_out, decoder_out, labels, encoder_out_len, decoder_out_len, prune_range, simple_loss_scaling, lm_scale, am_scale, loss_type, reduction, padding_idx) and returns: loss_transducer