Skip to navigation

nemo_automodel.components.models.gs1.reader

View as MarkdownOpen in Claude

GS1 decision reads: the checkpoint’s own compiler, one question per read, the native decision head.

Module Contents

Classes

NameDescription
GS1BranchCompiler metadata consumed by GS1Model.forward and its readout.
GS1CompiledRequestCompiled shared state and native decision branches.
GS1CompilerPublic compiler interface exposed by GS1 checkpoints.
GS1DecisionModelNative checkpoint methods needed to build the reader.
GS1DecisionReaderReads questions through a GS1 checkpoint’s own request schema, compiler and decision head.
GS1ReadOne compiled question: the shared state followed by the question’s branch, unpadded.
GS1ReaderConfigRead GS1 checkpoints (reader: {_target_: ...GS1ReaderConfig}); full fine-tuning only.

Data

STAGE_FORMAT

API

class nemo_automodel.components.models.gs1.reader.GS1Branch()
Protocol

Compiler metadata consumed by GS1Model.forward and its readout.

candidates
tuple[str, ...]
decision_position
int
option_spans
tuple[tuple[int, int], ...]
option_starts
tuple[int, ...]
question_end_position
int
question_span
tuple[int, int]
question_start_position
int
state_evidence_start
int
suffix
tuple[int, ...]
token_roles
tuple[str, ...]
visual_inputs
dict[str, Any] | None
class nemo_automodel.components.models.gs1.reader.GS1CompiledRequest()
Protocol

Compiled shared state and native decision branches.

branches
tuple[GS1Branch, ...]
state
tuple[int, ...]
class nemo_automodel.components.models.gs1.reader.GS1Compiler()
Protocol

Public compiler interface exposed by GS1 checkpoints.

nemo_automodel.components.models.gs1.reader.GS1Compiler.compile(
request: pydantic.BaseModel
class nemo_automodel.components.models.gs1.reader.GS1DecisionModel()
Protocol

Native checkpoint methods needed to build the reader.

nemo_automodel.components.models.gs1.reader.GS1DecisionModel.decision_compiler(
tokenizer: transformers.PreTrainedTokenizerBase,
max_context: int
class nemo_automodel.components.models.gs1.reader.GS1DecisionReader(
model: torch.nn.Module,
request_type: type[pydantic.BaseModel],
model_id: str,
max_input_tokens: int,
device: torch.device
)

Bases: DecisionReader[GS1Read]

Reads questions through a GS1 checkpoint’s own request schema, compiler and decision head.

nemo_automodel.components.models.gs1.reader.GS1DecisionReader.encode(
record: dict[str, typing.Any],
question_id: str,
shuffle_seed: int | None = None

Compile one question with the record’s state (see DecisionReader.encode).

Returns None for requests the checkpoint’s schema or compiler rejects (including reads longer than data.max_tokens; the compiler never truncates), for branches that need visual inputs (this reader passes token IDs only) and for questions with fewer than two candidates.

Raises:

  • ValueError: If shuffle_seed is set: the compiler fixes the candidate order.
nemo_automodel.components.models.gs1.reader.GS1DecisionReader.identity() -> dict[str, typing.Any]

Stage fields of a GS1 stage.

nemo_automodel.components.models.gs1.reader.GS1DecisionReader.logits(
) -> torch.Tensor

Candidate logits of one unpadded single-branch forward, fp32 tensor of shape [candidates].

class nemo_automodel.components.models.gs1.reader.GS1Read(
question_id: str,
labels: tuple[str, ...],
input_ids: tuple[int, ...],
state_length: int
)
Dataclass

Bases: DecisionRead

One compiled question: the shared state followed by the question’s branch, unpadded.

branch
GS1Branch

The compiler’s branch of the question; labels is its candidates.

input_ids
tuple[int, ...]

State tokens followed by the branch suffix.

state_length
int

Number of state tokens at the start of input_ids.

class nemo_automodel.components.models.gs1.reader.GS1ReaderConfig()
Dataclass

Bases: DecisionReaderConfig[GS1Read]

Read GS1 checkpoints (reader: {_target_: ...GS1ReaderConfig}); full fine-tuning only.

nemo_automodel.components.models.gs1.reader.GS1ReaderConfig._build(
model: torch.nn.Module,
tokenizer: transformers.PreTrainedTokenizerBase,
model_path: str,
revision: str | None,
max_tokens: int,
peft: bool,
device: torch.device

Build the checkpoint’s compiler and load its request schema from the same code revision.

nemo_automodel.components.models.gs1.reader.GS1ReaderConfig.prepare(
model_path: str,
revision: str | None
) -> None

Check the checkpoint code’s dependency and patch Transformers before the checkpoint code loads.

nemo_automodel.components.models.gs1.reader.STAGE_FORMAT = 'gs1-decision-stage-v1'