How waiting for the checkpoint write at the next step boundary lets it overlap training

NVIDIA-NeMo/RL #4859 โ€” opt-in flags sft.defer_async_checkpoint_finalize and async_rl.defer_async_checkpoint_finalize. Permalinks pin 0a4103fb, the head first reviewed; the normal path is unchanged at the current head 8841e8e4.

SFT v2SingleController (GRPO / PPO)
mainAfter an async save, a background thread runs the blocking finalize on the policy workers. The next training step queues behind the whole disk write.
This PR (flag on)The save is only marked pending. At the start of each step the controller asks the workers "is the write done?" without waiting, and finalizes once it is. The write overlaps the next step.
Since reviewTeardown now publishes a pending save, so an error does not drop it (5f93e1bae).The same, which also covers runs that end because the data ran out (5f93e1bae). Still open: reject the flag together with rollout snapshots (C3).
StatusWorks as described. The flag's lost-checkpoint bug is partly fixed: one exit is still open (C7) (page 2). v1 loops are untouched; SFT v1 rejects the flag.

Three pages on this PR, one question each โ€” this one: what the flag changes.

Background. With Megatron async_save, each policy worker hands the checkpoint files to a background writer and returns. Finalize is the step that waits for that write to end on every rank. After it, NeMo-RL renames tmp_step_N/ to step_N/, the name resume looks for. A Ray actor runs one call at a time, so any call that waits inside a worker blocks the calls queued behind it. Dotted words have a short explanation: hover or tap them.

On main, the save hands the folder to CheckpointManager.begin_finalization(path, wait_fn=finalize_async_save), which starts a thread that calls the workers' blocking finalize_async_save. That call reaches each worker first, so the next step's training call waits behind the write. With the flag on, the save only records the folder as pending (SFT v2, SingleController). Each step then starts with a quick, non-waiting check, poll_async_save.

Only the policy weights and optimizer overlap: they are the one Megatron async save. The dataloader state, the replay-buffer files, the TQ data-plane snapshot and, for PPO, the critic are all written before the save call returns, so training waits for them with the flag on or off. Page 3 shows the order.

Same save, two ways to wait for it

step 2 โ€” saves step 3 step 4 main background thread waits train 2 โ†’ save_checkpoint finalize, waits 8.1 s train 3 train 4 disk write โ†’ tmp_step_2/ โ†’ step_2/ thread: wait_fn() blocks the workers flag on controller polls each step train 2 โ†’ save_checkpoint poll train 3 poll+finalize ~1.0 s train 4 disk write โ†’ pending: tmp_step_2/ โ†’ False โ†’ True, then step_2/ _finish_pending_save(blocking=False) maybe_finalize_async_save(blocking=False) step waits for the write training runs during the write short finalize, write already done background disk write Times are the PR's 32-node SFT v2 run: 8.1 s before, ~1.0 s with the flag. The next save and the end of training still finalize blocking, as Megatron-Bridge does.
  1. Step 2 saves. Each worker starts its background write and returns at once โ€” the same on both paths.
  2. Main: the background thread's blocking finalize reaches the workers before step 3's training call, so step 3 waits the full write.
  3. Flag on: step 3 starts with Policy.poll_async_save(). All ranks agree "not done" in one quick check, so it returns False and step 3 trains while the write runs.
  4. Step 4's check finds the write done, so the workers run the short finalize and the controller renames the folder through the same begin_finalization(path), now without a wait_fn.

Where the two paths meet, and what still differs

Both end in CheckpointManager.begin_finalization, which renames the folder and prunes old checkpoints. The only difference is who waits for the write: on main a thread does, at a time the training loop does not control; with the flag on, the loop does, at a step boundary on every rank at once. That matters because the check runs a collective across all ranks. Megatron-Bridge's own loop does the same check at the top of each iteration (train.py#L408). The flag is opt-in because one thing gets worse: the save stays tmp_step_2/ until a later step boundary, so any exit that skips that boundary must finalize on its own. Two exits did not at first; teardown now covers them โ€” see page 2.

So what. For SFT v2 the PR measured the wait after a save drop from 8.1 s to about 1.0 s at 32 nodes. The SingleController has no numbers yet. There, with overlap_param_gather on, the weight sync before generation already finalizes the write, so part of the wait may just move into weight-sync time rather than go away.