fix(finetuning): thread keep_existing_predictor through sklearn wrappers - #86
Merged
Merged
Conversation
The keep_existing_predictor flag added in 0.0.22 was only accepted by Finetuner. FinetuningRegressor, FinetuningClassifier, and BaseFinetuner.reload_pretrained rejected it with TypeError, blocking matcha evaluate configs and any user code driving the sklearn API. Wire the kwarg through the sklearn signatures, forward it to both Finetuner(...) construction sites in reload_pretrained, and reject non-default values on the Chemprop branch — ChempropFinetuner has no notion of a stripped predictor. Closes #85. Co-Authored-By: Claude <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.
Summary
keep_existing_predictor: bool = TruetoBaseFinetuner.reload_pretrained,FinetuningRegressor.__init__, andFinetuningClassifier.__init__, forwarding the value to bothFinetuner(...)construction sites so that configs setting the flag (includingmatcha evaluate) no longer hitTypeErrorat the sklearn front door.reload_pretrainedraisesValueErrorwhenkeep_existing_predictor=Falseis set with a Chemprop pretrained model, sinceChempropFinetunerhas no notion of a stripped predictor. The defaultTruepasses through unchanged.TestKeepExistingPredictorForwardingintests/sklearn_misc/test_finetuner.py(10 parametrized tests) covering construction withTrue/False,hparamsforwarding to the underlying torch module, an end-to-end fit+predict smoke test, and both branches of the Chemprop guard.keep_existing_predictor=Falseparametrizations: its leaf encoder has nofp_dimattribute, which is a pre-existing torch-level limitation independent of this plumbing fix.Test plan
uv run pytest tests/sklearn_misc/test_finetuner.py -k 'not gpu'— full suite green (126 tests, incl. 10 new ones).uv run pytest tests/torch/models/finetuning/test_finetuner_nested_encoder.py -k 'not gpu'— existing torch-level tests unaffected (20 tests).uv run pre-commit run --files src/matcha/sklearn/finetuner.py tests/sklearn_misc/test_finetuner.py— ruff, ruff-format, pyright all clean.FinetuningRegressor(path=..., keep_existing_predictor=False)on a saved GIN/CNN pretrained model constructs withoutTypeError.Fixes #85
Generated with Claude Code