Skip to content

feat(nemo_gym): per-group rollout-metrics hook and union-of-fields agent metrics - #4448

Open
alexandery-nvidia wants to merge 50 commits into
mainfrom
alexandery/gym-rollout-metrics-hook
Open

alexandery-nvidia wants to merge 50 commits into
mainfrom
alexandery/gym-rollout-metrics-hook

Conversation

@alexandery-nvidia

@alexandery-nvidia alexandery-nvidia commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on alexandery/gym-health-check-during-collection (which is stacked on alexandery/gym-typed-failures-and-redispatch); review the commits after that branch only. The stack was rebased onto main on 2026-10-12.

What does this PR do?

The per-agent aggregation of a NeMo-Gym prompt group (_postprocess_single_nemo_gym_group in nemo_rl/experience/rollouts.py) logs the mean of every numeric field of the agents' full results over all rollouts. Three things it could not express:

  1. A statistic over a subset of the rollouts, for example the mean of a performance score over only the correct rollouts, or a pass-at-k over the group. env.nemo_gym.rollout_metrics_hook names, by dotted import path (package.module.function), a callable hook(rows, full_results): the group's input rows (each carrying agent_ref and the _ng_group_id prompt-group key) and, aligned with them, each rollout's own full_result mapping. It returns metrics to merge into the group's rollout metrics. The hook runs after every built-in metric of the group (the timing and routing keys are added afterwards), so a key it returns wins a collision with a built-in key, and the collision is warned once per hook. A hook that raises or returns something other than a mapping is warned once per hook with its traceback and contributes nothing for that group; a value the step aggregation cannot average (anything but a number, or a sequence of numbers under a histogram key) is dropped with one warning; the rollout never fails because of the hook. The group is one prompt's rollouts under the asynchronous collector and the single-controller path, and the whole step batch (mixed prompts, possibly mixed agents) under run_nemo_gym_rollout_sync; the hook also runs on validation batches, whose keys appear under val/. full_result["reward"] is already rewritten by effort shaping and reward penalties, except on the single-controller path under token capture (receipt mode), where it is the verifier's reward and shaping and penalties are applied at capture finalization; under asynchronous GRPO a returned key is averaged over prompt groups with equal weight. These facts are the docstring of get_nemo_gym_rollout_metrics_hook, which resolves the import path before any row is dispatched on both paths and raises ValueError for a path without a module part or one that does not name a callable, and the ImportError of a module that cannot be imported.
  2. A field that only some rollouts carry. The aggregated keys were the first rollout's keys, so a numeric field present on other rollouts only (a score only the successful rollouts report) was never aggregated. The per-agent keys are now the union over the agent's rollouts, in first-seen order; the mean divides by the number of rollouts covered, not by the number that carry the field, so such a field averages below its own minimum (the design doc says so).
  3. An environment-masked rollout's placeholder values. An environment that marks a rollout mask_sample (first-class on the result, or under instance_config) says its reward and scores are not measurements: a verifier that failed at the infrastructure level, for example, reports zeros. Those zeros used to vote in every per-agent mean, including the checkpoint-ranking key train:<agent>/correctness/mean. While env.should_mask_flagged_samples is on, a masked rollout now leaves every per-agent value metric: the mean divides by the unmasked rollouts, and max, min, median, and the histogram cover the unmasked values. <agent>/mask_sample/mean is the masked share over every rollout by the same predicate, so an environment that flags only instance_config reports it too, and an agent whose rollouts in a group are all masked emits only the share (a checkpointing.metric_name that names a per-agent key therefore fails the save of a step whose every group is fully masked; the design doc states it). With the gate off the flagged rollouts vote like any other, since the operator has declared them worth training on. The rule is uniform over all numeric fields rather than special to the ranking key, so an environment's other means (speedup, latency, score) are not dragged either.

One helper implements items 2 and 3 for both rollout paths: per_agent_result_metrics with is_environment_masked in rollouts.py, called from _postprocess_single_nemo_gym_group and from the single-controller _compute_rollout_metrics (rollout_manager.py), so the rule cannot drift between them.

