How the new rollout-checkpoint classes fit together, and whether the shape is clean

NVIDIA-NeMo/RL #5011, part 1 of 11 in the partial-checkpointing stack. All permalinks pin the PR head 7171e5d.

Before
About 30 save and restore methods sat on the single controller itself, with "is Gym present?" checks inside them.
This PR
The controller now owns three objects and calls them from 6 of its methods, 15 calls in all. Gym-specific code sits behind one of the three.
Status
The shape is clean. Calls go one way, down. A few extra pieces are flagged in review comments (C3, C5). None is a bug.

Two pages on this PR, one question each. This one: what calls what.

Read the figure top to bottom. The top box is the controller and the methods of its own that make calls. Each green arrow is a call, labelled with the method it calls. The middle row holds the three objects the controller owns: one that restores, one that saves, and one for the environment (Gym, or a do-nothing stand-in). The bottom row is the Gym chain under the environment object. Most of that chain existed before this PR.

call reads / uses flagged in review SingleControllerActor builds the three objects once in __init__ C3: tests copy this wiring by hand _run_pumps _rollout_pump _train_pump _save_checkpoint + 3 save helpers the controller reads none of the objects' fields; they read its counters through read_progress() check_startup() restore() run() redispatch_restored() begin/end_optimizer_commit() trainer_checkpoint() capture(), published() environment checkpoint GymEnvironmentCheckpoint, or NoEnvironmentCheckpoint (does nothing) check_startup() snapshot(path) restored(path) is_unavailable(err) holds_rollout_state RolloutRestorer restore.py ยท runs once at startup restore() -> bool redispatch_restored(launch, admit) โ† calls env restored() replay index, ledger, spare prompts RolloutSnapshotter snapshots.py ยท owns save lock and its own pump task run() stop_requested begin_optimizer_commit() end_optimizer_commit() trainer_checkpoint() capture(cut, path, kind) trainer_checkpoint_published() snapshot() is_unavailable() GymEnvironmentSnapshot what snapshot() hands back while Gym is paused check_against_cut() metrics() C5: calls back RolloutParts + RolloutRuntimeState state.py ยท the only things both halves share 12 refs: buffer, dataloader, sampler, rollout_manager, dp_client, env checkpoint, runtime_state, read_progress(), log_metrics(), โ€ฆ the two halves never call each other module functions (no state) inventory.py: validate_*_inventory manifest.py: commit_snapshot, anchors used by both halves; manifest by the saver only RolloutRecoveryLedger owned by RolloutManager; all three read it Gym chain under GymEnvironmentCheckpoint only the first box is new in this PR; the rest came with #4500 GymCheckpointCoordinator prepared() commit() retire() forget() restored() resume() Gym Ray actors (one per shard) checkpoint_prepare.remote() checkpoint_commit.remote() checkpoint_restore.remote() โ€ฆ GymCheckpointAdapter turns RL's request into Gym's HTTP calls, checks the replies Gym servers pause, save and restore their own episodes (outside RL) GymEnvironmentCheckpoint also writes the ledger (retire, forget) and pauses RolloutManager's request deadlines while Gym is paused.

Is this a good design?

What is clean

  • Calls go one way: controller โ†’ three objects โ†’ Gym. Nothing below calls up into the controller. It reads the controller's step counters through one callback, read_progress().
  • The saver and the restorer never call each other. They share only RolloutParts, and the only thing in it they change is RolloutRuntimeState.
  • All Gym-specific checkpoint code now sits behind one object. The do-nothing backend replaces the old "is Gym present?" checks in the controller.
  • The controller's whole contact with checkpointing is 15 calls in 6 of its methods.

What to watch

  • C5: GymEnvironmentSnapshot.check_against_cut only calls back into its parent's validate_cut. That is the one arrow that points back up.
  • C3: the controller's setup code (L713โ€“L749) is copied by hand into a test helper. Both copies must be edited together.
  • Gym is four hops deep: environment object โ†’ coordinator โ†’ Ray actor โ†’ adapter. Only the first hop is new. The other three came with #4500, so this PR is not the place to merge them.
  • The recovery ledger is the shared hub: the restorer, the saver and the Gym object all read it, and it lives in RolloutManager.
So what. The split is sound, and it is the right shape to build the next 10 PRs on. The extra pieces are small and each has a review comment. None of them changes behavior, so they can be fixed in this PR before later PRs copy the pattern.

C3 โ€” _rollout_checkpoints.py:32 C5 โ€” nemo_gym.py:131