> This page is for version 0.4.0 · 26.04.
> For other versions, use one of these documentation indexes:
> - Nightly (default): https://docs.nvidia.com/nemo/automodel/nightly/llms.txt
> - Latest: https://docs.nvidia.com/nemo/automodel/latest/llms.txt
> - 0.7.0 · 26.10: https://docs.nvidia.com/nemo/automodel/v0.7/llms.txt
> - 0.5.0 · 26.06: https://docs.nvidia.com/nemo/automodel/v0.5/llms.txt
> - 0.4.0 · 26.04: https://docs.nvidia.com/nemo/automodel/v0.4/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/automodel/llms.txt.

# nemo_automodel.components.datasets.mockable

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

## Module Contents

### Classes

| Name                                                                                          | Description                                                                                 |
| --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| [`MockSamples`](#nemo_automodel-components-datasets-mockable-MockSamples)                     | The token ids of the samples of a mock `MockableDataset`, which walk a vocabulary in order. |
| [`MockableDataset`](#nemo_automodel-components-datasets-mockable-MockableDataset)             | Base of datasets that can serve mock token ids instead of reading their data.               |
| [`MockableDatasetConfig`](#nemo_automodel-components-datasets-mockable-MockableDatasetConfig) | Base of dataset configs whose dataset can serve mock token ids instead of reading its data. |

### Data

[`_SampleT`](#nemo_automodel-components-datasets-mockable-_SampleT)

### API

```python
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)`

---

```python
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.

```python
nemo_automodel.components.datasets.mockable.MockSamples.__len__() -> int
```

```python
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`.

---

```python
nemo_automodel.components.datasets.mockable.MockableDataset.mocked(
    samples: nemo_automodel.components.datasets.mockable.MockSamples
) -> typing.Self
```

classmethod

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

```python
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.

---

```python
nemo_automodel.components.datasets.mockable.MockableDatasetConfig.mock_samples(
    tokenizer: transformers.tokenization_utils_base.PreTrainedTokenizerBase | None,
    length: int,
    num_samples: int | None = None
) -> nemo_automodel.components.datasets.mockable.MockSamples
```

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 | None` — default: 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.

```python
nemo_automodel.components.datasets.mockable._SampleT = TypeVar('_SampleT')
```