Skip to content

fix: keep unordered categorical choices intact in FLOW2 local search - #1680

Open
Anish Mehta (anishmehta24) wants to merge 2 commits into
microsoft:mainfrom
anishmehta24:fix/unordered-categorical-choice
Open

Anish Mehta (anishmehta24) wants to merge 2 commits into
microsoft:mainfrom
anishmehta24:fix/unordered-categorical-choice

Conversation

@anishmehta24

Copy link
Copy Markdown
Contributor

Why are these changes needed?

When FLOW2 moves an unordered categorical away from the incumbent, denormalize picks the new value with random_state.choice(...) on the remaining categories. NumPy turns that list into an array first, so:

  • tuple choices such as tune.choice([(1, 2), (3, 4), (5, 6)]) or tune.choice([(16,), (32,), (16, 16)]) raise ValueError (a must be 1-dimensional / inhomogeneous shape), which stops tune.run with CFO or BlendSearch;
  • mixed choices get cast to one dtype: ["sqrt", "log2", 0.5] gives the string '0.5', and [True, False, "auto"] gives the string 'False'.

It now draws an index and returns the category itself, as Categorical sampling in sample.py already does. For a given seed the same category is picked as before.

Related issue number

None found.

Checks

test/tune/test_unordered_categorical.py calls denormalize with the four category lists above and runs CFO on the two tuple spaces; all 6 cases fail on main and pass with the change. pytest test/tune passes (test_no_optuna deselected: it calls pip uninstall and fails the same way on main in my venv).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the change preserving tuple values and mixed Python types in categorical choices.

No open issues 🎉

What changed in this PR

This PR fixes FLOW2’s handling of unordered categorical choices, preserving tuple values and mixed Python types during local search.

Changes:

  • Selects an alternative category by index to avoid NumPy array conversion.
  • Adds regression tests for tuple and mixed-type choices, plus CFO integration tests for tuple search spaces.
File Description
test/​tune/​test_unordered_categorical.py Tests category value/type preservation and CFO exploration of tuple choices.
flaml/​tune/​space.py Samples an index and returns the original category without coercion.

Review effort: Balanced

@thinkall Li Jiang (thinkall) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whole-PR Low review at b4ae289722110f0e64d0d1364359c6fa99ab0932: category-index selection preserves tuple and heterogeneous category values. Targeted suites passed 12 tests versus 12 expected failures on the main control.

One low-priority test-setup issue remains: a preconstructed CFO() ignores low_cost_partial_config passed only to tune.run. Both native stacks retain an empty init config and start at a sampled x, not the declared x=0. Use CFO(low_cost_partial_config={"x": 0}) and remove the ignored run argument.

Approval is also blocked by the actual Ubuntu 3.12 Build failure: 42 failed, 549 passed and 13 skipped, with YAML parser errors reading generated MLflow mlruns/.../meta.yaml. Those failures were not attributed to this category patch without a reproducing control, and were not ignored or rerun. A Balanced approval recommendation does not replace successful CI.

The original issue-found verdict and local evidence are retained; no review outputs were pushed to this PR.

Posted by thinkall-agent-auto-reviewer

@anishmehta24

Copy link
Copy Markdown
Contributor Author

Changed the test to CFO(low_cost_partial_config={"x": 0}) and dropped the run argument in 0af0e78. From x=0 a continuous x never moved the tuple choice within 30 trials, so x is now tune.randint(0, 10) and the exact trial count check is gone.

The 3.12 failures all read one broken mlruns/.../meta.yaml that was already failing test/spark/test_tune.py, which runs before this test file. The new push starts a fresh CI run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues blocking the fix for preserving unordered categorical values during local search.

No open issues 🎉

Review effort: Balanced

@thinkall Li Jiang (thinkall) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whole-PR review at 0af0e78db6d66d8730d7051f08ca51bfd8904480 is clean. The CFO regression now configures its integer low-cost starting point through the constructor. The finite search visits multiple valid tuple categories without incorrectly requiring all 30 requested evaluations to complete.

Both native stacks pass the six targeted cases (12 passes total), and the real fixture starts at x=0. The same new tests produce 12 expected failures on explicitly source-verified unmodified main. The original unpinned-main positives were not accepted as baseline proof. This is targeted validation, not a full optional-dependency or supported-version matrix.

All-files pre-commit passed. The current-head Balanced Copilot review explicitly recommends approval, all threads are resolved, applicable checks are successful, and actual current-head Build, docs and formatting workflow runs completed successfully. The docs release-only job is explicitly disabled for pull requests by its verified source condition; no pending or unsuccessful workflow is ignored.

Approved. Review evidence is retained only in a detached local worktree and was not pushed to this PR.

Posted by thinkall-agent-auto-reviewer

This branch has not been deployed

No deployments
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.

3 participants