class_docstr: Base class for NLP Models.
      
class_docstr_tok: ["Base","class","for","NLP","Models","."]
docstr: Creates vocab file from tokenizer if vocab file is None.
  
  Args:
      vocab_file_config_path: path to the vocab_file in the config
      vocab_dict_config_path: path to the vocab_dict in the config
      cfg: tokenizer config
docstr_tok: ["Creates","vocab","file","from","tokenizer","if","vocab","file","is","None",".","Args",":","vocab_file_config_path",":","path","to","the","vocab_file","in","the","config","vocab_dict_config_path",":","path","to","the","vocab_dict","in","the","config","cfg",":","tokenizer","config"]
code: def _register_vocab_from_tokenizer(
      self,
      vocab_file_config_path: str = "tokenizer.vocab_file",
      vocab_dict_config_path: str = "tokenizer_vocab_dict",
      cfg: DictConfig = None,
  ):
      """Creates vocab file from tokenizer if vocab file is None.
  
      Args:
          vocab_file_config_path: path to the vocab_file in the config
          vocab_dict_config_path: path to the vocab_dict in the config
          cfg: tokenizer config
      """
      if self.tokenizer is None:
          raise ValueError(
              "Instantiate self.tokenizer before registering vocab from it."
          )
      else:
          if isinstance(self.tokenizer, AutoTokenizer):
              # extract vocab from tokenizer
              vocab_dict = self.tokenizer.tokenizer.get_vocab()
  
              # for fast and slow tokenizer vocabularies compatibility
              vocab_dict = dict(
                  sorted(vocab_dict.items(), key=lambda item: item[1])
              )
  
              # get hash of vocab_dict to create a unique directory to write vocab_dict and vocab_file
              m = hashlib.md5()
              if "tokenizer_name" in cfg:
                  if cfg.tokenizer_name is not None:
                      # different pretrained models with the same vocab will have different hash
                      m.update(cfg.tokenizer_name.encode())
              # get string representation of vocab_dict
              vocab_dict_str = json.dumps(
                  vocab_dict, sort_keys=True
              ).encode()
              m.update(vocab_dict_str)
              vocab_dict_hash = m.hexdigest()
  
              hash_path = os.path.join(NEMO_NLP_TMP, vocab_dict_hash)
              os.makedirs(hash_path, exist_ok=True)
  
              vocab_json_src = os.path.join(
                  hash_path, vocab_dict_config_path
              )
  
              with open(vocab_json_src, "w", encoding="utf-8") as f:
                  f.write(
                      json.dumps(vocab_dict, indent=2, sort_keys=True)
                      + "\n"
                  )
              self.register_artifact(
                  config_path=vocab_dict_config_path, src=vocab_json_src
              )
  
              tokenizer_name = (
                  self.tokenizer.tokenizer.__class__.__name__
              )
              # save vocab file
              # depending on the HuggingFace model, vocab file could mean different things, see VOCAB_FILE_NAME
              self.tokenizer.save_vocabulary(hash_path)
  
              # create vocab file
              vocab_file_src = os.path.join(
                  hash_path, VOCAB_FILE_NAME[tokenizer_name]
              )
              cfg.vocab_file = vocab_file_src
              self.register_artifact(
                  config_path=vocab_file_config_path, src=vocab_file_src
              )
          else:
              logging.info(
                  f"Registering tokenizer vocab for {self.tokenizer} is not yet supported. Please override this method if needed."
              )
  
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 5 for calling the NLPModel obj's underlying member method code with example usage: obj._register_vocab_from_tokenizer(vocab_file_config_path, vocab_dict_config_path, cfg) without return types