Skip to navigation

nemo_automodel.components.datasets.zephon.llm

View as MarkdownOpen in Claude

Text tokenizer IDs and pretokenized-document validation.

Module Contents

Classes

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

Functions

NameDescription
_validate_pretokenized_documentValidate tokens and supervision without allocating the delivered payload.
measure_pretokenized_documentCount supplied token IDs for mixture calibration, including masked tokens.
normalize_pretokenized_documentAdapt pretokenized fields while preserving IDs and supplied supervision.
prepare_text_document_without_packingSupply boundaries when packing is off, without guessing from token values.
resolve_token_idsResolve PAD/BOS/EOS using the effective AutoModel tokenizer.

API

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
nemo_automodel.components.datasets.zephon.llm._validate_pretokenized_document(
payload: collections.abc.Mapping[str, typing.Any],
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.

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.

nemo_automodel.components.datasets.zephon.llm.normalize_pretokenized_document(
payload: collections.abc.Mapping[str, typing.Any],
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
boolDefaults to 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].

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.
nemo_automodel.components.datasets.zephon.llm.resolve_token_ids(
tokenizer: transformers.PreTrainedTokenizerBase,
pad_token_id: int | None

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.