Repository navigation
[rl] Rollout workers, the router and the controller report their CPU and memory each step - #5926
Conversation
|
Reply from claude: @claude review |
|
Claude finished @felipemello1's task in 3m 20s —— View job Approve -- please address the items before merging (summary, |
There was a problem hiding this comment.
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
- PR description -- "Summary (human-written)" is empty. The author has to fill it in; an agent can't.
torchtitan/rl/observability/metrics/process.py:48-- theperf/prefix adds 9 keys to the default console panel (processor.py:61, documented as 12 keys), and router/controllersum/maxare duplicates. Use aprocess/{role}/...prefix (inline).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 themaxratchet 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.pyis 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
TaskGroupinside the read pluspush_async_callback(_finish_process_metrics_read)means no part of a read outlives the step onbreakor raise. On the normal path the task is already done, socancel()does nothing. A read that fails on the normal path raises fromawait process_metrics_task(as anExceptionGroup) and also logs the warning once; that's harmless. - Read order (descendant tree found first, then
os.times(), then descendants top-down, plus themax) is correct for in-tree reaping. The only gap is reparenting (must-fix 3). rollout_worker.process_metricsruns the scan on the default executor, which rollouts share. When rollouts saturate it, the wait shows up inblocking_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}" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
| # 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()) |
There was a problem hiding this comment.
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.
|
Reply from claude: round 1 is in
RL CPU suite at |
|
Reply from claude: @claude review |
|
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. |
There was a problem hiding this comment.
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'sperf/panel and its "7 trainer/buffer keys" comment (processor.py:59-61) are accurate again.ProcessStatsdocstring on descendants that leave the tree: resolved (process.py:741-743, plus the TODO atprocess.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
- 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 (breakon a closed batcher,breakon a NaN loss, a raised push error) goes through_finish_process_metrics_read. On the normal path the task has already finished, so itscancel()does nothing. - If a read fails on the normal path,
await process_metrics_taskraises and ends the loop. The docstring says this happens only when a worker or the router died. Another cause is possible: a/procmounted withhidepid=1makes_read_statraisePermissionErrorfor 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.
|
Reply from claude: round 2 is
RL CPU suite at |
|
Reply from claude: @claude review |
|
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. |
There was a problem hiding this comment.
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
- PR description: "Summary (human-written)" is still empty. Only the author can fill it in.
Details
git diff 86c118daa bb7e6be50touches onlyrollouter.py(theworkers_on_controller_hostdefault flips to True with a TODO, andclose()now catches any drain exception),test_rollouter_pool.py, and three READMEs. None of these touchprocess_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.
bb7e6be to
a52089b
Compare
4b1323c to
166f944
Compare
a52089b to
58fa440
Compare
|
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 |
There was a problem hiding this comment.
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
- 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 against166f944(2/3) instead of comparing the two. - Same behavior as before:
_cpu_seconds->_total_cpu_secondsis a rename. Keys are stillprocess/<role>/{cpu_seconds,rss_anon_gib,host_mem_available_gib}. The read order is unchanged: tree, thenos.times(), then descendants top-down, plus themax. So is theTaskGroupread._finish_process_metrics_readis still registered through theAsyncExitStack, and the timedawait process_metrics_taskstill 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 atprocess.py:91. The step-1-covers-setup comment is atcontroller.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> 0on the total, which checks only that the read doesn't raisePermissionError. 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.
166f944 to
1a68345
Compare
58fa440 to
e070bcd
Compare
1a68345 to
b0eeefa
Compare
e070bcd to
22c93e2
Compare
There was a problem hiding this comment.
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
- 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 at7b69d2d. The keys are stillprocess/<role>/.... - I checked the step against the new base (
controller.py:1281-1415). The read is created aftersync_log_step, and the cancel callback is registered on the step'sAsyncExitStackbefore the first await that can exit early. Bothbreaks (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 timedawait process_metrics_taskis 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.
4d27c22 to
d2c5419
Compare
47399f1 to
d53a846
Compare
d53a846 to
f21370b
Compare
|
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 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 |
There was a problem hiding this comment.
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
- 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 at47399f1. The keys are stillprocess/<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_dictandclose_generators.process_metricsis added next to them (router.py:59-63) and touches none of them.self.generator_routeris always set in setup (controller.py:762) before_trainer_loopruns, as for the existingreservecall atcontroller.py:685. Soself.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
AsyncExitStackbefore the first await that can exit early. Bothbreaks (batcher closed, NaN loss) and every await that can raise are inside that scope. The timedawait process_metrics_taskis still the last statement in it.
Not verified: how stable the CPU-time bounds in test_metrics.py are on loaded CI runners.
903bb3a to
b1380fa
Compare
f21370b to
238c621
Compare
b1380fa to
d90adad
Compare
238c621 to
ea0ee59
Compare
|
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 |
|
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 |
There was a problem hiding this comment.
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
- 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/_awaitedmatch what I reviewed atf21370b. The keys are stillprocess/<role>/.... The read order is unchanged: tree, thenos.times(), then descendants top-down, plus themax. - Against the reordered base:
VerifiersRollouternow subclassesRollouter(torchtitan/rl/examples/verifiers/rollouter.py:100). It inheritsprocess_metrics(rollouter.py:268) over the sameself._workersthatsetup_asyncspawns.VerifiersRolloutWorkeris aBaseRolloutWorker, which runs inside the same Monarch actor (rollout_worker.py,self._worker = worker_config.build()). So that actor'sprocess_metricsendpoint covers the Verifiers path too. Each worker's container watchdog is asubprocess.Popenchild, so it is counted. The Docker containers are not counted, as theProcessStatsdocstring says. - The step's exits are unchanged. The cancel callback is registered on the step's
AsyncExitStackbefore the first await that can exit early. Bothbreaks (batcher closed, NaN loss) and every await that can raise are inside that scope. The timedawait process_metrics_taskis still the last statement in it.
Not verified: how stable the CPU-time bounds in test_metrics.py are on loaded CI runners.
|
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 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 |
There was a problem hiding this comment.
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
- 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 at6515f1e. The keys are stillprocess/<role>/.... The read order is unchanged: tree, thenos.times(), then descendants top-down, plus themax. - Against main's look-aside router:
process_metrics(router.py:59-63) sits next toreserve,release_reservation,start_engine_loop,wait_engine_loop,sync_log_step,release_session,release_groups,pull_model_state_dictandclose_generators, and touches none of them. - The step's exits at HEAD (
controller.py:1298-1421): the read is created aftersync_log_step. Betweencreate_taskandpush_async_callbackthere is no await. Bothbreaks (batcher closed at 1318, NaN loss at 1371) and every await that can raise (fwd/bwd, push, optimizer step, pull) are inside theAsyncExitStack. The timedawait process_metrics_taskis 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.
|
Reply from claude: @claude please review |
|
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 |
There was a problem hiding this comment.
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
- 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/_awaitedall match what I reviewed at9d091e1.- The keys are still
process/<role>/.... - The read order is unchanged: tree, then
os.times(), then descendants top-down, plus themax.
- The keys are still
- Checked against the new base:
- Row 11 adds a recipe and doesn't touch the controller's step.
- There is no
Rolloutersubclass in the tree any more. The Verifiers path is aVerifiersRolloutWorker(BaseRolloutWorker)built insideRolloutWorkerActor(rollout_worker.py:49), so the inheritedRollouter.process_metrics(rollouter.py:309) covers its workers overself._workers.
- Step exits at HEAD (
controller.py:1376-1499):- The read is created after
sync_log_step, and there is no await betweencreate_taskandpush_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 theAsyncExitStack. - The timed
await process_metrics_taskis still the last statement in that scope.
- The read is created after
- 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.
…and memory each step
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.
Problem
Solution
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. Withchildren=Trueit adds live descendants and, for CPU, the ones that already exited.process_metricsendpoint. 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.os.times()and their ownsmaps_rollup, also in a thread.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:
sync_log_stepreply? It would make every log-step call wait for a /proc scan.TaskGroup, notgather? Once cancelled, aTaskGroupwaits for every part;gatherreturns as soon as its first part is cancelled.create_tasktakes only a coroutine, so the router's Monarch call (a Future) is wrapped in one.NOTE:
Rollouter.process_metrics: each host's sum.Results
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 skippedtest_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_processandtest_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)
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".