Repository navigation
[rl] Verifiers: one GenerateFn per running rollout group - #5948
felipemello1 wants to merge 1 commit into
Conversation
|
Reply from claude: @claude please review. This PR is part of a stack. Review only this PR's diff against its base branch. The human-written summary is Felipe's to write. |
|
Claude finished @felipemello1's task in 1m 33s —— View job Approve, with one optional suggestion (assert that a group id isn't already running before it is added): review |
There was a problem hiding this comment.
Verdict: Approve -- the fix is correct, in the right layer, and makes the server smaller. One small optional change is below.
Reviewed only this PR's diff against felipemello1/eval/1-validation-dataloader. As asked, the empty human-written summary is not flagged.
What this PR does. The Verifiers GenerationServer used to hold a single GenerateFn, and every running group shared it. Now it holds one per running rollout group, keyed by the torchtitan_group_id it already parses from each request. run_group_rollouts adds its group's entry before its rollouts start and removes it in a finally block. A call for a group with no entry gets HTTP 400. set_generate_fn and the 503 "not ready" path are deleted.
Example.
base: training group 7 running -> server.generate_fn = training_fn
validation group -1 starts -> server.generate_fn = validation_fn
group 7 makes a call -> validation_fn: metrics go to validation_generator/*
this PR: generate_fns = {7: training_fn, -1: validation_fn}
group 7 makes a call -> training_fn
group -1 ends -> entry removed; a late call from -1 gets 400 "rollout group -1 is not running"
Should consider
torchtitan/rl/examples/verifiers/rollouter.py:259-- assert that thegroup_idis not already registered. The dict relies on ids being unique among running groups. That holds today, but validation ids-(i + 1)repeat on every pass. If two passes overlap, the second one silently takes over the first one's calls, and thedelinfinallythen fails withKeyError(details inline).
Details
- Group ids at HEAD: training groups use
IterableRolloutDataLoader/MapStyleRolloutDataLoader._next_index, which only increases, so a training id never repeats while its group is running (torchtitan/rl/rollout/data.py:127,221). Validation uses-(i + 1)within one pass, and_collect_validation_rolloutsruns one pass at a time (controller.py:697). So no ids collide in this PR; the assert guards the next PR in the stack. - Storing
self._generation_serverin a local is justified:close()sets the attribute toNone, and without the local thefinallyblock would raiseAttributeErrorinstead of removing the entry. - Deleting the 503 is safe: a request can only arrive from a group that has already registered its entry, so the "not ready" state no longer exists.
- Tests: the new parametrize case extends an existing test rather than adding one, and it guards the new 400 path. The extra assert in the failing-group test checks that the
finallycleanup ran. Both are cheap CPU tests.
| ), | ||
| return_exceptions=True, | ||
| ) | ||
| generation_server.generate_fns[group_id] = generate_fn |
There was a problem hiding this comment.
The dict assumes no two running groups share a group_id, but nothing checks that. Today the ids are unique: training ids come from the dataloader's increasing _next_index, and validation uses -(i + 1) for one pass at a time. But validation ids repeat on every pass, and the next PR in this stack runs validation beside training. If two passes ever overlap, the failure looks like this:
- Group B (id -1) overwrites group A's entry, so A's calls go to B's
GenerateFn. That is the wrong-prefix bug this PR fixes, and nothing reports it. - A finishes and its
delremoves B's entry, so B's remaining calls get "rollout group -1 is not running". - B's
finallyraisesKeyError, which hides B's real result.
An assert at registration turns all three into one clear error:
| generation_server.generate_fns[group_id] = generate_fn | |
| assert ( | |
| group_id not in generation_server.generate_fns | |
| ), f"rollout group {group_id} is already running" | |
| generation_server.generate_fns[group_id] = generate_fn |
33a8459 to
270fde1
Compare
0270e15 to
2f3bafe
Compare
|
Reply from claude: rebased onto the new #5944 head (63d82dd) with no code change ( |
|
Claude finished @felipemello1's task in 49s —— View job Approve. The rebase left this PR's diff unchanged and I found no new problems. One optional suggestion from the last review is still open: assert that a group id isn't already running before adding it. Review |
There was a problem hiding this comment.
Verdict: Approve -- the rebase left this PR's diff unchanged, and I found no new problems.
This is a re-review. I looked only at this PR's diff against felipemello1/eval/1-validation-dataloader, at head 270fde1. I compared it with the diff from the last review (33a8459) and they are identical: same 3 files, +61/-37.
What this PR does. The Verifiers GenerationServer now keeps one GenerateFn per running rollout group, stored in generate_fns and keyed by group id. run_group_rollouts adds its group's entry before its rollouts start and removes it in a finally block. A call from a group with no entry gets HTTP 400.
Example.
base: training group 7 running, validation group -1 starts -> group 7's calls go to validation_fn
this PR: generate_fns = {7: training_fn, -1: validation_fn} -> group 7's calls go to training_fn
group -1 ends -> its entry is removed; a late call from -1 gets 400 "rollout group -1 is not running"
Should consider
- Still open from the last review:
torchtitan/rl/examples/verifiers/rollouter.py:259. Assert thatgroup_idis not already ingenerate_fnsbefore adding it. Group ids are still unique at the new base: training ids come from_next_index(torchtitan/rl/rollout/data.py:127,221), and validation uses-(i + 1)one pass at a time (torchtitan/rl/controller/controller.py:733). So nothing breaks in this PR. Validation ids repeat on every pass, though, and once the next PR runs validation beside training, two overlapping passes would silently send one group's calls to the other group's function. Thedelin thefinallyblock would then raiseKeyError. The inline suggestion from the last review still applies.
Details
- No callers of the old API are left:
set_generate_fnandgenerate_fnno longer appear in the repo outside this diff. - The earlier analysis still holds at the new base. The local
generation_serverkeepsclose()from turning thefinallycleanup into anAttributeError. Removing the 503 is safe because a request can only come from a group that has already added its entry.
… own (#5969) ## Summary (human-written) 1) we would like to visualize generatioin metrics for training and validation separately 2) currently we pass a "metric prefix" and have the generator add the suffix 3) this doesnt compose well with verifiers 4) we remove this, and let the evaluator add the suffix when they come back ## Agent details Stack: main <- #5944 <- this PR <- #5228. Supersedes #5948 (one `generate_fn` per group, kept in a dict). **TLDR:** The generate path no longer carries a metrics label. Generators always name their metrics `generator/*`, and validation renames its own to `validation_generator/*` after results return, so the W&B keys stay as on main. #5228 (validation beside training) needs this first: Verifiers' HTTP server holds one `generate_fn`, so once groups of both kinds overlap, a request can log under the other kind's label. ```text main: validation generate_fn(metrics_prefix="validation_generator") -> router -> generator -> "validation_generator/queue_time_ms" this PR: every generate_fn, no label -> router -> generator -> "generator/queue_time_ms" validation, after the group returns: "generator/queue_time_ms" -> "validation_generator/queue_time_ms" ``` **Problem** 1. The controller builds two kinds of `generate_fn`: training's sends `metrics_prefix="generator"`, validation's `"validation_generator"`. 2. The label travels through 7 layers to name each request's metrics: controller, `InterGeneratorRouter`, the Monarch router and generator, `Generator`, engine loop, dispatcher. 3. Verifiers runs its agents against an HTTP server that holds one `generate_fn` (`GenerationServer.set_generate_fn`). Each group that starts replaces it. 4. So while a training group and a validation group run at once, a request uses the function of the group that started last, and logs under that kind's label. Once validation runs beside training (#5228), that is most turns of a multi-turn env. 5. On main no logged metric is wrong: validation never overlaps a running training rollout. A late call from a cancelled rollout lands in metadata nobody reads. So on main this PR is a cleanup that prevents the bug. **Solution** 1. Drop `metrics_prefix` from the generate path. The dispatcher spells each key: `generator/queue_time_ms`, `generator/num_cached_tokens`, ... 2. `_collect_validation_rollouts` renames its turns' `generator/*` metrics to `validation_generator/*` after results return. 3. The Verifiers server keeps its one slot. Every group now passes a function with no label, so replacing it is safe (a comment at the call). 4. Unchanged: the W&B keys (`generator/*` for training, `validation_generator/*` for validation), the `GenerateFn` contract, routing and request ids. 5. The logic is in two places: the rename in `_collect_validation_rollouts` and the spelled keys in `_prepare_generation_request_metrics`. The other files only delete the parameter, plus one comment in the Verifiers rollouter and the new test. You may ask: - Why not one `generate_fn` per group in the Verifiers server, keyed by group id (#5948)? It fixes Verifiers only and adds a per-group lifetime. A function with no label can't be the wrong one, whatever calls it. This PR replaces #5948. - Why keep `validation_generator/*` and not `validation/generator/*`? Dashboards and old runs keep their keys. NOTE: - A metric about the whole engine shouldn't ride on one request's metrics: validation renames every `generator/*` key on its turns, and a failed group drops its turns' metrics. - Open PRs that pass `metrics_prefix` need a rebase that drops it. - The rollout recorder writes no metrics, so `rollout_samples.jsonl` is unchanged. **Test plan** ```text pytest tests/rl/unit_tests/cpu -q --ignore=tests/rl/unit_tests/cpu/test_vllm_wrapper.py # 551 passed, 7 skipped (base: 550 passed, 7 skipped) pytest tests/rl/unit_tests/cpu/test_verifiers*.py tests/rl/unit_tests/cpu/test_model_defaults.py # in a venv with verifiers # 61 passed pre-commit run --files <changed files> # all hooks pass pyrefly check # 1 error, the same on the base: FSDPModule.set_unshard_in_current_stream (torchtitan/distributed/fsdp.py:593) ``` - New: `test_async_controller.py::test_validation_renames_generator_metrics`. It fails when the rename is removed. - `test_generator.py`, `test_engine_loop.py`, `test_async_controller.py`: the calls drop `metrics_prefix`. `test_metric_timing_math` now checks `generator/*` keys. --------- Co-authored-by: Felipe Mello <[email protected]>
Summary (human-written)
Agent details
TLDR: The Verifiers generation server keeps one
GenerateFnper running rollout group, keyed by group id, instead of one for all groups. Each HTTP call goes to its own group's function. This is prevention. Its user is the next PR in this stack (the Evaluator), which runs validation groups beside training groups.Problem
GenerateFn. Training's logs generation metrics asgenerator/*, validation's asvalidation_generator/*.VerifiersRollouter.run_group_rolloutsstores it withGenerationServer.set_generate_fn: one slot for every group.Solution
GenerationServer.generate_fns: dict[int, GenerateFn]replacesgenerate_fnandset_generate_fn.sampling_params.torchtitan_group_id); it now looks up that group's function.run_group_rolloutsadds its entry before its rollouts start and removes it in afinallyonce they end.Test plan
test_a_failing_rollout_fails_its_group_only_after_every_sibling_finishednow also checks that a failed group's entry is removed.