Repository navigation
Conversation
__init__ derives config, _preprocessor and _optimizer_type from the three config parameters, but set_params() only re-derived them when a config object replaced another one. On a default-constructed estimator (as cloned by GridSearchCV) a config object set through set_params() was ignored by fit(), and setting a config back to None kept the previous configuration. Both code paths now share one helper. Fixes #513
ChrisW09
force-pushed
the
fix/set-params-config-sync
branch
from
October 21, 2026 22:44
de29b2f to
a448034
Compare
This branch has not been deployed
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 #513
Problem
__init__derives the statefit()reads from the three config parameters: the architecture config frommodel_config(self.config), the preprocessor frompreprocessing_config(self._preprocessor,self._preprocessor_kwargs) and the optimizer fromtrainer_config(self._optimizer_type).SklearnBase.set_params()re-derived this state only when a config object replaced the config of an estimator that already held one. As a result:set_params()were stored but never trained.GridSearchCVclones such an estimator for every candidate, so searches overmodel_configobjects trained the default architecture.set_params(model_config=None),preprocessing_config=Noneortrainer_config=Nonekept the previous architecture, preprocessing and optimizer, and with all three set toNone,clone()raisedValueError.Fix
deeptab/models/base.py: a newSklearnBase._set_config_param(name, value)assigns one of the three config parameters and re-derives the statefit()reads from it, as__init__does:config/_config_kwargs, rebuilds the preprocessor from thePreprocessingConfig, or takes theTrainerConfig's optimizer;None(replacing a config) restores the defaults of an estimator constructed without it: the default model config, the default preprocessor with empty_preprocessor_kwargs, andAdam.Both branches of
set_params()use it. The legacy branch, which default-constructed estimators take, therefore keeps accepting flat keys such aslayer_sizesnext to a config object in the same call. Objects that aren't DeepTab configs are stored unchanged, as before. Theset_paramsdocstring says that assigning a config updates whatfit()trains with.Tests
tests/models/test_estimator_configuration.py::TestSetParamsConfigsReachFit:test_model_config_on_default_estimator_is_trainedtest_trainer_and_preprocessing_configs_on_default_estimatortest_grid_search_over_model_config_objects_trains_selected_configtest_setting_configs_to_none_restores_defaults(includingclone()afterwards)test_flat_keys_still_apply_next_to_a_config_object:MLPRegressor().set_params(trainer_config=..., layer_sizes=[4])keeps working.The first four fail on
mainand pass with this change. The last one passes onmaintoo and guards that behaviour.A related defect with its own cause,
model_config__*keys being dropped when the estimator has nomodel_config, is #613 (fixed in #614); the two PRs merge cleanly.Checks
just test: 3241 passed, 46 skipped, 28 xfailed; coverage 91.32%just docs: build succeeded (warnings treated as errors)just check: all hooks passed (ruff, prettier, pyright)