Skip to navigation

nemo_automodel.components.models.nemotron_decision.serving_prompt

View as MarkdownOpen in Claude

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 {"state", "question", "options": [{"code", "label", "meaning"}]};
  • 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"{seed}|perm"), independent of the coin that decides whether a row is shuffled.

Module Contents

Classes

NameDescription
DecisionContractA checkpoint’s decision prompt contract (decision.json and decision_template.jinja).
PreparedQuestionOne tokenized decision prompt (without the trailing mask) and its option readout.

Functions

NameDescription
_control_tokensSpecial tokens plus the declared (or, if none are declared, template-literal) added tokens.
_encode_markedEncode a rendered chat: marked control tokens as plain text, everything else normally.
_encode_piece-
_encode_without_added_tokensEncode text through the backend’s normalizer, pre-tokenizer and model, matching no added token.
_mark-
_pattern-
_read_checkpoint_file-
_template_literal_text-
label_token_idsToken ids of option codes, which must be distinct single known tokens.
perm_seedOption-permutation seed, independent of the shuffle coin drawn from random.Random(shuffle_seed).
prepare_questionRender one question with the checkpoint’s decision template, optionally with shuffled, re-coded options.
question_options(labels, meanings) of a question in checkpoint order (noul: false, true; score: level indices).
readout_token_idsEvery token id a question can read at its mask (all option codes of every type), sorted.
render_decision_idsToken ids of template rendered around content, with control tokens in content encoded as text.

Data

DECISION_CONFIG_FILE

DECISION_TEMPLATE_FILE

NOUL_DEFAULT_MEANINGS

NOUL_OPTIONS

QUESTION_TYPES

_QUESTION_FIELDS

API

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.

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

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.

nemo_automodel.components.models.nemotron_decision.serving_prompt._encode_piece(
tokenizer: typing.Any,
piece: str,
as_text: bool,
newline: list[int]
) -> list[int]
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.

nemo_automodel.components.models.nemotron_decision.serving_prompt._mark(
text: str,
pattern: re.Pattern[str]
) -> str
nemo_automodel.components.models.nemotron_decision.serving_prompt._pattern(
tokens: tuple[str, ...]
) -> re.Pattern[str]
nemo_automodel.components.models.nemotron_decision.serving_prompt._read_checkpoint_file(
path: str | pathlib.Path,
name: str,
revision: str | None
) -> str
nemo_automodel.components.models.nemotron_decision.serving_prompt._template_literal_text(
template: str
) -> str
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.
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).

nemo_automodel.components.models.nemotron_decision.serving_prompt.prepare_question(
tokenizer: typing.Any,
state: typing.Any,
question_id: str,
question: dict[str, typing.Any],
mask_token_id: int,
shuffle_seed: int | None = None

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]

{"type", "instructions", "criteria"} 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 | NoneDefaults to 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.
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.
nemo_automodel.components.models.nemotron_decision.serving_prompt.readout_token_ids(
tokenizer: typing.Any,
) -> tuple[int, ...]

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

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.

nemo_automodel.components.models.nemotron_decision.serving_prompt.DECISION_CONFIG_FILE = 'decision.json'
nemo_automodel.components.models.nemotron_decision.serving_prompt.DECISION_TEMPLATE_FILE = 'decision_template.jinja'
nemo_automodel.components.models.nemotron_decision.serving_prompt.NOUL_DEFAULT_MEANINGS = {'false': 'No, the condition does not hold.', 'true': 'Yes, the condition holds....
nemo_automodel.components.models.nemotron_decision.serving_prompt.NOUL_OPTIONS = ('false', 'true')
nemo_automodel.components.models.nemotron_decision.serving_prompt.QUESTION_TYPES = ('choice', 'noul', 'score')
nemo_automodel.components.models.nemotron_decision.serving_prompt._QUESTION_FIELDS = frozenset({'type', 'instructions', 'criteria'})