class_docstr: Base class for NLP Models.
      
class_docstr_tok: ["Base","class","for","NLP","Models","."]
docstr: Loads ModelPT from checkpoint, with some maintenance of restoration.
  For documentation, please refer to LightningModule.load_from_checkpoin() documentation.
docstr_tok: ["Loads","ModelPT","from","checkpoint",",","with","some","maintenance","of","restoration",".","For","documentation",",","please","refer","to","LightningModule.load_from_checkpoin","(",")","documentation","."]
code: def load_from_checkpoint(
      cls,
      checkpoint_path: str,
      map_location: Any = None,
      hparams_file: Optional[str] = None,
      strict: bool = True,
      **kwargs,
  ):
      """
      Loads ModelPT from checkpoint, with some maintenance of restoration.
      For documentation, please refer to LightningModule.load_from_checkpoin() documentation.
      """
      checkpoint = None
      try:
          cls._set_model_restore_state(is_being_restored=True)
  
          # dist checkpoint is a dir
          checkpoint_dir = None
          if os.path.isdir(checkpoint_path):
              # store dir for later use
              checkpoint_dir = checkpoint_path
  
              # metadata is stored in common.pt
              checkpoint_path = os.path.join(
                  checkpoint_path, "common.pt"
              )
  
              # we defer loading the state_dict until the class has been initialized
              # we need to set this for ptl_load_state
              strict = False
  
          # TODO: replace with proper PTL API
          with pl_legacy_patch():
              if map_location is not None:
                  checkpoint = pl_load(
                      checkpoint_path, map_location=map_location
                  )
              else:
                  checkpoint = pl_load(
                      checkpoint_path,
                      map_location=lambda storage, loc: storage,
                  )
  
          if hparams_file is not None:
              extension = hparams_file.split(".")[-1]
              if extension.lower() == "csv":
                  hparams = load_hparams_from_tags_csv(hparams_file)
              elif extension.lower() in ("yml", "yaml"):
                  hparams = load_hparams_from_yaml(hparams_file)
              else:
                  raise ValueError(
                      ".csv, .yml or .yaml is required for `hparams_file`"
                  )
  
              hparams["on_gpu"] = False
  
              # overwrite hparams by the given file
              checkpoint[cls.CHECKPOINT_HYPER_PARAMS_KEY] = hparams
  
          # for past checkpoint need to add the new key
          if cls.CHECKPOINT_HYPER_PARAMS_KEY not in checkpoint:
              checkpoint[cls.CHECKPOINT_HYPER_PARAMS_KEY] = {}
          # override the hparams with values that were passed in
          cfg = checkpoint[cls.CHECKPOINT_HYPER_PARAMS_KEY].get(
              "cfg", checkpoint[cls.CHECKPOINT_HYPER_PARAMS_KEY]
          )
          # TODO: can we do this without overriding?
          config_kwargs = kwargs.copy()
          if "trainer" in config_kwargs:
              config_kwargs.pop("trainer")
          cfg.update(config_kwargs)
  
          if (
              cfg.get("megatron_amp_O2", False)
              and checkpoint_dir is None
          ):
              new_state_dict = {}
              for key in checkpoint["state_dict"].keys():
                  new_key = key.replace("model.", "model.module.", 1)
                  new_state_dict[new_key] = checkpoint["state_dict"][
                      key
                  ]
              checkpoint["state_dict"] = new_state_dict
  
          if "cfg" in kwargs:
              model = ptl_load_state(
                  cls, checkpoint, strict=strict, **kwargs
              )
          else:
              model = ptl_load_state(
                  cls, checkpoint, strict=strict, cfg=cfg, **kwargs
              )
              # cfg = checkpoint[cls.CHECKPOINT_HYPER_PARAMS_KEY].cfg
  
          # if the checkpoint is distributed, we deferred loading the state_dict until now
          if checkpoint_dir is not None:
              sharded_state_dict = model.sharded_state_dict()
              checkpoint["state_dict"] = sharded_state_dict
              # dist checkpointing needs torch.distributed to load the checkpoint
              if parallel_state.is_unitialized():
  
                  def dummy():
                      return
  
                  if model.trainer.strategy.launcher is not None:
                      model.trainer.strategy.launcher.launch(
                          dummy, trainer=model.trainer
                      )
                  model.trainer.strategy.setup_environment()
              # load the checkpoint from disk
              checkpoint = dist_checkpointing.load(
                  sharded_state_dict=checkpoint,
                  checkpoint_dir=checkpoint_dir,
              )
              # restore the weights
              model.on_load_checkpoint(checkpoint)
              if hasattr(model, "setup_transformer_engine_tp_groups"):
                  model.setup_transformer_engine_tp_groups()
  
          # NMT models do not have a `tokenizer` attribute, they instead have an encoder_tokenizer and decoder_tokenizer attribute.
          if hasattr(cfg, "tokenizer"):
              if cfg.tokenizer.get("tokenizer_model") is not None:
                  model.register_artifact(
                      "tokenizer.tokenizer_model",
                      cfg.tokenizer.tokenizer_model,
                  )
              if cfg.tokenizer.get("vocab_file") is not None:
                  model.register_artifact(
                      "tokenizer.vocab_file", cfg.tokenizer.vocab_file
                  )
              if cfg.tokenizer.get("merge_file") is not None:
                  model.register_artifact(
                      "tokenizer.merge_file", cfg.tokenizer.merge_file
                  )
  
          if hasattr(cfg, "encoder_tokenizer"):
              if (
                  cfg.encoder_tokenizer.get("tokenizer_model")
                  is not None
              ):
                  model.register_artifact(
                      "encoder_tokenizer.tokenizer_model",
                      cfg.encoder_tokenizer.tokenizer_model,
                  )
              if cfg.encoder_tokenizer.get("vocab_file") is not None:
                  model.register_artifact(
                      "encoder_tokenizer.vocab_file",
                      cfg.encoder_tokenizer.vocab_file,
                  )
              if cfg.encoder_tokenizer.get("merge_file") is not None:
                  model.register_artifact(
                      "encoder_tokenizer.merge_file",
                      cfg.encoder_tokenizer.merge_file,
                  )
  
          if hasattr(cfg, "decoder_tokenizer"):
              if (
                  cfg.decoder_tokenizer.get("tokenizer_model")
                  is not None
              ):
                  model.register_artifact(
                      "decoder_tokenizer.tokenizer_model",
                      cfg.decoder_tokenizer.tokenizer_model,
                  )
              if cfg.decoder_tokenizer.get("vocab_file") is not None:
                  model.register_artifact(
                      "decoder_tokenizer.vocab_file",
                      cfg.decoder_tokenizer.vocab_file,
                  )
              if cfg.decoder_tokenizer.get("merge_file") is not None:
                  model.register_artifact(
                      "decoder_tokenizer.merge_file",
                      cfg.decoder_tokenizer.merge_file,
                  )
  
          checkpoint = model
  
      finally:
          cls._set_model_restore_state(is_being_restored=False)
      return checkpoint
  
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 11 for calling the NLPModel obj's underlying member method code with example usage: obj.load_from_checkpoint(cls, checkpoint_path, map_location, hparams_file, strict) and returns: checkpoint