Skip to content

[rl] Rollout workers, the router and the controller report their CPU and memory each step - #5926

Draft
felipemello1 wants to merge 1 commit into
felipemello1/tb-oss/1-taskset-workdirfrom
felipemello1/rollout-placement/3-process-metrics
Draft

felipemello1 wants to merge 1 commit into
felipemello1/tb-oss/1-taskset-workdirfrom
felipemello1/rollout-placement/3-process-metrics

Conversation

@felipemello1

@felipemello1 felipemello1 commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary (human-written)

Agent details

TLDR: Each rollout worker (with its agent subprocesses), the router and the controller report CPU seconds and memory once per step. Once workers run on other hosts, this is the only place their cost shows.

Each step, rollout workers (with their agents), the router and the controller report CPU and memory, and the controller logs process/<role>/... metrics.

process/rollout_worker/cpu_seconds/sum              79.2   CPU-s since the last read, all workers
process/rollout_worker/rss_anon_gib/sum             52.8
process/rollout_worker/rss_anon_gib/max             27.1   the largest worker
process/rollout_worker/host_mem_available_gib/min   512.0  the fullest worker host
(the same keys for router and controller; timing/step/blocking_read_process_metrics)

Problem

  1. Rollout workers can run on hosts other than the controller's ("Spread rollout workers over the job's hosts").
  2. Nothing reports a worker's, the router's or the controller's CPU or memory.
  3. A worker's own CPU misses its agents: on main's Verifiers DAPO Math env with 2 generators, subprocesses are 92% of the env's CPU (9.8 of 10.6 cores).

Solution

  1. ProcessStats(role, children=...) (new, observability/metrics/process.py) reads a process from /proc: CPU since the last read, anonymous memory, and the host's MemAvailable. With children=True it adds live descendants and, for CPU, the ones that already exited.
  2. Workers and the router expose it as a process_metrics endpoint. The controller starts the read when a step starts and awaits it at the step's end, so it overlaps the trainer. The wait is timed.
  3. Only workers scan /proc (~0.2 s, in a thread). The router and the controller read os.times() and their own smaps_rollup, also in a thread.
  4. Every exit from a step cancels an unfinished read and waits for it. After an early exit a read's error is logged, not raised.

