Skip to content

fix(training): checkpoint the metric the user asked to monitor - #432

Open
ChrisW09 wants to merge 2 commits into
mainfrom
fix/checkpoint-monitor
Open

fix(training): checkpoint the metric the user asked to monitor#432
ChrisW09 wants to merge 2 commits into
mainfrom
fix/checkpoint-monitor

Conversation

@ChrisW09

Copy link
Copy Markdown
Collaborator

Fixes #425

Problem

EarlyStopping is built with the user's monitor/mode, but ModelCheckpoint was hardcoded:

early_stop_callback = EarlyStopping(monitor=monitor, ..., mode=mode)
checkpoint_callback = ModelCheckpoint(monitor="val_loss", mode="min", ...)

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 in SklearnBaseLSS.fit.

Fix

Both callbacks now receive the same monitor/mode, in _FitMixin.fit and SklearnBaseLSS.fit.

Tests

New tests/test_checkpoint_monitor.py: a recording ModelCheckpoint subclass asserts the constructor receives the user's monitor/mode (parametrized over the default and a non-default metric), plus a test that the live EarlyStopping and ModelCheckpoint callbacks agree after a fit. tests/test_save_load.py still passes.

🤖 Generated with Claude Code

ChrisW09 and others added 2 commits July 27, 2026 21:26
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] EarlyStopping honors monitor/mode but ModelCheckpoint (and weight restore) is hardcoded to val_loss/min

1 participant