Repository navigation
feat(checkpoint): snapshot rollouts at the checkpoint deadline - #5056
Conversation
dea7ae5 to
a97d834
Compare
terrykong
left a comment
There was a problem hiding this comment.
Thanks, Anish. The deadline snapshot fills a real gap for turn-level runs, and a few parts are good reuse that keeps behaviour the same: rollout_snapshots_enabled replaces 8 scattered interval checks, _failure_reason is pulled out, and would_save is rebuilt on seconds_until_save(). The new snapshot_on_trainer_checkpoint knob is needed, since no existing key gives deadline-only saves. The pump's wait-or-skip logic before step 1 is the smallest shape that is correct.
Since this stack is already over 20k lines, every ask below either makes the PR smaller or closes a real test gap:
- (C1) Delete
save_reserve_seconds: it is always 0 in deadline-only mode, so the guide's promise is false there, and with C9 the snapshot overlaps the model write anyway. - (C2) Share one
_attempthelper betweenrun()andsave_at_deadlineinstead of copying the attempt block. - (C4) Run the deadline path once on GPU and post the log order, save time, and a resumed restore.
- (C5) Say the snapshot rules once (the guide table) instead of five times, and fix the false deadline line.
- (C6) Merge the new timeout test into the existing one, parametrized on
defer_finalize, so the new_finish_pending_savecall is tested. - (C7) One helper for the three interval-free pump tests; fold the wakeup test into a parametrize.
- (C8) Add setup tests for the two newly accepted configs.
- (C9) At the deadline, take the snapshot inside the trainer save, while the model is still being written to disk, so the two saves overlap instead of running one after the other. About +10 lines; it removes the deadline branch, so C6 no longer applies if you take it.
Size: C1, C2, C5, C6 and C7 together cut about 70 lines from the +462; C8 adds about 15 to close a real test gap, and C9 about 10.
Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-5056-deadline-snapshot.html
Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-5056-overlap-saves.html
Generated by Claude Code
a97d834 to
4e76506
Compare
|
/ok to test 4e76506 |
When checkpointing.checkpoint_must_save_by fired after a train step, the controller saved a trainer checkpoint and stopped at once. A trainer checkpoint holds no environment state, and stopping cancelled the snapshot pump before it could save one, so a turn-level run lost every unfinished turn at the deadline. Rollout snapshots are now on when snapshot_attempt_interval_s is set or rollout_recovery.target_level is "turn". With turn-level recovery: - The trainer checkpoint the deadline triggers is followed by a forced rollout snapshot before the run stops. A failure that leaves checkpoint state consistent only warns; the trainer checkpoint is still durable. - New rollout_checkpointing.snapshot_on_trainer_checkpoint (default true) keeps today's snapshot after every other trainer checkpoint. false with no interval saves environment state only at the deadline. - snapshot_attempt_interval_s is no longer required. Setup instead rejects a turn-level config that would never save. - The pump waits only for wakeups when no interval is set, and before the first step also for the deadline. Each snapshot also records how long it took, and the deadline is moved earlier by that much, so the trainer checkpoint and the snapshot both fit. Deferred checkpoint finalize stays rejected with an interval or with a snapshot after every trainer checkpoint; deadline-only is allowed, because the deadline publishes step_N before its snapshot. Unit: 563 passed (checkpointing, setup, timer and trace tests), Gym lane 7 passed. ruff and pyrefly clean. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
- Drop the deadline save reserve (C1). It was always 0 in deadline-only mode, covered the snapshot but never the trainer save, and was written into TimeoutChecker from another module. The guide now says to leave room in checkpoint_must_save_by for both saves. - Share one _attempt helper between the snapshot pump and save_at_deadline, which repeated its timing, failure classification and logging (C2). - Shorten the guide, the config docstring and both exemplar comments to one statement of when snapshots are saved, keeping the table (C5). - Tests: the deadline test now runs with and without deferred finalize and checks the snapshot runs after step_N is published (C6); the interval-free pump tests share one setup helper (C7); setup tests cover the two configs this PR newly accepts (C8). GPU (C4): a turn-level run with a 2-minute checkpoint_must_save_by and snapshot_on_trainer_checkpoint=false published the step 3 trainer checkpoint, then the deadline snapshot (total_save_seconds 5.67), then stopped; the resumed run restored it and continued 8 siblings from their Gym state. Unit: checkpointing, setup and timer tests pass; ruff and pyrefly clean. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
4e76506 to
97ece19
Compare
…ands The deadline snapshot started only after step_N's policy weights were written and renamed, so the last save took both back to back. On large runs the snapshot's own work (Gym prepare, TQ save) is about a minute, and an async policy write is as long or longer. - The deadline's trainer save starts publishing step_N in the background right away, also with defer_async_checkpoint_finalize, so nothing has to take the save lock to start the rename. - The deadline snapshot (save_snapshot(staged=True)) writes into a staging directory beside the checkpoints, pauses Gym and takes its cut as before, and only then waits for step_N. It is moved into step_N with one rename, or dropped if step_N never appears. step_N never waits for the snapshot; a job ended in between restores from step_N and redoes the unfinished turns. - A staging directory a killed run left behind is removed at the next one. - trainer_publish_wait_seconds logs how long the snapshot then waited for step_N, so a run shows how much of the policy write the overlap hid. GPU, the C4 run again: step 3 trained at 99.8 s; the snapshot took its cut at 101.1 s, before step_3 was renamed, waited 5.25 s for it and was published at 106.5 s (total_save_seconds 5.43); the resumed run restored it and continued 8 siblings from their Gym state. Unit: 3327 passed (single-controller, experience, telemetry, timer), Gym lane 27 passed. ruff and pyrefly clean. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
|
/ok to test 0942465 |
- C1: empty the sample unknown list; every final call in it is known. - C2: read all timeline pages (--paginate --slurp) in local use. - C3: drop the #5056 citation from the Dynamo design-first example. Signed-off-by: Terry Kong <[email protected]>
What does this PR do?
Saves a rollout snapshot at the
checkpointing.checkpoint_must_save_bydeadline, so a turn-level run keeps its unfinished turns across a walltime stop, and lets a run save environment state only at that deadline.Stacked on #5049 (batch age).
Why
When the deadline fired after a train step, the controller saved a trainer checkpoint and stopped at once. A trainer checkpoint holds no environment state, and stopping cancelled the snapshot pump before it could save one, so every unfinished turn was redone after the restore. There was also no way to save environment state only at the end: turn-level recovery required
snapshot_attempt_interval_s.Config
The recovery config decides what a snapshot preserves; these two fields decide when, beyond the deadline save, which is automatic with turn-level recovery.
snapshot_on_trainer_checkpointsnapshot_attempt_interval_struenullfalsenulltrue300How it works
rollout_recovery.target_levelisturn(rollout_snapshots_enabled). This replaces the eight checks of the interval in validation, data-plane support, bootstrap identity, restore and the pump.step_Nin the background straight away (also withdefer_async_checkpoint_finalize), and the train pump then callsRolloutSnapshotter.save_at_deadline(), a forced snapshot, before it stops. A failure that leaves checkpoint state consistent only warns, since the trainer checkpoint is durable; an invariant failure still raises.tmp_rollout_snapshot_step_Nbeside the checkpoints: it pauses Gym, takes its cut and saves TQ while the policy weights are still being written, then waits forstep_Nand moves in with one rename. Ifstep_Nnever appears, it is dropped.trainer_publish_wait_secondslogs that wait.Notes for review
checkpoint_must_save_byfor the longer of the policy write and the snapshot. Each snapshot logstotal_save_secondsandtrainer_publish_wait_seconds.step_Nnever waits for the snapshot, so a slow or failed snapshot can only cost the unfinished turns, never the trainer checkpoint.snapshot_on_trainer_checkpoint: false, no interval and nocheckpoint_must_save_by, which would never save.snapshot_on_trainer_checkpointat turn level. Deadline-only is allowed: the deadline publishesstep_Nbefore its snapshot, and the run then stops.Testing
step_Npublished, with and without deferred finalize;step_Nexists and moving in once it is published, and being dropped whenstep_Nnever appears;snapshot_on_trainer_checkpoint: false, no interval,checkpoint_must_save_by2 min):step_3was renamed, waited 5.25 s for the rename (trainer_publish_wait_seconds; Gym parked 0.10 s, TQ save 0.02 s) and published at 106.5 s, about 13 s before the deadline; then "Timeout has been reached", exit 0. No snapshot followed steps 1 and 2.attempt_resumed, no restarts) and trained to step 8.🤖 Generated with Claude Code