Why ~250 lines for "report CPU and memory": CPU must be read parents before children (a reaped child's CPU moves into its parent), and every step exit must cancel the read and wait for it. Each part has a test that failed without it.

You may ask:

  • Why not through the group's metrics? The controller overwrites them. Why not a sync_log_step reply? It would make every log-step call wait for a /proc scan.
  • Why a TaskGroup, not gather? Once cancelled, a TaskGroup waits for every part; gather returns as soon as its first part is cancelled. create_task takes only a coroutine, so the router's Monarch call (a Future) is wrapped in one.

NOTE:

  • CPU and memory are summed job-wide; only host memory is per host (the min). TODO in Rollouter.process_metrics: each host's sum.
  • A descendant that leaves the tree (its parent exited first, or it double-forked) is counted while inside it; then its CPU comes out of the next reads. A container's processes are not counted.
  • Step 1's read also covers setup (env and checkpoint loading).

Results

Local 50-step Verifiers DAPO Math run (Qwen3-4B-Base, trainer TP2 + 2 generators on one 4-GPU host, 4 rollout
workers on 2 simulated hosts), steps 3-50: these metrics vs an independent /proc sampler (every 30 s) of the same processes:
  rollout_worker cpu_seconds/sum               320 CPU-s per step   sampler 300.5 (+6.5%)
  router cpu_seconds/sum                       1.16                 sampler 1.1
  Measured before look-aside routing reached main, when the router forwarded each generate call.
  timing/step/blocking_read_process_metrics    P50 0.000 s, max 0.000 s
  rss_anon_gib: the worker tree swings between 53 and 223 processes within a step, so a 30 s sampler
  can't check it; test_process_stats_counts_each_child_cpu_second_once checks a 64 MiB child.
NOTE: the run above was measured on this PR's earlier base; it was not re-run on this one.
CPU suites at this commit (tests/rl/unit_tests/cpu, the renderer and config tests; Verifiers 0.4.1):
  999 passed, 1 skipped

Test plan

pytest tests/rl/unit_tests/cpu/test_metrics.py tests/rl/unit_tests/cpu/test_trainer_loop.py tests/rl/unit_tests/cpu/test_rollouter_pool.py
pytest tests/rl/unit_tests/cpu tests/unit_tests/cpu/components/test_renderer.py tests/unit_tests/cpu/config   # 999 passed, 1 skipped
  • test_process_stats_counts_each_child_cpu_second_once: an exited child's CPU counts once, a live child's CPU and memory count, the no-children read leaves them out.
  • test_process_stats_counts_a_descendant_once_when_it_is_reaped_mid_read[child|grandchild x 1|2]: a parent reaps its child right after the read looks at it. Reading children first, or this process last, counts it twice (over the test's 0.9 s bound).
  • test_process_stats_skips_a_pid_that_now_names_another_process and test_process_stats_reads_a_child_that_hides_its_memory (PR_SET_DUMPABLE=0).
  • test_trainer_loop.py: each step logs the 3 roles' metrics; an early exit (NaN loss, failed push) cancels the read and waits for it; a read that failed before an early exit is logged. Its endpoint fakes return Futures, as Monarch does.

Stack (15 PRs, bottom first; merging a PR also merges every PR below it; this PR in bold)

# PR What
1 Run Verifiers groups in rollout workers Verifiers groups run in rollout workers; the env server stays
2 Rollouts that fail outside the policy are recorded, not trained a failed rollout no longer drops its group
3 Rollouter: least-loaded placement; the controller sizes the pool from rollouts_per_worker least-loaded placement; the pool size follows the rollouts in flight
4 Rollout workers get generate_fn and release_session_fn once, at setup; the rollouter closes each worker before it stops them generator functions at setup; workers close before they stop
5 Verifiers: each example is an installed package; its name is the taskset id taskset ids are package names
6 Verifiers: each rollout worker runs its Verifiers envs; the env server is gone the env runs in the worker (Verifiers 0.4.0)
7 Verifiers: the generation server keeps one session per trace sessions; 1 GiB requests; the renderer refuses overlong prompts
8 Verifiers 0.4.1 and renderers 0.2.0 both pins move
9 Verifiers: only a rollout that Verifiers finished cleanly trains the failure rule
10 Verifiers README: terms, concurrency and sandboxes README only: terms, concurrency, sandboxes
11 Verifiers: time each rollout's sandbox start, setup, agent, model, finalize and scoring per-phase time metrics
12 Terminal-Bench: terminal_bench_env_config takes the package that exports the taskset a package argument for launchers outside the repo
13 Spread rollout workers over the job's hosts opt-in: rollout workers on the other hosts
14 Terminal-Bench: run each task in its image's WORKDIR and grade with task.toml timeouts Terminal-Bench task fixes
15 Rollout workers, the router and the controller report their CPU and memory each step per-role CPU and memory metrics

Alone on main, not in this stack: "Validation reads each prompt at most once; ValidationConfig.steps defaults to -1" and "Terminal-Bench 35B-A3B recipe: Dist-MoE in both roles, FULL CUDA graph generators, DAPO loss".

@pytorch-bot pytorch-bot Bot added the ciflow/rl label Nov 7, 2026
@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: @claude review

@claude

claude Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 3m 20s —— View job


Approve -- please address the items before merging (summary, perf/ key prefix, the docstring on orphaned descendants): review. A maintainer still needs to review.

@claude claude Bot 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.

Verdict: Approve -- please address the items below before merging. The design is sound: the read overlaps the step, and every exit cancels the read and waits for it. What's left is key naming, a docstring that misstates one case, and the empty human-written summary. A maintainer still needs to review, since this touches the RL controller loop.

What this PR does. Each rollout worker (with its descendant processes), the router and the controller get a ProcessStats that reads, from /proc, CPU seconds since the last read, anonymous memory and the host's MemAvailable. The controller starts one read per step right after sync_log_step, runs it alongside the step, awaits it at the end (timed as blocking_read_process_metrics), and logs the results with the step's metrics. An AsyncExitStack callback cancels an unfinished read on early exits (batcher closed, NaN loss, failed push) and waits for it to end.

Example.

2 workers on 2 hosts, step 7 (the read covers start of step 6 -> start of step 7):
  worker A: 40 s own + agents     worker B: 39.2 s
  perf/rollout_worker/cpu_seconds/sum   79.2
  perf/rollout_worker/rss_anon_gib/max  27.1   (largest worker tree)
  host_memory/rollout_worker_host_mem_available_gib/min  512.0
Before: none of this was logged; a worker on another host had no CPU or memory signal.

Must fix

  1. PR description -- "Summary (human-written)" is empty. The author has to fill it in; an agent can't.
  2. torchtitan/rl/observability/metrics/process.py:48 -- the perf/ prefix adds 9 keys to the default console panel (processor.py:61, documented as 12 keys), and router/controller sum/max are duplicates. Use a process/{role}/... prefix (inline).
  3. torchtitan/rl/observability/metrics/process.py:89 -- a descendant that leaves the tree isn't "never counted" (line 25). It is counted while live, and then the max ratchet takes its time back out of later deltas. Fix the docstring (inline).

Should consider

  • torchtitan/rl/controller/controller.py:1131 -- step 1's read also covers all of setup, because the baseline is set in __init__. Say so in the comment (inline).

Questions

  • Monarch or the cluster's own host monitoring could already report per-process CPU and RSS for remote hosts. If so, did you consider it, and why does torchtitan need its own /proc accounting? The 150-line process.py is justified only if there is no such source.
Details
  • Gate: the problem is real once 2/3 puts workers on other hosts. Before this PR, nothing logs their CPU or memory. The code stays inside torchtitan/rl/ and adds no dependency (psutil would be a non-PyTorch dependency).
  • Cancellation: a TaskGroup inside the read plus push_async_callback(_finish_process_metrics_read) means no part of a read outlives the step on break or raise. On the normal path the task is already done, so cancel() does nothing. A read that fails on the normal path raises from await process_metrics_task (as an ExceptionGroup) and also logs the warning once; that's harmless.
  • Read order (descendant tree found first, then os.times(), then descendants top-down, plus the max) is correct for in-tree reaping. The only gap is reparenting (must-fix 3).
  • rollout_worker.process_metrics runs the scan on the default executor, which rollouts share. When rollouts saturate it, the wait shows up in blocking_read_process_metrics, and there is already a TODO for one scan per host.

Not verified: how stable the CPU-time thresholds in test_metrics.py (< 0.9, < 0.4) are on loaded CI runners.

cpu_since_last_read = cpu_seconds - self._cpu_seconds
self._cpu_seconds = cpu_seconds
anon_gib = sum(map(_anonymous_kib, (os.getpid(), *live_descendants))) / 2**20
prefix = f"perf/{self._role}"

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.

perf/ is in the default console_log_keys_train (processor.py:61), which describes it as "the 12 metrics that diagnose any bottleneck at a glance... 7 trainer/buffer keys (everything under perf/)". This prefix adds 9 keys to every console train line: 3 for each of rollout_worker, router and controller. That comment is now wrong too.

For the two single-process roles, rss_anon_gib/sum and rss_anon_gib/max are always equal, so 2 of those 9 keys are duplicates.

Smallest fix: use a prefix the console doesn't print, e.g. process/{role}/cpu_seconds, process/{role}/rss_anon_gib, and process/{role}/host_mem_available_gib in place of host_memory/{role}_host_mem_available_gib. That keeps one namespace per role and drops the repeated "host". If you do want these on the console, update the panel comment and its key count in the same PR.

seconds += (
sum(int(field) for field in stat[_CPU_TIMES]) / _TICKS_PER_SECOND
)
return max(self._cpu_seconds, seconds), live_descendants

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.

The class docstring (line 25) says a descendant that left the tree is "never counted". That isn't what happens. It is counted while it is live, and when it leaves, its counted time is taken back out of later reads through this max.

Example: read 1 counts grandchild G at 50 s. The agent between the worker and G is SIGKILLed on a timeout and reaped, so G is reparented to init. Read 2's seconds is now 50 s lower, and max keeps read 1's total. As a result cpu_seconds reads 0 until the rest of the tree has done 50 s of new work. That work is the worker's and other agents' CPU, not G's, so it silently goes missing for one or more steps.

Smallest fix: make the docstring say what happens ("counted while live; when it leaves, its counted time is subtracted from the following reads"), so a dip after agent timeouts can be read correctly. A real fix needs per-process deltas or a cgroup's cpu.stat. That's fine as a TODO.

Comment on lines +1131 to +1133
# Read the workers', the router's and the controller's CPU and memory while the trainer
# steps. A read covers the time since the previous one (about the previous step).
process_metrics_task = asyncio.create_task(self._read_process_metrics())

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.

Each ProcessStats sets its baseline in __init__. That means step 1's read covers all of setup: tokenizer and env load in the workers, checkpoint and dataset load in the controller, and so on. On resume it is the first step after start_step.

So step 1 always shows a cpu_seconds spike that isn't a step's work, and reading the metric "about the previous step" doesn't hold for it. Smallest fix: say so in this comment ("step 1's read also covers setup"). Alternatively, take one discarded read right before the loop. That costs an extra worker /proc scan, so the comment alone is probably enough.

@felipemello1
felipemello1 added this pull request to stack #5878 November 7, 2026 06:02
@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: round 1 is in 86c118daa (after bcf0e3f63, which merges the fixes of 1/3 and 2/3).

  • Keys moved to process/<role>/{cpu_seconds,rss_anon_gib,host_mem_available_gib}, out of the console's perf/ panel, so the panel's comment ("7 trainer/buffer keys, everything under perf/") holds again. Every role still logs both sum and max: for the router and the controller they are equal, but one shape per role keeps ProcessStats free of a per-role branch.
  • ProcessStats' docstring now says a descendant that leaves the tree is counted while inside it, and then its CPU comes out of the next reads, with an example. TODO at the max: per-process deltas or the cgroup's cpu.stat.
  • The step's comment says step 1's read covers setup too.
  • Why our own /proc read: torchmonarch 0.7.0's Python package has no per-process CPU or memory source (no psutil, getrusage, /proc/<pid>/stat or RSS reads; its telemetry is tracing). Cluster tools report per job step, not per role or per worker tree, and not into the step's metrics.
  • The human-written summary is the author's to write.

RL CPU suite at 86c118daa: 576 passed, 8 skipped; with Verifiers 0.4.1 installed: 653 passed, 2 skipped. pyrefly: 0 errors.

@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: @claude review

@claude

claude Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 1m 26s —— View job


Approve -- please address the item before merging (the human-written summary is still empty; round 1's code items are fixed): review. A maintainer still needs to review.

@claude claude Bot 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.

Verdict: Approve -- please address the item below before merging. Round 1's code items are fixed at 86c118daa, and the new commit adds no problems. Only the empty human-written summary is left. A maintainer still needs to review, since this touches the RL controller loop.

What this PR does. Each rollout worker (with its descendant processes), the router and the controller have a ProcessStats. Once per step it reads from /proc the CPU seconds since the last read, the anonymous memory, and the host's MemAvailable. The controller starts the read right after sync_log_step and awaits it at the step's end (timed as blocking_read_process_metrics). On an early exit, an AsyncExitStack callback cancels the read and waits for it to end.

Example.

2 workers on 2 hosts, step 7 (the read covers start of step 6 -> start of step 7):
  worker A: 40 s own + agents     worker B: 39.2 s
  process/rollout_worker/cpu_seconds/sum              79.2
  process/rollout_worker/rss_anon_gib/max             27.1   (largest worker tree)
  process/rollout_worker/host_mem_available_gib/min   512.0
Before: nothing reported a worker's CPU or memory, and a worker on another host had no such signal at all.

Round 1, at HEAD

  • perf/ prefix -> process/<role>/...: resolved. The console's perf/ panel and its "7 trainer/buffer keys" comment (processor.py:59-61) are accurate again.
  • ProcessStats docstring on descendants that leave the tree: resolved (process.py:741-743, plus the TODO at process.py:806).
  • Step 1's read also covers setup: resolved (controller.py:1128-1130).
  • Question about Monarch or cluster monitoring: answered. torchmonarch 0.7.0 has no per-process CPU or RSS source, and cluster tools don't report per role or per worker tree.

Must fix

  1. PR description: "Summary (human-written)" is still empty. Only the author can fill it in.
Details
  • Re-checked at HEAD: controller.py:1134-1254. Every exit from the step (break on a closed batcher, break on a NaN loss, a raised push error) goes through _finish_process_metrics_read. On the normal path the task has already finished, so its cancel() does nothing.
  • If a read fails on the normal path, await process_metrics_task raises and ends the loop. The docstring says this happens only when a worker or the router died. Another cause is possible: a /proc mounted with hidepid=1 makes _read_stat raise PermissionError for other users' pids. That is uncommon, so this is not a finding.
  • The only change to an existing test, in test_optimizer_step_waits_for_the_previous_push, keeps it meaningful with the extra task per step: the push now waits until forward/backward 2 has started.

Not verified: how stable the CPU-time bounds in test_metrics.py (< 0.9, < 0.4) are on loaded CI runners.

@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: round 2 is bb7e6be50. It only merges the round-2 fixes of 1/3 (close() stops the workers whatever the drain raises) and 2/3 (spreading is opt-in). Nothing in this PR's own code changed.

  • The human-written summary is Felipe's to write.

RL CPU suite at bb7e6be50: 577 passed, 8 skipped; with Verifiers 0.4.1: 654 passed, 2 skipped. pyrefly: 0 errors.

@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: @claude review

@claude

claude Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 47s —— View job


Approve -- please address the item before merging (the human-written summary is still empty; the new commit only merges the round-2 fixes of 1/3 and 2/3, and this PR's own code is unchanged): review. A maintainer still needs to review.

@claude claude Bot 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.

Verdict: Approve -- please address the item below before merging. The one new commit since the last review (bb7e6be50) only merges the round-2 fixes of 1/3 and 2/3. This PR's own files are unchanged, so nothing new needs review. Only the empty human-written summary is left. A maintainer still needs to review, since this touches the RL controller loop.

What this PR does. Each rollout worker (with its descendant processes), the router and the controller have a ProcessStats. Once per step it reads from /proc the CPU seconds since the last read, the anonymous memory, and the host's MemAvailable. The controller starts the read right after sync_log_step, awaits it at the step's end (timed as blocking_read_process_metrics), and cancels it and waits for it on every early exit.

Example.

2 workers, step 7 (the read covers start of step 6 -> start of step 7):
  worker A: 40 s own + agents     worker B: 39.2 s
  process/rollout_worker/cpu_seconds/sum              79.2
  process/rollout_worker/rss_anon_gib/max             27.1   (largest worker tree)
  process/rollout_worker/host_mem_available_gib/min   512.0
Before: no metric reported a worker's, the router's or the controller's CPU or memory.

Must fix

  1. PR description: "Summary (human-written)" is still empty. Only the author can fill it in.
Details
  • git diff 86c118daa bb7e6be50 touches only rollouter.py (the workers_on_controller_host default flips to True with a TODO, and close() now catches any drain exception), test_rollouter_pool.py, and three READMEs. None of these touch process_metrics, ProcessStats, or the controller's read and cancel path. Both rollouter changes were reviewed in 1/3 and 2/3.
  • Since spreading is now opt-in, workers run on the controller's host by default. The PR is still justified: the agents' CPU (92% of the env's CPU on DAPO Math) and the per-role RSS weren't reported anywhere before. The TLDR's "Once workers run on other hosts" now describes the opt-in case. That's accurate, so it isn't a finding.
  • Round 1's items (process/<role>/ keys, the docstring on descendants that leave the tree, step 1 covering setup) are still resolved at HEAD.

Not verified: how stable the CPU-time bounds in test_metrics.py (< 0.9, < 0.4) are on loaded CI runners.

@felipemello1
felipemello1 removed this pull request from stack #5878 November 8, 2026 19:07
@felipemello1
felipemello1 changed the base branch from felipemello1/rollout-placement/2-spread-workers to main November 8, 2026 19:08
@felipemello1
felipemello1 force-pushed the felipemello1/rollout-placement/3-process-metrics branch from bb7e6be to a52089b Compare November 8, 2026 19:09
@felipemello1
felipemello1 changed the base branch from main to felipemello1/rollout-placement/2-spread-workers November 8, 2026 19:09
@felipemello1
felipemello1 added this pull request to stack #5950 November 8, 2026 19:09
@felipemello1
felipemello1 force-pushed the felipemello1/rollout-placement/2-spread-workers branch from 4b1323c to 166f944 Compare November 9, 2026 07:22
@felipemello1
felipemello1 force-pushed the felipemello1/rollout-placement/3-process-metrics branch from a52089b to 58fa440 Compare November 9, 2026 07:22
@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: @claude please review. This push is a code-style pass over every file (docstrings, comments, names, tests), rebased on main 98bbfe1. No behavior change.

@claude

claude Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 1m 20s —— View job


Approve -- please address the item before merging (the human-written summary is still empty; the style pass at 58fa440 changes no behavior): review. A maintainer still needs to review.

@claude claude Bot 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.

Verdict: Approve -- please address the item below before merging. The code-style pass at 58fa440 keeps the reviewed behavior: I read every changed line and found no change in logic, keys or cancellation. The human-written summary is still empty. A maintainer still needs to review, since this touches the RL controller loop.

What this PR does. Each rollout worker (with its descendant processes), the router and the controller have a ProcessStats. Once per step it reads from /proc the CPU seconds since the last read, the anonymous memory, and the host's MemAvailable. The controller starts the read right after sync_log_step and awaits it at the step's end (timed as blocking_read_process_metrics). On every early exit it cancels the read and waits for it to end.

Example.

2 workers, step 7 (the read covers start of step 6 -> start of step 7):
  worker A: 40 s own + agents     worker B: 39.2 s
  process/rollout_worker/cpu_seconds/sum              79.2
  process/rollout_worker/rss_anon_gib/max             27.1   (largest worker tree)
  process/rollout_worker/host_mem_available_gib/min   512.0
Before: no metric reported a worker's, the router's or the controller's CPU or memory.

Must fix

  1. PR description: "Summary (human-written)" is still empty. Only the author can fill it in.
Details
  • The earlier reviewed commits (86c118daa, bb7e6be50) aren't in this checkout after the rebase, so I re-read the whole diff against 166f944 (2/3) instead of comparing the two.
  • Same behavior as before: _cpu_seconds -> _total_cpu_seconds is a rename. Keys are still process/<role>/{cpu_seconds,rss_anon_gib,host_mem_available_gib}. The read order is unchanged: tree, then os.times(), then descendants top-down, plus the max. So is the TaskGroup read. _finish_process_metrics_read is still registered through the AsyncExitStack, and the timed await process_metrics_task still runs at the step's end (controller.py:1136-1259).
  • Round 1's items are still resolved at HEAD. The docstring on descendants that leave the tree is at process.py:25-27, with its TODO at process.py:91. The step-1-covers-setup comment is at controller.py:1133-1135.
  • No non-ASCII characters in the added lines.
  • Nit, not a finding: test_process_stats_reads_a_child_that_hides_its_memory's docstring says the child's memory "counts as 0". The assertion is > 0 on the total, which checks only that the read doesn't raise PermissionError. That is the invariant worth guarding, so only the docstring overstates it.

Not verified: how stable the CPU-time bounds in test_metrics.py (< 0.9, < 0.4) are on loaded CI runners.

@felipemello1
felipemello1 force-pushed the felipemello1/rollout-placement/2-spread-workers branch from 166f944 to 1a68345 Compare November 9, 2026 09:11
@felipemello1
felipemello1 force-pushed the felipemello1/rollout-placement/3-process-metrics branch from 58fa440 to e070bcd Compare November 9, 2026 09:11
@felipemello1
felipemello1 force-pushed the felipemello1/rollout-placement/2-spread-workers branch from 1a68345 to b0eeefa Compare November 9, 2026 12:18
@felipemello1
felipemello1 force-pushed the felipemello1/rollout-placement/3-process-metrics branch from e070bcd to 22c93e2 Compare November 9, 2026 12:18
@felipemello1
felipemello1 removed this pull request from stack #5950 November 9, 2026 17:31

@claude claude Bot 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.

Verdict: Approve -- please address the item below before merging. At 47399f1 this PR sits directly on 2/3, because the cancel PR was dropped from under it. Its own diff is unchanged, and its read-and-cancel path works without the dropped PR. The human-written summary is still empty. A maintainer still needs to review, since this touches the RL controller loop.

What this PR does. Each rollout worker (with its descendant processes), the router and the controller have a ProcessStats. Once per step it reads from /proc the CPU seconds since the last read, the anonymous memory, and the host's MemAvailable. The controller starts the read right after sync_log_step and awaits it at the step's end (timed as blocking_read_process_metrics). On every early exit it cancels the read and waits for it to end. A read that failed before an early exit is logged, not raised.

Example.

2 workers, step 7 (the read covers start of step 6 -> start of step 7):
  worker A: 40 s own + agents     worker B: 39.2 s
  process/rollout_worker/cpu_seconds/sum              79.2
  process/rollout_worker/rss_anon_gib/max             27.1   (largest worker tree)
  process/rollout_worker/host_mem_available_gib/min   512.0
Before: no metric reported a worker's, the router's or the controller's CPU or memory.

Must fix

  1. PR description: "Summary (human-written)" is still empty. Only the author can fill it in.
Details
  • I re-read the full diff at HEAD. process.py, rollouter.py, rollout_worker.py, router.py, the controller's _read_process_metrics / _finish_process_metrics_read / _awaited, and the three test files match what I reviewed at 7b69d2d. The keys are still process/<role>/....
  • I checked the step against the new base (controller.py:1281-1415). The read is created after sync_log_step, and the cancel callback is registered on the step's AsyncExitStack before the first await that can exit early. Both breaks (batcher closed at 1312, NaN loss at 1365) and every await that can raise (fwd/bwd, push, optimizer step, pull) are inside that scope. The timed await process_metrics_task is still the last statement in it. None of this depended on the dropped PR.
  • Out of scope here: without the dropped PR, base's TODO at controller.py:1458-1461 (the in-flight push/pull tasks aren't cancelled when the loop raises) is back. It belongs to the base, not to this PR. This PR's own read doesn't outlive the step either way.

Not verified: how stable the CPU-time bounds in test_metrics.py are on loaded CI runners.

@felipemello1
felipemello1 force-pushed the felipemello1/rollout-placement/2-spread-workers branch from 4d27c22 to d2c5419 Compare November 11, 2026 22:50
@felipemello1
felipemello1 force-pushed the felipemello1/rollout-placement/3-process-metrics branch from 47399f1 to d53a846 Compare November 11, 2026 22:51
@felipemello1
felipemello1 removed this pull request from stack #6034 November 12, 2026 00:33
@felipemello1
felipemello1 changed the base branch from felipemello1/rollout-placement/2-spread-workers to main November 12, 2026 00:34
@felipemello1
felipemello1 force-pushed the felipemello1/rollout-placement/3-process-metrics branch from d53a846 to f21370b Compare November 12, 2026 00:35
@felipemello1
felipemello1 changed the base branch from main to felipemello1/rollout-placement/2-spread-workers November 12, 2026 00:36
@felipemello1
felipemello1 added this pull request to stack #6040 November 12, 2026 00:36
@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: @claude please review. This push puts the stack on a draft copy of the look-aside router PR, rebased onto main (row 0, DO NOT REVIEW; it closes when the original lands). The generate answer now comes from the generator, so the docs and bodies say so; each body says not to merge while row 0 is under the stack.

@claude

claude Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 1m 13s —— View job


Approve -- please address the item before merging (the human-written summary is still empty; on the look-aside router base at f21370b, this PR's own diff is unchanged and its router process_metrics endpoint works alongside the new reserve/release_* endpoints): review. A maintainer still needs to review.

@claude claude Bot 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.

Verdict: Approve -- please address the item below before merging. At f21370b the stack sits on the look-aside router copy (row 0). This PR's own diff is unchanged, and it works with the look-aside router. The human-written summary is still empty. A maintainer still needs to review, since this touches the RL controller loop.

What this PR does. Each rollout worker (together with its descendant processes), the router and the controller have a ProcessStats. Once per step it reads three things from /proc: CPU seconds since the last read, anonymous memory, and the host's MemAvailable. The controller starts the read right after sync_log_step and awaits it at the end of the step, timed as blocking_read_process_metrics. On every early exit it cancels the read and waits for it to end. A read that failed before an early exit is logged, not raised.

Example.

2 workers, step 7 (the read covers start of step 6 -> start of step 7):
  worker A: 40 s own + agents     worker B: 39.2 s
  process/rollout_worker/cpu_seconds/sum              79.2
  process/rollout_worker/rss_anon_gib/max             27.1   (largest worker tree)
  process/rollout_worker/host_mem_available_gib/min   512.0
Before: no metric reported a worker's, the router's or the controller's CPU or memory.

Must fix

  1. PR description: "Summary (human-written)" is still empty. Only the author can fill it in.
Details
  • I re-read the full diff at HEAD. process.py, rollouter.py, rollout_worker.py, router.py, the controller's _read_process_metrics / _finish_process_metrics_read / _awaited, and the three test files match what I reviewed at 47399f1. The keys are still process/<role>/....
  • Against the look-aside base: the router actor's endpoints are now reserve, release_reservation, release_session, release_groups, sync_log_step, pull_model_state_dict and close_generators. process_metrics is added next to them (router.py:59-63) and touches none of them. self.generator_router is always set in setup (controller.py:762) before _trainer_loop runs, as for the existing reserve call at controller.py:685. So self.generator_router.process_metrics.call_one() needs no None check.
  • With look-aside routing, generate calls go directly to a generator, so the router's measured cpu_seconds/sum (1.16 CPU-s per step) is an upper bound now. The description says it was measured before row 0. That's accurate, so it isn't a finding.
  • The step's exits are unchanged. The cancel callback is registered on the step's AsyncExitStack before the first await that can exit early. Both breaks (batcher closed, NaN loss) and every await that can raise are inside that scope. The timed await process_metrics_task is still the last statement in it.

Not verified: how stable the CPU-time bounds in test_metrics.py are on loaded CI runners.

@felipemello1
felipemello1 force-pushed the felipemello1/rollout-placement/2-spread-workers branch from 903bb3a to b1380fa Compare November 12, 2026 00:44
@felipemello1
felipemello1 force-pushed the felipemello1/rollout-placement/3-process-metrics branch from f21370b to 238c621 Compare November 12, 2026 00:44
@felipemello1
felipemello1 force-pushed the felipemello1/rollout-placement/2-spread-workers branch from b1380fa to d90adad Compare November 12, 2026 03:07
@felipemello1
felipemello1 force-pushed the felipemello1/rollout-placement/3-process-metrics branch from 238c621 to ea0ee59 Compare November 12, 2026 03:07
@felipemello1
felipemello1 removed this pull request from stack #6040 November 12, 2026 07:00
@felipemello1
felipemello1 changed the base branch from felipemello1/rollout-placement/2-spread-workers to main November 12, 2026 07:01
@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: @claude please review. The stack is reordered: Verifiers groups in workers, then Verifiers 0.4.1, then worker placement come first (the stack table shows the new rows). It is also rebuilt with three reviewed passes: a code-style pass over every changed file, the rewritten placement docs (the VerifiersRollouter docstring and the two Verifiers READMEs; the old SVG is deleted), and the 3 newest main commits. No behavior change from the passes.

@claude

claude Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 1m 8s —— View job


Approve -- please address the item before merging. The human-written summary is still empty. After the reorder, this PR's code at 6515f1e is unchanged, and the inherited process_metrics covers VerifiersRollouter's workers. Review. A maintainer still needs to review.

@claude claude Bot 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.

Verdict: Approve -- please address the item below before merging. At 6515f1e the stack is reordered: Verifiers groups in workers, Verifiers 0.4.1 and worker placement now come first. This PR's own diff is unchanged, and the new base doesn't break its endpoints. The human-written summary is still empty. A maintainer still needs to review, since this touches the RL controller loop.

What this PR does. Each rollout worker (together with its descendant processes), the router and the controller have a ProcessStats. Once per step it reads three things from /proc: CPU seconds since the last read, anonymous memory, and the host's MemAvailable. The controller starts the read right after sync_log_step and awaits it at the end of the step, timed as blocking_read_process_metrics. On every early exit it cancels the read and waits for it to end. A read that failed before an early exit is logged, not raised.

Example.

2 workers, step 7 (the read covers start of step 6 -> start of step 7):
  worker A: 40 s own + agents     worker B: 39.2 s
  process/rollout_worker/cpu_seconds/sum              79.2
  process/rollout_worker/rss_anon_gib/max             27.1   (largest worker tree)
  process/rollout_worker/host_mem_available_gib/min   512.0
Before: no metric reported a worker's, the router's or the controller's CPU or memory.

Must fix

  1. PR description: "Summary (human-written)" is still empty. Only the author can fill it in.
Details
  • I re-read the full source diff at HEAD. process.py, rollouter.py, rollout_worker.py, router.py, and the controller's _read_process_metrics / _finish_process_metrics_read / _awaited match what I reviewed at f21370b. The keys are still process/<role>/.... The read order is unchanged: tree, then os.times(), then descendants top-down, plus the max.
  • Against the reordered base: VerifiersRollouter now subclasses Rollouter (torchtitan/rl/examples/verifiers/rollouter.py:100). It inherits process_metrics (rollouter.py:268) over the same self._workers that setup_async spawns. VerifiersRolloutWorker is a BaseRolloutWorker, which runs inside the same Monarch actor (rollout_worker.py, self._worker = worker_config.build()). So that actor's process_metrics endpoint covers the Verifiers path too. Each worker's container watchdog is a subprocess.Popen child, so it is counted. The Docker containers are not counted, as the ProcessStats docstring says.
  • The step's exits are unchanged. The cancel callback is registered on the step's AsyncExitStack before the first await that can exit early. Both breaks (batcher closed, NaN loss) and every await that can raise are inside that scope. The timed await process_metrics_task is still the last statement in it.

Not verified: how stable the CPU-time bounds in test_metrics.py are on loaded CI runners.

@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: @claude please review. The stack is rebased onto main (the look-aside router PR merged), and the PRs below this one are updated.

@claude

claude Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 52s —— View job


Approve -- please address the item before merging. The human-written summary is still empty. After the rebase onto main at 9d091e1, which now includes the look-aside router, this PR's own diff is unchanged. Review. A maintainer still needs to review.

@claude claude Bot 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.

Verdict: Approve -- please address the item below before merging. At 9d091e1 the stack is rebased onto main, where the look-aside router has now merged. This PR's own diff is unchanged, and it works with main's router. The human-written summary is still empty. A maintainer still needs to review, since this touches the RL controller loop.

What this PR does. Each rollout worker (together with its descendant processes), the router and the controller have a ProcessStats. Once per step it reads three things from /proc: CPU seconds since the last read, anonymous memory, and the host's MemAvailable. The controller starts the read right after sync_log_step and awaits it at the end of the step, timed as blocking_read_process_metrics. On every early exit it cancels the read and waits for it to end. A read that failed before an early exit is logged, not raised.

Example.

2 workers, step 7 (the read covers start of step 6 -> start of step 7):
  worker A: 40 s own + agents     worker B: 39.2 s
  process/rollout_worker/cpu_seconds/sum              79.2
  process/rollout_worker/rss_anon_gib/max             27.1   (largest worker tree)
  process/rollout_worker/host_mem_available_gib/min   512.0
Before: no metric reported a worker's, the router's or the controller's CPU or memory.

Must fix

  1. PR description: "Summary (human-written)" is still empty. Only the author can fill it in.
Details
  • I re-read the full diff at HEAD. process.py, rollouter.py, rollout_worker.py, router.py, the controller's _read_process_metrics / _finish_process_metrics_read / _awaited, and the three test files match what I reviewed at 6515f1e. The keys are still process/<role>/.... The read order is unchanged: tree, then os.times(), then descendants top-down, plus the max.
  • Against main's look-aside router: process_metrics (router.py:59-63) sits next to reserve, release_reservation, start_engine_loop, wait_engine_loop, sync_log_step, release_session, release_groups, pull_model_state_dict and close_generators, and touches none of them.
  • The step's exits at HEAD (controller.py:1298-1421): the read is created after sync_log_step. Between create_task and push_async_callback there is no await. Both breaks (batcher closed at 1318, NaN loss at 1371) and every await that can raise (fwd/bwd, push, optimizer step, pull) are inside the AsyncExitStack. The timed await process_metrics_task is still the last statement in it.
  • The stack table no longer lists the draft row 0, and the description still says the router's 1.16 CPU-s was measured before look-aside routing reached main. Both are accurate.

Not verified: how stable the CPU-time bounds in test_metrics.py are on loaded CI runners.

@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: @claude please review

@claude

claude Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 1m 12s —— View job


Approve -- please address the item before merging. The human-written summary is still empty. On the new base at ef6b242 (row 12, on top of the 35B-A3B recipe), this PR's own diff is unchanged. Review. A maintainer still needs to review.

@claude claude Bot 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.

Verdict: Approve -- please address the item below before merging. At ef6b242 the PR is now row 12 of the stack, on top of the Terminal-Bench 35B-A3B recipe (row 11). Its own diff hasn't changed since 9d091e1, and the new base doesn't affect it. The human-written summary is still empty. A maintainer still needs to review, because this touches the RL controller loop.

What this PR does. Each rollout worker (together with its descendant processes), the router and the controller have a ProcessStats. Once per step it reads three things from /proc: CPU seconds since the last read, anonymous memory, and the host's MemAvailable. The controller starts the read right after sync_log_step and awaits it at the end of the step, timed as blocking_read_process_metrics. On every early exit it cancels the read and waits for it to end. A read that failed before an early exit is logged, not raised.

Example.

2 workers, step 7 (the read covers start of step 6 -> start of step 7):
  worker A: 40 s own + agents     worker B: 39.2 s
  process/rollout_worker/cpu_seconds/sum              79.2
  process/rollout_worker/rss_anon_gib/max             27.1   (largest worker tree)
  process/rollout_worker/host_mem_available_gib/min   512.0
Before: no metric reported a worker's, the router's or the controller's CPU or memory.

Must fix

  1. PR description: "Summary (human-written)" is still empty. Only the author can fill it in.
Details
  • I re-read the full source diff at HEAD (git diff HEAD~1 HEAD -- torchtitan/). process.py, rollouter.py, rollout_worker.py, router.py, and the controller's _read_process_metrics / _finish_process_metrics_read / _awaited all match what I reviewed at 9d091e1.
    • The keys are still process/<role>/....
    • The read order is unchanged: tree, then os.times(), then descendants top-down, plus the max.
  • Checked against the new base:
    • Row 11 adds a recipe and doesn't touch the controller's step.
    • There is no Rollouter subclass in the tree any more. The Verifiers path is a VerifiersRolloutWorker(BaseRolloutWorker) built inside RolloutWorkerActor (rollout_worker.py:49), so the inherited Rollouter.process_metrics (rollouter.py:309) covers its workers over self._workers.
  • Step exits at HEAD (controller.py:1376-1499):
    • The read is created after sync_log_step, and there is no await between create_task and push_async_callback.
    • Both breaks (batcher closed at 1396, NaN loss at 1449) and every await that can raise (fwd/bwd, push, optimizer step, pull) are inside the AsyncExitStack.
    • The timed await process_metrics_task is still the last statement in that scope.
  • The PR description still says the run was measured on an earlier base and wasn't re-run on this one. That is accurate.

Not verified: how stable the CPU-time bounds in test_metrics.py are on loaded CI runners.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rl CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant