Skip to content

feat(checkpoint): snapshot rollouts at the checkpoint deadline - #5056

Merged
terrykong merged 3 commits into
mainfrom
amahishi/rollout-deadline-snapshot
Nov 9, 2026
Merged

terrykong merged 3 commits into
mainfrom
amahishi/rollout-deadline-snapshot

Conversation

@macandro96

@macandro96 macandro96 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Saves a rollout snapshot at the checkpointing.checkpoint_must_save_by deadline, 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

rollout_checkpointing:
  snapshot_attempt_interval_s: null     # existing: extra snapshots on a timer
  snapshot_on_trainer_checkpoint: true  # new

The recovery config decides what a snapshot preserves; these two fields decide when, beyond the deadline save, which is automatic with turn-level recovery.

Saves environment state snapshot_on_trainer_checkpoint snapshot_attempt_interval_s
After every trainer checkpoint and at the deadline (default) true null
Only at the deadline false null
After every trainer checkpoint, at the deadline, and every 300 s true 300

How it works

  • Snapshots on: when the interval is set or rollout_recovery.target_level is turn (rollout_snapshots_enabled). This replaces the eight checks of the interval in validation, data-plane support, bootstrap identity, restore and the pump.
  • Deadline: the trainer save the deadline triggers starts publishing step_N in the background straight away (also with defer_async_checkpoint_finalize), and the train pump then calls RolloutSnapshotter.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.
  • Overlap: the deadline snapshot is staged in tmp_rollout_snapshot_step_N beside the checkpoints: it pauses Gym, takes its cut and saves TQ while the policy weights are still being written, then waits for step_N and moves in with one rename. If step_N never appears, it is dropped. trainer_publish_wait_seconds logs that wait.
  • Pump: with no interval it waits only for a trainer checkpoint's wakeup, and before the first step also for the deadline. A wait timed for that deadline that the first step overtook saves nothing.

Notes for review

  • Budget: the deadline does not reserve time for either save; leave room in checkpoint_must_save_by for the longer of the policy write and the snapshot. Each snapshot logs total_save_seconds and trainer_publish_wait_seconds.
  • Order: step_N never waits for the snapshot, so a slow or failed snapshot can only cost the unfinished turns, never the trainer checkpoint.
  • Validation: turn level no longer requires an interval. Setup rejects turn level with snapshot_on_trainer_checkpoint: false, no interval and no checkpoint_must_save_by, which would never save.
  • Deferred finalize: still rejected with an interval or with snapshot_on_trainer_checkpoint at turn level. Deadline-only is allowed: the deadline publishes step_N before its snapshot, and the run then stops.
  • Sibling level: unchanged. The trainer checkpoint already holds that rollout state, so no snapshot follows it.
  • Backward compatible: existing turn-level configs set an interval, which keeps working; they now also get the deadline snapshot.

Testing

  • Unit:
    • the pump with no interval, with the trigger after a trainer checkpoint on and off;
    • the pre-step deadline, and ignoring a stale deadline wait;
    • each deadline-snapshot outcome (saved, skipped, I/O error, invariant failure);
    • the train pump's deadline snapshot finding step_N published, with and without deferred finalize;
    • a staged snapshot saving the environment before step_N exists and moving in once it is published, and being dropped when step_N never appears;
    • setup accepting deadline-only and interval-free turn level, and rejecting a config that never saves.
  • 3327 passed (single-controller, experience, telemetry and timer tests), Gym lane 27 passed. ruff and pyrefly clean.
  • GPU (8×H100, Qwen3-0.6B, Gym Workplace Assistant, turn level, snapshot_on_trainer_checkpoint: false, no interval, checkpoint_must_save_by 2 min):
    • Phase 1: step 3 trained at 99.8 s; the deadline snapshot took its cut at 101.1 s, before step_3 was 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.
    • Phase 2 selected that snapshot, loaded its 8 unfinished groups, continued 8 siblings from their Gym state (8 attempt_resumed, no restarts) and trained to step 8.
    • A test-only proxy delayed each post-tool model call by 15 s so turns were in flight at the deadline; that delay, not training, sets the ~20–30 s step times.

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Nov 3, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@macandro96
macandro96 added this pull request to stack #5057 November 3, 2026 23:39
@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Nov 4, 2026
@macandro96
macandro96 requested a review from terrykong November 4, 2026 00:12
@terrykong terrykong added CI:L1 Run doctests, unit tests, and functional tests CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) and removed CI:L1 Run doctests, unit tests, and functional tests labels Nov 5, 2026
@macandro96
macandro96 force-pushed the amahishi/rollout-deadline-snapshot branch from dea7ae5 to a97d834 Compare November 6, 2026 20:20

@terrykong terrykong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. (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.
  2. (C2) Share one _attempt helper between run() and save_at_deadline instead of copying the attempt block.
  3. (C4) Run the deadline path once on GPU and post the log order, save time, and a resumed restore.
  4. (C5) Say the snapshot rules once (the guide table) instead of five times, and fix the false deadline line.
  5. (C6) Merge the new timeout test into the existing one, parametrized on defer_finalize, so the new _finish_pending_save call is tested.
  6. (C7) One helper for the three interval-free pump tests; fold the wakeup test into a parametrize.
  7. (C8) Add setup tests for the two newly accepted configs.
  8. (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

Comment thread nemo_rl/utils/timer.py Resolved
Comment thread docs/guides/single-controller.md Resolved
Comment thread nemo_rl/algorithms/single_controller.py Resolved
@macandro96
macandro96 force-pushed the amahishi/rollout-deadline-snapshot branch from a97d834 to 4e76506 Compare November 8, 2026 02:31
@macandro96

Copy link
Copy Markdown
Contributor Author

/ok to test 4e76506

Base automatically changed from amahishi/rollout-trace-batch-age to main November 8, 2026 08:12
macandro96 and others added 2 commits November 8, 2026 00:12
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]>
…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]>
@macandro96

Copy link
Copy Markdown
Contributor Author

/ok to test 0942465

@terrykong
terrykong enabled stacked auto-merge (squash) November 9, 2026 22:32
@terrykong
terrykong merged commit b083540 into main Nov 9, 2026
96 checks passed
@terrykong
terrykong deleted the amahishi/rollout-deadline-snapshot branch November 9, 2026 23:30
terrykong added a commit that referenced this pull request Nov 24, 2026
- 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants