class_docstr: Builder class for the BlendedDataset and MegatronDataset classes
  
  Args:
      cls (Type[MegatronDataset]): The class to instantiate, must inherit from MegatronDataset
  
      sizes (List[int]): The minimum number of total samples to draw from each split, varies
      with blend
  
      config (BlendedMegatronDatasetConfig): The config object which informs dataset creation
class_docstr_tok: ["Builder","class","for","the","BlendedDataset","and","MegatronDataset","classes","Args",":","cls","(","Type","[","MegatronDataset","]",")",":","The","class","to","instantiate",",","must","inherit","from","MegatronDataset","sizes","(","List","[","int","]",")",":","The","minimum","number","of","total","samples","to","draw","from","each","split",",","varies","with","blend","config","(","BlendedMegatronDatasetConfig",")",":","The","config","object","which","informs","dataset","creation"]
docstr: Build the DistributedDataset
  
  Return None if and only if the underlying MegatronDataset class is not built on the current
  rank and torch.distributed is initialized.
  
  Args:
      cls (Type[DistributedDataset]): The DistributedDataset class to be built
  
      args (Tuple[Any]): The positional arguments used to build the provided
      DistributedDataset class
  
  Raises:
      Exception: When the dataset constructor raises an OSError
  
  Returns:
      Optional[DistributedDataset]: The DistributedDataset instantion or None
docstr_tok: ["Build","the","DistributedDataset","Return","None","if","and","only","if","the","underlying","MegatronDataset","class","is","not","built","on","the","current","rank","and","torch.distributed","is","initialized",".","Args",":","cls","(","Type","[","DistributedDataset","]",")",":","The","DistributedDataset","class","to","be","built","args","(","Tuple","[","Any","]",")",":","The","positional","arguments","used","to","build","the","provided","DistributedDataset","class","Raises",":","Exception",":","When","the","dataset","constructor","raises","an","OSError","Returns",":","Optional","[","DistributedDataset","]",":","The","DistributedDataset","instantion","or","None"]
code: def build_generic_dataset(
      cls: Type[DistributedDataset],
      is_built_on_rank: Callable,
      *args: Any,
  ) -> Optional[DistributedDataset]:
      """Build the DistributedDataset
  
      Return None if and only if the underlying MegatronDataset class is not built on the current
      rank and torch.distributed is initialized.
  
      Args:
          cls (Type[DistributedDataset]): The DistributedDataset class to be built
  
          args (Tuple[Any]): The positional arguments used to build the provided
          DistributedDataset class
  
      Raises:
          Exception: When the dataset constructor raises an OSError
  
      Returns:
          Optional[DistributedDataset]: The DistributedDataset instantion or None
      """
      if torch.distributed.is_initialized():
          rank = torch.distributed.get_rank()
  
          dataset = None
  
          # First, build on rank 0
          if rank == 0 and is_built_on_rank():
              try:
                  dataset = cls(*args)
              except OSError as err:
                  log = (
                      f"Failed to write dataset materials to the data cache directory. "
                      + f"Please supply a directory to which you have write access via "
                      + f"the path_to_cache attribute in BlendedMegatronDatasetConfig and "
                      + f"retry. Refer to the preserved traceback above for more information."
                  )
                  raise Exception(log) from err
  
          torch.distributed.barrier()
  
          # After, build on other ranks
          if rank != 0 and is_built_on_rank():
              dataset = cls(*args)
  
          return dataset
  
      return cls(*args)
  
file_path: megatron-lm/megatron/core/datasets/blended_megatron_dataset_builder.py
imports: import logging
  import math
  from typing import Any, Callable, List, Optional, Tuple, Type, Union
  import numpy
  import torch
  from megatron.core.datasets.blended_dataset import BlendedDataset
  from megatron.core.datasets.blended_megatron_dataset_config import BlendedMegatronDatasetConfig
  from megatron.core.datasets.indexed_dataset import MMapIndexedDataset
  from megatron.core.datasets.megatron_dataset import MegatronDataset
  from megatron.core.datasets.utils import Split, normalize
label_desc: Use image node_id 5 for calling the BlendedMegatronDatasetBuilder obj's underlying member method code with example usage: obj.build_generic_dataset(cls, is_built_on_rank) and returns: cls, dataset