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.
Internal dispatch shared by run_examples and Gym’s own collection paths.
Identical contract to run_examples, but each future resolves to a _CompletedRollout
that carries rollout_latency_ms alongside the raw /run result instead of inside it,
so internal-only timing never has to be smuggled through (and stripped back out of) a dict
that a direct caller of run_examples could also observe.
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 is
:func:~nemo_gym.global_config.resolve_dataset_agent — the same rules benchmark
discovery uses, so dispatch can never disagree with the listing. Conflicting agent:
pins across one instance’s datasets are a hard error (rows carry only the instance
name), as are unknown/non-routable instances; +agent_map is 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 makes a failed /run a failure row instead of an exception
that ends every rollout still in flight. It defaults off because those rollouts then leave
the score.
Every future resolves to exactly the (row, result) pair Gym’s own /run endpoint
returned — no Gym-private fields are ever added to result.
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
A finished /run dispatch, with timing carried alongside (not inside) the raw result.
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 over every model call referenced by a reasoning-turn
AgentInvocation. This includes compaction calls whenever the harness also lists
them in AgentInvocation.model_calls.
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.
State how much of the input the score covers, for the runs where it is not all of it.
Silence here is what makes a partial run look complete, so this reports against the materialized input rather than the rollouts one hop happened to dispatch.
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.
The last attempt recorded for each rollout across the failures sidecars.
In-progress view of what a run is losing to its environment rather than its policy.
scored covers persisted rollouts only, split into the unmasked ones (count,
reward) and the masked ones; dropped counts what never reached the main output
at all. reward_unmasked averages over the unmasked rollouts alone, so the gap
against the existing reward series is the score lost to infrastructure. Failed and
omitted attempts are reported as counts, never folded into a quality average.
Empty until something is actually masked or dropped, so a healthy run exports exactly
what it exported before. The final numbers come from /aggregate_metrics; this is
the progress view while the run is still going.
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.