class_docstr: Base class for encoder decoder RNNT-based models.
class_docstr_tok: ["Base","class","for","encoder","decoder","RNNT-based","models","."]
code: def __init__(self, cfg: DictConfig, trainer: Trainer = None):
      # Get global rank and total number of GPU workers for IterableDataset partitioning, if applicable
      # Global_rank and local_rank is set by LightningModule in Lightning 1.2.0
      self.world_size = 1
      if trainer is not None:
          self.world_size = trainer.world_size
  
      super().__init__(cfg=cfg, trainer=trainer)
  
      # Initialize components
      self.preprocessor = EncDecRNNTModel.from_config_dict(
          self.cfg.preprocessor
      )
      self.encoder = EncDecRNNTModel.from_config_dict(self.cfg.encoder)
  
      # Update config values required by components dynamically
      with open_dict(self.cfg.decoder):
          self.cfg.decoder.vocab_size = len(self.cfg.labels)
  
      with open_dict(self.cfg.joint):
          self.cfg.joint.num_classes = len(self.cfg.labels)
          self.cfg.joint.vocabulary = self.cfg.labels
          self.cfg.joint.jointnet.encoder_hidden = (
              self.cfg.model_defaults.enc_hidden
          )
          self.cfg.joint.jointnet.pred_hidden = (
              self.cfg.model_defaults.pred_hidden
          )
  
      self.decoder = EncDecRNNTModel.from_config_dict(self.cfg.decoder)
      self.joint = EncDecRNNTModel.from_config_dict(self.cfg.joint)
  
      # Setup RNNT Loss
      loss_name, loss_kwargs = self.extract_rnnt_loss_cfg(
          self.cfg.get("loss", None)
      )
  
      num_classes = (
          self.joint.num_classes_with_blank - 1
      )  # for standard RNNT and multi-blank
  
      if loss_name == "tdt":
          num_classes = num_classes - self.joint.num_extra_outputs
  
      self.loss = RNNTLoss(
          num_classes=num_classes,
          loss_name=loss_name,
          loss_kwargs=loss_kwargs,
          reduction=self.cfg.get("rnnt_reduction", "mean_batch"),
      )
  
      if (
          hasattr(self.cfg, "spec_augment")
          and self._cfg.spec_augment is not None
      ):
          self.spec_augmentation = EncDecRNNTModel.from_config_dict(
              self.cfg.spec_augment
          )
      else:
          self.spec_augmentation = None
  
      # Setup decoding objects
      self.decoding = RNNTDecoding(
          decoding_cfg=self.cfg.decoding,
          decoder=self.decoder,
          joint=self.joint,
          vocabulary=self.joint.vocabulary,
      )
      # Setup WER calculation
      self.wer = WER(
          decoding=self.decoding,
          batch_dim_index=0,
          use_cer=self._cfg.get("use_cer", False),
          log_prediction=self._cfg.get("log_prediction", True),
          dist_sync_on_step=True,
      )
  
      # Whether to compute loss during evaluation
      if "compute_eval_loss" in self.cfg:
          self.compute_eval_loss = self.cfg.compute_eval_loss
      else:
          self.compute_eval_loss = True
  
      # Setup fused Joint step if flag is set
      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)
  
      # Setup optimization normalization (if provided in config)
      self.setup_optim_normalization()
  
      # Setup optional Optimization flags
      self.setup_optimization_flags()
  
      # Setup encoder adapters (from ASRAdapterModelMixin)
      self.setup_adapters()
  
imports: import copy
  import json
  import os
  import tempfile
  from math import ceil
  from typing import Dict, List, Optional, Tuple, Union
  import torch
  from omegaconf import DictConfig, OmegaConf, open_dict
  from pytorch_lightning import Trainer
  from tqdm.auto import tqdm
  from nemo.collections.asr.data import audio_to_text_dataset
  from nemo.collections.asr.data.audio_to_text_dali import AudioToCharDALIDataset, DALIOutputs
  from nemo.collections.asr.data.audio_to_text_lhotse import LhotseSpeechToTextBpeDataset
  from nemo.collections.asr.losses.rnnt import RNNTLoss, resolve_rnnt_default_loss_name
  from nemo.collections.asr.metrics.wer import WER
  from nemo.collections.asr.models.asr_model import ASRModel, ExportableEncDecModel
  from nemo.collections.asr.modules.rnnt import RNNTDecoderJoint
  from nemo.collections.asr.parts.mixins import ASRModuleMixin
  from nemo.collections.asr.parts.submodules.rnnt_decoding import RNNTDecoding, RNNTDecodingConfig
  from nemo.collections.asr.parts.utils.audio_utils import ChannelSelectorType
  from nemo.collections.common.data.lhotse import get_lhotse_dataloader_from_config
  from nemo.collections.common.parts.preprocessing.parsers import make_parser
  from nemo.core.classes.common import PretrainedModelInfo, typecheck
  from nemo.core.classes.mixins import AccessMixin
  from nemo.core.neural_types import AcousticEncodedRepresentation, AudioSignal, LengthsType, NeuralType, SpectrogramType
  from nemo.utils import logging
label_desc: Use image node_id 1 to create a new EncDecRNNTModel object from inherited base classes: ASRModel, ASRModuleMixin, ExportableEncDecModel with example: obj = EncDecRNNTModel(cfg, trainer)