code: def _num_epochs(
      tokens_per_epoch, seq_length, num_samples, add_extra_token=1
  ):
      """Based on number of samples and sequence lenght, calculate how many
      epochs will be needed."""
      num_epochs = 0
      total_tokens = 0
      while True:
          num_epochs += 1
          total_tokens += tokens_per_epoch
          # -1 is because we need to retrieve seq_length + 1 token each time
          # but the last token will overlap with the first token of the next
          # sample except for the last sample.
          if (
              (total_tokens - add_extra_token) // seq_length
          ) >= num_samples:
              return num_epochs
  
imports: import os
  import time
  import numpy
  import torch
  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.core import Dataset
  from nemo.utils import logging
label_desc: Use image node_id 8 for calling a global function with example usage: _num_epochs(tokens_per_epoch, seq_length, num_samples, add_extra_token) and returns: num_epochs