code: def restore_model(nemo_file, cpu_only=False):
      dummy_trainer = Trainer(
          devices=1, accelerator="cpu", strategy=NLPDDPStrategy()
      )
      map_location = torch.device("cpu") if cpu_only else None
      model_config = MegatronGPTModel.restore_from(
          nemo_file,
          trainer=dummy_trainer,
          return_config=True,
          map_location=map_location,
      )
      model_config.use_cpu_initialization = cpu_only
  
      if model_config.get("sequence_parallel", None):
          model_config.sequence_parallel = False
  
      # To copy weights in the original precision, we have to turn on O2.
      orig_megatron_amp_O2_value = model_config.megatron_amp_O2
      if "target" in model_config and model_config.target.endswith(
          "MegatronGPTSFTModel"
      ):
          logging.warning(
              "⚠️ Model target is `MegatronGPTSFTModel` which may not work with this conversion script. "
              "This is a known issue. For now, please modify the config yaml file to use `MegatronGPTModel`."
          )
  
      if model_config.precision in ["bf16", "bf16-mixed"]:
          model_config.megatron_amp_O2 = True
  
      model = MegatronGPTModel.restore_from(
          nemo_file,
          trainer=dummy_trainer,
          override_config_path=model_config,
          map_location=map_location,
      )
  
      # restore O2 to the original value so mcore model has the same config
      model.cfg.megatron_amp_O2 = orig_megatron_amp_O2_value
      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 6 for calling a global function with example usage: restore_model(nemo_file, cpu_only) and returns: model