code: def extract_model_ctc(args, hybrid_model):
      """
      A function which converts a hybrid model to a pure ctc model.
      Args:
          args (argparse): the args collection from ArgumentParser created by running this script
          hybrid_model (ASRModel): the loaded hybrid RNNT-CTC Nemo model
      """
      BPE = False
      ctc_class = EncDecCTCModel
      if "tokenizer" in hybrid_model.cfg.keys():
          BPE = True
          ctc_class = EncDecCTCModelBPE
  
      hybrid_model_cfg = OmegaConf.to_container(hybrid_model.cfg)
  
      new_cfg = deepcopy(hybrid_model_cfg)
      new_cfg["ctc_reduction"] = hybrid_model_cfg["aux_ctc"][
          "ctc_reduction"
      ]
      new_cfg["decoder"] = hybrid_model_cfg["aux_ctc"]["decoder"]
      del new_cfg["compute_eval_loss"]
      del new_cfg["model_defaults"]
      del new_cfg["joint"]
      del new_cfg["decoding"]
      del new_cfg["aux_ctc"]
      del new_cfg["loss"]
      if BPE and "labels" in new_cfg:
          del new_cfg["labels"]
      elif (not BPE) and "tokenizer" in new_cfg:
          del new_cfg["tokenizer"]
      del new_cfg["target"]
      del new_cfg["nemo_version"]
  
      new_cfg_oc = OmegaConf.create(new_cfg)
  
      # we call restore_from with strict=False because the .nemo file we're restoring from is a hybrid model, which will have named
      # tensors in the state_dict that do not exist in the pure CTC model class, which would result in an exception with strict=True
      ctc_model = ctc_class.restore_from(
          args.input,
          map_location=torch.device("cpu"),
          override_config_path=new_cfg_oc,
          strict=False,
      )
  
      assert all(
          [
              torch.allclose(
                  hybrid_model.state_dict()[x],
                  ctc_model.state_dict()[x],
              )
              for x in hybrid_model.state_dict().keys()
              if x.split(".")[0] in ["preprocessor", "encoder"]
          ]
      ), "Encoder and preprocessor state dicts don't match!"
  
      ctc_model.decoder.load_state_dict(
          hybrid_model.ctc_decoder.state_dict()
      )
  
      assert all(
          [
              torch.allclose(
                  hybrid_model.ctc_decoder.state_dict()[x],
                  ctc_model.decoder.state_dict()[x],
              )
              for x in hybrid_model.ctc_decoder.state_dict().keys()
          ]
      ), "Decoder state_dict load failed!"
  
      assert isinstance(
          ctc_model, ctc_class
      ), "Extracted CTC model is of the wrong expected class!"
  
      return ctc_model
  
file_path: NeMo/examples/asr/asr_hybrid_transducer_ctc/helpers/convert_nemo_asr_hybrid_to_ctc.py
imports: import argparse
  import os
  from copy import deepcopy
  import torch
  from omegaconf import OmegaConf
  from nemo.collections.asr.models import ASRModel, EncDecCTCModel, EncDecCTCModelBPE, EncDecRNNTBPEModel, EncDecRNNTModel
  from nemo.utils import logging
label_desc: Use image node_id 1 for calling a global function with example usage: extract_model_ctc(args, hybrid_model) and returns: ctc_model