> 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.models.ergo.tokenization

SentencePiece and token-level chat formatting for Ergo.

The chat protocol implemented here (speaker labels, the default system prompt, the CONTROL token boundaries,
tool definitions and tool calls) is the one of the chat template published with the weights:
Amazon-FMR/Ergo-bf16 at revision f47e685ec4b5095a0880e05cc514a4026859f9ed,
[https://huggingface.co/Amazon-FMR/Ergo-bf16/tree/f47e685ec4b5095a0880e05cc514a4026859f9ed](https://huggingface.co/Amazon-FMR/Ergo-bf16/tree/f47e685ec4b5095a0880e05cc514a4026859f9ed)
Original files: `chat_template.jinja` (the protocol) and `tokenizer.model` (the SentencePiece model this
tokenizer loads), under the Amazon Ergo Open-Weights License (`LICENSE.md` of that repository).

CONTROL boundaries are inserted by ID; encoding literal message text never creates these boundaries.

## Module Contents

### Classes

| Name                                                                                 | Description                                                              |
| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------ |
| [`ErgoTokenizer`](#nemo_automodel-components-models-ergo-tokenization-ErgoTokenizer) | HF tokenizer using explicit CONTROL IDs and exact assistant token masks. |

### Functions

| Name                                                                                         | Description |
| -------------------------------------------------------------------------------------------- | ----------- |
| [`_ordered_messages`](#nemo_automodel-components-models-ergo-tokenization-_ordered_messages) | -           |
| [`_text`](#nemo_automodel-components-models-ergo-tokenization-_text)                         | -           |
| [`_tool_definitions`](#nemo_automodel-components-models-ergo-tokenization-_tool_definitions) | -           |

### Data

[`CHAT_PROTOCOL`](#nemo_automodel-components-models-ergo-tokenization-CHAT_PROTOCOL)

[`DEFAULT_SYSTEM_PROMPT`](#nemo_automodel-components-models-ergo-tokenization-DEFAULT_SYSTEM_PROMPT)

[`JsonValue`](#nemo_automodel-components-models-ergo-tokenization-JsonValue)

[`SPEAKERS`](#nemo_automodel-components-models-ergo-tokenization-SPEAKERS)

### API

```python
class nemo_automodel.components.models.ergo.tokenization.ErgoTokenizer(
    vocab_file: str,
    add_bos_token: bool = False,
    add_eos_token: bool = False,
    kwargs: typing.Any = {}
)
```

**Bases:** `PreTrainedTokenizer`

HF tokenizer using explicit CONTROL IDs and exact assistant token masks.

**`additional_stop_token_ids`** `= {self.control_ids['<ctrl100>']}`

---

**`control_ids`**

---

**`model_input_names`** `= ['input_ids', 'attention_mask']`

---

**`sp_model`** `= spm.SentencePieceProcessor(model_file=vocab_file)`

---

**`vocab_files_names`** `= {'vocab_file': 'tokenizer.model'}`

---

**`vocab_size`** `int`

Return the unmodified SentencePiece vocabulary size.

---

```python
nemo_automodel.components.models.ergo.tokenization.ErgoTokenizer._convert_id_to_token(
    index: int
) -> str
```

```python
nemo_automodel.components.models.ergo.tokenization.ErgoTokenizer._convert_token_to_id(
    token: str
) -> int
```

```python
nemo_automodel.components.models.ergo.tokenization.ErgoTokenizer._decode(
    token_ids: list[int],
    skip_special_tokens: bool = False,
    kwargs: typing.Any = {}
) -> str
```

```python
nemo_automodel.components.models.ergo.tokenization.ErgoTokenizer._encode_chat(
    messages: collections.abc.Sequence[collections.abc.Mapping[str, typing.Any]],
    tools: collections.abc.Sequence[collections.abc.Mapping[str, typing.Any]] | None,
    add_generation_prompt: bool,
    thinking: bool,
    continue_final_message: bool
) -> tuple[list[int], list[int]]
```

```python
nemo_automodel.components.models.ergo.tokenization.ErgoTokenizer._tokenize(
    text: str,
    kwargs: typing.Any = {}
) -> list[str]
```

```python
nemo_automodel.components.models.ergo.tokenization.ErgoTokenizer.apply_chat_template(
    conversation: list[dict[str, typing.Any]] | list[list[dict[str, typing.Any]]],
    tools: list[dict[str, typing.Any]] | None = None,
    tokenize: bool = True,
    add_generation_prompt: bool = False,
    continue_final_message: bool = False,
    thinking: bool = True,
    padding: bool | str = False,
    truncation: bool = False,
    max_length: int | None = None,
    return_tensors: str | None = None,
    return_dict: bool = False,
    return_assistant_tokens_mask: bool = False,
    kwargs: typing.Any = {}
) -> typing.Any
```

Serialize chats by ID, preserving assistant masks through padding.

Text rendering cannot represent this CONTROL protocol: tokenize=False
is rejected so callers cannot accidentally train on literal delimiters.
The shared SFT formatter consumes the IDs and owns the next-token shift.

```python
nemo_automodel.components.models.ergo.tokenization.ErgoTokenizer.build_inputs_with_special_tokens(
    token_ids_0: list[int],
    token_ids_1: list[int] | None = None
) -> list[int]
```

Add the begin and end tokens to plain text only as the tokenizer settings say.

**Parameters:**

**`token_ids_0`** `list[int]`

Token IDs of the text, of any length.

---

**`token_ids_1`** `list[int] | None` — default: None

Optional token IDs of a second text, appended to the first.

---

**Returns:** `list[int]`

The IDs of both texts, with `bos_token_id` in front when `add_bos_token` is set and

```python
nemo_automodel.components.models.ergo.tokenization.ErgoTokenizer.convert_tokens_to_string(
    tokens: list[str]
) -> str
```

Decode ordinary SentencePiece pieces.

```python
nemo_automodel.components.models.ergo.tokenization.ErgoTokenizer.get_vocab() -> dict[str, int]
```

Return SentencePiece's vocabulary plus any explicitly added tokens.

```python
nemo_automodel.components.models.ergo.tokenization.ErgoTokenizer.save_vocabulary(
    save_directory: str,
    filename_prefix: str | None = None
) -> tuple[str]
```

Save the exact SentencePiece binary for lossless tokenizer reload.

```python
nemo_automodel.components.models.ergo.tokenization.ErgoTokenizer.tokenize(
    text: str,
    kwargs: typing.Any = {}
) -> list[str]
```

Encode ordinary text without HF's special-token string matching.

```python
nemo_automodel.components.models.ergo.tokenization._ordered_messages(
    messages: collections.abc.Sequence[collections.abc.Mapping[str, typing.Any]]
) -> list[dict[str, typing.Any]]
```

```python
nemo_automodel.components.models.ergo.tokenization._text(
    content: str | list[str | collections.abc.Mapping[str, str]] | None
) -> str
```

```python
nemo_automodel.components.models.ergo.tokenization._tool_definitions(
    tools: collections.abc.Sequence[collections.abc.Mapping[str, typing.Any]]
) -> str
```

```python
nemo_automodel.components.models.ergo.tokenization.CHAT_PROTOCOL = '{# Ergo token-ID protocol; reasoning_content #}{% generation %}{% endgeneration...
```

```python
nemo_automodel.components.models.ergo.tokenization.DEFAULT_SYSTEM_PROMPT = 'You are Ergo, a model built by Amazon. You are a helpful agent that is good at ...
```

```python
nemo_automodel.components.models.ergo.tokenization.JsonValue: TypeAlias = str | int | float | bool | None | list['JsonValue'] | dict[str, 'JsonValue']
```

```python
nemo_automodel.components.models.ergo.tokenization.SPEAKERS = {'system': 'System', 'developer': 'System', 'user': 'User', 'assistant': 'Assist...
```