镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

fix: keep suggested configs independent of the portfolio - #1632

Merged
Li Jiang (thinkall) merged 5 commits into
microsoft:mainfrom
ktz03:fix/default-config-copy
Oct 19, 2026
Merged

Li Jiang (thinkall) merged 5 commits into
microsoft:mainfrom
ktz03:fix/default-config-copy

Conversation

@ktz03

Copy link
Copy Markdown
Contributor

Why are these changes needed?

suggest_config() returns dictionaries from the cached configuration portfolio. Updating a suggested hyperparameter therefore changes later suggestions in the same process. It also removes FLAML_sample_size directly from a caller-provided predictor.

Copy each selected configuration before removing the sample-size key. This keeps the existing selection and returned values while allowing callers to customize a suggestion without changing the predictor or subsequent calls.

For example, using the bundled random-forest regression portfolio:

import numpy as np
from flaml.default import suggest_config

X = np.arange(40).reshape(20, 2)
y = np.arange(20)
config = suggest_config("regression", X, y, "rf", k=1)[0]
original = config["hyperparameters"]["n_estimators"]
config["hyperparameters"]["n_estimators"] = 1
again = suggest_config("regression", X, y, "rf", k=1)[0]
assert again["hyperparameters"]["n_estimators"] == original

The assertion fails before this change: the second call returns the caller's 1 instead of the portfolio's 960.

Related issue number

No existing issue; the reproducer is above.

Checks

Local validation on Windows with Python 3.12.14, NumPy 1.26.4, pandas 3.0.6 and scikit-learn 1.9.1:

  • Nine new regression cases fail on the unchanged base and pass with the fix, covering four bundled estimators for regression/classification and a caller-provided predictor with nested values.
  • Four existing related tests pass on both versions: portfolio generation, classification suggestions, Iris AutoML and zero-budget defaults. The combined run is 9 failed/4 passed on the base and 13 passed with the fix; eight unrelated tests are deselected. Both versions retain existing pandas deprecation and estimator convergence warnings.
  • Public calls across the eight bundled estimator/task combinations retain the same unmodified suggestions, selection order, k=1 prefix and empty k=0 result.
  • pre-commit run --all-files: all 15 checks pass on both the pristine base and the candidate.
  • Coverage was measured for flaml/default using the same 13 selected tests; the covered fraction does not decrease. This is focused coverage, not a full-project result.
  • The complete optional-dependency test suite and documentation build were not 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

The focused fix preserves selection behavior and includes targeted regression coverage, with no unresolved findings.

No open issues 🎉

What changed in this PR

Prevents callers from modifying FLAML’s cached portfolio or caller-provided predictors through suggested configurations.

Changes:

  • Deep-copies selected configurations before removing FLAML_sample_size.
  • Documents that returned configurations can be safely modified.
  • Adds regression coverage for bundled estimators and nested caller-provided values.
File Description
test/​default/​test_defaults.py Adds tests for suggestion independence and predictor preservation.
flaml/​default/​suggest.py Copies selected configurations and documents mutation safety.

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.

Overall review of the complete PR: no blocking code issue found; approval withheld pending CI.

Deep-copying each selected portfolio entry before sample-size removal protects both cached and caller-supplied predictors, including nested mutable values, without changing selection order or the result structure. The focused regression command passed 9 tests locally. The review-code harness is clean and Copilot's current Balanced review recommends approval with no open issues. However, the current head has failing build checks, so it does not meet the required all-CI-passed approval gate. This is a formal comment review, not an approval.

Posted by thinkall-agent-auto-reviewer

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

The focused fix preserves selection behavior and includes targeted regression coverage, with no unresolved findings.

No open issues 🎉

Review effort: Balanced

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

The localized fix preserves selection behavior and includes targeted regression coverage, with no blocking issues identified.

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.

Overall review at 3b7f286e1a117bb3eba8fe34125ccfe386b8bb93: re-reviewed the complete PR with review-code, including the copy boundary, predictor cache, caller-owned nested values, and downstream configuration consumers. Copying each selected portfolio entry before cleanup prevents mutations from leaking into later suggestions while preserving selection order and the returned configuration shape. No remaining correctness issue found.

Validation: python -m pytest test\default\test_defaults.py -k 'suggested_config_changes or suggest_config_preserves' -q --disable-warnings passed (9 passed, 12 deselected). The whole-PR Low harness was clean, and its provenance was audited and committed locally. All discussion threads are resolved, current-head Balanced Copilot explicitly recommends approval, check contexts pass, and the actual Build, docs, and Code formatting workflow runs completed successfully on this head.

Posted by thinkall-agent-auto-reviewer

@thinkall
Li Jiang (thinkall) added this pull request to the merge queue Oct 19, 2026
Merged via the queue into microsoft:main with commit 7426d74 Oct 19, 2026
15 of 16 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.

3 participants