code: def set_virtual_parallel_rank_safely(rank: int):
      AppState().virtual_pipeline_model_parallel_rank = rank
  
      try:
          from megatron.core import parallel_state
  
          parallel_state.set_virtual_pipeline_model_parallel_rank(rank)
  
          if rank is None:
              parallel_state.set_virtual_pipeline_model_parallel_world_size(
                  None
              )
  
      except (ImportError, ModuleNotFoundError):
          logging.warning(
              "`megatron-core` not installed, cannot set virtual parallel rank !"
          )
  
imports: import os
  import shutil
  import tarfile
  import tempfile
  from argparse import ArgumentParser
  from typing import Dict, List
  import torch
  import torch.nn
  from omegaconf import OmegaConf, open_dict
  from pytorch_lightning import Trainer
  from nemo.collections.nlp.parts.nlp_overrides import NEMO_MEGATRON_MODEL_PARALLEL_APPSTATE_OVERRIDE, GradScaler, MegatronHalfPrecisionPlugin, NLPDDPStrategy, NLPSaveRestoreConnector, PipelineMixedPrecisionPlugin
  from nemo.utils import logging, model_utils
  from nemo.utils.app_state import AppState
label_desc: Use image node_id 1 for calling a global function with example usage: set_virtual_parallel_rank_safely(rank) without return types