code: def load_from_checkpoint_dir(cls, cfg, trainer, modify_confg_fn):
      app_state = AppState()
      if (
          cfg.model.tensor_model_parallel_size > 1
          or cfg.model.pipeline_model_parallel_size > 1
      ):
          app_state.model_parallel_size = (
              cfg.model.tensor_model_parallel_size
              * cfg.model.pipeline_model_parallel_size
          )
          app_state.tensor_model_parallel_size = (
              cfg.model.tensor_model_parallel_size
          )
          app_state.pipeline_model_parallel_size = (
              cfg.model.pipeline_model_parallel_size
          )
          (
              app_state.tensor_model_parallel_rank,
              app_state.pipeline_model_parallel_rank,
              app_state.model_parallel_size,
              app_state.data_parallel_size,
              app_state.pipeline_model_parallel_split_rank,
              app_state.virtual_pipeline_model_parallel_rank,
          ) = fake_initialize_model_parallel(
              world_size=app_state.model_parallel_size,
              rank=trainer.global_rank,
              tensor_model_parallel_size_=cfg.model.tensor_model_parallel_size,
              pipeline_model_parallel_size_=cfg.model.pipeline_model_parallel_size,
              pipeline_model_parallel_split_rank_=cfg.model.pipeline_model_parallel_split_rank,
          )
      checkpoint_path = inject_model_parallel_rank(
          os.path.join(
              cfg.model.pretrained_checkpoint.checkpoint_dir,
              cfg.model.pretrained_checkpoint.checkpoint_name,
          )
      )
      hparams_file = OmegaConf.load(
          cfg.model.pretrained_checkpoint.hparams_file
      )
      gpt_cfg = modify_confg_fn(
          hparams_file.cfg, cfg, add_cfg_to_tree=True
      )
      with tempfile.NamedTemporaryFile(suffix=".yaml") as f:
          OmegaConf.save(config=gpt_cfg, f=f.name)
          model = cls.load_from_checkpoint(
              checkpoint_path=checkpoint_path,
              trainer=trainer,
              hparams_file=f.name,
          )
          return model
  
file_path: NeMo/examples/nlp/language_modeling/tuning/megatron_gpt_sft.py
imports: import os
  import tempfile
  import torch.multiprocessing
  from omegaconf.omegaconf import OmegaConf, open_dict
  from pytorch_lightning import Trainer
  from pytorch_lightning.plugins.environments import TorchElasticEnvironment
  from nemo.collections.nlp.data.language_modeling.megatron.gpt_sft_chat_dataset import get_prompt_template_example
  from nemo.collections.nlp.models.language_modeling.megatron_gpt_sft_model import MegatronGPTSFTModel
  from nemo.collections.nlp.modules.common.megatron.megatron_init import fake_initialize_model_parallel
  from nemo.collections.nlp.parts.nlp_overrides import CustomProgressBar, GradScaler, MegatronHalfPrecisionPlugin, NLPDDPStrategy, NLPSaveRestoreConnector, PipelineMixedPrecisionPlugin
  from nemo.core.config import hydra_runner
  from nemo.utils import AppState, logging
  from nemo.utils.decorators import deprecated
  from nemo.utils.exp_manager import exp_manager
  from nemo.utils.model_utils import inject_model_parallel_rank
label_desc: Use image node_id 3 for calling a global function with example usage: load_from_checkpoint_dir(cls, cfg, trainer, modify_confg_fn) and returns: model