Skip to content

fix(rollouts): fail loudly on silent NeMo-Gym agent failure - #2643

Closed
lonexreb wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
lonexreb:fix/2305-gym-empty-epoch-loud-error
Closed

lonexreb wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
lonexreb:fix/2305-gym-empty-epoch-loud-error

Conversation

@lonexreb

Copy link
Copy Markdown
Contributor

Summary

Closes #2305.

When the NeMo-Gym agent crashes silently — most commonly CPU OOM during rollout collection on oversized batches — `run_rollouts.remote(...)` may return fewer results than input rows. The previous code accepted the mismatch and built a partial `final_batch` from whatever came back, producing "empty epochs" downstream. Training continued without crashing, masking the underlying agent failure (exactly what was reported in #2305).

What changed

`run_async_nemo_gym_rollout` in `nemo_rl/experience/rollouts.py` now compares `len(results)` against `len(nemo_gym_rows)` immediately after the `ray.get` and raises a `RuntimeError` if they don't match:

```
RuntimeError: NeMo-Gym returned 0 rollout result(s) for 1024 input row(s).
This usually means the Gym agent crashed silently (most commonly CPU OOM
during rollout collection for large batches). Check the Gym agent logs
for OOM / killed-process messages and consider reducing
grpo.num_prompts_per_step * grpo.num_generations_per_prompt, or the
per-row max_output_tokens, to fit available memory.
```

The error names the size mismatch, the likely cause, where to look (Gym agent logs), and which knobs to turn. The check is O(1) and only fires on the failure path; the success case (one result per input row) is unaffected.

Test plan

  • New regression test `test_run_async_nemo_gym_rollout_raises_on_silent_agent_failure` covers both partial (1-of-2 returned) and total (0-of-2 returned) agent failures by monkeypatching `ray.get`. Runs without GPU / Gym / Ray.
  • `ruff check` — clean
  • `ruff format --check` — clean
  • `python3 -m py_compile` — clean
  • CI `L0_Unit_Tests` — runs the new test
  • CI `tests/functional/grpo_async_gym.sh` — exercises the happy path and confirms no false-positive

Refs: #2305

Closes NVIDIA-NeMo#2305.

When the NeMo-Gym agent crashes silently (e.g. CPU OOM during rollout
collection on oversized batches), `run_rollouts.remote(...)` may
return fewer results than input rows. The previous code accepted the
mismatch and built a partial `final_batch` from whatever came back,
producing "empty epochs" downstream — training continued without
crashing, masking the underlying agent failure.

`run_async_nemo_gym_rollout` now compares `len(results)` against
`len(nemo_gym_rows)` immediately after the `ray.get`, and raises a
`RuntimeError` naming the size mismatch, the likely cause (silent OOM /
crash inside Gym), where to look (Gym agent logs), and which knobs to
turn (`grpo.num_prompts_per_step`, `grpo.num_generations_per_prompt`,
per-row `max_output_tokens`).

The check is O(1) and never fires on the success path, where Gym
returns exactly one result per input row.

Added a regression test
(`test_run_async_nemo_gym_rollout_raises_on_silent_agent_failure`)
that monkeypatches `ray.get` to return both a short-by-one and a
fully empty result list, asserting the RuntimeError fires with the
expected message in both cases.

Signed-off-by: Shubhankar Tripathy <[email protected]>
@lonexreb
lonexreb requested review from a team as code owners May 30, 2026 07:17
@copy-pr-bot

copy-pr-bot Bot commented May 30, 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.

@lonexreb

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate of #2394 — same issue (#2305), better layer. #2394 patches NemoGym.run_rollouts (root cause: where the iterator silently runs out and None rollouts get appended), so a malformed list never leaves the function. The check I added here was at the caller boundary in run_async_nemo_gym_rollout, which would be defense-in-depth at best and dead code once #2394 lands. Apologies for the noise — I missed #2394 in my triage. Picking up the wrong half of the prior-work scan on my end.

@lonexreb lonexreb closed this May 30, 2026
DanialTaheri added a commit that referenced this pull request Aug 21, 2026
The image tools env landed upstream as squash-merge 4a582181
("Add image tools agent and PivotRL verifier", NVIDIA-NeMo/Gym#2624), plus
follow-up 0951c9b1 ("fix(ci): make image tools agent discoverable", #2643)
which adds responses_api_agents/image_tools_agent/README.md. Neither of the
branch's own commits is an ancestor of main, so the previous pointer at
8c53f682 referenced a fork-only commit that upstream CI cannot fast-forward to.

Pointing at origin/main (fa0d2515) instead. Verified this tree carries every
fix from the branch: the asyncio.to_thread wrapper around
process_nonterminal_turn, the corrected response-model keys in the agent test
(zero remaining references to the non-existent image_tool_call_count), and
both data/example_rollouts.jsonl and data/example_metrics.json.

Signed-off-by: DanialTaheri <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gym: Empty epochs if Gym agent fails

1 participant