Repository navigation
Conversation
Signed-off-by: khazic <[email protected]>
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe checkpointer now preserves full-precision optimizer state during single-GPU and distributed checkpoint saves and loads. A regression test verifies exact restoration of AdamW step counters and moment tensors. ChangesOptimizer checkpoint precision
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Merge Protections🔴 1 of 1 protections blocking · waiting on 👀 reviews
🔴 Require approval from approved reviewers listWaiting for any of
This rule is failing.All pull requests must have at least one approving review from a member of the approved reviewers list before merging.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fd79c7fbe9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # model dtype (e.g. bf16), undoing the full-precision save. | ||
| for opt, state_dict in zip(optimizers, loaded_list, strict=True): | ||
| opt.load_state_dict(convert_float_dtype(state_dict, dtype)) | ||
| opt.load_state_dict(state_dict) |
There was a problem hiding this comment.
Restore legacy step tensors to float32
When SingleGPUCheckpointer resumes a checkpoint written by the previous implementation, AdamW's step tensors are stored as BF16. The default non-capturable optimizer loader deliberately leaves step in its saved dtype, so this direct load preserves BF16; once the count is sufficiently large, in-place increments round or stop changing, corrupting bias correction during the resumed run. The old code converted these tensors back to the FP32 model dtype, and the distributed path still explicitly repairs legacy steps, so the single-GPU path needs the equivalent post-load conversion.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed: the single-GPU load path now casts step tensors back to float32, matching the distributed path. Added a test that writes a bf16-step checkpoint and asserts the repair.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/speculators/train/checkpointer.py`:
- Around line 327-332: Update load_optimizer_state_dict at both
src/speculators/train/checkpointer.py:327-332 and
src/speculators/train/checkpointer.py:395-403 so optimizer state restoration
preserves saved float32 moments and step tensors instead of casting them to bf16
parameter dtypes; retain strict optimizer/state alignment and apply the same fix
to single-GPU and distributed loading paths. Update
tests/unit/train/test_checkpoint.py:320-352 to verify restored optimizer
floating-point state remains float32 for bf16 parameters.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: d6bed57f-d1f3-48f5-bd7f-ef4850a8d0b0
📒 Files selected for processing (2)
src/speculators/train/checkpointer.pytests/unit/train/test_checkpoint.py
The distributed path already casts step tensors back to float32 after loading; the single-GPU path did not, and the non-capturable optimizer loader keeps step in its saved dtype. A checkpoint written by the previous bf16 save path would therefore resume with a bf16 counter whose in-place increments round, corrupting bias correction. Signed-off-by: khazic <[email protected]>
load_optimizer_state_dict maps the state onto the current accelerator, so on a GPU host the restored tensors are on cuda while the reference is on cpu and torch.equal raises. CPU-only CI never hit it. Also assert the moment dtype explicitly, which is what the test is really about. Signed-off-by: khazic <[email protected]>
|
Gentle follow-up on this one. It saves and restores optimizer state at full precision so a resumed run does not lose Adam moments to a dtype round-trip; checks are green. Happy to rebase or adjust if anything is off. |
|
This pull request has been automatically marked as stale because it has not had any activity within 60 days. It will be automatically closed if no further activity occurs within 30 days. |
Merge Protections🔴 1 of 1 protections blocking · waiting on 👀 reviews and 🙋 you
🔴 Require approval from approved reviewers listWaiting for
This rule is failing.All pull requests must have the human-review checklist item checked and at least one approving review from a member of the approved reviewers list before merging.
|
1 similar comment
Merge Protections🔴 1 of 1 protections blocking · waiting on 👀 reviews and 🙋 you
🔴 Require approval from approved reviewers listWaiting for
This rule is failing.All pull requests must have the human-review checklist item checked and at least one approving review from a member of the approved reviewers list before merging.
|
|
Closing this pull request because the "I (a human) have written or reviewed the code in this pr to the best of my ability." checklist item is unticked and there has been no activity for 7 days. Pull requests are reviewed only once a human has written or reviewed the code. |
Problem
Checkpointing converts the entire optimizer state dict to bf16 (the default
float_dtype), including the AdamWexp_avg/exp_avg_sqmoments and the floatstepcounters. bf16 has an 8-bit mantissa: any step count above 256 rounds (10000 rounds to a multiple of 64), and the second moments lose their low bits, so resumed runs use wrong bias correction and quantized moments, visibly deviating from an uninterrupted run. BothSingleGPUCheckpointerandDistributedCheckpointerare affected, and the load paths re-applied the same cast (to the model dtype), so bf16 models were re-quantized even when the file was fine.Fix
Optimizer state is saved and loaded without any dtype conversion.
Optimizer.load_state_dictalready aligns per-param float state with the param dtype and leavesstepuntouched; the distributed loader's step-to-float32 repair loop is kept for legacy bf16-saved checkpoints. Model weights still save as bf16 as before.Note on scope: this changes what new checkpoints contain (optimizer state roughly doubles in size, fp32 instead of bf16) while remaining able to load old bf16-saved files. Flagging it here since it touches the checkpoint save/load path; happy to adjust if you prefer an opt-in flag.
Tests
A round-trip unit test in
test_checkpoint.pysteps AdamW past step 10000, saves, reloads through the checkpointer, and asserts the step counters and moments are bit-exact fp32. Fails on main.