class_docstr: Base class for NLP Models.
      
class_docstr_tok: ["Base","class","for","NLP","Models","."]
code: def __init__(
      self, cfg: DictConfig, trainer: Trainer = None, no_lm_init=False
  ):
      self.hidden_size = None
      self.bert_model = None
      vocab_file = None
      nemo_file = None
      config_dict = None
      config_file = None
  
      # tokenizer needs to get initialized before the super.__init__()
      # as dataloaders and datasets need it to process the data
      pretrain_model_name = ""
      if cfg.get("language_model") and cfg.language_model.get(
          "pretrained_model_name", ""
      ):
          pretrain_model_name = cfg.language_model.get(
              "pretrained_model_name", ""
          )
      all_pretrained_megatron_bert_models = (
          get_megatron_pretrained_bert_models()
      )
  
      if cfg.get("tokenizer"):
          # Some models have their own tokenizer setup
          if (
              not hasattr(self, "tokenizer")
              and cfg.tokenizer.get("tokenizer_name")
              and pretrain_model_name
              not in all_pretrained_megatron_bert_models
          ):
              self.setup_tokenizer(cfg.tokenizer)
          elif (
              pretrain_model_name in all_pretrained_megatron_bert_models
          ):
              copy_cfg = copy.deepcopy(cfg)
              bert_model = get_lm_model(
                  config_file=config_file,
                  config_dict=config_dict,
                  vocab_file=vocab_file,
                  trainer=trainer,
                  cfg=copy_cfg,
              )
              # set the tokenizer if it is not initialized explicitly
              if (
                  (
                      hasattr(self, "tokenizer")
                      and self.tokenizer is None
                  )
                  or not hasattr(self, "tokenizer")
              ) and hasattr(bert_model, "tokenizer"):
                  self.tokenizer = bert_model.tokenizer
          if (
              cfg.get("tokenizer")
              and hasattr(cfg.get("tokenizer"), "vocab_file")
              and cfg.get("tokenizer").get("vocab_file")
          ):
              vocab_file = self.register_artifact(
                  "tokenizer.vocab_file", cfg.tokenizer.vocab_file
              )
      super().__init__(cfg, trainer)
  
      # handles model parallel save and restore logic
      self._save_restore_connector = NLPSaveRestoreConnector()
  
      if cfg.get("language_model") and not no_lm_init:
          if cfg.get("language_model").get("nemo_file"):
              nemo_file = self.register_artifact(
                  "language_model.nemo_file",
                  cfg.language_model.nemo_file,
              )
          if cfg.get("language_model").get("config"):
              config_dict = OmegaConf.to_container(
                  cfg.language_model.config
              )
          if cfg.get("language_model").get("config_file"):
              config_file = self.register_artifact(
                  "language_model.config_file",
                  cfg.language_model.config_file,
              )
          bert_model = get_lm_model(
              config_file=config_file,
              config_dict=config_dict,
              vocab_file=vocab_file,
              trainer=trainer,
              cfg=cfg,
          )
          # set the tokenizer if it is not initialized explicitly
          if (
              (hasattr(self, "tokenizer") and self.tokenizer is None)
              or not hasattr(self, "tokenizer")
          ) and hasattr(bert_model, "tokenizer"):
              self.tokenizer = bert_model.tokenizer
  
          # Required to pull up the config for MegatronBert models
          self.pretrained_model_name = (
              cfg.language_model.pretrained_model_name
          )
  
          if (
              (
                  cfg.tokenizer is not None
                  and cfg.tokenizer.get("tokenizer_name", "")
                  is not None
                  and "megatron"
                  in cfg.tokenizer.get("tokenizer_name", "")
              )
              or pretrain_model_name
              in all_pretrained_megatron_bert_models
          ):
              self.hidden_size = bert_model.cfg.hidden_size
          else:
              self.hidden_size = bert_model.config.hidden_size
  
      if cfg.get("language_model") and not no_lm_init:
          self.bert_model = bert_model
          # register encoder config
          self.register_bert_model()
  
imports: import copy
  import hashlib
  import json
  import os
  from typing import Any, Mapping, Optional, Union
  import torch
  from lightning_fabric.utilities.cloud_io import _load
  from omegaconf import DictConfig, OmegaConf
  from pytorch_lightning import Trainer
  from pytorch_lightning.core.saving import _load_state
  from pytorch_lightning.core.saving import load_hparams_from_tags_csv, load_hparams_from_yaml
  from pytorch_lightning.utilities import rank_zero_only
  from pytorch_lightning.utilities.migration import pl_legacy_patch
  from transformers import TRANSFORMERS_CACHE
  from nemo.collections.common.tokenizers.huggingface.auto_tokenizer import AutoTokenizer
  from nemo.collections.nlp.modules import BertModule
  from nemo.collections.nlp.modules.common.huggingface.huggingface_utils import VOCAB_FILE_NAME
  from nemo.collections.nlp.modules.common.lm_utils import get_lm_model
  from nemo.collections.nlp.modules.common.megatron.megatron_utils import MEGATRON_CONFIG_MAP, get_megatron_pretrained_bert_models
  from nemo.collections.nlp.modules.common.tokenizer_utils import get_tokenizer
  from nemo.collections.nlp.parts.nlp_overrides import NLPSaveRestoreConnector
  from nemo.core.classes import ModelPT
  from nemo.core.classes.exportable import Exportable
  from nemo.core.connectors.save_restore_connector import SaveRestoreConnector
  from nemo.utils import AppState, logging
label_desc: Use image node_id 1 to create a new NLPModel object from inherited base classes: ModelPT, Exportable with example: obj = NLPModel(cfg, trainer, no_lm_init)