Repository navigation
Support config_constraints in AutoML - #1670
Ankit Dhandharia (ankitdhandharia) wants to merge 3 commits into
Conversation
|
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
🟡 Changes recommended
Estimator constraints are inconsistently enforced across search methods, strict < checks incorrectly allow equality, and infeasible initialization can prevent discovery of valid models.
3 open issues
What changed in this PR
Adds an estimator-level configuration-constraint hook to AutoML, extending Tune’s existing constraint mechanism toward the support requested in #840.
Changes:
- Adds optional
BaseEstimator.config_constraints(), returning no constraints by default. - Combines estimator constraints with memory limits in sequential and joint searches, with learner-specific dispatch for joint configurations.
- Adds a sequential regression test checking that the best and all logged configurations satisfy an estimator-count limit.
| File | Description |
|---|---|
test/automl/test_constraints.py |
Adds a constrained custom-estimator regression test. |
flaml/automl/model.py |
Defines and documents the optional estimator constraint hook. |
flaml/automl/automl.py |
Registers estimator constraints and adds joint-search dispatch helpers. |
Review effort: Balanced
| max_resource=max_resource, | ||
| config_constraints=[(learner_class.size, "<=", self._mem_thres)], | ||
| config_constraints=[(learner_class.size, "<=", self._mem_thres)] | ||
| + list(learner_class.config_constraints()), |
There was a problem hiding this comment.
Fixed in 27fa648. If an estimator's default (low-cost) starting config violates its constraints, SearchState now samples the search space. It uses the feasible config closest to the default (in normalized space) as both the initial point and the low-cost partial config. User starting points that violate the constraints are dropped with a warning, the same way out-of-space starting points already are. Because sequential and joint search both take their starting points from SearchState, this covers both. With n_estimators >= 16, the search now starts at about 21 trees instead of never training. There are tests for the sequential path (all hpo_methods) and the joint path (test_config_constraints_joint_search, spark, cfo/bs).
| config_constraints=[(learner_class.size, "<=", self._mem_thres)] | ||
| + list(learner_class.config_constraints()), |
There was a problem hiding this comment.
Fixed in 27fa648. AutoMLState._compute_with_config_base now checks the estimator's config_constraints() before training. A violating config is reported with val_loss=inf and never fitted, the same way the parallel path already handles the memory constraint. Every hpo_method goes through this check, in both sequential and joint search. RandomSearch also resamples (up to 100 draws) until it gets a config that satisfies the constraints, so it doesn't waste iterations. test_config_constraints_enforced covers cfo/bs/random/optuna with <=, < and >= constraints, and asserts on every config that reaches fit().
| Returns: | ||
| A list of ``(function, operator, threshold)`` tuples, where | ||
| ``function`` maps a hyperparameter-config dict to a float, | ||
| ``operator`` is one of ``"<="``, ``">="``, ``"<"`` or ``">"``, |
There was a problem hiding this comment.
Fixed in 27fa648. The comparison is now a shared config_constraints_violated helper in blendsearch.py, and "<" rejects value >= threshold. test_config_constraint_boundary checks all four operators at the threshold, and also checks that tune.run skips the boundary point x=16 for x < 16.
Li Jiang (thinkall)
left a comment
There was a problem hiding this comment.
Confirmed a current-head estimator-constraint bypass with actual public AutoML/Optuna and native LightGBM fits. A LGBMEstimator subclass whose config_constraints() returns [(lambda config: config["n_estimators"], "<=", 4)], a feasible cap present in the search space, and hpo_method="optuna", max_iter=3, n_jobs=1 trained configurations entering fit with tree counts 6 and 13; its best config also had n_estimators=6. The new constraint API therefore is not consistently enforced across the supported search methods. Please enforce the constraints for those methods, or explicitly reject/document unsupported methods rather than silently violating them. This confirms one of Copilot's existing concerns; the other peer concerns and threads remain separate and unresolved.
The proposed single-learner default-search test passes on both native stacks when run serially. Its first two failures were caused by this validation runner writing the same training-log filename concurrently; those original outputs and the serial recovery are retained and are not presented as a contributor-code regression. An earlier cap-16 Optuna probe happened to draw only feasible values and did not discriminate the issue; it is also retained. The cap-4 run used actual model fitting, not a mocked searcher or a full optional/distributed matrix.
The required Medium independent review-code lens batch is still running; no complete six-lens or clean whole-PR signoff is claimed at this point. These driver-confirmed P2 findings justify the changes request independently of pending CI. No approval is submitted and no earlier review was dismissed.
Posted by thinkall-agent-auto-reviewer
- Skip configs that violate an estimator's config_constraints before training, so search methods that don't enforce them (optuna, random) can't train an infeasible config. Applies to sequential and joint search. - RandomSearch resamples until a config satisfies the constraints. - Treat '<' as strict: a value equal to the threshold now violates it. - If the default (low-cost) starting config violates the constraints, start from the nearest feasible sampled config instead of stalling; drop user starting points that violate them. - Add regression tests for all hpo_methods, the strict boundary, starting points and joint search with spark.
|
Li Jiang (@thinkall) Thanks for the review. Your Optuna reproduction (
Tests:
Nine of the new tests fail on the previous commit, as do both spark joint-search tests. Locally the new tests pass, along with the tune and automl constraint, searcher, warm-start and log tests (66 passed) and the existing spark custom-learner test. |

Why are these changes needed?
flaml.tunehas long supportedconfig_constraints, but AutoML ignored them: both search-construction paths inflaml/automl/automl.pybuilt the searcher'sconfig_constraintsfrom a single hard-coded memory-size constraint and offered no way for a user or a custom estimator to constrain which hyperparameter configurations are explored.This adds the optional, maintainer-proposed hook
BaseEstimator.config_constraints()(default[]), which an estimator can override to declare constraints in the existing tuneconfig_constraintssyntax — a list of(function, operator, threshold)tuples, with operators<=,>=,<,>. AutoML now merges each estimator's constraints with the memory-size constraint:learner_class.config_constraints()directly (the constraint function receives the raw single-estimator config).sizedispatch), leaving other learners unconstrained.There is no behavior change for estimators that don't override the method (they return
[]). Configs that violate a constraint are skipped during search by the existing BlendSearch constraint-checking logic (_violate_config_constriants), so they are never trained.Related issue number
Closes #840
Checks
Testing
Added a regression test
test_config_constraintsintest/automl/test_constraints.py. It registers a custom estimator subclassingLGBMEstimatorwhoseconfig_constraintscapsn_estimators <= 16, fits AutoML on syntheticmake_classificationdata (n_jobs=1, the sequential search path), and asserts both thatbest_config["n_estimators"] <= 16and that every trained/logged config satisfies the constraint (read back from the training log).python -m pytest test/automl/test_constraints.py::test_config_constraints -q→ 1 failed (AutoML never consulted the hook, so configs withn_estimatorsup to 41 were trained;assert 41 <= 16failed).python -m pytest test/automl/test_constraints.py::test_config_constraints -q→ 1 passed.python -m pytest test/automl/test_constraints.py -q→ 3 passed (the two existing metric-constraint tests plus the new one).python -m pytest test/automl/test_classification.py -q -k "multiclass or binary or custom_learner or lrl1"→ 3 passed.