code: def main():
      args = parse_arguments()
  
      device = "cuda" if torch.cuda.is_available() else "cpu"
  
      # Instantiate pytorch model
      if args.nemo_model is not None:
          nemo_model = args.nemo_model
          nemo_model = ASRModel.restore_from(
              nemo_model, map_location=device
          )  # type: ASRModel
          nemo_model.freeze()
      elif args.pretrained_model is not None:
          nemo_model = args.pretrained_model
          nemo_model = ASRModel.from_pretrained(
              nemo_model, map_location=device
          )  # type: ASRModel
          nemo_model.freeze()
      else:
          raise ValueError(
              "Please pass either `nemo_model` or `pretrained_model` !"
          )
  
      if torch.cuda.is_available():
          nemo_model = nemo_model.to("cuda")
  
      export_model_if_required(args, nemo_model)
  
      # Instantiate RNNT Decoding loop
      encoder_model = args.ts_encoder
      decoder_model = args.ts_decoder
      ts_cfg = OmegaConf.load(args.ts_cfg)
      max_symbols_per_step = args.max_symbold_per_step
      decoding = TorchscriptGreedyBatchedRNNTInfer(
          encoder_model,
          decoder_model,
          ts_cfg,
          device,
          max_symbols_per_step,
      )
  
      audio_filepath = resolve_audio_filepaths(args)
  
      # Evaluate Pytorch Model (CPU/GPU)
      actual_transcripts = nemo_model.transcribe(
          audio_filepath, batch_size=args.batch_size
      )[0]
  
      # Evaluate Torchscript model
      with tempfile.TemporaryDirectory() as tmpdir:
          with open(
              os.path.join(tmpdir, "manifest.json"),
              "w",
              encoding="utf-8",
          ) as fp:
              for audio_file in audio_filepath:
                  entry = {
                      "audio_filepath": audio_file,
                      "duration": 100000,
                      "text": "nothing",
                  }
                  fp.write(json.dumps(entry) + "\n")
  
          config = {
              "paths2audio_files": audio_filepath,
              "batch_size": args.batch_size,
              "temp_dir": tmpdir,
          }
  
          nemo_model.preprocessor.featurizer.dither = 0.0
          nemo_model.preprocessor.featurizer.pad_to = 0
  
          temporary_datalayer = nemo_model._setup_transcribe_dataloader(
              config
          )
  
          all_hypothesis = []
          for test_batch in tqdm(
              temporary_datalayer, desc="Torchscript Transcribing"
          ):
              input_signal, input_signal_length = (
                  test_batch[0],
                  test_batch[1],
              )
              input_signal = input_signal.to(device)
              input_signal_length = input_signal_length.to(device)
  
              # Acoustic features
              (
                  processed_audio,
                  processed_audio_len,
              ) = nemo_model.preprocessor(
                  input_signal=input_signal, length=input_signal_length
              )
              # RNNT Decoding loop
              hypotheses = decoding(
                  audio_signal=processed_audio,
                  length=processed_audio_len,
              )
  
              # Process hypothesis (map char/subword token ids to text)
              hypotheses = nemo_model.decoding.decode_hypothesis(
                  hypotheses
              )  # type: List[str]
  
              # Extract text from the hypothesis
              texts = [h.text for h in hypotheses]
  
              all_hypothesis += texts
              del processed_audio, processed_audio_len
              del test_batch
  
      if args.log:
          for pt_transcript, ts_transcript in zip(
              actual_transcripts, all_hypothesis
          ):
              print(f"Pytorch Transcripts        : {pt_transcript}")
              print(f"Torchscript Transcripts    : {ts_transcript}")
          print()
  
      # Measure error rate between torchscript and pytorch transcipts
      pt_ts_cer = word_error_rate(
          all_hypothesis, actual_transcripts, use_cer=True
      )
      assert pt_ts_cer < args.threshold, "Threshold violation !"
  
      print(
          "Character error rate between Pytorch and Torchscript :",
          pt_ts_cer,
      )
  
file_path: NeMo/examples/asr/export/transducer/infer_transducer_ts.py
imports: import glob
  import json
  import os
  import tempfile
  from argparse import ArgumentParser
  import torch
  from omegaconf import OmegaConf
  from tqdm import tqdm
  from nemo.collections.asr.metrics.wer import word_error_rate
  from nemo.collections.asr.models import ASRModel
  from nemo.collections.asr.parts.submodules.rnnt_greedy_decoding import TorchscriptGreedyBatchedRNNTInfer
  from nemo.utils import logging
label_desc: Use image node_id 5 for calling a global function with example usage: main() without return types