NVIDIA-NeMo/RL #4859, flag
async_rl.defer_async_checkpoint_finalize: true. The bug links pin 0a4103fb, the head first reviewed; the fix links pin the current head 8841e8e4.
| SFT v2 | SingleController (GRPO / PPO) | |
|---|---|---|
| main | Every exit publishes the last save: run()'s cleanup calls CheckpointManager.shutdown(), which waits for the background thread that finalizes and renames it. | |
| First push (flag on) | Only a normal exit finalizes. An error after a save leaves it as tmp_step_N/. | Same for errors, and for the normal end of an epoch-limited run: the loop leaves through an early return that skips the final finalize. |
| Now (5f93e1bae) | The cleanup loop publishes the pending save first, before checkpoint close. | Teardown publishes the pending save right after the pumps stop, before checkpoint close, in its own try/except. |
| Status | Partly fixed. The flag introduced this bug. 5f93e1bae fixes every common exit (table below). One narrow case is still open: the train loop is stopped while it waits for the checkpoint lock (review comment C7). Runs with the flag off were never affected. | |
Three pages on this PR, one question each β this one: which exits lose the last save.
As first pushed, with the flag on, a save was published only by
_finish_pending_save.
The train loop calls it at the top of each step and once more, blocking, after the loop
(L3906).
But a run limited by epochs ends differently: when the data is used up, the last step is marked final and saves
(L3725),
the loop goes round once more, finds nothing to train, and leaves through a plain
return
that skips L3906. The GRPO example config ends this way: max_num_epochs: 1, max_num_steps: 1000000.
max_num_steps, so the loop runs once more. Its first poll comes right after the save, so the write is not done: False.run()'s cleanup calls CheckpointManager.shutdown(). The manager was never told about the pending save, so it does nothing.An error in the step after a save takes the same route to the cleanup, in both the SingleController and SFT v2, and drops the save the same way. On main, that cleanup publishes it.
Where the fix lands: RL only, two functions. Each loop now publishes a still-pending save in its
teardown, before checkpoint close. One spot covers every exit: the early return, errors, and cancellation.
The finalize after the loop stays; the teardown call does nothing once no save is pending.
@@ single_controller.py L941-L951 Β· SingleControllerActor._run_pumps (finally) for task in tasks: task.cancel() await asyncio.gather(*tasks, return_exceptions=True) + try: + # With the train pump stopped, publish a save that + # defer_async_checkpoint_finalize left pending: a failure or an + # orderly rollout-checkpoint stop ends the pump before its own + # blocking finalize. Before checkpoint close, which joins the rename. + await self._finish_pending_save(blocking=True) + except Exception as e: # teardown must not mask the original failure + print(f"Error publishing the pending checkpoint: {e}", flush=True) if self._engine_supervisor is not None: @@ sft_v2.py L257-L265 Β· SFTSingleControllerActor.run (finally) finally: for cleanup, name in ( + # A save deferred by defer_async_checkpoint_finalize is published only + # here when the run raised after it. Before checkpoint close, so that + # close joins the rename this starts. + ( + lambda: self._finish_pending_save(blocking=True), + "pending checkpoint publish", + ), (self._close_loaders, "loader close"),
_finish_pending_save(blocking=True): wait for the write on every worker, then rename the folder. Main's cleanup already did this through shutdown(), so a stuck worker hangs here exactly as it does on main.{step_1, step_2}.| How the run ends (flag on) | What publishes the last save | Checked |
|---|---|---|
max_num_steps reached | blocking finalize after the loop (L3927; SFT v2 L255) | PR's tests |
Save-by-time limit (checkpoint_must_save_by) | save, then break to the same finalize | CPU test, flag on |
| Data runs out | teardown publish (L949) | CPU test, flag on |
| Error in a later step | teardown publish (SFT v2: first cleanup entry, L259) | author's tests (C8 fixes the SFT v2 one) |
| Orderly stop after a rollout checkpoint | teardown publish | by reading the code |
| Stopped while waiting for the checkpoint lock | nothing: the save was already cleared (C7) | CPU test fails at head |
| Process killed (preemption, node loss) | nothing can run. Flag off loses an unfinished write the same way; flag on adds up to one step after the write lands. | β |
_finish_pending_save clears the pending
save before waiting for the checkpoint lock. If teardown cancels the train pump during that wait, the workers have
already finalized, but the new teardown publish finds nothing pending and tmp_step_N/ stays. Nothing below is
implemented: clearing it inside the lock, right after the rename starts, closes the gap.
@@ single_controller.py L5430-L5433 Β· SingleControllerActor._finish_pending_save checkpoint_path, step = self._pending_checkpoint - self._pending_checkpoint = None async with self._checkpoint_save_lock: self._checkpointer.begin_finalization(checkpoint_path) + # Cleared only once published: a cancel while waiting for the lock + # leaves it for the teardown publish. + self._pending_checkpoint = None