Repository navigation
feat(nemo_gym): typed /run failure rows and bounded re-dispatch - #4446
alexandery-nvidia wants to merge 20 commits into
Conversation
terrykong
left a comment
There was a problem hiding this comment.
@asolergi-nv can you help review?
|
/ok to test ebffc0e |
|
/ok to test 04c6fbd |
ebffc0e to
04c6fbd
Compare
|
/ok to test e0b2859 |
04c6fbd to
e0b2859
Compare
…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]>
|
/ok to test 1592ea4 |
e0b2859 to
1592ea4
Compare
…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]>
|
Merged |
|
/ok to test 9be9fec |
…andery/gym-health-check-during-collection Brings #4446's merge of main after RL #4435's squash (c30bbd4): main's appended rollouts test and this stack's appended tests both stay, and the redispatch tests' metric stubs accept the keyword argument main now passes. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: alexandery <[email protected]>
yaoyu-33
left a comment
There was a problem hiding this comment.
Thanks for this. Keeping the other rows of a stream alive when one /run dies is a real improvement, and consuming Gym's existing route_failures_to_sidecar failure-row contract is the right way to do it. I checked the contract against the pinned Gym (da9f671): the key names match _agent_request_failure_row, only ClientError/JSONDecodeError/TimeoutError become rows, _rowidx survives, and the status rule (including below 400) matches what the collector produces. Re-dispatch index alignment, attempt counting, the per-label timing and the finally cancellation all behaved correctly in a stubbed run of the merge and accumulator. The merge of main (9be9fec) matches git's own merge apart from the test conflict, and #4749 applies cleanly on top.
Inline: the failure-row check (_ng_failure_type is also stamped by a verifier), the single-controller marker path with cohort verifiers, and data failures being masked by a later budget exhaustion.
A question on the motivation. Gym's vllm_model picks the engine by hashing a fresh session id (vllm_model/app.py#L1790-L1798), and route_around_failing_endpoints defaults to False (#L357); NeMo RL sets neither it nor endpoint_file. So each re-dispatch lands on the dead engine again with probability 1/E, and with E=8 engines and a budget of 3, a step with ~256 rows on the dead engine still fails ~98% of the time. Did the downstream runs have route_around_failing_endpoints on? If so, could the design doc recommend pairing max_infra_attempts_per_rollout with it? Also, an engine that refuses connections doesn't produce a 5xx at all: without endpoint_file the connection retries are unbounded (openai_utils.py#L1545-L1551), and Gym's internal client has no deadline (server_utils.py#L397), so the row hangs rather than yielding a marker. The "no status = connection failure or timeout" wording in _typed_gym_failure may want the same caveat.
Smaller things, no action required: with a cohort verifier (genrm_compare), a single-row retry reuses the group identity, so it only recovers failures before /verify (budget > 1 can't save a cohort that already failed); each re-dispatch gets its own retry<n> timing label (a dead engine adds many wandb series); nemo_gym_infra_redispatches is emitted only when non-zero, so the async collector averages over the non-zero groups; and int(value) accepts True/2.5 for the budget.
Local validation (CPU, macOS): the changed test files under tests/unit/experience and tests/unit/environments passed (204 + 103); the --nemo-gym-only lane of test_captured_media.py was not run.
Generated by Claude Code
…ast attempt at a marker Review follow-ups on #4446. Only Gym's _agent_request_failure_row writes _ng_failure_http_status (None when nothing replied), while a verifier may echo _ng_failure_type on a row it scored (Terminal-Bench does, and the sandboxed agent returns that verify JSON as the /run result). run_rollouts now recognises a failure row by the status key, so such a verifier row is postprocessed like any result instead of ending the step at the default budget. Single-controller path: a failure marker now ends the last attempt at once (_stream_rows stop_on_infra_failure). Nothing would re-dispatch the row after that attempt, and a verifier that scores a prompt group together would otherwise hold the stream open in /verify until its cohort timeout. The exemplar recipes say when to use the prompt_group granularity and rollout_timeout_s instead of row re-dispatch. Driver merge: once a data failure has ended the rollout, markers from the other instances are no longer re-dispatched, so an exhausted budget cannot hide the 400 behind a transport error. Also: the budget reader refuses a bool or a float instead of truncating it, nemo_gym_infra_redispatches is reported on every rollout (zero included) so its mean is a rate, the _typed_gym_failure docstring says why a refused connection yields no status-less row, and the design doc recommends pairing the budget with route_around_failing_endpoints in the vllm_model configuration. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: alexandery <[email protected]>
…failures-and-redispatch main gained #4745, #4542 and #4596 since the previous merge, which put this head eleven commits behind it; the merge keeps the head within main's up-to-date rule for CI. No conflicts. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: alexandery <[email protected]>
…andery/gym-health-check-during-collection Picks up #4446's review follow-ups (failure rows keyed on the status key, the single-controller last attempt ending at a marker, no re-dispatch after a data failure) and its merge of main. No conflicts. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: alexandery <[email protected]>
…river-loop only Review follow-ups on #4447. _nemo_gym_rollout_config bounds the rollout_config call (NEMO_GYM_ROLLOUT_CONFIG_TIMEOUT_SECONDS) and raises GymTransportError on a miss. The read is the first thing a rollout awaits, before the health check polls, and the asynchronous trajectory collector retries a failed batch against the same actors, so an actor whose event loop is blocked would otherwise turn the probe's timeout into a retry that hangs. The design doc, the nanov3 recipe and the two docstrings say that health_check_interval_seconds and max_infra_attempts_per_rollout belong to the driver rollout loop (synchronous GRPO, the asynchronous collector, PPO, distillation) and that the single-controller rollout manager reads neither: it bounds a rollout with rollout_timeout_s and re-dispatches rows under max_row_attempts. The health-polling test expects nemo_gym_infra_redispatches to be reported as zero, since #4446 now reports the count on every rollout. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: alexandery <[email protected]>
|
Thanks for the review. The three inline threads are answered; the fixes are in 19a06a5, and 907d2e7 merges On the motivation question: yes, the downstream runs set On the smaller things: the budget reader now refuses a bool or a float instead of truncating; Gate on 19a06a5: |
|
/ok to test 907d2e7 |
…xandery/gym-rollout-metrics-hook Picks up #4447's and #4446's review follow-ups and their merge of main. Two conflicts: the design doc, where both branches extended the knob comment and added prose after the configuration block (both kept, the reliability paragraphs before the hook paragraphs, the comment naming all three knobs), and test_rollouts.py, where tests were appended at the same place (both kept). Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: alexandery <[email protected]>
…path too The driver path reports nemo_gym_infra_redispatches on every rollout, zero included. The single-controller rollout manager did not report it, so the nemo_gym CI lane's parity test, which requires every driver metric key from the manager, failed, and the lane's driver test, which lists the driver's metric keys, lacked the new key. The manager's _run_rollouts now counts the rows it sends again across its later attempts and reports them under the same key, and both lane tests carry the key. Two CPU tests pin the count: one row sent again counts one, and a clean group reports zero. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: alexandery <[email protected]>
|
The Gate on a73688d: |
|
/ok to test a73688d |
…failures-and-redispatch main gained #4481, #4771, #4458, #4770, #4640, #4765, #4525 and #4670 since the previous merge. #4640 (rubric-mean and fixed-baseline GenRM scoring) rewrote the metric assertions in tests/unit/experience/test_rollouts.py that this branch also edits for nemo_gym_infra_redispatches: the resolution keeps main's per-key assertions and adds the redispatch count beside them, and the expected rollout_metrics dict carries both sides' new keys. test_rollouts.py, test_rollout_manager.py and test_nemo_gym.py pass locally on the merged tree. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: alexandery <[email protected]>
|
/ok to test 8fecfa2 |
…failures-and-redispatch
…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]>
|
Pushed a merge of main plus three commits. (1) The retry timing of an instance folds into one |
|
/ok to test e79f66a |
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]>
|
/ok to test d67d738 |
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]>
|
/ok to test de0b842 |
|
#4500 (merged as d3d22f1) put typed per-row What
Two things differ on
#4447 and #4448 are stacked on this branch. I will rebuild them on Thank you for the review of this pull request. 🤖 Generated with Claude Code |
What does this PR do?
A NeMo-Gym
/runthat fails currently ends every rollout still in flight: the actor's stream raises, the driver loses the other rows of that stream, and one dead engine costs the whole step.Two changes, both in the driver's NeMo-Gym rollout path:
NemoGymactor asks Gym's rollout collector for a failure row instead of an exception (route_failures_to_sidecar=True, the collector's existing contract), so the stream survives the failed row. The row carries the failure's class, HTTP status, type, message, and response body as plain values, and_typed_gym_failureinnemo_rl/environments/nemo_gym.pyclassifies it on the actor side with the onehttp_status_is_infrarule the driver applies: a 5xx, a retriable 4xx, a status below 400 on a request that still failed (the reply broke after its status line: the body read or parse failed, as when a relayed multi-megabyte response is cut mid-body), or a row without a status (a connection failure or a timeout before any reply) becomesGymTransportError; only a non-retriable 4xx describes the request and becomesRolloutDataFailure. The detail names the failure type, because the type (a payload or JSON decode error) is the diagnosis when the status says success. 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) while the other rows keep running. A scoreable result that only carries_ng_failure_class(Gym's judge failsafe) is still postprocessed like any result.run_async_nemo_gym_rolloutinnemo_rl/experience/rollouts.pydispatches a marked row again as a fresh single-row stream on the instance whose stream reported the failure, up toenv.nemo_gym.max_infra_attempts_per_rolloutattempts in total; the last failure raisesGymTransportErrorwith the failure's detail. The retry stays on its own instance because bucketing is by prompt group and a group split across instances deadlocks verifiers that buffer whole groups; a dead engine is not the instance's fault, since every instance holds the same engine URLs and Gym picks the engine per request. The merge of the per-instance streams requires two callbacks, the per-row budget and the timing sink, and records each stream's actor timing itself: a failure marker can be the tuple that carries a stream's timing, and a retry stream reports under its own<instance>/retry<n>label, so the timing metrics of a step with a re-dispatch are the buckets' totals. The_NemoGymStreamAccumulatorkeeps the per-row budget, and the final rollout metrics reportnemo_gym_infra_redispatches, the number of rows dispatched again, on every rollout, zero included, so a mean over steps is a rate. The single-controller path (rollout_manager.py) leaves a marked row's slot empty so its own attempt loop dispatches it again, reports the samenemo_gym_infra_redispatchescount in the rollout's metrics, reports a later attempt's actor timing under<instance>/retry<n>so a one-row re-dispatch never replaces the group's totals, and when a row runs out of attempts there, the final error names the marker's detail (and any row that never arrived) instead of reporting a stream that ended early.Design note
env.nemo_gym.max_infra_attempts_per_rollout(optional, default 1 = today's single attempt) is read by the driver only, so_build_gym_actor_configkeeps it as a top-level field of the actor's configuration and out of Gym's global configuration (DRIVER_ROLLOUT_KEYS);NemoGym.rollout_confighands it back, and the rollout function reads it there unless a caller passes it, so every caller of the rollout function (synchronous GRPO, the asynchronous trajectory collector, PPO, distillation) applies the same configured value. The single-controller path keeps its ownRolloutRetryPolicy.max_gym_row_attempts, whose comments in the single-controller config and its two exemplars now describe the marker. The key isNotRequiredon theNemoGymConfigTypedDict; an absent key means the default; the exemplarexamples/nemo_gym/grpo_nanov3.yamlanddocs/design-docs/nemo-gym-integration.mdcarry it.failure_kind/failure_reason. Those act inside one Gym collection. This change is the NeMo-RL-side counterpart: it consumes the typed failure row the collector already produces and decides, on the driver, whether a row lost to infrastructure is dispatched again as a new session. The driver budget, the single-controllerRolloutRetryPolicy.max_gym_row_attempts, and itsmax_attempts_per_promptstay separate knobs; the docstring ofget_nemo_gym_max_infra_attemptssays why.Issue
No issue filed; observed in multi-engine training runs where one engine process died mid-step and every rollout pinned to it failed with a 5xx, which ended the step for the other rollouts too.
Validation
tests/unit/environments/test_nemo_gym.py,tests/unit/environments/test_nemo_gym_health.py,tests/unit/environments/test_nemo_gym_actor_config.py(new),tests/unit/experience/test_rollouts.py,tests/unit/experience/test_rollout_manager.py,tests/unit/experience/test_failures.py,tests/unit/experience/test_nemo_gym_router.py,tests/unit/experience/test_rollout_generation_failures.py: 302 passing on this branch rebased ontomaine1a2e9a;tests/unit/data/test_captured_media.py(thenemo_gymlane), whose retained-media test now hands_typed_gym_failurethe failure row the collector produces, passes with--nemo-gym-only. Tests cover the failure-row classification on both sides of the pickling boundary for statuses 0 through 503 (one rule below 400 as well), the marker row yielded by_stream_rolloutsfor a 5xx and the data failure raised for a 4xx, the class-annotated judge row that is still scored, the accumulator's budget, re-dispatch throughrun_async_nemo_gym_rollout(the metric, the exhausted-budget error, a two-replica shard set whose retry goes back to the failing replica, a bucket's timing surviving a one-row retry that finishes last, and a retry stream that fails again and is dispatched a third time under its own retry label), the actor-config split, and the single-controller path re-dispatching only the failed row, counting it innemo_gym_infra_redispatches(and reporting zero for a clean group), keeping the group's timing across the re-dispatch, and naming the failure detail and the rows that never arrived when the budget runs out. Thenemo_gymCI lane's GPU tests pin the metric on both paths:test_run_async_nemo_gym_rolloutlists it among the driver's metric keys, andtest_async_nemo_gym_rollout_manager_matches_originalrequires every driver key, this one included, from the manager.pre-commit run --files <changed files>: ruff, ruff-format, and the recipe minimize check pass; thepyreflyhook needs the submodules, which this checkout lacks, so the type check is CI's lint job.🤖 Generated with Claude Code