code: def initialize_model_parallel_for_nemo(
      world_size,
      global_rank,
      local_rank,
      tensor_model_parallel_size=1,
      pipeline_model_parallel_size=1,
      virtual_pipeline_model_parallel_size=None,
      pipeline_model_parallel_split_rank=None,
      context_parallel_size=1,
      micro_batch_size=None,
      global_batch_size=None,
      rampup_batch_size=None,
      use_fp8=False,
      init_mpi_proc_group=False,
      seed=1234,
      apex_transformer_log_level=30,
  ):
      if (
          virtual_pipeline_model_parallel_size is not None
          and not HAVE_INTERLEAVED
      ):
          raise ValueError(
              "set_virtual_pipeline_model_parallel_world_size is needed in megatron-core for interleaved."
          )
  
      # updating NeMo globals
      app_state = AppState()
      app_state.global_rank = global_rank
      app_state.world_size = world_size
      app_state.local_rank = local_rank
      app_state.tensor_model_parallel_size = tensor_model_parallel_size
      app_state.pipeline_model_parallel_size = (
          pipeline_model_parallel_size
      )
      app_state.virtual_pipeline_model_parallel_size = (
          virtual_pipeline_model_parallel_size
      )
      app_state.context_parallel_size = context_parallel_size
      app_state.use_fp8 = use_fp8
      app_state.init_mpi_proc_group = init_mpi_proc_group
      (
          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=world_size,
          rank=global_rank,
          tensor_model_parallel_size_=tensor_model_parallel_size,
          pipeline_model_parallel_size_=pipeline_model_parallel_size,
          virtual_pipeline_model_parallel_size_=virtual_pipeline_model_parallel_size,
          pipeline_model_parallel_split_rank_=pipeline_model_parallel_split_rank,
          context_parallel_size_=context_parallel_size,
      )
  
      # update apex.transformer globals
      set_tensor_model_parallel_world_size(
          app_state.tensor_model_parallel_size
      )
      set_tensor_model_parallel_rank(
          app_state.tensor_model_parallel_rank
      )
  
      set_pipeline_model_parallel_rank(
          app_state.pipeline_model_parallel_rank
      )
      if HAVE_INTERLEAVED:
          set_virtual_pipeline_model_parallel_world_size(
              app_state.virtual_pipeline_model_parallel_size
          )
      set_virtual_pipeline_model_parallel_rank(
          app_state.virtual_pipeline_model_parallel_rank
      )
      set_pipeline_model_parallel_world_size(
          app_state.pipeline_model_parallel_size
      )
      set_pipeline_model_parallel_split_rank(
          app_state.pipeline_model_parallel_split_rank
      )
  
      _set_random_seed(seed)
  
      if global_batch_size and micro_batch_size is not None:
          # TODO: add rampup_batch_size here when we have it implemented
          from apex.transformer.pipeline_parallel.utils import (
              _GLOBAL_NUM_MICROBATCHES_CALCULATOR,
          )
  
          if _GLOBAL_NUM_MICROBATCHES_CALCULATOR is None:
              setup_microbatch_calculator(
                  rank=global_rank,
                  global_batch_size=global_batch_size,
                  micro_batch_size=micro_batch_size,
                  data_parallel_size=app_state.data_parallel_size,
                  rampup_batch_size=rampup_batch_size,
              )
          else:
              if isinstance(
                  _GLOBAL_NUM_MICROBATCHES_CALCULATOR,
                  ConstantNumMicroBatches,
              ):
                  assert (
                      _GLOBAL_NUM_MICROBATCHES_CALCULATOR.current_global_batch_size
                      == global_batch_size
                  )
                  assert (
                      _GLOBAL_NUM_MICROBATCHES_CALCULATOR.micro_batch_size
                      == micro_batch_size
                  )
                  assert (
                      _GLOBAL_NUM_MICROBATCHES_CALCULATOR.num_micro_batches
                      == global_batch_size
                      // (
                          micro_batch_size
                          * app_state.data_parallel_size
                      )
                  )
              else:
                  raise Exception(
                      "Microbatch calculator already initialized."
                  )
  
      app_state._is_megatron_initialized = True
  
      set_logging_level(apex_transformer_log_level)
  
imports: import random
  import numpy
  import torch
  from nemo.utils import AppState, logging
label_desc: Use image node_id 1 for calling a global function with example usage: initialize_model_parallel_for_nemo(world_size, global_rank, local_rank, tensor_model_parallel_size, pipeline_model_parallel_size, virtual_pipeline_model_parallel_size, pipeline_model_parallel_split_rank, context_parallel_size, micro_batch_size, global_batch_size, rampup_batch_size, use_fp8, init_mpi_proc_group, seed, apex_transformer_log_level) without return types