code: def get_samples_mapping(
      indexed_dataset,
      data_prefix,
      num_epochs,
      max_num_samples,
      max_seq_length,
      short_seq_prob,
      seed,
      name,
      binary_head,
      index_mapping_dir: str = None,
      samples_mapping: Any = None,
  ):
      """Get a list that maps a sample index to a starting sentence index, end sentence index, and length"""
  
      if not num_epochs:
          if not max_num_samples:
              raise ValueError(
                  "Need to specify either max_num_samples "
                  "or num_epochs"
              )
          num_epochs = np.iinfo(np.int32).max - 1
      if not max_num_samples:
          max_num_samples = np.iinfo(np.int64).max - 1
  
      # Filename of the index mapping
      if index_mapping_dir is not None:
          indexmap_filename = os.path.join(
              index_mapping_dir, os.path.basename(data_prefix)
          )
      else:
          indexmap_filename = data_prefix
      indexmap_filename += "_{}_indexmap".format(name)
      if num_epochs != (np.iinfo(np.int32).max - 1):
          indexmap_filename += "_{}ep".format(num_epochs)
      if max_num_samples != (np.iinfo(np.int64).max - 1):
          indexmap_filename += "_{}mns".format(max_num_samples)
      indexmap_filename += "_{}msl".format(max_seq_length)
      indexmap_filename += "_{:0.2f}ssp".format(short_seq_prob)
      indexmap_filename += "_{}s".format(seed)
      indexmap_filename += ".npy"
  
      # Build the indexed mapping if not exist and not provided externally.
      if (
          samples_mapping is None
          and torch.distributed.get_rank() == 0
          and not os.path.isfile(indexmap_filename)
      ):
          # Fake index mapping if missing
          if (getattr(indexed_dataset, "doc_idx", None) is None) and (
              getattr(indexed_dataset, "sizes", None) is None
          ):
              make_indexed_dataset_compatibility(indexed_dataset)
  
          print(
              " > WARNING: could not find index map file {}, building "
              "the indices on rank 0 ...".format(indexmap_filename)
          )
  
          # Make sure the types match the helpers input types.
          assert indexed_dataset.doc_idx.dtype == np.int64
          assert indexed_dataset.sizes.dtype == np.int32
  
          # Build samples mapping
          verbose = torch.distributed.get_rank() == 0
          start_time = time.time()
          logging.info(
              " > building samples index mapping for {} ...".format(
                  name
              )
          )
          # First compile and then import.
          try:
              if is_global_rank_zero():
                  compile_helper()
              from nemo.collections.nlp.data.language_modeling.megatron import (
                  helpers,
              )
          except ImportError:
              raise ImportError(
                  f"Could not compile megatron dataset C++ helper functions and therefore cannot import helpers python file."
              )
          samples_mapping = helpers.build_mapping(
              indexed_dataset.doc_idx,
              indexed_dataset.sizes,
              num_epochs,
              max_num_samples,
              max_seq_length,
              short_seq_prob,
              seed,
              verbose,
              2 if binary_head else 1,
          )
          logging.info(" > done building samples index maping")
          np.save(indexmap_filename, samples_mapping, allow_pickle=True)
          logging.info(
              " > saved the index mapping in {}".format(
                  indexmap_filename
              )
          )
          # Make sure all the ranks have built the mapping
          logging.info(
              " > elasped time to build and save samples mapping "
              "(seconds): {:4f}".format(time.time() - start_time)
          )
      torch.distributed.barrier()
      counts = torch.cuda.LongTensor([1])
      torch.distributed.all_reduce(
          counts,
          group=parallel_state.get_data_parallel_group(
              with_context_parallel=True
          ),
      )
      torch.distributed.all_reduce(
          counts,
          group=parallel_state.get_pipeline_model_parallel_group(),
      )
      assert counts[0].item() == (
          torch.distributed.get_world_size()
          // torch.distributed.get_world_size(
              group=parallel_state.get_tensor_model_parallel_group()
          )
      )
      # Load indexed dataset if not given externally.
      if samples_mapping is None:
          logging.info(
              " > loading indexed mapping from {}".format(
                  indexmap_filename
              )
          )
          start_time = time.time()
          samples_mapping = np.load(
              indexmap_filename, allow_pickle=True, mmap_mode="r"
          )
          logging.info(
              "    loaded indexed file in {:3.3f} seconds".format(
                  time.time() - start_time
              )
          )
          logging.info(
              "    total number of samples: {}".format(
                  samples_mapping.shape[0]
              )
          )
  
      # Deallocate temporary numpy arrays that were created for `get_samples_mapping()` when needed
      if hasattr(indexed_dataset, "doc_idx") and hasattr(
          indexed_dataset, "sizes"
      ):
          deallocate_indexed_dataset_memory(indexed_dataset)
  
      return samples_mapping
  
imports: import collections
  import os
  import subprocess
  import time
  from typing import Any
  import numpy
  import torch
  from omegaconf import OmegaConf
  from omegaconf.dictconfig import DictConfig
  from nemo.collections.nlp.data.language_modeling.megatron.base_dataset_utils import get_datasets_weights_and_num_samples, get_train_valid_test_split_
  from nemo.collections.nlp.data.language_modeling.megatron.blendable_dataset import BlendableDataset
  from nemo.collections.nlp.data.language_modeling.megatron.indexed_dataset import deallocate_indexed_dataset_memory
  from nemo.collections.nlp.data.language_modeling.megatron.indexed_dataset import make_dataset
  from nemo.collections.nlp.data.language_modeling.megatron.indexed_dataset import make_indexed_dataset_compatibility
  from nemo.collections.nlp.data.language_modeling.megatron.length_distribution_type import LengthDistribution
  from nemo.collections.nlp.data.language_modeling.megatron.lm_adapted_t5_dataset import T5LMAdaptedDataset
  from nemo.utils import logging
  from nemo.utils.get_rank import is_global_rank_zero
label_desc: Use image node_id 15 for calling a global function with example usage: get_samples_mapping(indexed_dataset, data_prefix, num_epochs, max_num_samples, max_seq_length, short_seq_prob, seed, name, binary_head, index_mapping_dir, samples_mapping) and returns: samples_mapping