fix(training): checkpoint the metric the user asked to monitor - #432
Open
ChrisW09 wants to merge 2 commits into
Open
fix(training): checkpoint the metric the user asked to monitor#432ChrisW09 wants to merge 2 commits into
ChrisW09 wants to merge 2 commits into
Conversation
EarlyStopping honored fit(monitor=..., mode=...) but ModelCheckpoint was hardcoded to val_loss/min -- and the best checkpoint's weights are restored at the end of fit(), so a user monitoring val_acc still got the best-val-loss weights, silently. Both callbacks now track the same metric, in the fit mixin and in SklearnBaseLSS. Fixes #425 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
model._trainer is typed Trainer | None, which pyright will not let us index for .callbacks. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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 #425
Problem
EarlyStoppingis built with the user'smonitor/mode, butModelCheckpointwas hardcoded:Since the best checkpoint's weights are restored at the end of
fit(),fit(monitor="val_acc", mode="max")stopped on accuracy but returned the best-val-loss weights — silently, with no warning and nothing in the docstrings about the divergence. The same pattern existed inSklearnBaseLSS.fit.Fix
Both callbacks now receive the same
monitor/mode, in_FitMixin.fitandSklearnBaseLSS.fit.Tests
New
tests/test_checkpoint_monitor.py: a recordingModelCheckpointsubclass asserts the constructor receives the user's monitor/mode (parametrized over the default and a non-default metric), plus a test that the liveEarlyStoppingandModelCheckpointcallbacks agree after a fit.tests/test_save_load.pystill passes.🤖 Generated with Claude Code