Repository navigation
[Observability 5/7] RolloutLogger for RL rollout JSONL with filtering - #2605
felipemello1 wants to merge 1 commit into
Conversation
[ghstack-poisoned]
| logger.info("Actors spawned.") | ||
|
|
||
| rollout_dir = os.path.join(OUTPUT_DIR, "rollouts") | ||
| rollout_logger = RolloutLogger( |
There was a problem hiding this comment.
Would it be good for each actor to have its logger, as long as they created on their dedicated mesh/process?
There was a problem hiding this comment.
Would it be good for each actor to have its logger
Can you help me understand a bit better what you mean?
'RolloutLogger' is an specific class to log rollouts, where the rollout is a product of generation + rewards. So the flow is:
- Controller calls actors
- Controller puts together the rollout for training
- Controller calls
RolloutLogger(rollouts, filter, metadata)
it produces this guy
{"prompt": "what is 2+2?", "response": "4", "reward": 0.95, "__metadata__": {"step": 42, "batch_size": 64}}
{"prompt": "write a poem", "response": "roses...", "reward": 0.3, "__metadata__": {"step": 42, "batch_size": 64}}
There was a problem hiding this comment.
so is it fair to say it's a helper for RL just like MetricsProcessor for sft?
There was a problem hiding this comment.
I don't if i would call it a 'helper'. It is another axis of logging. Users want to inspect their rollouts frequently. TBR and Tinker also log their rollouts.
| if fn is not None: | ||
| records = fn(records) | ||
| extra = {"__metadata__": metadata} if metadata else {} | ||
| self._file.write("\n".join(json.dumps({**r, **extra}) for r in records) + "\n") |
There was a problem hiding this comment.
who's consuming the logs from RolloutLogger?
| @@ -16,6 +16,7 @@ | |||
| record_metric, | |||
There was a problem hiding this comment.
high level this seems potentially useful but a) not part of this PR stack and b) should not be in "titan/observability" but rather in the RL experiments.
There was a problem hiding this comment.
i am ok with that. It is self contained. We can promote to /torchtitan later if it seems fit.

Stack from ghstack (oldest at bottom):
How to review
Prioritize the files under /observability. Check how they are used in the toy example. No need to nitpick the toy example.
Summary
RolloutLoggerwrites RL rollouts to JSONL with optional filtering. Takes alist[dict]with no enforced schema — users pass whatever fields their rollouts have (prompt, response, reward, etc). Metadata is nested under__metadata__to avoid key collisions.Optional
filter_fnfor selecting which rollouts to log, e.g.filter_top_bottom(records, key, k)keeps the top-k and bottom-k by a given key — useful for logging only the best and worst rollouts per batch.Integrated into toy_rl: the controller logs filtered rollouts after each RL step.
Example
Output JSONL (metadata stored under
__metadata__to avoid key collisions):{"prompt": "what is 2+2?", "response": "4", "reward": 0.95, "__metadata__": {"step": 42, "batch_size": 64}} {"prompt": "write a poem", "response": "roses...", "reward": 0.3, "__metadata__": {"step": 42, "batch_size": 64}}Test plan
Run toy_rl:
python -m torchtitan.experiments.observability.toy_rlOutput folder (toy_rl on PR6 — note rollouts/ directory)