Skip to content

feat(rollout-collection): add --interleave-repeats - #3822

Merged
jubick1337 merged 4 commits into
mainfrom
feat/interleave-repeats
Oct 1, 2026
Merged

jubick1337 merged 4 commits into
mainfrom
feat/interleave-repeats

Conversation

@jubick1337

Copy link
Copy Markdown
Contributor

What does this PR do?

Validation

Rollouts

Compatibility and benchmark impact

Checklist

  • I have read the contributing guidelines.
  • The change is focused; unrelated "drive-by" edits are tracked as separate issues/PRs.
  • Tests added or updated and pass locally, or N/A for docs-only / non-code changes (so CI unit/server checks pass when applicable).
  • Documentation added or updated, or N/A with justification.
  • Pre-commit checks pass locally (pre-commit run --all-files) (so CI lint/format checks pass).
  • New source files include the required Apache-2.0 SPDX header.
  • All commits have DCO sign-off (git commit -s) (so the DCO check passes).

@copy-pr-bot

copy-pr-bot Bot commented Sep 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.

@jubick1337
jubick1337 requested review from ananthsub and bxyu-nvidia and removed request for bxyu-nvidia September 30, 2026 20:22
@yaoyu-33 yaoyu-33 added area:evaluation Evaluation, rollout collection, reward profiling, comparison, and exporters complexity:low Localized change in one scope with a small, straightforward review surface feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer labels Sep 30, 2026

@yuhezhang-ai yuhezhang-ai 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.

This looks useful as an opt-in scheduling policy. The main issue to fix before merge is preserving the interleaved order through the default dispatcher; the second comment is a nonblocking documentation clarification.

Validation at 4d85e43: all 500 tests in tests/unit_tests/test_cli_main.py and tests/unit_tests/test_rollout_collection.py passed, along with Ruff lint and formatting checks. Focused reproductions exercised production preprocessing and dispatch with mocked server transport. No live model rollout or memory measurement was performed.

Comment thread nemo_gym/rollout_collection.py Resolved
@jubick1337

Copy link
Copy Markdown
Contributor Author

Thanks for review, addressed issues!
@yuhezhang-ai

| `--output`, `-o` | Output rollouts JSONL file. |
| `--limit` | Maximum number of tasks to run. |
| `--num-repeats` | Rollouts per task (for mean@k metrics). Pass an int to apply to every task, or a dict keyed by `agent_ref.name` for per-agent counts (e.g. `'{simple_agent: 32, swe_agent: 1}'`) when one input file mixes agents. In dict form, the special key `_default` is the fallback for agents not explicitly listed; without it, any unlisted row's agent raises a single consolidated error. |
| `--interleave-repeats` | Start repeats round by round (every task's first rollout, then every task's second) rather than each task's back to back. Use it when a task is heavy on the machine running it, for example when its sandbox loads large data, to spread its repeats over the run. This is best effort: repeats still overlap when the concurrency is high or rollouts are long. GDPVal's multistage orchestrator rebuilds its stage rows per task and does not keep this order. Maps to legacy `+interleave_repeats=true`. |

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.

would suggest removing gpdval specific note here and put that in the gpdval readme instead

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.

oh i see this mightve came from comment above? happy to defer to team

@yuhezhang-ai

Copy link
Copy Markdown
Contributor

/ok to test fae6660

@yuhezhang-ai yuhezhang-ai 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 the latest changes at fae6660. Both earlier comments are addressed: the default dispatcher creates tasks in input order, with a request-start-order regression test, and the docs correctly explain overlap and the GDPVal multistage limitation. No remaining blocking findings.

Validation on this head: 501 tests passed across tests/unit_tests/test_cli_main.py and tests/unit_tests/test_rollout_collection.py; Ruff lint, formatting checks, and git diff --check passed. Existing lint, copyright, secrets, and DCO checks are green. Full repository CI has been requested and is still pending; this approval does not assert it has passed.

No live model rollout or production memory measurement was performed; the change concerns collector scheduling rather than agent or verifier behavior.

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/36810320804

Merged via the queue into main with commit fadd0c7 Oct 1, 2026
43 checks passed
@jubick1337
jubick1337 deleted the feat/interleave-repeats branch October 1, 2026 03:38
linj-glitch pushed a commit to linj-glitch/Gym that referenced this pull request Oct 15, 2026
…A-NeMo#4644)

## What does this PR do?

Rollout collection kept every finished `/run` result in the driver's
memory until the last rollout of the run finished, even with
`retain_results_in_memory=false`, whose description promises that
results are not retained during collection.

The cause is in `_run_examples_with_metadata` in
`nemo_gym/rollout_collection.py`, the dispatcher shared by `gym eval
run` (through `run_from_config`) and by `run_examples`, which NeMo RL
calls. When `max_resident_tasks` is unset, its inner generator
`_start_in_input_order` created every rollout task up front in a list
and passed that list to `tqdm.as_completed`. The list stayed alive in
the generator frame for the whole run, and `tqdm.as_completed` also kept
it as its `fs` argument. A finished asyncio task holds its result, so
the consumer dropping a result did not free it.

