Skip to content

fix(finetuning): thread keep_existing_predictor through sklearn wrappers - #86

Merged
dahvida merged 1 commit into
mainfrom
feature/issue-85-keep-existing-predictor-sklearn
Aug 19, 2026
Merged

fix(finetuning): thread keep_existing_predictor through sklearn wrappers#86
dahvida merged 1 commit into
mainfrom
feature/issue-85-keep-existing-predictor-sklearn

Conversation

@dahvida

@dahvida dahvida commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds keep_existing_predictor: bool = True to BaseFinetuner.reload_pretrained, FinetuningRegressor.__init__, and FinetuningClassifier.__init__, forwarding the value to both Finetuner(...) construction sites so that configs setting the flag (including matcha evaluate) no longer hit TypeError at the sklearn front door.
  • Guards the Chemprop branch: reload_pretrained raises ValueError when keep_existing_predictor=False is set with a Chemprop pretrained model, since ChempropFinetuner has no notion of a stripped predictor. The default True passes through unchanged.
  • Adds TestKeepExistingPredictorForwarding in tests/sklearn_misc/test_finetuner.py (10 parametrized tests) covering construction with True/False, hparams forwarding to the underlying torch module, an end-to-end fit+predict smoke test, and both branches of the Chemprop guard.
  • The tabular MLP encoder is excluded from keep_existing_predictor=False parametrizations: its leaf encoder has no fp_dim attribute, 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.
  • Manual smoke: FinetuningRegressor(path=..., keep_existing_predictor=False) on a saved GIN/CNN pretrained model constructs without TypeError.

Fixes #85


Generated with Claude Code

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>
@dahvida
dahvida merged commit eac4a6e into main Aug 19, 2026
5 checks passed
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.

keep_existing_predictor kwarg not threaded through sklearn FinetuningRegressor/FinetuningClassifier

1 participant