Repository navigation
[rl][Observability] log host memory per process kind - #5492
Draft
felipemello1 wants to merge 3 commits into
Draft
felipemello1 wants to merge 3 commits into
felipemello1 wants to merge 3 commits into
Conversation
compute_host_memory_metrics() runs once per step with the other controller metrics, in a thread inside the metrics_log span. It sums RssAnon from /proc/<pid>/status over every process in the controller's cgroup v2, grouped by TORCHTITAN_RL_ROLE in each process's spawn env (controller, trainer, generator, env_server_worker, other), and logs the process count per role and the cgroup's memory.current. spawn_proc_mesh tags trainer and generator procs; the Verifiers env server tags its pool workers.
Before Linux 6.16, status's RssAnon misses memory each CPU hasn't reported yet (up to ~18 MiB per CPU), so on GB300 hosts (Linux 6.14) it read about 2x low and could not attribute growth. smaps_rollup walks the page tables: exact on every kernel, ~1.5 ms per process vs ~0.1 ms for status. The step waits for the scan.
…group compute_host_memory_metrics read only the controller cgroup's cgroup.procs. Under Slurm's cgroup v2 plugin each job step has its own cgroup (job_<id>/step_<step>/user/task_<n>). SlurmLauncher (#5572) runs the controller as the batch step and starts the Monarch workers with srun, in another step, so the trainer ranks on the controller's host were missed: host_memory/*/trainer read 0 in a real Slurm job that had 12 trainer processes on that host. Now the metric scans the controller's nearest job_<id> ancestor and every cgroup below it; outside Slurm it reads the controller's own cgroup as before. host_memory/cgroup_memory_current_gib becomes the job's total on this host, and `other` now includes the job's other steps (step_extern).
felipemello1
force-pushed
the
felipemello1/obs/3-host-memory-per-role
branch
from
November 5, 2026 00:40
d726791 to
0dd1649
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TLDR: The controller logs host memory every step, per process role: anonymous memory and process count for the controller, trainer, generators, env-server workers and the rest, plus the cgroup's total. Always on, no knob, like GPU memory. One pass takes ~1.5-2 ms per process (320 ms for 219 processes on a devserver), in a thread that the step loop awaits: about 1% of a GB300 step at ~600 processes (estimate).
Problem
Solution
compute_host_memory_metrics()(controller/metrics.py) runs once per step inside themetrics_logspan, in a thread, so its/procreads don't block the event loop. The training loop awaits it, so its time adds to each step, outsidetiming/step/total./proc/self/cgroup, thencgroup.procs). On multi-host jobs, trainer ranks are not the controller's children, so walking its process tree would miss them. Under Slurm (e.g.SlurmLauncher), each job step has its own cgroup, and the workers run in another step than the controller. So when the controller's cgroup is inside ajob_<id>cgroup, it scans that job cgroup and every cgroup below it.TORCHTITAN_RL_ROLEin its spawn env, and children inherit it.spawn_proc_mesh(actors/monarch/provisioning.py) setstrainerandgeneratoron the Monarch procs, and the env server setsenv_server_workerbefore it spawns workers. This process iscontroller. Untagged processes, or unknown values, areother.Anonymous:in/proc/<pid>/smaps_rollup) and counts the processes. Then it reads the cgroup'smemory.current. All 5 roles are logged every step, 0 when empty.Results
You may ask:
smaps_rollup, notstatus'sRssAnon? The kernel counts RSS per CPU, and before Linux 6.16statusreads only the shared total, missing up to ~18 MiB per CPU. On GB300 hosts (Linux 6.14, 144 CPUs, 64 KiB pages) it read 5.97 GiB wheresmaps_rollupread 12.13 GiB over 70 processes, and 0 kB for asleepchild. A devserver with the same CPUs and page size on Linux 6.16 reads the same from both.smaps_rollupwalks the page tables, so a pass costs ~20x more (above)./proctells them apart. Each role's procs already get their own spawn env (CUDA_VISIBLE_DEVICES), so the role is one more key in it./proc/<pid>/smaps_rollup.NOTE:
otherincludes the batcher, the generator router and the rollout-worker procs (untagged for now, TODO in the code), Monarch host agents, and the env-server process itself (it tags only what it spawns). Withnum_workers=1the env server serves episodes itself, so they count asother.memory.currentincludes page cache, so it can sit well above the summed anonymous memory./proc/<pid>/environ.metrics_logspan; the logic is unchanged.Test plan
test_compute_host_memory_metrics_groups_processes_by_role: a child taggedtraineradds one trainer process, with non-zero memory.test_host_memory_scans_every_step_of_the_slurm_job_only,test_host_memory_outside_slurm_scans_the_own_cgroupandtest_compute_host_memory_metrics_counts_trainers_in_another_job_step, on fake cgroup trees: every step of the controller's Slurm job is scanned, another job is not, and outside Slurm only the own cgroup is.test_spawn_proc_mesh_gives_roles_sharing_a_host_mesh_disjoint_gpusnow also checks the role of each spawned proc mesh. The single-node path calls the same_spawn_proc_mesh.