nemo_gym.rollout_collection
nemo_gym.rollout_collection
Module Contents
Classes
Functions
Data
AGENT_REQUEST_FAILED_FAILURE_CLASS
API
Bases: SharedRolloutCollectionConfig
Spin up all necessary servers and perform a batch of rollout collection using each dataset inside the provided configs.
Examples:
Bases: BaseNeMoGymCLIConfig
Aggregate metrics across rollout shards produced by gym eval run --no-serve +disable_aggregation=true.
Reads every JSONL file matching input_glob, computes aggregate metrics by POSTing to each
agent server’s /aggregate_metrics endpoint over the global union of records, and writes a
single <output_jsonl_fpath stem>_aggregate_metrics.json next to the rollouts. By default
also concatenates all shards into output_jsonl_fpath.
Examples:
Bases: BaseModel
Bases: SharedRolloutCollectionConfig
Perform a batch of rollout collection.
Examples:
Bases: BaseModel
Call /aggregate_metrics on each agent server after rollouts complete.
Writes a single _aggregate_metrics.json with one entry per agent (same shape as the old _agent_metrics.json). Returns the file path.
Fail before any dispatch when a row names an agent absent from the running config.
Without this, the first bad row dies mid-collection with a raw omegaconf ConfigKeyError after valid rows have already been dispatched.
Fail before dispatch when a row points to agent incompatible with the resources server it runs on.
Apply run-level routing and repetition to caller-held rows.
Public entry point for direct run_examples callers (e.g. trainer integrations that
drive dispatch themselves): run_examples resolves task_sources and validates agent
names, but agent_map, fan_out and num_repeats are applied only during
preprocessing. Call this first, then pass the returned rows to run_examples.
Pass global_config_dict (the merged config) to also resolve task_source-only rows to
their agents here; leave it None to defer that to run_examples, which does it against
the head server’s config. Input rows are not mutated; the expanded, stamped copies are
returned.
Stamp an agent_ref onto every row that carries only a task_source.
task_source names the config instance that declared the row’s dataset. Resolution against the merged config, first match wins:
- the instance is an agent (self-contained environment) -> route to it directly;
- the instance is a resources server -> route to the unique agent whose resources_server.name edge points at it (inversion of the edge every agent config already declares);
- zero or 2+ candidate agents, or an unknown/non-routable instance -> hard error (2+ names +agent_map as the disambiguator).
Rows that already have an agent_ref are left untouched, so this is a no-op on legacy datasets and on already-resolved (materialized) rows. Runs before any dispatch.
We provide this function as a lower level interface for running rollout collection.
Rows are dispatched as given: task_sources are resolved and agent names validated here,
but run-level knobs (agent_map, fan_out, num_repeats) are NOT applied — call
preprocess_examples first if you need them.
route_failures_to_sidecar is set by managed collection (run_from_config), where a
failed /run becomes a failure row instead of ending every rollout still in flight.
Direct callers such as NeMo-RL leave it off and keep receiving the exception.
Collect rollouts for a whole config. Wrapped in the run-scoped job span.
This is the driver side of an evaluation run and the outermost span Gym produces,
so every rollout it dispatches is a descendant of it. job is in the default
preset but deliberately not in per_rollout, where each rollout is meant to be
its own bounded root trace.
Bases: UploadRolloutsConfigMixin, BaseNeMoGymCLIConfig
One sidecar row for a /run call that came back without a result.
No reward and no response: an infrastructure failure is not a verifier score of zero, and a
placeholder would read as real generation data to token capture, aggregation and trainers.
The class says whether the rollout ran. A NeMo Gym agent answers 500 when its own handler
raises, so any status it answered with means the agent ran and broke, which is also how a
model server rejecting the model’s own output arrives here. A gateway status, or no reply to
take a status from, says nothing about the rollout. Neither class carries a reward; an evaluation that wants the
first counted names it in count_failure_classes_as_zero.
Assemble the per-rollout ng_perf summary from ng_trajectory.
Returns None (ng_perf stays absent) unless at least one reasoning turn was
observed: per-turn evidence is needed rather than just raw model-call capture,
so a rollout collected with observability disabled produces no ng_perf at all.
Token fields are summed only over model calls owned by a reasoning-turn AgentInvocation,
excluding compaction calls — mixing in compaction overhead would skew the token efficiency signal.
num_turns counts reasoning turns summed across all invocations (an AgentInvocation
is one root-agent or subagent conversation that may span many turns). Each invocation
contributes its explicit TrajectoryTurn count when the harness emits turn records,
falling back to its owned model-call count (one assistant response per turn), then to 1
(an invocation that ran had at least one turn) — so hybrid trajectories where only some
invocations report turns still count every conversation.
token_observability_coverage reports what fraction of those turns actually resolved to a
captured call: a turn whose ModelCallRef was unmatched or ambiguous silently loses its
tokens from the sums below, and this is the only signal that it happened.
Expand a glob-or-comma-separated-globs string into a sorted, deduplicated list of paths.
Examples:
Sidecar rows the caller opted to count in the metrics denominator.
The last attempt of a rollout is the one that stands, so it is selected across every failure class before the wanted classes are picked out. Selecting the other way round would let a stale attempt be counted after a later one landed in a class the caller did not ask for.
A row that already carries a reward is counted as it stands. A row that carries none
records that no rollout happened, so it is counted as a zero here and only here: the score
enters the metric input, never the sidecar or the rollouts jsonl, which keeps the artifacts
free of a verdict no verifier gave. A rollout that also succeeded is never counted.
Read NEMO_GYM_MAX_ROLLOUT_ATTEMPTS (positive int) or default to 3.
Return an exporter view without the complete trajectory or raw capture payloads.
Decode at most the kept prefix, so a huge error page is never decoded in full.
Parse one JSONL line, raising a clean ConfigError (naming file + line) on malformed JSON.