nemo_gym.token_id_capture.config

View as Markdown

Define run-wide training-token capture settings.

env:
nemo_gym:
token_id_capture:
enabled: true
dir: /tmp/ng_tokcap # The writer and consumer share this node-local directory.
sink: my_pkg.sinks:MyDataPlaneSink # This optional sink replaces the file store.

Evaluation capture uses /ng-rollout/<id>/.... Training capture uses /ng-rollout/<id>/training-token-capture/.... Training capture records token ids and log probabilities. Evaluation capture records request and response summaries. A run can enable either path independently. Training capture applies through the static agent flag or run-level all_agents. Native agents normally leave the static flag disabled. Their responses already carry token ids. The top-level model_call_capture_dir is the fallback file-store directory.

Choosing where records go

sink names a class implementing TokenSink, as module.path:ClassName. Each server process constructs its sink at app startup. A framework must make that class importable in the server process. A configured sink replaces the file store. Consumers construct and inject their TokenSource in their own process. Consumers call TokenSource.freeze to obtain an atomic snapshot. Consumers retire that exact snapshot with its snapshot_id and version. There is no HTTP token reader. Uvicorn workers use spawned processes. They do not inherit a sink installed by a launcher. Configure the sink here so each worker builds its own. Programmatic installation must occur inside the serving process.

Choosing who reads them back

rebuild_response controls whether Gym rebuilds a finished rollout. Gym freezes captured records before rebuilding response.output. Rebuilding does not retire the frozen snapshot. Gym retires a successful build only after durable handoff. Retirement uses the frozen snapshot_id and version. Failed or masked builds retain their capture evidence. Set it to false when a framework reads through its own TokenSource. Gym then stops after the write. Read ownership is independent of write ownership.

Module Contents

Classes

NameDescription
TokenIdCaptureConfigThe capture block plus the one top-level key it falls back to.
TokenIdCaptureSettingsThe token_id_capture block.

Functions

NameDescription
token_id_capture_configRead the capture settings out of a global config dict.
token_id_capture_enabled_for_agentReturn whether one configured agent participates in capture.

Data

TOKEN_ID_CAPTURE_BLOCK

logger

API

class nemo_gym.token_id_capture.config.TokenIdCaptureConfig()

Bases: BaseModel

The capture block plus the one top-level key it falls back to.

enabled
bool
model_call_capture_dir
Path | None = None
model_config
= ConfigDict(extra='ignore')
token_id_capture
TokenIdCaptureSettings = TokenIdCaptureSettings()
nemo_gym.token_id_capture.config.TokenIdCaptureConfig._build_endpoint(
target: str,
kwargs: dict[str, typing.Any],
protocol: type,
kind: str
)
staticmethod
nemo_gym.token_id_capture.config.TokenIdCaptureConfig._validate() -> 'TokenIdCaptureConfig'
nemo_gym.token_id_capture.config.TokenIdCaptureConfig.build_sink() -> nemo_gym.token_id_capture.protocols.TokenSink | None

Construct the configured sink.

Return None when the file store is in use. Call this once in each server process. Launcher-installed sinks do not reach spawned workers.

nemo_gym.token_id_capture.config.TokenIdCaptureConfig.resolved_dir() -> pathlib.Path | None
class nemo_gym.token_id_capture.config.TokenIdCaptureSettings()

Bases: BaseModel

The token_id_capture block.

all_agents
bool = False
dir
Path | None = None
enabled
bool = False
mask_fraction_min_samples
int = 50
max_mask_fraction
float | None = None
model_config
= ConfigDict(extra='forbid')
rebuild_response
bool = True
sink
str | None = None
sink_kwargs
dict[str, Any] = Field(default_factory=dict)
nemo_gym.token_id_capture.config.token_id_capture_config(
global_config_dict: typing.Any
) -> nemo_gym.token_id_capture.config.TokenIdCaptureConfig

Read the capture settings out of a global config dict.

nemo_gym.token_id_capture.config.token_id_capture_enabled_for_agent(
global_config_dict: typing.Any,
agent_name: str | None
) -> bool

Return whether one configured agent participates in capture.

nemo_gym.token_id_capture.config.TOKEN_ID_CAPTURE_BLOCK = 'token_id_capture'
nemo_gym.token_id_capture.config.logger = logging.getLogger(__name__)