code: def compute_split_index(
      self,
      model,
      idx,
      tp_rank,
      pp_rank,
      pp_split_rank,
      tp_size,
      pp_size,
  ):
      final_idx = idx
  
      # Special case for T5 models - where the embeddings are shared between encoder and decoder
      # and the rank of decoder split is arbitrary.
      # Megatron T5 check for pipeline_model_parallel_split_rank in order to inject encoder embeddings
      self.shared_enc_dec_embeddings = (
          pp_split_rank > 0
          and pp_split_rank == pp_rank
          and model.cfg.get("share_token_embeddings", True)
      )
      # If embedding sharing is active, both vocab and position embeddings are shared
      if self.shared_enc_dec_embeddings:
          self.enc_dec_share_token_embeddings_count = 2
      else:
          self.enc_dec_share_token_embeddings_count = 0
  
      # Start to calculate new idx
      final_idx = final_idx + self.enc_dec_share_token_embeddings_count
  
      # Special case for T5 models - where the embeddings are shared between encoder and decoder
      # For all decoder ranks which are not the pp_split_rank, we need to inject the vocab embeddings only at
      # an intermediate location of the model (usually second last location).
      # Megatron T5 check for pipeline_model_parallel_split_rank in order to inject encoder embeddings
      # when the pipeline_model_parallel_split_rank is not the last PP rank
      self.shared_enc_dec_embeddings_intermediate = (
          pp_split_rank > 0
          and pp_split_rank < pp_size
          and hasattr(model, "enc_dec_model")
          and hasattr(model.enc_dec_model, "word_embeddings")
      )
  
      if self.shared_enc_dec_embeddings_intermediate:
          # Loop until we get the location of this tensor
          self.intermediate_shared_embedding_location = -1
          for (
              param_name,
              param,
          ) in model.named_parameters():  # special case for T5
              if param_name == "enc_dec_model.word_embeddings.weight":
                  self.intermediate_shared_embedding_location += 1
                  break
              self.intermediate_shared_embedding_location += 1
      else:
          self.intermediate_shared_embedding_location = -1
  
      # Re-evaluate the intermediate shared embedding flag
      self.shared_enc_dec_embeddings_intermediate = (
          self.shared_enc_dec_embeddings_intermediate
          and (self.intermediate_shared_embedding_location >= 0)
      )
      # If module is present, add a module offset to the index
      if self.shared_enc_dec_embeddings_intermediate:
          final_idx += 1
  
      if self.enc_dec_share_token_embeddings_count:
          logging.info(
              f"EncDec share_token_embeddings_count: {self.enc_dec_share_token_embeddings_count}"
          )
      if self.shared_enc_dec_embeddings_intermediate:
          logging.info(
              f"EncDec share_enc_dec_embeddings_intermediate: {self.intermediate_shared_embedding_location}"
          )
  
      return final_idx
  
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 2 for calling the T5Handler obj's underlying member method code with example usage: obj.compute_split_index(model, idx, tp_rank, pp_rank, pp_split_rank, tp_size, pp_size) and returns: final_idx