> This page is for version 0.7.0 · 26.10.
> 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.nemotron_decision.serving_prompt

The decision prompt of a Nemotron 3.5 Decision checkpoint: one question per read, one trailing mask token.

The checkpoint owns its prompt contract, and training reads each question exactly as the checkpoint does:

* `decision.json` gives the option codes per question type and the read limits; `decision_template.jinja` renders
  the prompt around `decision_content`, the JSON `&#123;"state", "question", "options": [&#123;"code", "label", "meaning"&#125;]&#125;`;
* options keep the question's order (`choice`: criteria order; `noul`: `false`, `true`; `score`: level 0
  upwards) and take the type's codes by position;
* control tokens inside the user content are encoded as plain text, so only the template's own control tokens are
  special;
* the template ends with the mask token, and the answer is the head's distribution at that mask restricted to the
  option codes.

An optional, explicit option shuffle (training only) permutes the options and re-codes them by position, so the model
learns option meanings rather than codes. The permutation seed is `crc32(f"&#123;seed&#125;|perm")`, independent of the coin
that decides whether a row is shuffled.

## Module Contents

### Classes

| Name                                                                                                      | Description                                                                              |
| --------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| [`DecisionContract`](#nemo_automodel-components-models-nemotron_decision-serving_prompt-DecisionContract) | A checkpoint's decision prompt contract (`decision.json` and `decision_template.jinja`). |
| [`PreparedQuestion`](#nemo_automodel-components-models-nemotron_decision-serving_prompt-PreparedQuestion) | One tokenized decision prompt (without the trailing mask) and its option readout.        |

### Functions

| Name                                                                                                                              | Description                                                                                              |
| --------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
| [`_control_tokens`](#nemo_automodel-components-models-nemotron_decision-serving_prompt-_control_tokens)                           | Special tokens plus the declared (or, if none are declared, template-literal) added tokens.              |
| [`_encode_marked`](#nemo_automodel-components-models-nemotron_decision-serving_prompt-_encode_marked)                             | Encode a rendered chat: marked control tokens as plain text, everything else normally.                   |
| [`_encode_piece`](#nemo_automodel-components-models-nemotron_decision-serving_prompt-_encode_piece)                               | -                                                                                                        |
| [`_encode_without_added_tokens`](#nemo_automodel-components-models-nemotron_decision-serving_prompt-_encode_without_added_tokens) | Encode `text` through the backend's normalizer, pre-tokenizer and model, matching no added token.        |
| [`_mark`](#nemo_automodel-components-models-nemotron_decision-serving_prompt-_mark)                                               | -                                                                                                        |
| [`_pattern`](#nemo_automodel-components-models-nemotron_decision-serving_prompt-_pattern)                                         | -                                                                                                        |
| [`_read_checkpoint_file`](#nemo_automodel-components-models-nemotron_decision-serving_prompt-_read_checkpoint_file)               | -                                                                                                        |
| [`_template_literal_text`](#nemo_automodel-components-models-nemotron_decision-serving_prompt-_template_literal_text)             | -                                                                                                        |
| [`label_token_ids`](#nemo_automodel-components-models-nemotron_decision-serving_prompt-label_token_ids)                           | Token ids of option codes, which must be distinct single known tokens.                                   |
| [`perm_seed`](#nemo_automodel-components-models-nemotron_decision-serving_prompt-perm_seed)                                       | Option-permutation seed, independent of the shuffle coin drawn from `random.Random(shuffle_seed)`.       |
| [`prepare_question`](#nemo_automodel-components-models-nemotron_decision-serving_prompt-prepare_question)                         | Render one question with the checkpoint's decision template, optionally with shuffled, re-coded options. |
| [`question_options`](#nemo_automodel-components-models-nemotron_decision-serving_prompt-question_options)                         | `(labels, meanings)` of a question in checkpoint order (noul: false, true; score: level indices).        |
| [`readout_token_ids`](#nemo_automodel-components-models-nemotron_decision-serving_prompt-readout_token_ids)                       | Every token id a question can read at its mask (all option codes of every type), sorted.                 |
| [`render_decision_ids`](#nemo_automodel-components-models-nemotron_decision-serving_prompt-render_decision_ids)                   | Token ids of `template` rendered around `content`, with control tokens in `content` encoded as text.     |

### Data

[`DECISION_CONFIG_FILE`](#nemo_automodel-components-models-nemotron_decision-serving_prompt-DECISION_CONFIG_FILE)

[`DECISION_TEMPLATE_FILE`](#nemo_automodel-components-models-nemotron_decision-serving_prompt-DECISION_TEMPLATE_FILE)

[`NOUL_DEFAULT_MEANINGS`](#nemo_automodel-components-models-nemotron_decision-serving_prompt-NOUL_DEFAULT_MEANINGS)

[`NOUL_OPTIONS`](#nemo_automodel-components-models-nemotron_decision-serving_prompt-NOUL_OPTIONS)

[`QUESTION_TYPES`](#nemo_automodel-components-models-nemotron_decision-serving_prompt-QUESTION_TYPES)

[`_QUESTION_FIELDS`](#nemo_automodel-components-models-nemotron_decision-serving_prompt-_QUESTION_FIELDS)

### API

```python
class nemo_automodel.components.models.nemotron_decision.serving_prompt.DecisionContract(
    template: str,
    labels: dict[str, tuple[str, ...]],
    max_input_tokens: int
)
```

Dataclass

A checkpoint's decision prompt contract (`decision.json` and `decision_template.jinja`).

**`labels`** `dict[str, tuple[str, ...]]`

Option codes per question type, in position order.

---

**`max_input_tokens`** `int`

Longest read the checkpoint accepts, mask included.

---

**`sha256`** `str`

Identity of the contract (template, codes and limit).

---

**`template`** `str`

The Jinja decision template; it renders `decision_content` and ends with the mask token.

---

```python
nemo_automodel.components.models.nemotron_decision.serving_prompt.DecisionContract.from_pretrained(
    path: str | pathlib.Path,
    revision: str | None = None
) -> nemo_automodel.components.models.nemotron_decision.serving_prompt.DecisionContract
```

classmethod

Load and validate the contract of a local checkpoint directory or Hugging Face repository.

**Raises:**

* `ValueError`: If a file is missing or the contract is malformed.

```python
class nemo_automodel.components.models.nemotron_decision.serving_prompt.PreparedQuestion(
    question_id: str,
    kind: str,
    labels: tuple[str, ...],
    code_token_ids: tuple[int, ...],
    input_ids: tuple[int, ...]
)
```

Dataclass

One tokenized decision prompt (without the trailing mask) and its option readout.

**`code_token_ids`** `tuple[int, ...]`

---

**`input_ids`** `tuple[int, ...]`

---

**`kind`** `str`

---

**`labels`** `tuple[str, ...]`

---

**`question_id`** `str`

---

```python
nemo_automodel.components.models.nemotron_decision.serving_prompt._control_tokens(
    tokenizer: typing.Any,
    template: str
) -> tuple[str, ...]
```

Special tokens plus the declared (or, if none are declared, template-literal) added tokens.

```python
nemo_automodel.components.models.nemotron_decision.serving_prompt._encode_marked(
    tokenizer: typing.Any,
    chat: str
) -> list[int]
```

Encode a rendered chat: marked control tokens as plain text, everything else normally.

```python
nemo_automodel.components.models.nemotron_decision.serving_prompt._encode_piece(
    tokenizer: typing.Any,
    piece: str,
    as_text: bool,
    newline: list[int]
) -> list[int]
```

```python
nemo_automodel.components.models.nemotron_decision.serving_prompt._encode_without_added_tokens(
    tokenizer: typing.Any,
    text: str
) -> list[int]
```

Encode `text` through the backend's normalizer, pre-tokenizer and model, matching no added token.

```python
nemo_automodel.components.models.nemotron_decision.serving_prompt._mark(
    text: str,
    pattern: re.Pattern[str]
) -> str
```

```python
nemo_automodel.components.models.nemotron_decision.serving_prompt._pattern(
    tokens: tuple[str, ...]
) -> re.Pattern[str]
```

```python
nemo_automodel.components.models.nemotron_decision.serving_prompt._read_checkpoint_file(
    path: str | pathlib.Path,
    name: str,
    revision: str | None
) -> str
```

```python
nemo_automodel.components.models.nemotron_decision.serving_prompt._template_literal_text(
    template: str
) -> str
```

```python
nemo_automodel.components.models.nemotron_decision.serving_prompt.label_token_ids(
    tokenizer: typing.Any,
    codes: tuple[str, ...]
) -> tuple[int, ...]
```

Token ids of option codes, which must be distinct single known tokens.

**Raises:**

* `ValueError`: If a code is not exactly one known token or two codes share a token.

```python
nemo_automodel.components.models.nemotron_decision.serving_prompt.perm_seed(
    shuffle_seed: int
) -> int
```

Option-permutation seed, independent of the shuffle coin drawn from `random.Random(shuffle_seed)`.

```python
nemo_automodel.components.models.nemotron_decision.serving_prompt.prepare_question(
    tokenizer: typing.Any,
    contract: nemo_automodel.components.models.nemotron_decision.serving_prompt.DecisionContract,
    state: typing.Any,
    question_id: str,
    question: dict[str, typing.Any],
    mask_token_id: int,
    shuffle_seed: int | None = None
) -> nemo_automodel.components.models.nemotron_decision.serving_prompt.PreparedQuestion
```

Render one question with the checkpoint's decision template, optionally with shuffled, re-coded options.

**Parameters:**

**`tokenizer`** `Any`

Tokenizer of the checkpoint.

---

**`contract`** `DecisionContract`

The checkpoint's decision contract.

---

**`state`** `Any`

JSON-serializable evidence shared by the question.

---

**`question_id`** `str`

Key of the question (used in errors).

---

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

`&#123;"type", "instructions", "criteria"&#125;` of a choice, noul or score question.

---

**`mask_token_id`** `int`

The checkpoint's mask token, which the template must write exactly once, at the end.

---

**`shuffle_seed`** `int | None` — default: None

When set, permute the options with `perm_seed(shuffle_seed)` and re-code them by position;
`None` keeps the checkpoint's option order.

---

**Returns:** `PreparedQuestion`

The prepared prompt; token ids exclude the trailing mask.

**Raises:**

* `ValueError`: If the question is malformed, has more options than codes, or the template does not end in exactly
  one mask token.

```python
nemo_automodel.components.models.nemotron_decision.serving_prompt.question_options(
    question: dict[str, typing.Any]
) -> tuple[list[str], list[typing.Any]]
```

`(labels, meanings)` of a question in checkpoint order (noul: false, true; score: level indices).

**Raises:**

* `ValueError`: If the question has unsupported fields, an unknown type or criteria that do not fit the type.

```python
nemo_automodel.components.models.nemotron_decision.serving_prompt.readout_token_ids(
    tokenizer: typing.Any,
    contract: nemo_automodel.components.models.nemotron_decision.serving_prompt.DecisionContract
) -> tuple[int, ...]
```

Every token id a question can read at its mask (all option codes of every type), sorted.

```python
nemo_automodel.components.models.nemotron_decision.serving_prompt.render_decision_ids(
    tokenizer: typing.Any,
    template: str,
    content: str
) -> list[int]
```

Token ids of `template` rendered around `content`, with control tokens in `content` encoded as text.

```python
nemo_automodel.components.models.nemotron_decision.serving_prompt.DECISION_CONFIG_FILE = 'decision.json'
```

```python
nemo_automodel.components.models.nemotron_decision.serving_prompt.DECISION_TEMPLATE_FILE = 'decision_template.jinja'
```

```python
nemo_automodel.components.models.nemotron_decision.serving_prompt.NOUL_DEFAULT_MEANINGS = {'false': 'No, the condition does not hold.', 'true': 'Yes, the condition holds....
```

```python
nemo_automodel.components.models.nemotron_decision.serving_prompt.NOUL_OPTIONS = ('false', 'true')
```

```python
nemo_automodel.components.models.nemotron_decision.serving_prompt.QUESTION_TYPES = ('choice', 'noul', 'score')
```

```python
nemo_automodel.components.models.nemotron_decision.serving_prompt._QUESTION_FIELDS = frozenset({'type', 'instructions', 'criteria'})
```