feat: enable immediate saving on UI stop and enhance optimizer state backup#727
Open
avan06 wants to merge 2 commits intoostris:mainfrom
Open
feat: enable immediate saving on UI stop and enhance optimizer state backup#727avan06 wants to merge 2 commits intoostris:mainfrom
avan06 wants to merge 2 commits intoostris:mainfrom
Conversation
- Modified maybe_stop in DiffusionTrainer to trigger self.save() when a stop signal is detected. - Added _is_saving flag to manage saving state and prevent infinite recursion during emergency saves. - Ensures LoRA weights, Metadata, and optimizer state are synchronized at the exact exit step. - Enables users to resume training from the precise interruption point instead of rolling back to the last scheduled save.
Now maintains a backup of the previous optimizer state. When saving, the current optimizer.pt is moved to optimizer_prev.pt rather than being overwritten.
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.
This PR improves the training interruption workflow by ensuring that training progress is captured immediately when a user requests a stop via the UI. It also introduces a backup mechanism for the optimizer state to provide users with more flexibility when resuming or rolling back training.
Key Changes
Immediate Save on UI Stop (DiffusionTrainer)
Modified maybe_stop to trigger self.save() as soon as a stop signal is detected.
Added a _is_saving flag to manage the saving state, preventing infinite recursion or redundant calls during emergency saves.
Benefit: Users can now resume training from the precise step of interruption rather than being forced to roll back to the last scheduled checkpoint. This ensures LoRA weights, Metadata, and optimizer states are perfectly synchronized at the exit point.
Optimizer State Rotation (BaseSDTrainProcess)
Implemented a backup system for the optimizer state. When saving, the existing optimizer.pt is moved to optimizer_prev.pt instead of being directly overwritten by the new state.
Example Scenario (How to roll back)
If a user decides they prefer the results from a previous scheduled save over the final interrupted save:
These changes have been verified in a local environment and are confirmed to be working as intended.