nemo_automodel.components.datasets.llm.megatron.builder
nemo_automodel.components.datasets.llm.megatron.builder
Module Contents
Classes
Functions
Data
API
Bases: Dataset
Conjugating class for a set of MegatronDataset instances
Parameters:
The MegatronDataset instances to blend
The weights that determine the dataset blend ratios
The number of samples to draw from the blend. If None, for each dataset index idx draw exactly weights[idx] samples from datasets[idx].
The config
Raises:
RuntimeError: When the dataset has fewer or more samples than ‘size’ post-initialization
Build and optionally cache the dataset index and the dataset sample index
The dataset index is a 1-D mapping which determines the dataset to query. The dataset sample index is a 1-D mapping which determines the sample to request from the queried dataset.
Returns: Tuple[numpy.ndarray, numpy.ndarray]
Tuple[numpy.ndarray, numpy.ndarray]: The dataset index and the dataset sample index
Builder class for the BlendedDataset and MegatronDataset classes
Args:
sizes (List[Optional[int]]): The minimum total number of samples to draw, or None, per split
is_built_on_rank (Callable): A callable which returns True if the dataset should be built on the current rank and False otherwise. It should be Megatron Core parallelism aware i.e. global rank, local group rank, and virtual rank may inform its return value.
config (BlendedMegatronDatasetConfig): The config object which informs dataset creation
Build all dataset splits according to the provided blend(s)
See the BlendedMegatronDatasetBuilder.build alias for more information.
Returns: List[Optional[GPTDataset]]
List[Optional[GPTDataset]]: A list containing a dataset instance (or None) per split
Build each MidLevelDataset split from a single LowLevelDataset
Parameters:
The path on disk which defines the underlying LowLevelDataset, or None for mock dataset classes
The dataset split matrix
The number of total samples to draw from each split
Whether to call barrier for rank-0 / barrier / other-ranks behavior. Set to False when we enforce this behavior at higher level.
Returns: List[Optional[GPTDataset]]
List[Optional[GPTDataset]]: The GPTDataset (or None) per split
Build the megatron datasets for a list of prefixes in parallel
Parameters:
The list of prefix strings
The dataset split ratios (must sum to 1.00)
The number of samples to request
Returns: List[List[Optional[GPTDataset]]]
List[List[Optional[GPTDataset]]]: For each split, have a list of
Return True if a given split index should be built.
If no enabled_splits were provided, all splits are enabled.
Mask splits that are not enabled by setting their bookends to None.
This preserves the original split ratios while skipping construction for disabled splits.
Build all dataset splits according to the provided blend(s)
This method is distributed-aware and must be called on all ranks.
The dataset splits returned can vary according to the config. Supply config.blend and config.split to build BlendedDataset and/or MegatronDataset splits from the same distribution. Supply config.blend_per_split to build BlendedDataset and/or MegatronDataset splits from separate distributions. In either case, for each split, handle the following cases:
(1) The split is None
- do nothing
(2) The split has one contributing dataset, and…
(a) ‘size’ is not None
- Build a mid-level dataset with low-level dataset sampling in proportion to the size
(b) ‘size’ is None
- Build mid-level datasets with no excess low-level dataset sampling
(3) The split has multiple contributing datasets, and…
(a) ‘weights’ is not None and ‘size’ is not None
- Build mid-level datasets with low-level dataset sampling in proportion to their weights and the size
- Build a top-level dataset of length marginally greater than ‘size’ with mid-level dataset sampling in proportion to their weights and the size
(b) ‘weights’ is not None and ‘size’ is None
- Error
(c) ‘weights’ is None and ‘size’ is not None
- Build mid-level datasets with no excess low-level dataset sampling
- Build a top-level dataset of length ‘size’ (capped at the sum of the mid-level dataset lengths) with mid-level dataset sampling in proportion to their lengths and the size
(d) ‘weights’ is None and ‘size’ is None
- Build mid-level datasets with no excess low-level dataset sampling
- Build a top-level dataset with no excess mid-level dataset sampling
Returns: List[Optional[GPTDataset]]
List[Optional[GPTDataset]]: A list containing a dataset instance (or None) per split
Build the GPTDataset or BlendedDataset
Return None if and only if the underlying dataset class is not built on the current rank and torch.distributed is initialized.
Parameters:
The GPTDataset or BlendedDataset class to be built. In special cases, e.g. when we are building the low level dataset for a RawMegatronDataset instance, we can accept a Callable which returns an Iterable.
Whether to call barrier for rank-0 / barrier / other-ranks behavior. Set to False when we enforce this behavior at higher level.
The positional arguments used to build the provided GPTDataset or BlendedDataset class
Returns: Optional[Union[GPTDataset | BlendedDataset, Iterable]]
Optional[Union[GPTDataset | BlendedDataset, Iterable]]: The GPTDataset or BlendedDataset instantion, the Iterable instantiation, or None
Raises:
Exception: When the dataset constructor raises an OSError
Determine the contribution of the MegatronDataset splits to the BlendedDataset splits
Parameters:
e.g. [0.3, 0.7]
The number of samples to target for each BlendedDataset split
The sample surplus to build per split per dataset
Returns: List[List[int]]
List[List[int]]: The number of samples to request per MegatronDataset per split