Repository navigation
fix(nemo-gym): keep token capture ledgers on node-local disk - #5249
Conversation
With token capture enabled and no capture_dir set, setup put every Gym ledger under <logger.log_dir>/gym_token_capture. The log dir is usually on a shared filesystem, so each model call became small-file metadata traffic on it. Setup now derives a fresh directory under /tmp/nemo_rl/token_capture, named after the Slurm job ID (or "local") plus a random suffix. Each Gym shard runs all of its servers on one node, nothing in NeMo RL reads ledger files directly, and a checkpoint commit copies the ledger rows it needs into the checkpoint directory, so no reader needs the ledgers from another node or after the run. Because a node-local directory would otherwise keep every run's ledgers, each Gym actor removes its subdirectory on shutdown when setup chose the directory, and the last actor on a node removes the run's directory. A configured capture_dir is never removed. capture_dir_derived joins capture_dir in the bootstrap fingerprint exclusions. Signed-off-by: Ananth Subramaniam <[email protected]>
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
The shared /tmp/nemo_rl/token_capture parent outlives the run, so a second user on the same node could not create a run directory in it. The derived default is now /tmp/nemo_rl-<user>/token_capture/.... Shutdown skips cleanup when the actor's capture directory does not exist, so a second shutdown, or one before Gym created the directory, no longer reports a removal failure. Comments now say that each Gym actor, not each shard, runs its servers on one node, and name the case the getattr guard in shutdown covers. Signed-off-by: Ananth Subramaniam <[email protected]>
getpass.getuser() raises OSError in a container running as a uid with no user name, which would fail setup. The capture root then uses the uid. Signed-off-by: Ananth Subramaniam <[email protected]>
Resolve conflicts with the Dynamo capture backend (#4979): keep capture_dir_derived next to the three-way generation_backend literal, and keep the dynamo_enabled backend derivation in setup. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
|
/ok to test 5b6f29b |
… set, flush telemetry before removing ledgers Setup now assigns token_capture.capture_dir_derived on every path, so a value carried in by a reused config dump cannot mark a user-configured capture_dir for removal on shutdown. NemoGym.shutdown removes the derived capture directory after the telemetry flush instead of before it. Removing a long run's ledgers can outlast the shutdown timeout, and the actor is then killed; with this order that costs only the removal, not the flush. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
|
/ok to test 89a0f59 |
terrykong
left a comment
There was a problem hiding this comment.
One design ask:
- (C1) Replace the hidden
capture_dir_derivedflag with a user setting,capture_dir_cleanup: bool = True.
Moving the default capture directory off the shared log dir and onto each Gym node's local disk is a good change, and the safety argument in the description matches the code:
- Only the Gym actor's own servers open the ledger files, and Gym starts them as local subprocesses on that actor's node (
server_supervisor.py). - Resume reads only the rows a checkpoint copied (
export_model_records), never the live folder. - Shutdown deletes only the actor's own subfolder and any empty parents up to the run's folder, and leaves a folder the user set alone (
_remove_derived_capture_dir). - The new tests guard each change: removing the cleanup call, skipping the parent cleanup, not resetting
capture_dir_derived, not passingcapture_root, or dropping the resume-check exclusion each makes a test fail.
Thanks for the clear write-up of what is and isn't covered.
Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-5249-capture-dir-cleanup.html
nemo-rl-review: kind=expert harness=claude-code/2.1.332 model=claude-opus-5-5 effort=medium review-pr-team=v3 reviewed=89a0f59
…up setting Review feedback on #5249: capture_dir_derived only recorded who picked the capture directory, so a user who set capture_dir lost cleanup and nobody could turn cleanup off. token_capture.capture_dir_cleanup (default true) is a user setting. Each Gym actor removes its own ledger directory on shutdown, then the empty layers above it up to capture_dir, whether setup or the user picked the path. Set it to false to keep the ledgers. Setup no longer resets a flag on every run, and the actor always gets the run's root. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
|
/ok to test 77c613f2c687100ba7e06b0bc32b597e422d8832 |
@pthombre, there was an error processing your request: See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/ |
|
CI label:
|
|
/ok to test 77c613f |
terrykong
left a comment
There was a problem hiding this comment.
C2 · 1 action item. TL;DR — the code for C1 landed, but the PR description still says a configured capture_dir is never removed. That is now wrong: a run that sets capture_dir loses its ledgers at shutdown unless it sets capture_dir_cleanup: false.
This is a docs fix, not a code bug.
Fixed in 77c613f: capture_dir_derived is gone and capture_dir_cleanup: bool = True is the user setting (config.py L743-L747); shutdown reads it (nemo_gym.py L1038); every actor gets the run's root (nemo_gym.py L3271-L3273); the fingerprint exclusion is renamed (manifest.py L81); and a test covers capture_dir_cleanup: false (test_nemo_gym_shutdown.py L429).
Still open: five spots in the PR description still describe the old flag:
- What changed → Cleanup on shutdown explains
capture_dir_derivedand says "Acapture_dirthe user configured is never removed." - What changed → Fingerprint names
capture_dir_derived. - Compatibility says runs that set
capture_dir"keep their directory and their files", and "To keep ledgers for debugging, setcapture_direxplicitly." - Not covered here → #4798 says to point that check at an explicitly configured
capture_dir. That check now also needscapture_dir_cleanup: false, or the ledgers are gone before it reads them. - Validation lists tests for the old flag ("not marked derived", "passes the run's root to the actor only for a derived directory", "
capture_dir_deriveddoes not change the bootstrap fingerprint").
AI-1
Rewrite those five spots for capture_dir_cleanup. For Compatibility, for example: "Runs that set token_capture.capture_dir keep their directory, but each Gym actor now deletes its own ledgers there on a clean shutdown. To keep ledgers for debugging, set token_capture.capture_dir_cleanup: false." Not a suggestion block: this is the PR description, not code.
…leanup Signed-off-by: Pranav Thombre <[email protected]>
After merging main, NemoGym reads token_capture["forest"]["enabled"] when it is built, so the capture dicts in test_nemo_gym_shutdown.py raised KeyError: 'forest'. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
|
/ok to test fc821d2 |
What and why
Gym's capture ledgers turn every model call into small-file metadata operations, and with
token_capture.capture_dirunset, setup put them under<logger.log_dir>/gym_token_capture. Recipes worked around this one by one by settingcapture_dirto a node-local path.Moves the default token capture directory from the run's log dir, which is usually on a shared filesystem, to a fresh per-run directory on each Gym node's local disk, and removes that directory when the Gym actor shuts down.
Why a node-local directory is safe
Setup resolves
token_capture.capture_dironce, andbuild_nemo_gym_actorsgives each Gym actor its own subdirectory,<capture_dir>/gym-instances/<shard>/replica-<n>. The actor hands that subdirectory to Gym as its token store and lineage store. Three facts make a node-local directory safe:RunHelperstarts every server of an actor as a local subprocess, so the processes that open the directory, the policy model server and its workers and the actor's own rollout collection, all run on the actor's node. Each Gym actor is its own Gym deployment, and the actor is never restarted elsewhere (max_restarts=0). The defaultSTRICT_SPREADplacement puts shards on distinct nodes, and actors that do share a node still have separate subdirectories.export_model_records, which copies the ledger rows of each continued episode into<checkpoint_root>/gym-instances/<instance_id>on durable storage. A restore imports those rows into the new actor's live directory and retries every unsealed attempt under a fresh rollout ID.token_capture.capture_dirwas already excluded from the bootstrap fingerprint, so a restart may use a different directory.#4247 reads ledgers directly from the NemoGym actor and requires the actor and the policy model server to share the directory on one node, which a node-local default provides.
What changed
capture_dirunset, setup uses/tmp/nemo_rl-<user>/token_capture/<SLURM_JOB_ID or "local">-<8 hex chars>. Gym creates it on each node that hosts a Gym actor. The parent directory is per user because it outlives the run: a shared parent created by one user would refuse another user's run directory. Without a user name, for example in a container running as an arbitrary uid, the parent uses the uid instead. The random suffix keeps two runs on one node apart, even within one Slurm job, because Gym rollout IDs are deterministic and two runs sharing a directory could mix ledgers. The path does not depend onTMPDIR.token_capture.capture_dir_cleanup(defaulttrue), controls it.NemoGym.shutdownremoves the actor's subdirectory after its servers stop and telemetry is flushed, and the last actor on a node also removes the empty layers above it up tocapture_dir. Without this, each node's disk would keep every run's ledgers. This applies whether setup or the user chosecapture_dir; setcapture_dir_cleanup: falseto keep the ledgers. A second shutdown, or one before Gym created the directory, does nothing.token_capture.capture_dir_cleanupjoinstoken_capture.capture_dirin the bootstrap fingerprint exclusions, so a restart that changes the directory or the cleanup setting still restores.Compatibility
Runs that set
token_capture.capture_dir, such as recipes that use/tmp/nemo_rl/token_capture/${SLURM_JOB_ID}, keep their directory, but each Gym actor now deletes its own ledgers there on a clean shutdown. Runs that relied on the default no longer find ledgers under<log_dir>/gym_token_capture, and the default directory is gone after a clean shutdown. To keep ledgers for debugging, settoken_capture.capture_dir_cleanup: false. Where/tmpis a RAM-backed filesystem, ledgers use memory, and until #4798 retires ledgers during the run, that use grows with the run.Not covered here
NemoGym.shutdownruns leaves its subdirectory on that node.DEFAULT_ENV_SHUTDOWN_TIMEOUT_SECONDSto stop its servers, flush telemetry and remove its directory beforeray.kill. If that runs out, the directory is left in place or partly removed. Ledgers are not retired during a run until feat(nemo-gym): retire capture ledgers NeMo RL is done with #4798, so the removal time grows with the run, and a long run can exceed this budget. The removal runs after the telemetry flush, so running out of time costs only the removal.<log_dir>/gym_token_capture. Whichever PR lands second needs to point that check at an explicitly configuredcapture_dirand setcapture_dir_cleanup: false, or the ledgers are gone before the check reads them.Issues
No tracking issue.
Convergence / perf / functionality proof
This PR changes where capture ledgers are written and when they are deleted. It does not change training math, so there are no convergence or perf runs; the proof is functional.
capture_diris kept, thatbuild_nemo_gym_actorspasses the run's root to the actor, that the default directory is under a per-user parent, or a per-uid one when there is no user name, that shutdown removes one actor's ledgers while a sibling actor's stay and removes the run's directory after the last actor, that a second shutdown reports no failure, that shutdown leaves the directory alone whencapture_dir_cleanupis false, and thatcapture_dir_cleanupdoes not change the bootstrap fingerprint. Each of these fails on the previous code.tests/unit/environments/test_nemo_gym_shutdown.py,test_nemo_gym_utils.py(with and without--nemo-gym-only),test_nemo_gym.py,test_nemo_gym_token_capture.py,test_gym_checkpoint_adapter.py,test_gym_environment_checkpoint.py,test_nemo_gym_shards.py,tests/unit/single_controller/test_setup.pyandtest_rollout_checkpoint.py. One video-defaults test intest_nemo_gym.pyfails locally onmaintoo, because of a Hugging Face cache permission error on the workstation.pre-commiton the changed files, andpyrefly checkwith the project interpreter.capture_dirunset, checking that the run's directory is gone from the Gym node after a clean exit.capture_dir_cleanupand the merge ofmain: the same unit test files, plus theL0_Unit_Tests_EnvironmentsandL0_Unit_Tests_Vllm_Nemo_Gymshards, pass on a GPU node. TheL0_Unit_Tests_Nemo_Gymshard was run against a test image built beforemain's latest Gym bump; 7 tests that depend on the newer Gym failed there and the rest passed, so CI is the check for that shard.Needs upstream changes
None
PR commands and CI
CI:Lfast: the default for most PRs. Runs a fast test subset.CI:L1: dependency or container changes (pyproject.toml,uv.lock,Dockerfile) or broad core changes. Builds a new image and runs unit and functional tests.CI:docs: docs-only changes. Runs doc tests only./ok to test <full-commit-sha>: start CI for that commit. Post again after each push./nightly-ci test-case=<test>: run NVIDIA's nightly CI for the PR head; eligible teams only./review: automated review comments. Addmode=strictfor a stricter review,reset=truefor a fresh full review./resolve-conflict: Autobot mergesmaininto this PR and resolves the conflicts. PRs from forks must allow edits by maintainers./review-pr-team <pr-number>for a team review before you ask for human review.