How a rollout snapshot now writes the data plane to disk after rollouts resume

NVIDIA-NeMo/RL #5139 ยท builds on the merged capture API from #5137 ยท links pinned to head c98a1322fb (base 8f3595a112)

Before
A rollout snapshot did every step while holding the data-plane barrier: no TQ writes, Gym parked. That included writing every TQ shard to disk and pickling the recovery state.
This PR
With data_plane.simple.async_checkpoint: true (default off), the barrier only covers a cheap capture of the TQ data. Rollouts resume, and the disk write and pickling run after. Trainer checkpoints get the same split.
Status
In review. No crash or data-loss bug found. Open asks: two tests and a shorter, usage-only README section (see the review).

Background. TQ (TransferQueue) holds finished rollouts until training reads them. A rollout snapshot must save TQ and the controller's recovery state as one consistent picture. To get that, it takes the data-plane barrier, which stops every TQ change while held. Dotted words have a short explanation: hover or tap them.

Why it should be faster. The barrier no longer waits for disk. Writing every shard and pickling the recovery state move to after the barrier. Under the barrier, TQ only keeps references to its shards and turns the controller's index into bytes. The listing of replay and staging keys and the ledger copy stay inside, so they set the new floor.

Measured. On the PR's CPU script (131k rollouts), moving only the pickling cut the hold from 22.82 s to 15.21 s; the pickling now takes 6.57 s after the barrier. There is no number yet for main versus this PR, which is the main change. Cost: the pickling thread competes with the controller's event loop for the GIL after resume (the PR measured 5 ms median loop lag, one 0.37 s stall). Backends without the capture API keep the old path.

What moved out of the pause

Both rows are the same function, save_snapshot. The red bar is the time the barrier is held. Red boxes are the steps that move after it; green boxes are new.

barrier held: TQ writes wait, Gym parked moves out of the pause new step same as before main: everything under the barrier hold: not measured on main list replaykeys build recoverystate torch.save +sha256 list stagingkeys write TQ: controller metadata+ every shard, to disk sidecars, thenpublish this PR, with data_plane.simple.async_checkpoint: true hold: 15.21 s (CPU, synthetic) list replaykeys build recoverystate list stagingkeys capture: keep shardviews, metadata to bytes Gym + dispatch resume torch.save +sha256: 6.57 s write TQ, thenmetadata.json release views,then publish holds: shard views (no copy) + controller metadata as bytes (1.9โ€“2.3 s here) metadata.json gets the recovery file's sha256 trainer checkpoint (checkpointing.save_data_plane: true) Same capture under the barrier, then persist + release right after it, before the model weights are saved. Gym is never parked here; the trainer save still waits for the write. Source: _save_checkpoint_impl Box widths show order, not time. Numbers: the PR's CPU script, 131k rollouts, 2 storage units.

The same change as pseudocode

Rollout snapshot, before

# controller event loop, RolloutSnapshotter.save_snapshot (main)
with barrier.checkpoint():                        # TQ writes wait, Gym parked
    validate_replay_inventory()                   # list replay keys
    state = build_rollout_recovery_state(ledger)  # copy of the ledger
    payload = torch.save(state); sha = sha256(payload)
    validate_rollout_recovery_inventory()         # list staging keys
    save_data_plane_checkpoint(meta + sha)        # writes every shard to disk
# barrier released, Gym resumes
write_controller_sidecars(payload); publish()

Rollout snapshot, after

# controller event loop, same function, data_plane.simple.async_checkpoint: true
with barrier.checkpoint():
    validate_replay_inventory()
    state = build_rollout_recovery_state(ledger)     # shares nothing with the live ledger
    payload = torch.save(state); sha = sha256(payload)
    validate_rollout_recovery_inventory()
    save_data_plane_checkpoint(meta + sha)
    view = capture_checkpoint(meta)                  # keep shard views; controller -> bytes
    dataloader, reserve = deepcopy(...)              # they outlive the barrier
# barrier released, Gym and dispatch resume
payload, sha = await to_thread(torch.save + sha256)  # competes with the loop for the GIL
await view.persist(extra_metadata=sha)               # shards, then metadata.json last
await view.release()                                 # on failure: release, or stop if unsure
write_controller_sidecars(payload); publish()

Real code: capture, SnapshotCapture.persist, SimpleCheckpointCapture.persist, trainer path _save_checkpoint_impl.

Two paths now save TQ, and each picks one by asking the backend: capture_checkpoint returns None when the backend cannot keep a view, and the code falls back to the old in-barrier save. The recovery hash reaches metadata.json the same way on both: one helper, _serialize_recovery_state, builds it.

What to check before merging

AskWhy
A test that a deferred trainer save writes rollout_recovery.pt and its hash

๐Ÿ’ฌ review comment โ€” C1 ยท test_checkpointing.py:3653

The trainer only gets the recovery payload from the value persist() returns. Dropping it passes every current test, and restore then rejects the checkpoint.
Replace the README section with a short usage section

๐Ÿ’ฌ review comment โ€” C5 ยท README.md:818

It explains classes and lock order, copies the list of phase names, and names environment_paused_seconds, which is never logged (the key is gym_parked_seconds).
A test for the deferred-path timing metrics

๐Ÿ’ฌ review comment โ€” C4 ยท test_checkpointing.py:2446

The existing metric test only runs the old path, so tq_persist_seconds or tq_release_seconds could log 0 unnoticed.
The barrier holds the same picture as before. Only the disk work moves, and the save still finishes, with hash and sidecars, before the snapshot is published. What is missing is the number that shows how much of the pause that saves against main.