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 v2 | SingleController (GRPO / PPO) | |
|---|---|---|
| main | After 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 review | Teardown 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). |
| Status | Works 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.
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.
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.begin_finalization(path), now without a wait_fn.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.
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.