How a forest-training run now saves and resumes, next to an ordinary capture run

PR #4200 · issues #4558, #4557 · stacked on #4124 (what forest training is) · permalinks at c9c1b020

Before
A forest-training run with checkpointing on stopped at startup: Forest checkpoint/resume is not supported initially (config.py at the base). The list of model calls picked for training lived only inside one request, so a retry or restart had nothing to rebuild from.
This PR
Saves that list in the same recovery file ordinary capture already uses, and teaches restore to load forest rows. It also lets forest groups use the normal retry budget.
Status
Implemented in this PR. One open review item: resume does not check that the forest setting or the padding size still match the checkpoint. (A failing RNG unit test from the first review was fixed at 93d1e8ff; the code on this page is unchanged there.)
Background. With forest training, one agent rollout can turn into several training rows. Gym reports every model call; RL keeps a selection of which replies to train on. A recovery ledger tracks groups still being generated; finished groups wait in the replay buffer. Dotted words have a short explanation: hover or tap them.

What the ledger is. An RL object, not a Gym one: RolloutRecoveryLedger in nemo_rl/experience/rollout_recovery.py. The RL rollout manager owns one. It is RL's notebook of every prompt group that has been sent to Gym but not yet trained on: for each rollout, which attempt is current, whether it finished, its reward, and the receipt Gym sent back. Gym only supplies the receipt; it keeps no ledger. RL writes the ledger to rollout_recovery.pt at each checkpoint and reads it on resume.

At a checkpoint, two things are saved. Groups still generating go into the ledger: one record per rollout (a sibling), holding Gym's receipt, the reward, and now the selection (logical_selection, written in state_dict, recovery schema 4). Finished groups are saved as rows in the replay buffer; forest rows carry owner tags that say which rollout each row belongs to. On resume, prepare_for_restart keeps finished siblings and regenerates the rest. The retry path now reads the selection back from the ledger (rollout_manager.py) instead of from the request.

Same path, two extra pieces of data

step ordinary capture (already resumable) forest training (this PR) 1 · rolloutfinishes receipt {manifest: [call0, call1, call2]} reward 0.5 → one training row same receipt + selection: response_ids ("response0","response2"), truncated True 2 · saveledger attempt {status: sealed, receipt, reward} state_dict() → rollout_recovery.pt attempt {…, logical_selection: {…}} schema 4 same file, one new field 3 · savereplay buffer group "g": 2 rows, one per rollout g_g0, g_g1 group "g": g_g0_s0, g_g0_s1, g_g0_s2, g_g1_s0, g_pad0 (padding, no owner) + owner tags 4 · resumereplay check: exactly 2 rows per group load rows have owner tags? → check every owner and every segment once, then load 5 · resumeledger prepare_for_restart(): group "g7", sibling 0 sealed → kept as is; sibling 1 unfinished → new attempt ID both lanes share this step; forest sibling 0 keeps ("response0","response2"), sibling 1 starts with selection None 6 · resumemode check forest_training must match the checkpoint: checked only on sealed ledger siblings not checked: replay rows (step 4) and the padding size → open review item new in this PR gap found in review values from the PR's unit tests (groups "g", "g7")

The two paths share one ledger, one TQ snapshot and one restart rule. They split in two places only: the attempt record gains logical_selection, and replay restore checks owner tags instead of "one row per rollout" (replay_buffer.py). Ordinary schema-3 files still load; forest files older than schema 4 are refused.

🔴 C2 review comment — single_controller.py:1222-1234 (mode and padding check)

The code that does it

Where the change lands: RL only. No Gym change: the receipt Gym already sends is enough.

The PR makes four changes:

  1. Ledger saves the selection. logical_selection is a new field on each attempt record (file format 3 → 4), and rollout_manager.py reads it from there instead of from a dict that lived only in one request. First hunk below.
  2. Replay buffer reloads forest rows. load_state_dict accepts groups whose rows carry owner tags, instead of insisting on one row per rollout. Step 4 in the figure.
  3. Forest groups get the normal retry limits. Before, a forest group never retried: a data error stopped the run, and an infra error dropped the group. Both happened because the selection would have been lost on a retry. Now forest groups retry like any other group. The only error that still stops the run is an unresolved capture write (UnresolvedCaptureAcknowledgement), and that now applies to every capture run, not just forest runs. Second hunk.
  4. The three bans are deleted: checkpointing on, mid-rollout snapshots on, and resuming from an existing checkpoint. Last two hunks.
@@ rollout_manager.py L2477-L2484 · _generate_for_finalization_attempt
                 logical_selections=(
-                    tuple(rollout_selections[i] for i in range(len(rollout_ids)))
+                    tuple(
+                        sibling.current_attempt.logical_selection
+                        for sibling in self._recovery_ledger.get_group(
+                            group_id
+                        ).siblings
+                    )
                     if self._forest_training
@@ rollout_manager.py (base L2243-L2259, head L2244-L2252) · generate_for_finalization
             except Exception as error:
-                if (
-                    self._forest_training
-                    and classify_rollout_failure(error) is not FailureClass.INFRA
-                ):
+                if isinstance(error, UnresolvedCaptureAcknowledgement):
                     raise
                 reason = type(error).__name__
                 if classify_rollout_failure(error) is FailureClass.INFRA:
                     infra_attempts += 1
                     last_infra_error = error
-                    # Forest selections are request-local until checkpoint recovery
-                    # persists them. Drop this abandoned group through the usual
-                    # bounded policy; do not redispatch and lose sealed selections.
-                    if self._forest_training:
-                        break
                     if infra_attempts >= policy.max_infra_attempts:
                         break
@@ config.py (base L1516-L1521) · validate_single_controller_config
-        if master_config.checkpointing["enabled"]:
-            raise ValueError("Forest checkpoint/resume is not supported initially")
-        if master_config.rollout_checkpointing.snapshot_attempt_interval_s is not None:
-            raise ValueError(
-                "Forest rollout checkpoint/resume is not supported initially"
-            )
@@ setup.py (base L1349-L1350) · setup_single_controller
     trainer_checkpoint_path = checkpointer.get_latest_checkpoint_path()
-    if token_capture_cfg.forest_training and trainer_checkpoint_path is not None:
-        raise ValueError("Forest checkpoint/resume is not supported initially")

Also in the PR: every Megatron resume now restores the saved random-number state (load_rng), for all algorithms, not only forest runs.

🟡 C5 review comment — single-controller.md:189-214 (move RNG and capture-stop lines out of the forest section)

So what. Forest runs can now checkpoint, resume and retry like ordinary capture runs, using the same files plus one field. Before merge, the review asks for two things: check at resume that forest_training and the padding size match the checkpoint; and run CI on the head, which has not run yet. No CI test runs a forest save, kill and resume end to end yet.