Skip to navigation

nemo_automodel.components.datasets.mockable

View as MarkdownOpen in Claude

Datasets, and their configs, that can serve mock token ids in place of their data.

Module Contents

Classes

NameDescription
MockSamplesThe token ids of the samples of a mock MockableDataset, which walk a vocabulary in order.
MockableDatasetBase of datasets that can serve mock token ids instead of reading their data.
MockableDatasetConfigBase of dataset configs whose dataset can serve mock token ids instead of reading its data.

Data

_SampleT

API

class nemo_automodel.components.datasets.mockable.MockSamples(
vocab_size: int,
length: int,
excluded_ids: collections.abc.Iterable[int] = (),
num_samples: int | None = None
)

The token ids of the samples of a mock MockableDataset, which walk a vocabulary in order.

The walk is k, k + 1, k + 2, ... over the vocabulary, wrapping around at its end. samples[i] is the length ids that follow the first i * length ids of the walk, so reading a sample costs one slice and no random numbers. len(samples) is the number of samples of a map-style dataset.

_period
= ids.size
_walk
= np.resize(ids, ids.size + length - 1)
nemo_automodel.components.datasets.mockable.MockSamples.__getitem__(
index: int
) -> numpy.ndarray

Return the int64 token ids of sample index, as a read-only view.

Raises:

  • IndexError: If index is outside a map-style dataset’s num_samples (counted from the end when negative), so that iterating the dataset ends.
nemo_automodel.components.datasets.mockable.MockSamples.__len__() -> int
class nemo_automodel.components.datasets.mockable.MockableDataset()

Bases: Dataset[_SampleT]

Base of datasets that can serve mock token ids instead of reading their data.

mocked builds a dataset without running its data-loading __init__. Each subclass’s data methods check is_mock and serve mock_samples through their own mock implementation when it is true.

is_mock
bool = False

Whether the dataset serves mock_samples instead of its data.

mock_samples
MockSamples

The token ids of the mock samples, set when the dataset is built with mocked.

nemo_automodel.components.datasets.mockable.MockableDataset.mocked(
) -> typing.Self
classmethod

Return a mock of this dataset without running its data-loading __init__.

class nemo_automodel.components.datasets.mockable.MockableDatasetConfig(
mock: bool = False,
mock_vocab_size: int | None = None
)
Dataclass

Base of dataset configs whose dataset can serve mock token ids instead of reading its data.

Subclassing it gives a dataset config the mock switch. With mock: true the dataset keeps what its config describes (sequence length, sample fields and dtypes, number of samples, …) but takes its token ids from MockSamples instead of its files, so a recipe runs without its data and without preprocessing, for example to benchmark it. With mock set, each subclass’s build returns its dataset’s MockableDataset.mocked of mock_samples.

mock
bool = False

Serve mock token ids instead of reading the dataset’s files.

mock_vocab_size
int | None = None

Mock token ids are below this; defaults to the tokenizer’s vocabulary size.

nemo_automodel.components.datasets.mockable.MockableDatasetConfig.mock_samples(
tokenizer: transformers.tokenization_utils_base.PreTrainedTokenizerBase | None,
length: int,
num_samples: int | None = None

Return the samples a mock of this dataset serves.

Their token ids walk the vocabulary without its special tokens, which keeps padding and document boundaries out of the mock samples, so every position is trained on.

Parameters:

tokenizer
PreTrainedTokenizerBase | None

Runtime tokenizer of the recipe, or None when the recipe has none.

length
int

Token ids per sample.

num_samples
int | NoneDefaults to None

Number of samples of a map-style dataset; None for an endless stream.

Raises:

  • ValueError: If neither mock_vocab_size nor tokenizer gives the vocabulary size.
nemo_automodel.components.datasets.mockable._SampleT = TypeVar('_SampleT')