Skip to content

[rl][Observability] log host memory per process kind - #5492

Draft
felipemello1 wants to merge 3 commits into
mainfrom
felipemello1/obs/3-host-memory-per-role
Draft

felipemello1 wants to merge 3 commits into
mainfrom
felipemello1/obs/3-host-memory-per-role

Conversation

@felipemello1

@felipemello1 felipemello1 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

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

  1. Many roles share the controller host: the controller, the env-server workers, and often trainer ranks and generators.
  2. Only GPU memory is logged. Nothing tracks host memory.
  3. So an OOM is a guess. One run's 978 GB controller host went from 17% to 100% used in 40 minutes. We could not tell which role grew: more workers, bigger workers, the controller, or the trainer ranks.

Solution

  1. compute_host_memory_metrics() (controller/metrics.py) runs once per step inside the metrics_log span, in a thread, so its /proc reads don't block the event loop. The training loop awaits it, so its time adds to each step, outside timing/step/total.
  2. It lists every process in the controller's cgroup v2 (/proc/self/cgroup, then cgroup.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 a job_<id> cgroup, it scans that job cgroup and every cgroup below it.
  3. A process's role is TORCHTITAN_RL_ROLE in its spawn env, and children inherit it. spawn_proc_mesh (actors/monarch/provisioning.py) sets trainer and generator on the Monarch procs, and the env server sets env_server_worker before it spawns workers. This process is controller. Untagged processes, or unknown values, are other.
  4. Per role, it sums anonymous memory (Anonymous: in /proc/<pid>/smaps_rollup) and counts the processes. Then it reads the cgroup's memory.current. All 5 roles are logged every step, 0 when empty.
  5. A process that exits mid-scan, or can't be read, is skipped. Without cgroup v2 it warns once and logs nothing.

Results

New keys, per role: host_memory/rss_anon_gib/<role>, host_memory/num_processes/<role>
          and once: host_memory/cgroup_memory_current_gib
Real VerifiersEnvServer with 2 pool workers (CPU): env_server_worker 0.65 GiB, 2 processes
One pass on a devserver (aarch64, 64 KiB pages), 219 processes holding 80 GiB: 320 ms (status's RssAnon would take 16 ms)

You may ask:

  • Why anonymous memory, not RSS or PSS? Summed RSS counts shared library pages once per process (~380 MB per worker with torch). PSS splits those pages among the processes that map them, so one role's value moves when another role starts or exits.
  • Why smaps_rollup, not status's RssAnon? The kernel counts RSS per CPU, and before Linux 6.16 status reads 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 where smaps_rollup read 12.13 GiB over 70 processes, and 0 kB for a sleep child. A devserver with the same CPUs and page size on Linux 6.16 reads the same from both. smaps_rollup walks the page tables, so a pass costs ~20x more (above).
  • Why an env var for the role? The trainer and generator procs run the same command (the Monarch bootstrap), so nothing else in /proc tells them apart. Each role's procs already get their own spawn env (CUDA_VISIBLE_DEVICES), so the role is one more key in it.
  • Why not psutil? It is not a dependency, and the anonymous total is one line of /proc/<pid>/smaps_rollup.

NOTE:

  • other includes 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). With num_workers=1 the env server serves episodes itself, so they count as other.
  • Only the controller's cgroup is scanned, or under Slurm its job's cgroup on this host with every step below it. Processes outside it are missed. On a hybrid cgroup v1/v2 host it logs nothing.
  • memory.current includes page cache, so it can sit well above the summed anonymous memory.
  • One sample per step, at its end: it misses the peak during forward/backward.
  • Not run: a GPU RL run. The trainer and generator tags are checked with a fake host mesh; a real single-node Monarch proc carried the tag in its /proc/<pid>/environ.
  • Results are from the branch before the port to main's file layout. The port moves the code and puts the scan inside the metrics_log span; the logic is unchanged.

Test plan

pytest tests/rl/unit_tests/cpu/test_metrics.py tests/rl/unit_tests/cpu/test_shutdown.py \
  tests/rl/unit_tests/cpu/test_trainer_loop.py tests/rl/unit_tests/cpu/test_verifiers_terminal_bench.py
  • New test_compute_host_memory_metrics_groups_processes_by_role: a child tagged trainer adds one trainer process, with non-zero memory.
  • New test_host_memory_scans_every_step_of_the_slurm_job_only, test_host_memory_outside_slurm_scans_the_own_cgroup and test_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_gpus now also checks the role of each spawned proc mesh. The single-node path calls the same _spawn_proc_mesh.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 18, 2026
Felipe Mello and others added 3 commits November 4, 2026 16:21
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).

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