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.
Fixes #6549.
Problem
General sharded optimizer loading restores parameter groups and accumulates state with
optimizer.state.update(...), but it never removes the destination optimizer's earlier state. Parameters absent from a checkpoint retain stale momentum or Adam moments. In a native reproduction, saving a checkpoint before the first SGD step, accumulating momentum, then restoring that checkpoint makes the next update produce 0.81 instead of 0.9.Changes
After the saved parameter groups pass compatibility validation and the parameter mapping is built, replace the destination state with a fresh
defaultdict(dict). This happens once before loading the shards, so successive shards continue to accumulate normally. Incompatible groups still raise before changing existing groups or state.Validation
Base:
297c8cf6d91cb0bff795cba961d3aea1e66fa370.GeneralCheckpointIO.save_optimizer/load_optimizertests restore real on-disk empty-state sharded checkpoints into already-trained SGD, Adam and AdamW optimizers, covering one/two parameter groups and float32/float64. Three subsequent updates match nativeOptimizer.load_state_dictexactly for parameters and every state tensor.git diff --checkpassed.Command:
Validated on Linux/Python 3.12 and PyTorch 2.15.0+cpu. Legacy-format cases follow the repository's PyTorch >=2.10 requirement. All 25 new tests run without replacing accelerator methods. Two existing nonempty-shard cases use their existing
cpu_syncfixture because the CPU accelerator does not implementsynchronize(); this is not a claim of complete native GPU or distributed checkpoint validation. The full repository suite was not run.