code: def load_model(cls, checkpoint, strict, **kwargs):
      try:
          if "cfg" in kwargs:
              model = ptl_load_state(
                  cls, checkpoint, strict=strict, **kwargs
              )
          else:
              model = cls(
                  cfg=checkpoint[cls.CHECKPOINT_HYPER_PARAMS_KEY],
                  **kwargs,
              )
              for name, module in model.named_parameters():
                  if name in checkpoint["state_dict"]:
                      module.data = checkpoint["state_dict"][name]
                      checkpoint["state_dict"].pop(name)
                  else:
                      print(
                          f"Unexpected key: {name} not in checkpoint but in model."
                      )
  
              for name, buffer in model.named_buffers():
                  if name in checkpoint["state_dict"]:
                      buffer.data = checkpoint["state_dict"][name]
                      checkpoint["state_dict"].pop(name)
  
              if len(checkpoint["state_dict"].keys()) != 0:
                  raise RuntimeError(
                      f"Additional keys: {checkpoint['state_dict'].keys()} in checkpoint but not in model."
                  )
  
              # register the artifacts
              cfg = checkpoint[cls.CHECKPOINT_HYPER_PARAMS_KEY]
              if cfg.tokenizer.model is not None:
                  model.register_artifact(
                      "tokenizer.tokenizer_model", cfg.tokenizer.model
                  )
              if cfg.tokenizer.vocab_file is not None:
                  model.register_artifact(
                      "tokenizer.vocab_file", cfg.tokenizer.vocab_file
                  )
              if cfg.tokenizer.merge_file is not None:
                  model.register_artifact(
                      "tokenizer.merge_file", cfg.tokenizer.merge_file
                  )
      finally:
          cls._set_model_restore_state(is_being_restored=False)
      return model
  
file_path: NeMo/scripts/nlp_language_modeling/convert_hf_llama_to_nemo.py
imports: import os
  from argparse import ArgumentParser
  from collections import OrderedDict
  import torch
  from omegaconf import OmegaConf
  from pytorch_lightning.core.saving import _load_state
  from pytorch_lightning.trainer.trainer import Trainer
  from transformers import LlamaForCausalLM, LlamaTokenizer
  from nemo.collections.nlp.models.language_modeling.megatron_gpt_model import MegatronGPTModel
  from nemo.collections.nlp.parts.nlp_overrides import GradScaler, MegatronHalfPrecisionPlugin, NLPDDPStrategy, NLPSaveRestoreConnector, PipelineMixedPrecisionPlugin
  from nemo.collections.nlp.parts.utils_funcs import torch_dtype_from_precision
  from nemo.utils import logging
label_desc: Use image node_id 2 for calling a global function with example usage: load_model(cls, checkpoint, strict) and returns: model