Repository navigation
perf(checkpoint): reduce recovery metadata capture overhead - #5185
Conversation
|
/ok to test d3e2af6 |
terrykong
left a comment
There was a problem hiding this comment.
Thanks for the clear write-up and the thorough tests. A team review found no bugs. The checkpoint output matches the old code. We ran a script against both the base and this head, and both gave the same saved state in every case: no exclusions, an empty exclusion set, and one or two excluded groups. We also fuzz-tested _copy_checkpoint_value against copy.deepcopy on 5,000 random receipts and found no differences. If someone adds a field to RewardChecks, RewardLogContext or FinalizedReward, the new tests fail, so the hand-written copies cannot quietly fall out of date.
Two small asks, both inline:
- (C1) Finalizer rewards are filtered twice. Filter only the metrics in the old loop.
- (C2) The end-to-end capture test makes its baseline with the code under test. Use
copy.deepcopyinstead.
Not blocking: the timings come from a synthetic CPU benchmark. build_rollout_recovery_state runs on the controller's event loop (snapshots.py#L400-L413). Numbers from one real snapshot would show how much this matters in practice: the group count, and the build time before and after, next to the save time.
Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-5185-faster-recovery-copy.html
nemo-rl-review: kind=expert harness=claude-code/2.1.332 model=claude-opus-5-5 effort=medium review-pr-team=v3 reviewed=d3e2af6
Copy scalar-heavy receipt containers without generic deepcopy bookkeeping, project reward fields directly, and exclude canonically owned groups before copying their attempt metadata. Preserve the checkpoint schema, detached mutable state, custom copy behavior and current-main recovery fields. Validation: 846 CPU recovery, reward and checkpoint tests passed; scoped Ruff and Pyrefly passed. A 500-group, 64-entry-per-receipt CPU comparison measured 2.55x faster construction without exclusions and 5.00x with half the groups excluded; all twelve trials matched baseline contents and passed weights-only/native restore checks. Timings exclude serialization and disk I/O. Signed-off-by: Anish Mahishi <[email protected]>
… test baseline The finalizer-rewards comprehension already keeps only canonical groups, so the later loop filtered those rewards a second time. Filter only the finalizer metrics there, so the ownership rule for rewards lives in one place. test_capture_matches_legacy_projection built its "ledger unchanged" baseline with ledger.state_dict(), the copy code under test. A copy that shared lists with the ledger would have aliased the baseline too and passed. Take the baseline with copy.deepcopy; with lists left uncopied the test now fails in all three cases. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
…ecks main's #5206 added RewardChecks.length_penalty after this branch was cut. _reward_checks_state listed the three boolean fields by hand, so a checkpoint written with it dropped the length-penalty input and a resumed run restored that attempt without its length penalty. Copy the field the way dataclasses.asdict does. Cover a real LengthPenaltyInput in the projection, capture and restore tests, and expect the multi_harness_routes key main's #5158 added to the recovery state. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
d3e2af6 to
16453a5
Compare
|
/ok to test 16453a5 |
|
/ok to test 16453a5 |
_populated_ledger seals each attempt with a Forest selection, and sealing checks call ownership through Gym's rebuild rule, which imports nemo_gym. The default unit lane has no nemo_gym, so mark the three tests that build that ledger, as the ledger tests in test_rollout_recovery.py are. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
|
/ok to test 7827d39 |
…r fake build_rollout_recovery_state now calls ledger.state_dict(exclude_group_ids=...). The _PendingLedger stand-in in test_checkpoint_dispatch_races.py still took no arguments, so six tests failed with a TypeError. Give it the same keyword and drop the excluded groups, as RolloutRecoveryLedger.state_dict does. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
|
/ok to test 5737e4a |
What and why
Reduce controller-side recovery metadata capture cost without changing checkpoint contents or the checkpoint schema:
deepcopyfor custom types and subclasses.asdictfallback for dataclass subclasses. The reward-check projection includes thelength_penaltyinput main added in feat(single_controller): support group length penalties #5206.This is a focused port of the recovery-copy optimizations from the integrated checkpoint branch (
c795e0219and the recovery-ledger hunks ofa37a013ec), adapted to main. Logical selection, attribution, short-batch state, and the existing restore validation remain intact.Scope / compatibility
Targets main directly, rebased onto
d93ba7ddb4, which already includes #5137 and #5139; this reduces their capture overhead.Only one runtime module and one regression-test module change. No new flags, dependencies, Gym changes, checkpoint-format migration, writer actors, or asynchronous serialization/persistence behavior. Deferring recovery serialization/hash until after Gym resume is a separate follow-up.
Issues
No separate issue; scoped performance follow-up to the rollout-checkpoint work, independently useful on main.
Convergence / perf / functionality proof
Checkpoint contents and schema are unchanged, so no convergence run is needed. CPU timing and unit-test evidence below.
CPU comparison
Compared against the actual main implementation at the base commit using 500 prompt groups, 64 manifest entries per group's sealed receipt, and three counterbalanced trials per method/scenario.
All 12 trials matched baseline checkpoint contents and passed weights-only load plus native ledger restore. Timings measure synthetic CPU recovery-state construction only; serialization, restore, disk I/O, and full rollout-pause timing are excluded. This is not an end-to-end snapshot speedup claim. No GPU smoke or full pre-commit suite was run.
Validation
846 CPU tests passed at the original base
defdaef48:Used that base's Gym pin
5911d628c744d0bf43fe1d9ddf3bda72d59b0f9a, Python 3.13.14, and a pre-existing CPU test environment. No Ray actors or GPU job were launched for this change.nemo_rl/experience/rollout_recovery.py: zero errors, zero ignored.git diff --checkpassed.After rebasing onto
d93ba7ddb4(main's Gym pin9e2e5d0ad0d1723acef1b63beb28292da16f7c5b):test_rollout_recovery_capture_copy.pypass, plus the length-penalty and reward-check checkpoint round-trip tests intest_rollout_recovery.py.length_penaltyprojection removed, 12 of those tests fail.nemo_rl/experience/rollout_recovery.py: zero errors.Needs upstream changes
None.
PR commands and CI
CI:Lfast: the default for most PRs. Runs a fast test subset.CI:L1: dependency or container changes (pyproject.toml,uv.lock,Dockerfile) or broad core changes. Builds a new image and runs unit and functional tests.CI:docs: docs-only changes. Runs doc tests only./ok to test <full-commit-sha>: start CI for that commit. Post again after each push./internal-ci test-case=<job>: run NVIDIA's internal nemo-ci pipeline for the PR head; eligible teams only./review: automated review comments. Addmode=strictfor a stricter review,reset=truefor a fresh full review./resolve-conflict: Autobot mergesmaininto this PR and resolves the conflicts. PRs from forks must allow edits by maintainers./review-pr-team <pr-number>for a team review before you ask for human review.