Design note

  • env.nemo_gym.rollout_metrics_hook (optional, default absent or null = today's aggregation) is a driver-side key like the other two of this stack: _build_gym_actor_config keeps it out of Gym's global configuration, NemoGym.rollout_config hands it back, and run_async_nemo_gym_rollout reads it from the environment's configuration before preparing its rows. The single-controller path (AsyncNemoGymRolloutImpl in rollout_manager.py) resolves the same key from the actor's rollout_config once, before its first dispatch, and applies the hook through the same helper (apply_nemo_gym_rollout_metrics_hook) after its built-in metrics, so both paths apply the configured hook the same way and a bad path fails before any rollout on both.
  • The hook receives the rows and each rollout's own full_result mapping (the same object on both paths; it treats them as read-only, since later stages read them too) and returns a flat mapping of metric name to number; it has no access to the batch or the trainer, which keeps it a pure metrics function. The per-agent aggregation's receipt-mode projection, which drops the raw reward and the receipt bookkeeping keys from the logged means, is a logging choice and does not apply to the hook. The module the hook lives in must be importable in the process that runs the rollout loop (under asynchronous GRPO, the trajectory collector actor); the hook runs synchronously on that loop.
  • The masked-rollout exclusion is a metrics rule only; the loss mask (_mask_sample_flags, which fix(nemo-gym): read first-class sample mask flags #4435 widens to the first-class flag) and the baselines are governed by the trainer's mask_sample handling. Once fix(nemo-gym): read first-class sample mask flags #4435 lands, _mask_sample_flags can read is_environment_masked so the loss mask and the metrics cannot drift.
  • The key is documented beside its siblings in docs/design-docs/nemo-gym-integration.md, together with the exclusion rule, the metrics that still count masked rollouts, and the all-masked behavior, and as a commented line in examples/nemo_gym/grpo_nanov3.yaml.

Issue

No issue filed; the need came from an environment whose reward is correctness-gated: the mean of the performance score over all rollouts mixes zeros from incorrect ones with real scores, the per-agent means could not report the field the incorrect rollouts do not carry, and a wave of infrastructure-masked rollouts dragged the ranking metric that selects checkpoints.

Validation

  • tests/unit/experience/test_rollouts.py, tests/unit/experience/test_rollout_manager.py, tests/unit/test_effort_shaping.py, tests/unit/experience/test_rollout_generation_failures.py, tests/unit/environments/test_nemo_gym_actor_config.py, and the stack's other files (test_failures.py, test_nemo_gym_router.py, test_nemo_gym.py, test_nemo_gym_health.py): 341 passed on the stack rebased onto main e1a2e9a. Tests: the hook resolves by import path and rejects a path without dots, a non-callable, and a missing module; the hook sees the group's rows and aligned full results and its metrics are merged, while a raising hook is reported with its traceback and the generic per-agent means stay; a hook that returns no mapping is reported once and cannot fail the rollout, a value the step aggregation cannot average is dropped with one warning while the hook's other metrics survive, and each condition (a failure, a collision) is reported once per hook; a key the hook returns survives the per-agent means with a collision warning; the rollout resolves the hook from the actor's configuration and hands it to the group postprocess, and an unresolvable path fails before any row is dispatched on both paths; a field two of three rollouts carry is aggregated over the agent's three rollouts on both paths; the helper excludes a masked rollout under either flag form and reports the share, lets the flagged rollouts vote with the gate off, and reports only the share for an all-masked group; the single-controller path excludes masked completions under either form, agrees with the driver path with the gate off, and hands the hook rows and results aligned in row order whatever order the inputs arrive in; the actor-config split and rollout_config cover the new key.
  • pre-commit run --files <changed files>: ruff, ruff-format, and the recipe minimize check pass; pyrefly check on rollout_manager.py (the one of the two sources in pyrefly.toml's includes) reports the same findings as its base, none new.
  • Rollout evidence: this change has run for weeks in a downstream fork's GRPO training with NeMo-Gym agent environments on Slurm clusters; the hook reports the per-step correctness rate and the mean score over the correct rollouts beside the generic per-agent means, and the exclusion keeps a masked wave out of the checkpoint-ranking mean. The fork's hook took the full results alone; it now takes the rows as well.

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Oct 3, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Oct 7, 2026
@alexandery-nvidia alexandery-nvidia changed the title feat(nemo_gym): a rollout-metrics hook per prompt group, and per-agent metrics over the union of result fields feat(nemo_gym): per-group rollout-metrics hook and union-of-fields agent metrics Oct 10, 2026
@alexandery-nvidia
alexandery-nvidia marked this pull request as ready for review October 10, 2026 08:13
@alexandery-nvidia alexandery-nvidia added the CI:L0 Run doctests and unit tests label Oct 12, 2026
@alexandery-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 9cd33af

@alexandery-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 4627588

@alexandery-nvidia
alexandery-nvidia force-pushed the alexandery/gym-rollout-metrics-hook branch from 9cd33af to 4627588 Compare October 12, 2026 20:13
alexandery-nvidia and others added 16 commits October 12, 2026 17:40
…ws lost to infrastructure

A NeMo-Gym /run that fails ends every rollout still in flight, because the
aiohttp exception cannot cross the Ray actor boundary (its headers are a
CIMultiDictProxy that cloudpickle cannot serialize) and the actor's stream
ends with it. The driver then classifies the failure from a bare RayTaskError,
and one dead engine costs the whole step.

The NemoGym actor now asks Gym's rollout collector for a failure row instead
of an exception (route_failures_to_sidecar=True). The row carries the failure's
class, HTTP status, type, message, and response body as plain values, so
_typed_gym_failure classifies it on the actor side with the same
http_status_is_infra rule the driver applies: a 5xx, a retriable 4xx, or a
row without a status is a GymTransportError, any other status a
RolloutDataFailure. A data failure still ends the batch at once. An
infrastructure failure is yielded in place of the result as a one-key marker
row (GYM_INFRA_FAILURE_KEY), so the other rows keep running.

On the driver, run_async_nemo_gym_rollout dispatches a marked row again as a
fresh single-row stream on the instance its route picks, up to
env.nemo_gym.max_infra_attempts_per_rollout attempts in total; the last
failure raises GymTransportError with the failure's detail, as an unretried
failure does. The default of 1 keeps today's single attempt. The accumulator
keeps the per-row budget and reports nemo_gym_infra_redispatches in the final
rollout metrics. The asynchronous collector leaves a marked row's slot empty
so its own attempt loop dispatches it again.

The setting is read by the driver only, so _build_gym_actor_config keeps it
as a top-level field of the actor's configuration and out of Gym's global
configuration; NemoGym.rollout_config hands it back, and the rollout function
reads it there unless a caller passes it, so every caller applies the same
configured value.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
…timing and failure detail

Three review fixes to the typed-infra-failure path:

- Re-dispatch a failure marker's row on the instance whose stream
  reported it instead of routing through shard_set.pick_handle, which
  rotates on every call and, with replicas > 1, lands the retry on a
  different replica. That splits the row's prompt group across
  instances, which the bucketing invariant forbids: a group split
  across instances deadlocks verifiers that buffer whole groups. The
  dead-engine case loses nothing, since every instance holds the same
  engine base_urls and Gym picks the engine per request. The shard_set
  parameter of _merge_nemo_gym_instance_streams goes away unused.

- Let the merge own the per-instance timing dict through a
  record_timing callback. The actor attaches its batch timing to a
  stream's last tuple, which can be the failure marker the merge never
  yields, and the one-row retry stream shared its bucket's label and
  finished last, so the consumer's plain assignment replaced a bucket's
  totals with the retry's. Retries record under <instance_label>/retry<n>.

- Record each failure marker's detail on the single-controller path
  (_stream_rows) and name it when a row runs out of attempts. A marker
  ends an attempt's stream cleanly, so the previous error claimed the
  stream ended before all rows arrived, with no cause attached.

Also rewrite _typed_gym_failure's docstring lead: the pinned Gym already
rewrites the aiohttp error into a picklable form in raise_for_status;
the property only a failure row provides is that the stream survives.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: alexandery <[email protected]>
…ailure

A failure row carrying a status below 400 means the reply broke after its
status line: the body read or parse failed, as when a relayed multi-megabyte
response is cut mid-body. That is the transport's trouble, not the request's,
so the row is re-dispatched as GymTransportError instead of ending the step
as RolloutDataFailure. Only a non-retriable 4xx still describes the request
itself. The docstring states the rule and a test pins it across the actor
boundary.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
…s behavior

The test asserted that the landed row had been shaped, a side effect of the
stream that main now applies only to non-receipt results; the receipt result
the test streams carries reward checks instead. The test keeps the assertions
that are about the marker: the marker's slot stays empty for the attempt
loop, the landed row is delivered, and the failure detail is recorded.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
…failure row

_typed_gym_failure takes the failure row Gym's rollout collector returns
for a failed /run, not the exception, since the typed-failure change; the
retained-media test in the nemo_gym lane still passed a ClientResponseError
and failed with AttributeError on failure_row.get. It now builds the row the
collector produces for Gym's 500 (the status line as the message, the body
the collector read beside it).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
…00 too

The actor-side rule for a failure row carrying a status below 400 (a reply
that broke after its status line) lived beside http_status_is_infra instead
of inside it, so the predicate the driver applies and the one the actor
applies had drifted, and the test that pins "one rule, not two" never
visited a status where they differ. The sub-400 case now lives in
http_status_is_infra, the actor calls the predicate alone, and the test
walks 0, 200 and 302 as well. The failure row's detail names the failure
type in the status branch too, because the type (a payload or JSON decode
error) is the diagnosis when the status says success; the sub-400 test
builds the ClientPayloadError Gym's collector records for a cut body.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
…ross a re-dispatch

A failure marker ends an attempt's stream cleanly, so a re-dispatch now
produces a second timing payload for the same prompt group, and the plain
assignment in _run_rollouts kept the one-row retry's numbers as the group's.
The first payload stays under the instance label and every later one is
reported under <instance label>/retry<n>, the rule the driver path's stream
merge applies. Tests pin the surviving group timing and the final error for
a group that ends with both a marked row and a row that never arrived.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
…ields no timing

record_infra_failure and record_timing defaulted to None, which re-opened
the mode the re-dispatch change removed: a merge without the first yields a
failure marker the consumer cannot tensorize, and one without the second
drops the timing a marker carries. The actor always returns a failed /run
as a marker, so no caller wants that mode; both callbacks are now required
keyword arguments and the callback is the merge's only timing channel, so
the yielded tuple no longer carries a timing slot. A test pins that a retry
stream which fails again is dispatched a third time on the same instance
under its own retry label. The budget accessor's docstring names the
single-controller path, not the asynchronous collector, as the component
with its own attempt loop, and the timing roll-up's docstring states that a
re-dispatched row adds a retry label on an unsharded step.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
…ts describe the marker

The exemplar YAML and the design doc carry the new env.nemo_gym key with its
default. The max_row_attempts comments in the single-controller config and
its two exemplars said Gym's stream dies on its first failing row; a row
whose /run fails at the infrastructure level now comes back as a marker and
is re-sent by itself, which is what the knob budgets.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
…t metrics over the union of result fields

The per-agent aggregation of a NeMo-Gym prompt group logs the mean of every
numeric field of the agents' full results over all rollouts. Two things it
cannot express: a statistic over a subset of the rollouts (a mean over only
the successful ones, for example), and a field that only some rollouts
carry, because the aggregated keys were the first rollout's keys.

env.nemo_gym.rollout_metrics_hook names, by dotted import path, a callable
that takes one prompt group's full results and returns metrics to merge into
the step's rollout metrics. The hook is read from the environment's own
configuration by the rollout function (NemoGym.rollout_config hands the
driver-side key back), it runs after the per-agent aggregation, and a hook
that raises is reported once and cannot fail the rollout. Unset keeps today's
aggregation.

The per-agent keys are now the union of the keys over the agent's rollouts,
in first-seen order, so a numeric field present on some rollouts only is
aggregated with calculate_single_metric's existing convention (the mean
divides by the agent's rollout count).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
… the single-controller path

Review fixes to the rollout-metrics hook, and the single-controller
parity the hook was described as having:

- The hook now runs after every built-in metric writer, through a
  shared apply_nemo_gym_rollout_metrics_hook helper. It previously ran
  before the per-agent aggregation, so a key it returned that collided
  with a built-in key (agent/<field>/mean, mean_gen_tokens_per_sample)
  was silently overwritten or silently replaced a logged training
  metric. A collision now keeps the hook's value and warns once per
  hook; a failing hook warns once with its traceback and the hook's
  qualified name, and still cannot fail the rollout.

- The hook contract carries the group's rows: hook(rows, full_results),
  aligned pairwise, so a hook can read agent_ref and the _ng_group_id
  prompt-group key. Under run_nemo_gym_rollout_sync the group is the
  whole step batch, and without row identity a mixed-agent batch left a
  hook no way to namespace or recover prompt boundaries. Widened now,
  before the contract has users on main.

- The single-controller asynchronous path resolves the same configured
  hook from the Gym actor's rollout_config and applies it through the
  same helper, and its per-agent metrics now aggregate the union of
  result fields instead of the first completion's keys, matching
  _postprocess_single_nemo_gym_group.

The hook getter's docstring now states the contract a hook author
needs (reward already shaped, per-caller group semantics, equal-weight
group aggregation, import in the rollout-loop process), and the key is
documented beside its sibling env.nemo_gym knobs in the design doc and
the exemplar YAML.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: alexandery <[email protected]>
While the driver waits for NeMo-Gym rows, a Gym server process that has died
goes unnoticed: the rows it owned never arrive, and the step waits on them
until the walltime guard ends the job. NemoGym already has a health_check
method that raises when one of its server processes has exited; nothing
called it during collection.

With env.nemo_gym.health_check_interval_seconds set, the merged stream of
actor rows waits at most that long for the next row; when the interval
passes without a row, every actor of the shard set is health-checked, and a
failed check ends the rollout with GymTransportError, which the driver
classifies as an infrastructure failure. The default (absent or null) keeps
today's unbounded wait. The setting is a driver-side key: it stays out of
Gym's global configuration, NemoGym.rollout_config hands it back, and the
rollout function reads it there unless a caller passes it.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
…e metric

An environment that marks a rollout mask_sample says its reward and scores
are placeholders, not measurements. Those placeholders voted in every
per-agent mean, including the checkpoint-ranking key
train:<agent>/correctness/mean. A masked rollout now leaves every per-agent
value metric on both rollout paths: the mean divides by the unmasked
rollouts, and the observed-value statistics cover the unmasked values. The
one exception is the mask_sample flag itself, whose mean over every rollout
is the masked share. The rule is uniform over all numeric fields rather than
special to the ranking key, so no other per-agent mean is dragged either.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
…ability knobs

NemoGym is an asyncio actor, so a live actor whose event loop is
blocked, or whose process is stopped, never resolves a health_check
call: the unbounded gather turned the watchdog into the hang it exists
to end, and in the asynchronous collector it also stopped consumption
of groups from healthy shards. Bound the probe with asyncio.wait_for
using the poll interval as the timeout, the same way the
single-controller watchdog bounds _check_env_health, and report an
unanswered probe like a failing one. A scripted never-answering actor
pins the bound.

Document the driver-side reliability knobs where the sibling
env.nemo_gym keys live: a commented block in
examples/nemo_gym/grpo_nanov3.yaml (off by default, so copying the
example does not enable polling) and the design doc's env.nemo_gym
block. Correct the rollout docstring to say the probe runs only after
an interval with no completed row, and list GymTransportError in
run_nemo_gym_rollout_sync's raises: its callers have no retry, so the
error ends the run.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: alexandery <[email protected]>
… output, eager hook resolution

The per-agent aggregation was written twice, once per rollout path, and the
two copies had already drifted: the masked share came from the first-class
mask_sample field alone while the exclusion also honored
instance_config.mask_sample, so an environment that flags only the nested
form reported a share of 0.0 while its rollouts were being excluded, and the
exclusion ignored env.should_mask_flagged_samples while the single-controller
path dropped the nested flag before its metrics, so the two paths disagreed
with the gate off. per_agent_result_metrics is now the one implementation
both paths call: the union of numeric fields, the share by
is_environment_masked over every rollout, and the exclusion only while the
gate honors the flag, since a gate-off operator has declared the flagged
rollouts worth training on. An agent whose rollouts are all masked emits only
the share, which the design doc now states together with the
checkpointing.metric_name consequence.

The hook helper validated the hook's return value outside its guard, so a
hook that returned None or a list failed the group despite the documented
"never fails the rollout" contract; the check now runs inside the guard, a
value the step aggregation cannot average (anything but a number, or a
sequence of numbers under a histogram key) is dropped with one warning, and
the one warned-once set keys every condition by hook and condition. The
single-controller path resolved the hook after the first prompt group had
streamed back, so a bad dotted path cost a generated group (and a data-retry)
before failing; it resolves before dispatch, as the driver path does. The
single-controller hook now receives each rollout's own full_result, the
object the driver path passes, instead of a projection that leaked the
receipt-mode bookkeeping keys; the getter docstring states the receipt-mode
reward caveat, that the hook also runs on validation batches, that
full_results include masked rollouts, the value rules, and the import errors
it raises.

Tests cover the helper with both flag forms, the gate-off vote, and the
all-masked group; the single-controller exclusion, row alignment, and
fail-before-dispatch; and the hook's output validation and once-per-condition
reporting.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
@alexandery-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 1cb0dd0

…failures-and-redispatch

RL #4435 merged on main as c30bbd4 and appended a test to the rollouts unit-test file where
this branch had appended its own; both sides stay. Two redispatch tests stubbed `_compute_rollout_metrics` with a positional-only lambda; main's #4435 passes the aligned Gym results to it by keyword (`full_results`), so the stubs now accept keyword arguments.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
@alexandery-nvidia

Copy link
Copy Markdown
Contributor Author

No action needed — one more commit, found while smoke-testing this path end to end on a 5-node GB300 run.

The single-controller rollout implementation is built on the driver and pickled into SingleControllerActor. _HOOK_UNRESOLVED was a module-level object() compared by identity, so the unpickled copy inside the actor was a different object: _resolve_rollout_metrics_hook took it for an already-resolved hook, the call raised TypeError: 'object' object is not callable, and every prompt group's hook metrics were skipped behind the once-only warning. The new commit replaces the sentinel with a _rollout_metrics_hook_resolved flag and adds a test that pickles the implementation and resolves the hook on the restored copy.

The previous commit replaced the unresolved-hook marker with a flag that
the test fixtures building AsyncNemoGymRolloutImpl without its
constructor do not carry: they set `_rollout_metrics_hook = None` and
nothing else, so `_resolve_rollout_metrics_hook` raised AttributeError
(test_rollout_generation_failures.py::TestGymRolloutDeadline in CI).

The marker returns as a module-level instance whose `__reduce__` names
the module attribute. pickle and cloudpickle then restore the same
object inside the controller actor, so the identity check holds there,
and None stays the resolved "no hook" answer those fixtures rely on. The
pickling test checks both picklers.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
@alexandery-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 8b2c98c

@alexandery-nvidia

Copy link
Copy Markdown
Contributor Author

No action needed — follow-up to the previous commit: L0_Unit_Tests_Other failed on TestGymRolloutDeadline::test_a_hung_gym_stream_raises_rollout_timeout because that fixture builds AsyncNemoGymRolloutImpl without its constructor and sets only _rollout_metrics_hook = None, which the new flag did not cover. The marker is back as a module-level instance whose __reduce__ names the module attribute, so pickle and cloudpickle restore the same object in the controller actor and None stays the resolved "no hook" value; the pickling test now checks both picklers. test_rollout_manager.py, test_rollout_generation_failures.py, test_effort_shaping.py and test_rollouts.py pass locally.

alexandery-nvidia and others added 10 commits October 19, 2026 18:43
…rked re-dispatches

The driver's stream merge gave every re-dispatch of a row its own
<instance>/retry<n> timing label, so the number of timing keys grew with
the failure rate and a one-row retry's postprocessing percentage could
become the step's. The retry streams of one instance now add up into a
single <instance>/retry payload: the time keys are summed and the
percentage is recomputed from the sums, and the roll-up keeps a retry
label's percentages out of the maximum. The timing tests script the
payload keys the actor really emits.

On the single-controller path nemo_gym_infra_redispatches counted every
row sent again after an attempt ended without it, stream death included,
while the driver path counts only the rows a failure marker named. Both
paths now count marked rows only; a stream-death re-send is still
counted by the attempt counter. The unread failure-class key is removed,
the two tests of the one failure-row membership rule are one
parametrized test, and the actor's timing read is typed as the float the
sum reduction yields.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
…lout id

On the single-controller path under token capture, a row whose /run
failed at the infrastructure level was dispatched again as the same row
dict, so the second session ran under the first session's gate rollout
id. The capture ledger is keyed by that id and admits a second root under
a live id, and the receipt builder cannot tell the two chains apart:
without a witness its heuristic walks the root admitted first, the
failed session's, and a failure row of either session poisons the
receipt of the other.

A row that carries a gate rollout id is now never dispatched again inside
the attempt loop. Under sibling recovery the stream drains so the siblings
that land are sealed, and the marked row ends the attempt with the
transport error the recovery loop retries; that retry mints a fresh
attempt, and with it a fresh gate rollout id, for every sibling that did
not seal, which is the only place an attempt can be bumped. Prompt-group
recovery already dispatched once per attempt and keeps ending the attempt
at the first marker, since the whole cohort is replaced.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
…ing label once

The metric key nemo_gym_infra_redispatches and the retry timing label
were spelled on both rollout paths. The key is now a constant in
rollouts.py and the label comes from one helper there, both used by the
driver's stream merge and by the single-controller attempt loop. One
label means one payload, so the single-controller path now adds its
later attempts' timing up under <instance>/retry the way the driver's
stream merge does.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
…xandery/gym-rollout-metrics-hook

# Conflicts:
#	nemo_rl/experience/rollout_manager.py
… hook into their own module

The env.nemo_gym settings the rollout loop reads, their readers, the
actor-configuration fetch and the rollout-metrics hook machinery lived in
rollouts.py and were imported from there by the single-controller path.
They now form nemo_rl/experience/nemo_gym_rollout_config.py, which both
paths import, and the two rollout functions describe the settings in one
place.

The hook's dotted path is imported once while the actor configuration is
built on the driver, so a path that names no importable callable is
refused before any actor starts; before, the single-controller path
discovered it on the first prompt group and classified it as a data
failure. The single-controller path now also reports, once per process,
a configured health_check_interval_seconds or
max_infra_attempts_per_rollout, naming the settings that apply on that
path instead. _mask_sample_flags reuses is_environment_masked, so the
two-form masking rule has one definition. The caller tests of the
per-agent aggregation keep one wiring assertion each and the
union-of-keys rule is tested on the helper.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
The three env.nemo_gym keys the rollout loop reads were spelled in the
actor-configuration split, the driver key list and each reader. They are
now constants in nemo_rl.environments.nemo_gym that the key list, the
pops, the driver-side import check and the readers share.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
@alexandery-nvidia

Copy link
Copy Markdown
Contributor Author

Pushed a merge of main and of the updated #4447 base, plus two commits. (1) The three Gym rollout settings readers and the metrics hook machinery move out of rollouts.py into nemo_rl/experience/nemo_gym_rollout_config.py, imported by both rollout paths; a bad rollout_metrics_hook path is imported once on the driver when the actor config is built, so it fails at configuration time instead of as a prompt data failure on the first group; _mask_sample_flags reuses is_environment_masked; the single-controller path prints one notice when the two driver-only settings are set; helper rules are tested once at the helper. (2) The three rollout setting keys are named once and used by the pops, the import check and the readers. Tests: test_rollouts.py 117, test_rollout_manager.py 78, test_rollout_generation_failures.py 44, test_nemo_gym.py 57, test_failures.py 60, test_nemo_gym_router.py 18, test_nemo_gym_health.py 9, test_nemo_gym_actor_config.py 4 passing locally; pyrefly reports zero errors on the new module, rollouts.py and rollout_manager.py.

@alexandery-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 0450216

alexandery-nvidia and others added 3 commits October 20, 2026 00:51
Brings in the raised nightly GPU-hour cap (#4802) so L0_Unit_Tests_Other passes; no change of this branch's own code.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
Brings the base branch forward, which carries main's raised nightly GPU-hour cap (#4802) so L0_Unit_Tests_Other passes; no change of this branch's own code.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
Brings the base branch forward, which carries main's raised nightly GPU-hour cap (#4802) so L0_Unit_Tests_Other passes; no change of this branch's own code.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
@alexandery-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test c331672

alexandery-nvidia and others added 3 commits October 21, 2026 18:38
main gained #4472 (Super video RL data and model loading), which added an
import of verify_static_video_media_alignment to rollouts.py at the line
where this branch imports GymTransportError; the resolution keeps both
imports in module order. The other files #4472 and this branch both touch
(nemo_gym.py, rollout_manager.py, test_nemo_gym.py, test_rollouts.py)
merged without conflict, and the rollout, rollout-manager, failure, router
and Gym environment unit tests pass locally on the merged tree.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
…andery/gym-health-check-during-collection

Carries the base branch's merge of main, which brought in #4472 (Super
video RL data and model loading). The only textual conflict, two imports
added at the same line of rollouts.py, was resolved on the base branch;
this merge applied cleanly, and the rollout, rollout-manager, failure,
router and Gym environment unit tests pass locally on the merged tree.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
…xandery/gym-rollout-metrics-hook

Carries the stack's merge of main, which brought in #4472 (Super video RL
data and model loading). The only textual conflict, two imports added at
the same line of rollouts.py, was resolved on the stack's base branch;
this merge applied cleanly, and the rollout, rollout-manager, failure,
router, effort-shaping and Gym environment unit tests pass locally on the
merged tree.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
@alexandery-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 9fe8695

@terrykong terrykong added CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) and removed CI:L0 Run doctests and unit tests labels Oct 29, 2026

@linj-glitch linj-glitch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed final head c0fc4d8, including the small follow-up fix. No remaining blocking correctness or logic issues found. Reviewed the full inherited stack and added a focused signed-off fix with regression coverage so malformed metric names are dropped without aborting the rollout. Valid hook metrics and built-in aggregation are preserved.

Validation: 407 targeted tests passed. Lint/format/recipe checks passed, and pinned Pyrefly comparison found no new diagnostics. The normal type-check hook could not bootstrap the empty Automodel submodule, so the pinned checker was compared directly against the original head. No fresh GPU/model integration run was performed. DCO passes; full CI has not rerun on this added commit.

@terrykong terrykong removed the Documentation Improvements or additions to documentation label Nov 28, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants