> This page is for version Nightly (default).
> 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.zephon.llm

Text tokenizer IDs and pretokenized-document validation.

## Module Contents

### Classes

| Name                                                                  | Description                                                         |
| --------------------------------------------------------------------- | ------------------------------------------------------------------- |
| [`TokenIds`](#nemo_automodel-components-datasets-zephon-llm-TokenIds) | Resolved existing vocabulary IDs; no tokens are added to the model. |

### Functions

| Name                                                                                                                            | Description                                                                |
| ------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
| [`_validate_pretokenized_document`](#nemo_automodel-components-datasets-zephon-llm-_validate_pretokenized_document)             | Validate tokens and supervision without allocating the delivered payload.  |
| [`measure_pretokenized_document`](#nemo_automodel-components-datasets-zephon-llm-measure_pretokenized_document)                 | Count supplied token IDs for mixture calibration, including masked tokens. |
| [`normalize_pretokenized_document`](#nemo_automodel-components-datasets-zephon-llm-normalize_pretokenized_document)             | Adapt pretokenized fields while preserving IDs and supplied supervision.   |
| [`prepare_text_document_without_packing`](#nemo_automodel-components-datasets-zephon-llm-prepare_text_document_without_packing) | Supply boundaries when packing is off, without guessing from token values. |
| [`resolve_token_ids`](#nemo_automodel-components-datasets-zephon-llm-resolve_token_ids)                                         | Resolve PAD/BOS/EOS using the effective AutoModel tokenizer.               |

### API

```python
class nemo_automodel.components.datasets.zephon.llm.TokenIds(
    bos: int | None,
    eos: int | None,
    pad: int
)
```

Dataclass

Resolved existing vocabulary IDs; no tokens are added to the model.

**`bos`** `int | None`

---

**`eos`** `int | None`

---

**`pad`** `int`

---

```python
nemo_automodel.components.datasets.zephon.llm._validate_pretokenized_document(
    payload: collections.abc.Mapping[str, typing.Any],
    config: nemo_automodel.components.datasets.zephon.config.ZephonPretokenizedTextDatasetConfig,
    valid_token_ids: numpy.ndarray
) -> tuple[numpy.ndarray, numpy.ndarray | None]
```

Validate tokens and supervision without allocating the delivered payload.

`valid_token_ids` is a sorted int64 vocabulary array constructed once per
pipeline. Exact vectorized membership preserves holes in tokenizer IDs.

```python
nemo_automodel.components.datasets.zephon.llm.measure_pretokenized_document(
    payload: collections.abc.Mapping[str, typing.Any],
    tokens_field: str
) -> int
```

Count supplied token IDs for mixture calibration, including masked tokens.

Calibration reads the raw document before field normalization, so it needs
the configured token field. There is no tokenizer or filtering to replay;
delivery validates the payload and preserves the token count.

**Parameters:**

**`payload`** `Mapping[str, Any]`

Raw document containing token IDs of shape \[tokens].

---

**`tokens_field`** `str`

Field holding the unshifted token IDs.

---

**Returns:** `int`

Number of supplied tokens, independent of their loss-mask values.

```python
nemo_automodel.components.datasets.zephon.llm.normalize_pretokenized_document(
    payload: collections.abc.Mapping[str, typing.Any],
    config: nemo_automodel.components.datasets.zephon.config.ZephonPretokenizedTextDatasetConfig,
    valid_token_ids: numpy.ndarray,
    preserve_positions: bool = False
) -> dict[str, numpy.ndarray]
```

Adapt pretokenized fields while preserving IDs and supplied supervision.

Uniform loss-mask fields keep supervision aligned when masked and unmasked
documents are packed together. Short and fully masked documents are retained;
document-boundary masking belongs to to_training's mask_segment_starts option.

**Parameters:**

**`payload`** `Mapping[str, Any]`

Document with token IDs of shape \[tokens] and an
optional binary loss mask of shape \[tokens], both before shifting.
Offline packs may include zero-based reset `positions` \[tokens].

---

**`config`** `ZephonPretokenizedTextDatasetConfig`

Source field names; absent loss masks select all tokens.

---

**`valid_token_ids`** `np.ndarray`

Sorted vocabulary IDs of shape \[vocab].

---

**`preserve_positions`** `bool` — default: False

Accept offline boundaries when online packing is off.

---

**Returns:** `dict[str, np.ndarray]`

int64 input_ids and uint8 loss_mask arrays, each of shape \[tokens].

```python
nemo_automodel.components.datasets.zephon.llm.prepare_text_document_without_packing(
    payload: dict[str, typing.Any],
    max_length: int
) -> dict[str, typing.Any]
```

Supply boundaries when packing is off, without guessing from token values.

to_training needs scalar reset positions to derive document IDs and boundary
loss masks. Offline exports can supply those positions; absent metadata means
exactly one document, even when the tokens contain multiple EOS markers.

**Parameters:**

**`payload`** `dict[str, Any]`

Tokenized document with input_ids \[tokens], optional aligned
loss_mask \[tokens], and optional validated positions \[tokens].

---

**`max_length`** `int`

Unshifted token budget, including the final prediction target.

---

**Returns:** `dict[str, Any]`

The input mapping when it already has positions, otherwise a new mapping

**Raises:**

* `ValueError`: When the document exceeds the configured input/target budget.

```python
nemo_automodel.components.datasets.zephon.llm.resolve_token_ids(
    tokenizer: transformers.PreTrainedTokenizerBase,
    pad_token_id: int | None
) -> nemo_automodel.components.datasets.zephon.llm.TokenIds
```

Resolve PAD/BOS/EOS using the effective AutoModel tokenizer.

Honor the declared tokenizer padding ID or a compatible explicit override.
Otherwise prefer a named padding token, a reserved special token, UNK, then
EOS. Reusing an existing ID avoids resizing model embeddings; preferring a
non-EOS ID keeps padding distinct from document ends when possible. Padding
is masked by position, including when PAD equals EOS.