class_docstr: Base class for encoder decoder RNNT-based models with auxiliary CTC decoder/loss and subword tokenization.
class_docstr_tok: ["Base","class","for","encoder","decoder","RNNT-based","models","with","auxiliary","CTC","decoder\/loss","and","subword","tokenization","."]
docstr: Changes decoding strategy used during RNNT decoding process.
  Args:
      decoding_cfg: A config for the decoder, which is optional. If the decoding type
          needs to be changed (from say Greedy to Beam decoding etc), the config can be passed here.
      decoder_type: (str) Can be set to 'rnnt' or 'ctc' to switch between appropriate decoder in a
          model having both RNN-T and CTC decoders. Defaults to None, in which case RNN-T decoder is
          used. If set to 'ctc', it raises error if 'ctc_decoder' is not an attribute of the model.
docstr_tok: ["Changes","decoding","strategy","used","during","RNNT","decoding","process",".","Args",":","decoding_cfg",":","A","config","for","the","decoder",",","which","is","optional",".","If","the","decoding","type","needs","to","be","changed","(","from","say","Greedy","to","Beam","decoding","etc",")",",","the","config","can","be","passed","here",".","decoder_type",":","(","str",")","Can","be","set","to","'rnnt","'","or","'ctc","'","to","switch","between","appropriate","decoder","in","a","model","having","both","RNN-T","and","CTC","decoders",".","Defaults","to","None",",","in","which","case","RNN-T","decoder","is","used",".","If","set","to","'ctc","'",",","it","raises","error","if","'ctc_decoder","'","is","not","an","attribute","of","the","model","."]
code: def change_decoding_strategy(
      self, decoding_cfg: DictConfig = None, decoder_type: str = None
  ):
      """
      Changes decoding strategy used during RNNT decoding process.
      Args:
          decoding_cfg: A config for the decoder, which is optional. If the decoding type
              needs to be changed (from say Greedy to Beam decoding etc), the config can be passed here.
          decoder_type: (str) Can be set to 'rnnt' or 'ctc' to switch between appropriate decoder in a
              model having both RNN-T and CTC decoders. Defaults to None, in which case RNN-T decoder is
              used. If set to 'ctc', it raises error if 'ctc_decoder' is not an attribute of the model.
      """
      if decoder_type is None or decoder_type == "rnnt":
          if decoding_cfg is None:
              # Assume same decoding config as before
              logging.info(
                  "No `decoding_cfg` passed when changing decoding strategy, using internal config"
              )
              decoding_cfg = self.cfg.decoding
  
          # Assert the decoding config with all hyper parameters
          decoding_cls = OmegaConf.structured(RNNTBPEDecodingConfig)
          decoding_cls = OmegaConf.create(
              OmegaConf.to_container(decoding_cls)
          )
          decoding_cfg = OmegaConf.merge(decoding_cls, decoding_cfg)
  
          self.decoding = RNNTBPEDecoding(
              decoding_cfg=decoding_cfg,
              decoder=self.decoder,
              joint=self.joint,
              tokenizer=self.tokenizer,
          )
  
          self.wer = WER(
              decoding=self.decoding,
              batch_dim_index=self.wer.batch_dim_index,
              use_cer=self.wer.use_cer,
              log_prediction=self.wer.log_prediction,
              dist_sync_on_step=True,
          )
  
          # Setup fused Joint step
          if self.joint.fuse_loss_wer or (
              self.decoding.joint_fused_batch_size is not None
              and self.decoding.joint_fused_batch_size > 0
          ):
              self.joint.set_loss(self.loss)
              self.joint.set_wer(self.wer)
  
          self.joint.temperature = decoding_cfg.get("temperature", 1.0)
  
          # Update config
          with open_dict(self.cfg.decoding):
              self.cfg.decoding = decoding_cfg
  
          self.cur_decoder = "rnnt"
          logging.info(
              f"Changed decoding strategy of the RNNT decoder to \n{OmegaConf.to_yaml(self.cfg.decoding)}"
          )
  
      elif decoder_type == "ctc":
          if not hasattr(self, "ctc_decoding"):
              raise ValueError(
                  "The model does not have the ctc_decoding module and does not support ctc decoding."
              )
          if decoding_cfg is None:
              # Assume same decoding config as before
              logging.info(
                  "No `decoding_cfg` passed when changing decoding strategy, using internal config"
              )
              decoding_cfg = self.cfg.aux_ctc.decoding
  
          # Assert the decoding config with all hyper parameters
          decoding_cls = OmegaConf.structured(CTCBPEDecodingConfig)
          decoding_cls = OmegaConf.create(
              OmegaConf.to_container(decoding_cls)
          )
          decoding_cfg = OmegaConf.merge(decoding_cls, decoding_cfg)
  
          self.ctc_decoding = CTCBPEDecoding(
              decoding_cfg=decoding_cfg, tokenizer=self.tokenizer
          )
  
          self.ctc_wer = WER(
              decoding=self.ctc_decoding,
              use_cer=self.ctc_wer.use_cer,
              log_prediction=self.ctc_wer.log_prediction,
              dist_sync_on_step=True,
          )
  
          self.ctc_decoder.temperature = decoding_cfg.get(
              "temperature", 1.0
          )
  
          # Update config
          with open_dict(self.cfg.aux_ctc.decoding):
              self.cfg.aux_ctc.decoding = decoding_cfg
  
          self.cur_decoder = "ctc"
          logging.info(
              f"Changed decoding strategy of the CTC decoder to \n{OmegaConf.to_yaml(self.cfg.aux_ctc.decoding)}"
          )
      else:
          raise ValueError(
              f"decoder_type={decoder_type} is not supported. Supported values: [ctc,rnnt]"
          )
  
imports: import copy
  import os
  from typing import Dict, List, Optional, Union
  import torch
  from omegaconf import DictConfig, ListConfig, OmegaConf, open_dict
  from pytorch_lightning import Trainer
  from nemo.collections.asr.data import audio_to_text_dataset
  from nemo.collections.asr.data.audio_to_text_dali import AudioToBPEDALIDataset
  from nemo.collections.asr.data.audio_to_text_lhotse import LhotseSpeechToTextBpeDataset
  from nemo.collections.asr.losses.ctc import CTCLoss
  from nemo.collections.asr.losses.rnnt import RNNTLoss
  from nemo.collections.asr.metrics.wer import WER
  from nemo.collections.asr.models.hybrid_rnnt_ctc_models import EncDecHybridRNNTCTCModel
  from nemo.collections.asr.parts.mixins import ASRBPEMixin
  from nemo.collections.asr.parts.submodules.ctc_decoding import CTCBPEDecoding, CTCBPEDecodingConfig
  from nemo.collections.asr.parts.submodules.rnnt_decoding import RNNTBPEDecoding, RNNTBPEDecodingConfig
  from nemo.collections.common.data.lhotse import get_lhotse_dataloader_from_config
  from nemo.core.classes.common import PretrainedModelInfo
  from nemo.utils import logging, model_utils
label_desc: Use image node_id 5 for calling the EncDecHybridRNNTCTCBPEModel obj's underlying member method code with example usage: obj.change_decoding_strategy(decoding_cfg, decoder_type) without return types