Repository navigation
Check metric constraints when the constrained metric is exactly zero - #1671
Sohail Shaikh (sohailshk) wants to merge 7 commits into
Conversation
BlendSearch.on_trial_complete() read the constrained metric with 'if value:', so a reported value of 0 (for example recall 0.0 against recall >= 0.5) skipped the constraint and the trial was treated as feasible. Only skip when the metric is missing.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the change to check zero-valued metrics against tuning constraints.
No open issues 🎉
What changed in this PR
This PR fixes FLAML’s tuning constraint handling so zero-valued metrics are checked rather than skipped, complementing the zero-metric reporting fix in #1603.
Changes:
- Replace the truthiness check with an explicit
Nonecheck when applying metric constraints. - Add a regression test verifying that zero-recall violations lower maximized scores while feasible trials retain their raw scores.
| File | Description |
|---|---|
test/tune/test_metric_constraint_zero.py |
Tests penalties for zero-valued constraint violations and unchanged scores for feasible trials. |
flaml/tune/searcher/blendsearch.py |
Applies constraint checks to zero-valued metrics. |
Review effort: Balanced
Li Jiang (thinkall)
left a comment
There was a problem hiding this comment.
The zero-valued metric presence check was independently reviewed with review-code (Low, actual gpt-6.2-astra at max reasoning). The regression passes on native Python 3.10 and 3.13 and fails on exact main. The retained low-priority finding is test determinism: seed explicit points on both sides of the recall boundary rather than requiring the optimizer's first 20 suggestions to cover both. No production correctness regression was identified in this single-line correction.
No PR approval submitted. Whole required review evidence, resolved threads, explicit current-head Balanced Copilot approval and every applicable check/context and actual workflow must all pass. At this guarded readback, non-successful actual runs: [{"name": "Build", "status": "in_progress", "conclusion": null}]. No foreign thread was resolved and no earlier review was dismissed.
Posted by thinkall-agent-auto-reviewer
|
Thanks for the review, thinkall. I've addressed the low-priority feedback about test determinism and pushed the update in commit
This removes the dependency on search behavior to determine which configurations get evaluated.
This confirms that the test detects the original issue and behaves deterministically with the fix. |
Li Jiang (thinkall)
left a comment
There was a problem hiding this comment.
The deterministic float-zero test passes, but the full PR still mishandles unsigned zero metrics on NumPy 2.
P2: a feasible np.uint8(0) count can be penalized, and the opposite constraint can stop trial completion. In actual sequential tune.run, metric errors=np.uint8(0) with integer threshold 1 and <= changes score 5 to -2549999999995. With >=, completion raises OverflowError: Python integer -1 out of bounds for uint8. The raw recorded metric remains uint8. Float controls and NumPy 1.26 behave correctly.
The preceding PR head has the same issue; exact main leaves the valid <= score unchanged but incorrectly skips the violating >= check. This is a remaining full-PR regression from exposing zero to fixed-width arithmetic, not a defect introduced by the latest test rewrite. Please normalize NumPy integer operands before subtraction/multiplication and cover both constraint directions with unsigned zero.
Posted by thinkall-agent-auto-reviewer
…arithmetic A metric stored as an unsigned numpy integer (for example np.uint8(0)) wrapped around or overflowed in (value - threshold), so a feasible zero count was penalized and the opposite constraint direction raised OverflowError on NumPy 2.
…nt difference cannot wrap
|
Fixed thinkall's
Tests: With NumPy 2.5.5, 27 tests pass, compared with 12 failures using the earlier source. |
Li Jiang (thinkall)
left a comment
There was a problem hiding this comment.
Whole-PR review at 7cdc8269a736ef6a900509e3b3d4f9f885d0493b: two dtype combinations still produce incorrect penalty-adjusted scores in actual NumPy 2 Tune runs.
errors=np.array(0, dtype=np.uint8), constrained to<= 1, withscore=5receives2550000000005.0instead of5.0. The metric-side conversion misses zero-dimensional arrays. Current and predecessor reproduce it; main does not. This is a remaining whole-PR regression, not newly introduced by this correction.score=np.float16(5)witherrors=np.float64(2)constrained to<= 1now produces infinity instead of10000000005.0. The current.item()conversion changes promotion during penalty addition; predecessor/main remain finite. This is new in the latest correction.
NumPy 1.26 and Python-float objective controls remain finite. Normalize zero-dimensional metric operands consistently with thresholds, and normalize the local objective before penalty addition without changing the raw reported score. Add these exact regression cases.
The targeted current suites passed 54 tests, but do not cover these combinations. The Low skill verdict remains issues found despite successful workflows and the Balanced approval recommendation. Evidence remains local only.
Posted by thinkall-agent-auto-reviewer
…the constraint penalty A 0-d unsigned array was not converted like an unsigned scalar and wrapped around in the violation. A float16 objective overflowed to infinity when the penalty was added; the objective is now a Python number for the arithmetic and the reported result is unchanged.
A 1-d array with one element was not converted and wrapped around like an unsigned scalar in the constraint violation.
Why are these changes needed?
BlendSearch.on_trial_complete()applies the penalty onlyif value:, so a reported 0 / 0.0 skipped the constraint: withmetric_constraints=[("recall", ">=", 0.5)]a trial reportingrecall=0.0was treated as feasible (its lagrange objective equal to the raw objective). Now the constraint is skipped only when the metric is missing (if value is not None).Test: recall is 0.0 above x=5 with
mode="max"; infeasible trials must get a lagrange-modified score below the raw score, feasible ones the raw score. It fails on main (7.71 < 7.71) and passes now.Related issue number
Same pattern as #1603 (FLOW2 /
tune.report); this check was not part of it.Checks
Checks run: the new test, the tune/automl constraint tests and test_tune/test_lexiflow (9 passed, 1 skipped); black (line length 120) and ruff on the changed files. The pinned pre-commit hook versions were not run. No doc changes are needed.