The fix passes a generator of tasks instead of a list.
`_start_in_input_order` was added in NVIDIA-NeMo#3822 because
`asyncio.as_completed` builds its tasks from a set, which would start
rollouts in an arbitrary order. That property still holds:
`asyncio.as_completed` iterates the generator in order (`set(aws)`)
before building its set, so `asyncio.ensure_future` still creates the
tasks in input order. After that, only `asyncio.as_completed`'s own
bookkeeping references a task, and it lets go of a task once it hands
the result to the consumer. The progress bar keeps its explicit `total`,
so it is unchanged.

The bounded admission path (`_BoundedCompletionIterator`, used when
`max_resident_tasks` is set) already released finished tasks: it pops
each task from its ready list before awaiting it, so it needed no
change.

NeMo RL's `run_examples` path benefits too, since it goes through the
same dispatcher.

No issue was filed; the bug and the fix are both contained in this PR.

## Validation

- A new test,
`test_dispatch_releases_a_taken_result_while_rollouts_are_pending`, runs
both `run_examples` and `_run_examples_with_metadata`, with and without
`max_resident_tasks`. The first rollout finishes while the others are
held pending. The test takes and drops the first result, then asserts
through a weak reference that the result was freed before the remaining
rollouts finish. On the code before this change, the cases without
`max_resident_tasks` fail and the bounded cases pass.
- The existing `test_default_dispatch_starts_rollouts_in_input_order`
still passes, confirming that rollouts start in input order.
- `PYTHONPATH=. .venv/bin/python -m pytest -n 16 -q tests/unit_tests
--ignore=tests/unit_tests/test_exporters.py` in a venv built with `uv
sync --extra dev --extra telemetry`. The only failures are
environment-dependent ones in `test_opensandbox_compose.py`,
`test_reward_profile.py`, `test_dataset_orchestrator.py`, and
`test_sandbox_stop_retry.py`, which fail identically on `main` on the
same machine.
- `pre-commit run --all-files`.

## Rollouts

N/A: the change only affects when the driver releases results it has
already handed to the consumer. It does not change which rollouts run,
in what order they start, or any agent, model, or verifier decision.

Memory evidence comes from a CPU capacity simulator with the production
topology (simulated engine and tools, real Gym servers and driver). Each
run collected 4,096 long-context rollouts (64 repeats, 80 history
messages of 2,000 characters each) with 1,024 in flight,
`++retain_results_in_memory=false`, and rollout observability on. The
driver's `process.memory.usage` came from console metric exports every
10 seconds. The table shows the highest reading taken while rollouts
were still completing, with the number of completed rollouts at that
sample.

| Variant | Repeat | Peak driver memory during collection |
| --- | --- | --- |
| `main` (974d1a9) | 0 | 4.56 GB at 3,697 of 4,096 |
| `main` (974d1a9) | 1 | 4.52 GB at 3,652 of 4,096 |
| this PR | 0 | 0.70 GB at 3,726 of 4,096 |
| this PR | 1 | 0.82 GB at 3,235 of 4,096 |

On `main`, driver memory grew steadily with the number of completed
rollouts. With this change it stayed between 0.5 and 0.8 GB for the
whole collection. Both variants still jump to about 5.6 GB after the
last rollout, because the no-retention mode reads the output file back
into memory for aggregation. That is a separate issue and is not
addressed here.

## Compatibility and benchmark impact

None. Results, their order of delivery, and the progress bar are
unchanged.

## Checklist

- [x] I have read the [contributing
guidelines](https://github.com/NVIDIA-NeMo/Gym/blob/main/CONTRIBUTING.md).
- [x] The change is focused; unrelated "drive-by" edits are tracked as
separate issues/PRs.
- [x] Tests added or updated and pass locally, or N/A for docs-only /
non-code changes (so CI unit/server checks pass when applicable).
- [x] Documentation added or updated, or N/A with justification. N/A: no
documented behavior changes; the existing `retain_results_in_memory`
description now holds.
- [x] Pre-commit checks pass locally (`pre-commit run --all-files`) (so
CI lint/format checks pass).
- [x] New source files include the required Apache-2.0 SPDX header. N/A:
no new files.
- [x] All commits have DCO sign-off (`git commit -s`) (so the DCO check
passes).

Signed-off-by: Ananth Subramaniam <[email protected]>

This branch was previously deployed

1 inactive deployment
public — fae66602 Deployed Oct 1, 2026 by copy-pr-bot[bot] via release / finalize / notify #4078
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:evaluation Evaluation, rollout collection, reward profiling, comparison, and exporters complexity:low Localized change in one scope with a small, straightforward review surface feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants