nemo_gym.token_id_capture.sink
nemo_gym.token_id_capture.sink
Capture training tokens from one complete model response.
Streaming responses omit token ids from the wire.
The model server still holds the complete response before streaming.
Middleware provides a request-scoped token sink.
The model server passes its complete response to capture_tokens.
The sink writes a TokenEntry.
Its model_call_id joins the corresponding evaluation record.
Untagged traffic has no capture context.
Module Contents
Classes
Functions
Data
API
Describe one in-flight training-token capture.
The context identifies the rollout and model call.
token_sink receives the resulting record.
A framework may provide any TokenSink implementation.
Report a capture failure without letting it reach the model call.
Bad token payloads must not fail the model call.
Mark the rollout so consumers can mask the sample.
Call this only from an except block.
Mark the rollout when a call this process should have recorded produced nothing.
A response with no token ids is a hole in the chain rather than traffic to skip. The builder reads the gap between one call’s tokens and the next call’s prompt as tool output. A skipped call’s generated tokens then enter the next prompt with mask zero. Policy tokens would train as if the environment produced them.
Two cases are not holes and are left alone. A committed call was recorded by another capture path. A context without a sink delegates completeness to external staging.
Mark the rollout, or say loudly why it could not be marked.
A missing mark_incomplete method can hide incomplete capture.
Log that condition as an error.
Record a TokenEntry from a complete model response.
Accept a Pydantic model or dictionary. Return without work when no capture context exists. Mark local capture incomplete when required token ids are absent. Await the write before the model call returns.
Durably record a finished entry against the in-flight call.
capture_tokens extracts arrays from a served response.
Engine-side capture may already have those arrays.
Engine-side callers can use this method directly.
Return without work when no capture context exists.
Capture failures mark the rollout incomplete.
This method never fails the model call.
Return the capture context for the in-flight call.
Return None for untagged traffic.
Framework inference workers use this identity for staged records.
Record that the captured call is about to be dispatched.
begin_call is an optional sink extension.
It lets a source detect a call whose entry was lost.
A failure happens before generation and must fail the model call.