Repository navigation
Conversation
|
@claude review |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. The fields this PR drops are read only by worker-side scoring and controller-side logging, the training sample builder's equivalence is now tested, and the remaining items are small edits. A maintainer still needs to review.
What this PR does. RolloutWorkerActor.run_group now finishes training groups itself. It computes rollout/* metrics with compute_rollout_metrics, encodes the recorder's JSONL lines with the new RolloutSampleEncoder, then returns a slim copy of the group. The slim copy has no messages, env_rewards, per-turn metrics, reward_breakdown or logs, and keeps one bytes object per image hash. The controller appends the lines and hands the slim group to the work buffer. Validation passes for_training=False and works as before.
Example. One training group, G=8, every rollout carrying a 1 MiB image:
before: worker -> pickle(8 x image, messages, reward_breakdown, logs, turn metrics) -> controller
controller: compute_rollout_metrics + recorder encode on the event loop -> add_group pickles it all again
after: worker: compute_rollout_metrics + encode -> slim_rollout_group
worker -> pickle(1 x image, arrays, group.metrics) + JSONL str -> controller
controller: recorder.append_lines(str) -> add_group pickles only the slim group
I checked that nothing after the controller reads a dropped field. reward_breakdown and turn.metrics are read only in controller/metrics.py:312,328, which now runs in the worker. env_rewards and completion_message are read only by rubrics inside score_group, before slimming. TrainingSampleBuilder and the batcher read only arrays, images, reward and advantage.
Must fix
- PR description: "Human note: TODO (Jiani)" is still the placeholder. The human-written summary needs to be filled in (
CLAUDE.md, PR Expectations 2).
Should consider
torchtitan/rl/rollout/finished_group.py:93--for_trainingleaves two ways to record rollouts. Please add a TODO for the follow-up that drops it (inline comment).tests/rl/unit_tests/cpu/test_finished_group.py:171-- the validation test duplicates coverage intest_async_controller.py; consider deleting it (inline comment).
Questions
- Each worker now builds the
RolloutSampleRecorder.Config.filteritself (recorder.py:971).KeepExtremeRewardsFilteris stateless and was already called with one group at a time, so recorder output is unchanged. A user filter that keeps state across calls, such as a per-step budget, would now see only one worker's groups. Is that worth one sentence on the filter's config docstring?
Not verified: the GPU timing and bitwise-loss results in the description (I couldn't run them).
| then slim it. Validation groups are returned as is: the controller computes their metrics | ||
| and records them. | ||
| """ | ||
| if not for_training: |
There was a problem hiding this comment.
This flag means there are now two ways to record rollouts: training groups are encoded in the worker and written with append_lines, and validation groups are encoded in the controller with record. The worker could finish validation groups too. RolloutSampleEncoder.encode already takes is_validation, and the controller only needs a prefix (plus the validation_ rename of turn metrics) to reduce the per-group Metrics. That would remove for_training from four signatures, RolloutSampleRecorder.record, and the full-group branch here. The PR description already calls this a follow-up, so please add a TODO here so the flag doesn't become permanent.
There was a problem hiding this comment.
from claude: Obsolete: the for_training flag is gone; workers record training and validation groups the same way (6e2d4ba).
| assert len(pickle.dumps(finished)) < 2 * _IMAGE_BYTES | ||
|
|
||
|
|
||
| def test_finish_rollout_group_for_validation_returns_the_full_group() -> None: |
There was a problem hiding this comment.
This test only checks the one-line if not for_training: return branch. test_async_controller.py::test_validation_renames_turn_metrics_and_uses_fresh_group_ids already asserts that validation passes for_training=False and uses the full group. Consider deleting it (rules/tests.md: tests must guard an otherwise-unguarded invariant).
There was a problem hiding this comment.
from claude: Obsolete: test_finished_group.py is deleted in 6e2d4ba.
a27d1a5 to
1aa70dd
Compare
|
@claude review again |
There was a problem hiding this comment.
Verdict: Approve -- please address the item below before merging. All three code items from the last review are fixed at 1aa70dd, and the new commit adds no new problems. The human-written summary is still a placeholder. A maintainer still needs to review.
Earlier items
- Fixed:
finished_group.py:864now has a TODO to finish validation groups in the worker and then dropfor_trainingandRolloutSampleRecorder.record. - Fixed: the duplicate validation test in
test_finished_group.pyis deleted.test_async_controller.py::test_validation_renames_turn_metrics_and_uses_fresh_group_idsstill covers that path: it assertsfor_training=Falseand uses the full group. - Fixed:
recorder.py:901now says onRolloutSampleRecorder.Config.filterthat each worker builds its own filter, so a filter that keeps state across calls sees only its own worker's groups. - Still open: "Human note: TODO (Jiani)" in the description (see below).
New since the last review. I checked every caller of Rollouter.setup_async, run_group_rollouts and RolloutSampleRecorder.record again. The only Rollouter subclass in the repo is VerifiersRollouter, and it forwards rollout_recorder_config. VerifiersRolloutWorker.setup_async (examples/verifiers/rollouter.py:216) is the worker-level hook, which never receives the recorder config. Validation still records in the controller (controller.py:949). payload/rollout_group_array_bytes counts images by id(image.data). That deduplicates correctly on the controller because pickle keeps shared references when it unpickles. Validation groups aren't slimmed, so their image count is unchanged.
Must fix
- PR description: "Human note: TODO (Jiani)" is still the template placeholder. The author needs to write the human summary (
CLAUDE.md, PR Expectations 2).
Not verified: the GPU timing and bitwise-loss results in the description.
1aa70dd to
9491bde
Compare
9491bde to
d49c187
Compare
d49c187 to
6f31766
Compare
e286df2 to
35d85be
Compare
|
@claude review again |
There was a problem hiding this comment.
Verdict: Approve -- the last open item is resolved: the human-written summary is now filled in. The rebased, squashed head 35d85be keeps the same design I reviewed at e286df2, and I found no new problems. A maintainer still needs to review.
What this PR does. RolloutWorkerActor.run_group passes every scored group, training or validation, through finish_rollout_group. That function extends group.metrics with compute_rollout_metrics, using the prefix rollout or validation, and sets the new RolloutGroup.recorder_lines with RolloutSampleEncoder. The controller then only calls recorder.append_lines. For training it clears the lines before the group goes to the batcher. For validation it concatenates the per-group metrics and applies the same validation_ rename to turn metrics.
Example.
before: worker -> group -> controller: group.metrics += compute_rollout_metrics(...); recorder.record([group])
after: worker: finish_rollout_group(group, is_validation=False, encoder) # metrics + lines
controller: recorder.append_lines(group.recorder_lines); group.recorder_lines = ""
Earlier items
- Fixed: the human-written summary in the description.
- Still fixed: the
RolloutSampleEncoderdocstring (recorder.py:153), the note onConfig.filterabout per-worker filters, the trimmedtest_finished_group.pyfixture, and the deletion of_settle.
Should consider
torchtitan/rl/rollout/finished_group.py:11--compute_rollout_metricsnow has only one production caller, in the rollout package. Consider moving it out ofcontroller/metrics.py(see the inline comment).
Details
Re-checked at 35d85be:
- Callers of
Rollouter.setup_async/run_group_rollouts: the controller (controller.py:860,:936,:1305),VerifiersRollouter.setup_async, which forwardsrollout_recorder_config, and the tests. Worker-levelsetup_asyncandrun_group(BaseRolloutWorker,MessageEnvRolloutWorker,VerifiersRolloutWorker) don't take the new arguments:RolloutWorkerActorconsumes them. Sotest_rollout_worker.pyandtest_alphabet_sort.pyneed no change. RolloutSampleRecorder.recordhas no remaining callers intorchtitan/ortorchtitan_recipes/.- Validation groups have negative ids, so
flush_process_metricsadds no worker metrics to them. Thevalidation_rename in_collect_validation_rolloutstherefore only touches turn metrics, as before.
Overlap search: finish_rollout_group and "rollout recorder" find only this stack (#6302, #6303, #6334) and unrelated RL PRs.
Not verified: the GPU timing, bitwise-loss and rollout_samples.jsonl results in the description.
|
|
||
| from __future__ import annotations | ||
|
|
||
| from torchtitan.rl.controller.metrics import compute_rollout_metrics |
There was a problem hiding this comment.
After this PR the controller no longer calls compute_rollout_metrics. The validation path (controller.py:965) now just concatenates group.metrics. That leaves this file as its only production caller, so the rollout worker imports torchtitan.rl.controller.metrics to get code only the worker runs. rules/design.md says to group code by owner. Consider moving compute_rollout_metrics (lines 239-end of controller/metrics.py, with its private helpers) into torchtitan/rl/rollout/, next to finish_rollout_group, and updating the two test imports (test_metrics.py, test_finished_group.py). It is a mechanical move with no logic change. A follow-up PR in this stack is also fine.
There was a problem hiding this comment.
from claude: Moved to torchtitan/rl/rollout/metrics.py in 6e2d4ba.
| rollout_recorder_config: RolloutSampleRecorder.Config, | ||
| vision_processor_config: VisionProcessor.Config | None = None, | ||
| ) -> None: | ||
| self._encoder = RolloutSampleEncoder(rollout_recorder_config) |
There was a problem hiding this comment.
monarch/ folder should only host thin actor wrapper -- the actual logic should go to rollouter.py
There was a problem hiding this comment.
from claude: Done in 6e2d4ba: the actor's run_group only calls BaseRolloutWorker.run_and_record_group (rollouter.py), which runs the group, adds its rollout metrics and records it.
|
|
||
| recorder_lines: str = "" | ||
| """The group's `RolloutSampleRecorder` JSONL lines, encoded by the rollout worker that scored | ||
| it (`finish_rollout_group`); the controller appends them.""" |
There was a problem hiding this comment.
This makes controller don't need to access the actual data of each rollout, build the foundation of bypassing controller read the actual data/rollout content
What's the eventual design?
- before this PR, the controller receives rollout, and do the transformation and recording
- after this PR, the controller receives the recording as
recorder_lines, which doesn't bypass controller at all
I wonder if we should consider putting recorder as part of rollouter / rollout worker and move the recording entirely off controller?
There was a problem hiding this comment.
from claude: Moved recording entirely off the controller in 6e2d4ba: each rollout worker owns a RolloutSampleRecorder and writes rollout_samples.rank_<N>.jsonl; recorder_lines and RolloutSampleEncoder are gone. Eventual design: the controller only gets each group's metadata + a ref (#6303), and the bytes stay in the worker until a trainer leader reads them. Checked on a 10-step bitwise run: same 184 recorded lines as the base (as a set), loss and validation metrics identical.
…aseRolloutWorker Review fixes: - The Monarch actor is a thin wrapper again: BaseRolloutWorker.run_and_record_group runs the group, adds its rollout metrics and records it (was finish_rollout_group, called from the actor). - Each rollout worker owns a RolloutSampleRecorder and writes the training and validation groups it runs to rollout_samples.rank_<N>.jsonl under dump_folder. The controller no longer records anything, so rollout content never passes through it for recording: RolloutSampleEncoder, RolloutGroup.recorder_lines and append_lines are gone, and the recorder is back to main's record() API. Rollouter.close closes the workers' recorders before stopping them. - compute_rollout_metrics moves to torchtitan/rl/rollout/metrics.py, next to its only caller.
There was a problem hiding this comment.
Verdict: Approve -- please address the item below before merging. 6e2d4ba takes recording off the controller completely and leaves the Monarch actor as a thin wrapper, which answers both of @tianyu-l's comments. One mechanical config-ownership item is left. A maintainer still needs to review, and @tianyu-l's CHANGES_REQUESTED still stands until they re-review.
What changed since the last review. finish_rollout_group, RolloutSampleEncoder, RolloutGroup.recorder_lines and append_lines are gone. BaseRolloutWorker.run_and_record_group (rollouter.py:550) runs run_group, extends group.metrics with compute_rollout_metrics (now in rollout/metrics.py), and calls self._recorder.record(...). Each worker builds its own recorder in setup_async via start_recorder, writing to rollout_samples.rank_<N>.jsonl. Rollouter.close calls worker_actors.close after the in-flight calls finish and before it stops the pool. The actor only forwards, and adds worker_rank=current_rank().rank plus a close endpoint.
Example.
before (35d85be): worker: metrics + encode -> group.recorder_lines -> controller: append_lines(...)
after (6e2d4ba): worker k: metrics + recorder.record(...) -> rollout_samples.rank_k.jsonl
controller: receives the group with metrics, writes nothing
Earlier items
- Fixed:
compute_rollout_metricsmoved totorchtitan/rl/rollout/metrics.py(unchanged move). - Addressed (@tianyu-l): the actor is a thin wrapper (
rollout_worker.py:86), and the controller no longer receives or writes recorder content.
Must fix
torchtitan/rl/controller/controller.py:363--rollout_recorderstays onController.Configeven though only the rollout worker reads it, so it is passed through four forwarding signatures. Move it toBaseRolloutWorker.Config(see the inline comment).
Details
- Every
BaseRolloutWorker.setup_asyncoverride starts the recorder. The base andVerifiersRolloutWorkerboth callstart_recorder, andMessageEnvRolloutWorkerdoesn't overridesetup_async. Nothing else intorchtitan/ortorchtitan_recipes/callsRolloutSampleRecorder.Config.build. - Failure path: if
recordraises in the worker,run_and_record_groupraises, and_rollout_loopturns that into the one-failure-metric group. This matches the old behavior when the controller'srecordraised. - Shutdown edge: if a
run_groupcall is still running after_RUN_GROUP_DRAIN_TIMEOUT_S,closecancels only the controller-side call. The worker can then callrecordafter its recorder is closed, and the executor raises "cannot schedule new futures after shutdown". The worker is stopped right after, so that group is lost either way. This costs one log line, not data. - Validation metrics:
test_validation_metrics_merged_over_groups_equal_the_whole_batchguards the per-group merge equivalence. That is a real invariant: thevalidation/*values must not change. - Overlap search ("rollout_recorder", "RolloutSampleRecorder"): #6302 (this stack), plus #5303 and #6378, which change recorder encoding. Those two will need a small rebase over the
worker_rankconstructor change.
Not verified: the GPU timing results and the 10-step bitwise / 184-recorded-lines comparison in the description.
| rollout_recorder: RolloutSampleRecorder.Config = field( | ||
| default_factory=RolloutSampleRecorder.Config | ||
| ) | ||
| """JSONL recorder to save sampled rollouts to disk for further inspection and debugging.""" | ||
| """JSONL recorder to save sampled rollouts to disk for further inspection and debugging. Each | ||
| rollout worker records the groups it runs to its own file under `dump_folder`, e.g. | ||
| `rollout_samples.rank_3.jsonl`.""" |
There was a problem hiding this comment.
Only the rollout worker reads this config now, but it still lives on Controller.Config. So it gets passed down through four signatures that only forward it: Controller.setup_async -> Rollouter.setup_async (and VerifiersRollouter.setup_async) -> RolloutWorkerActor.setup_async -> BaseRolloutWorker.setup_async / VerifiersRolloutWorker.setup_async. rules/config.md says a component owns its config, and a function takes only the config it reads.
The worker config already reaches every worker at spawn, so you can move the field there:
# BaseRolloutWorker.Config
recorder: RolloutSampleRecorder.Config = field(default_factory=RolloutSampleRecorder.Config)
"""JSONL recorder for the groups this worker runs; each worker writes its own file under
`dump_dir`, e.g. `rollout_samples.rank_3.jsonl`."""Then keep config.recorder in __init__ and have start_recorder(dump_dir=..., worker_rank=...) build from it. That removes rollout_recorder_config from all five signatures and deletes this field. Only dump_dir (from the controller) and worker_rank (from the actor) still need to be passed in. In-repo users to update: the three rollout_recorder= sites in torchtitan_recipes/rl/verifiers_terminal_bench.py (they become rollouter.worker.recorder), test_shutdown.py:136, and the tests that pass rollout_recorder_config=.
There was a problem hiding this comment.
from claude: Moved it to BaseRolloutWorker.Config.recorder. Controller.Config.rollout_recorder and the forwarding args are gone; the terminal-bench recipe sets recorder= on its worker config.
…tWorker.Config Only the rollout worker reads it now, so it no longer passes through Controller/Rollouter/actor setup_async. Each worker builds its recorder from its own Config.recorder; setup_async still gets dump_dir and worker_rank.
|
from claude: Changes since the last review (485eec8):
@claude review |
There was a problem hiding this comment.
Verdict: Approve -- 485eec8 moves the recorder config onto the rollout worker's own config, which fixes the last open item, and I found no new problems. A maintainer still needs to review. @tianyu-l's CHANGES_REQUESTED stays in place until they re-review.
What changed since the last review. Controller.Config.rollout_recorder is gone and BaseRolloutWorker.Config.recorder replaces it. BaseRolloutWorker.__init__ saves it as self._recorder_config. start_recorder(*, dump_dir, worker_rank) now builds the recorder from that saved config. rollout_recorder_config is removed from five setup_async signatures: Controller -> Rollouter / VerifiersRollouter -> RolloutWorkerActor -> BaseRolloutWorker / VerifiersRolloutWorker. The terminal-bench recipe now sets the filter once, in _terminal_bench_rollouter_config, instead of in three Controller.Config sites.
Example.
before: Controller.Config(rollout_recorder=RolloutSampleRecorder.Config(filter=...), rollouter=...)
-> setup_async(rollout_recorder_config=...) x4 -> worker.start_recorder(config, dump_dir, rank)
after: VerifiersRolloutWorker.Config(..., recorder=RolloutSampleRecorder.Config(filter=...))
-> worker.start_recorder(dump_dir=..., worker_rank=...) # builds from self._recorder_config
Earlier items
- Fixed:
rollout_recordermoved fromController.ConfigtoBaseRolloutWorker.Config.recorder, and the forwarding arguments are removed.
Details
- No
rollout_recorderorrollout_recorder_configreferences are left intorchtitan/,torchtitan_recipes/,tests/or the docs. I also found no--overridestrings that target the old path. VerifiersRolloutWorker.__init__callssuper().__init__(config), so_recorder_configis set before itssetup_asynccallsstart_recorder.VerifiersRolloutWorker.ConfigsubclassesBaseRolloutWorker.Config, so it inheritsrecorder.- All three terminal-bench recipes build their rollouter through
_terminal_bench_rollouter_config. So all three keep theKeepExtremeRewardsFilter(keep_errors=True)filter, as before. - The tests set
_recorder_configby hand only where they skip__init__(object.__new__, or a_LoopBlockingWorkerthat doesn't score). - Overlap search ("rollout_recorder"): only this PR and #6302 (same stack).
Not verified: the GPU gate in the trigger comment (the 184 recorded lines and the 92/92 TensorBoard tags).
Human note:
TLDR: Each rollout worker computes its groups' rollout metrics and records them to its own
rollout_samples.rank_<N>.jsonl; the controller no longer encodes or writes rollouts. This lets #6303 keep the arrays off the controller. At T1 the recorder's encode (127-132 ms per step) leaves the controller's event loop and controller CPU per step drops 2-3%.Merge bottom-up. T1 numbers include #6269 (on main) on both sides.
Problem
compute_rollout_metricsand the recorder's encode and write on its event loop, for training and validation.Solution
BaseRolloutWorker.run_and_record_group(rollout/rollouter.py) runsrun_group, addscompute_rollout_metricstogroup.metricsand records the group. The Monarch actor only calls it.RolloutSampleRecorderinsetup_async(start_recorder) fromBaseRolloutWorker.Config.recorderanddump_folder, writingrollout_samples.rank_<N>.jsonl. The controller config no longer hasrollout_recorder.Rollouter.closecloses the recorders before stopping the workers.run_group_rolloutstakesis_validation(each JSONL line carries it).compute_rollout_metricsmoves fromcontroller/metrics.pytorollout/metrics.py, next to its only caller.validation/*metrics are now per group, merged when logged: equal up to float summation order. Metric names are unchanged.Results
NOTE:
cat rollout_samples.rank_*.jsonl.KeepExtremeRewardsFilter, but a stateful filter sees only its worker's groups.batcher_add_groupand the batch wait stay flat: arrays cross the controller by value until [WIP] [rl] Trainer DP replica leaders read their rollouts from the rollout workers and pack them #6303.Test plan
pytest tests/rl/unit_tests/cpu: 778 passed, 8 skipped, 4 failed. The 4 also fail on main locally: atorch_checkpointing.storage.fsspec_storageimport error.test_verifiers.pywith Verifiers installed: 65 passed.test_run_and_record_group.py: the worker adds the rollout metrics and records the group (training and validation); per-group validation metrics merge to the whole-batch values.