Repository navigation
fix(models): score the in-memory model without reloading the checkpoint - #504
Merged
Merged
Conversation
_PredictMixin._score (used by the regressors' score()) loaded the best checkpoint from disk into the task model before predicting. fit() has already restored that checkpoint, so the reload only made score() fail with FileNotFoundError once the checkpoint directory was removed and silently replaced any weights changed after fitting. Score the current model, like predict() and the classifiers' score(). Fixes #503
mkumar73
approved these changes
Nov 30, 2026
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 #503
Problem
_PredictMixin._score, which backsSklearnBaseRegressor.score(), loaded_best_model_pathfrom disk into the task model before predicting.fit()already restores that checkpoint before returning, so the reload added nothing and caused two problems:score()raisedFileNotFoundErroronce the checkpoint directory had been removed, even thoughpredict()worked.score()silently replaced any weights changed afterfit()with the checkpoint's.Fix
_scorenow just predicts with the current model and applies the metric, the same aspredict(),evaluate()and the classifiers'score(). The docstring now describes this.Tests
tests/integration/test_fit_lifecycle.py::TestRegressorScoreUsesCurrentModel:test_score_works_after_checkpoint_directory_is_removedtest_score_does_not_replace_current_weights:score()equals the R² of the current predictions, and predictions are unchanged afterwards.Both fail on
mainand pass with this change.Docs
The
_scoredocstring and the_PredictMixinoverview, which still said_scorereloads the best checkpoint foroptimize_hparams, are updated. No user-facing page described the reload.Checks
just test: 3238 passed, 46 skipped, 28 xfailed; coverage 91.29%just docs: build succeeded (warnings treated as errors)just check: all hooks passed (ruff, prettier, pyright)