code: def load_model(model, state_dict, ignore_if_missing=tuple()):
      # try:
      for name, module in model.named_parameters():
          if name in state_dict:
              module.data = state_dict.pop(name)
          else:
              raise RuntimeError(
                  f"Unexpected key: {name} not in state_dict but in model."
              )
  
      for name, buffer in model.named_buffers():
          if name in state_dict:
              buffer.data = state_dict.pop(name)
  
      # Some previous buffers are known to be removed in new mcore models => it is ok to ignore them.
      for key in list(state_dict):
          if any(key.endswith(suffix) for suffix in ignore_if_missing):
              state_dict.pop(key)
  
      if state_dict:
          raise RuntimeError(
              f"Additional keys: {state_dict.keys()} in state_dict but not in model."
          )
  
      return model
  
file_path: NeMo/scripts/nlp_language_modeling/convert_nemo_gpt_to_mcore.py
imports: import os
  from argparse import ArgumentParser
  from collections import OrderedDict
  import torch
  from omegaconf import OmegaConf, open_dict
  from pytorch_lightning.trainer.trainer import Trainer
  from nemo.collections.nlp.models.language_modeling.megatron_gpt_model import MegatronGPTModel
  from nemo.collections.nlp.parts.nlp_overrides import NLPDDPStrategy
  from nemo.utils import AppState, logging
label_desc: Use image node_id 5 for calling a global function with example usage: load_model(model, state_dict, ignore_if_missing) and returns: model