Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses the unresolved counter behavior first reported by @mshvartsman in a 24 January 2024 comment on #1601.
What does this PR do?
A fresh process starts with
project_configuration.iteration=0.load_state()restores a checkpoint but leaves that counter at zero, including when the caller supplies an explicit path.With
total_limit=2, the next save can delete oldcheckpoint_0and reuse its name for the newest state. A later restart loads oldercheckpoint_1because its number is higher. In the reproduction, a newly saved weight of0.7is replaced on resume by the older0.8.Change
After a successful load with automatic checkpoint naming enabled, scan the project's
checkpointsdirectory and advance the counter to:Regression coverage
test_automatic_loading_after_restartload_state()test_explicit_loading_after_restartcheckpoint_0supplied by pathBoth tests save twice with
total_limit=2, rebuild the accelerator, load, train, and save. They check that the next save ischeckpoint_2, then rebuild again and verify that the newly saved parameters are restored.Both tests cover PyTorch and safetensors model serialization.
Validation
tests/test_state_checkpointing.py: 22 passed locally, including both new tests in both serialization formats.git diff --checkpass.Tested on Accelerate
mainatf47439c, Python 3.12.13, PyTorch 2.15.0, macOS arm64, CPU.Before submitting
Reproduction
Runnable example and observed output before the fix
mainatf47439c(1.16.0.dev0).Observed output before the fix: