Repository navigation
Conversation
ScoringBase.on_train_begin picks up the best score from a loaded history, but PassthroughScoring (which records the default train_loss and valid_loss) did not. After load_params(f_history=...) and partial_fit, the first new epoch was therefore always flagged as valid_loss_best, even when it was worse, so a Checkpoint monitoring valid_loss_best would overwrite the better checkpoint. Move the lookup into a shared helper and call it from both callbacks.
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.
ScoringBase.on_train_begin(#268) picks up the best score from the history, soEpochScoring/BatchScoringkeep track of it when training continues from a loaded history.PassthroughScoringhas no such hook. It is what records the defaulttrain_lossandvalid_loss, so afterits
best_score_starts again frominf, and the first new epoch is flaggedvalid_loss_best=Truewhatever its value. ACheckpointwith the defaultmonitor='valid_loss_best'then overwrites the better checkpoint.Repro (5 epochs, then one more epoch with a learning rate that is far too high):
On master, the resumed epoch has
valid_loss1.27 against a previous best of 0.22. Even so,valid_loss_bestisTrue, whileneg_log_loss_best(anEpochScoring) is correctlyFalse. With this change both areFalse.Change: I moved the lookup from
ScoringBase.on_train_begininto a small helper,_best_score_from_history, and call it from a newPassthroughScoring.on_train_begin.ScoringBasebehaves as before.Tests: I added
TestPassthrougScoring::test_uses_best_score_when_continuing_training, which mirrors the existingEpochScoring/BatchScoringtest of the same name with the same score sequence and expected flags. On master, 5 of its 8 cases fail.skorch/tests/callbacks/,test_net.pyandtest_classifier.pypass locally, except the twoTestTorchCompiletests, which also fail on master with my local torch 2.2.2.I also added a CHANGES.md entry under Fixed.