code: def megatron_lm_inject_model_parallel_rank(filepath):
      """
      Injects tensor/pipeline model parallel ranks into the filepath.
      Does nothing if not using model parallelism.
      """
      # first make sure filepath does not have rank
      filepath = uninject_model_parallel_rank(filepath)
  
      app_state = AppState()
      if (
          app_state.model_parallel_size is not None
          and app_state.model_parallel_size > 1
      ):
          # filepath needs to be updated to include mp_rank
          dirname = os.path.dirname(filepath)
          basename = os.path.basename(filepath)
          if (
              app_state.pipeline_model_parallel_size is None
              or app_state.pipeline_model_parallel_size == 1
          ):
              filepath = f"{dirname}/mp_rank_{app_state.tensor_model_parallel_rank:02d}/{basename}"
          else:
              filepath = f"{dirname}/mp_rank_{app_state.tensor_model_parallel_rank:02d}_{app_state.pipeline_model_parallel_rank:03d}/{basename}"
          return filepath
      else:
          return filepath
  
imports: import importlib
  import os
  import pathlib
  import sys
  from argparse import ArgumentParser
  from collections import OrderedDict
  from typing import Any, Optional
  import torch
  from lightning_fabric.utilities.cloud_io import _load
  from megatron.core import parallel_state
  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.trainer.trainer import Trainer
  from pytorch_lightning.utilities.migration import pl_legacy_patch
  from nemo.collections.nlp.models.language_modeling.megatron_bert_model import MegatronBertModel
  from nemo.collections.nlp.models.language_modeling.megatron_gpt_model import MegatronGPTModel
  from nemo.collections.nlp.modules.common.megatron.megatron_init import initialize_model_parallel_for_nemo
  from nemo.collections.nlp.parts.nlp_overrides import NLPSaveRestoreConnector
  from nemo.utils import AppState, logging
  from nemo.utils.distributed import initialize_distributed
  from nemo.utils.model_utils import inject_model_parallel_rank, uninject_model_parallel_rank
label_desc: Use image node_id 7 for calling a global function with example usage: megatron_lm_inject_model_parallel_rank(filepath) and returns: filepath, filepath