NVIDIA-NeMo/RL #5139 ยท builds on the merged capture API from #5137 ยท links pinned to head c98a1322fb (base 8f3595a112)
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.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.
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.
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.
| Ask | Why |
|---|---|
A test that a deferred trainer save writes rollout_recovery.pt and its hash | 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 | 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 | The existing metric test only runs the old path, so tq_persist_seconds or tq_release_seconds could log 0 unnoticed. |