nemo_gym.token_id_capture.records
nemo_gym.token_id_capture.records
Define training-token records extracted from served responses.
A TokenEntry contains one model call’s training data.
It stores the exact prompt token ids.
It stores generated token ids and their log probabilities.
Evaluation uses a separate ModelCallRecord.
Evaluation records do not carry token arrays.
Both records share a model_call_id.
Module Contents
Classes
Functions
Data
TOKEN_ENTRY_RECORD_SCHEMA_VERSION
API
Bases: BaseModel
Store one model call’s content and token metadata.
The rollout id identifies the training sample.
The model call id joins evaluation context.
output_items preserves assistant text and tool calls.
Text-based penalties require that content.
Token arrays are stored once at the top level.
token_item_index identifies their original output item.
A trajectory builder can restore chain-correct token fields there.
Accept older records and reject newer records.
Missing older fields use their defaults. Unknown newer fields may change token semantics. Rejecting them prevents silent training corruption.
Pull the token-id fields off a served response, or None if absent.
Handle Responses output items and Chat Completions messages.
Exactly one item may carry token metadata.
Return None when no item carries token ids.
Normalize a served response to a list of content-bearing Responses output items.
Responses payloads already carry output.
Chat payloads carry choices[*].message.
Wrap each assistant message as a Responses message item.
Drop the token arrays from output items, keeping the content.
Return the stripped items and the index of their token-bearing item. Capture requires exactly one token-bearing item. The arrays are held once on the entry. Storing them again per item would roughly double the record size.