Repository navigation
Preserve best-validation model weights during later training - #256
Open
davrens101 wants to merge 1 commit into
Open
davrens101 wants to merge 1 commit into
davrens101 wants to merge 1 commit into
Conversation
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 5 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
This branch has not been deployed
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.
Problem
Trainer.save_checkpointsaves the correct best-energy checkpoint to disk, but setsself.best_model = self.model. Later optimizer updates mutate that same object. Consequently,get_best_model()returns the latest weights rather than the weights with the lowest validation energy MAE.A real CHGNet energy-training step reproduces the discrepancy: the saved best model predicts -3.002830982 eV/atom, while the API returns the later model predicting -2.573733807 eV/atom, after a worse validation epoch.
Change
Snapshot the model only when the best-energy checkpoint is selected. Retrieving the best model does not copy it again or reload a file. Keep the existing validation-selection rule, checkpoint format and public API.
The regression covers subsequent weight updates, a worse validation epoch and a later improvement replacing the stored snapshot.
Verification
CPU, Python 3.12, PyTorch 2.15.0+cpu:
tests/test_trainer.py: 6 passed, including the new multi-epoch regression and existing training/checkpoint tests (W&B offline).No GPU validation is claimed.
Review and assistance
Human review: davrens101 confirmed reviewing the work live before submission. AI assistance was used for investigation, implementation and verification. No maintainer review or approval is claimed.