Repository navigation
fix(automl): preserve SVC random state during sklearn cloning - #1679
Aditya Kumar (adityakumar027) wants to merge 2 commits into
Conversation
Signed-off-by: Aditya Kumar <adi.workspace76865@gmail.com>
There was a problem hiding this comment.
🟡 Changes recommended
The integration test still clones and fits with the default random state rather than 7, so it does not verify that stacking preserves the supplied NumPy integer state.
1 open issue
What changed in this PR
Fixes SVCEstimator parameter normalization to preserve configured random states during scikit-learn cloning, supporting FLAML’s ensemble and stacking workflows.
Changes:
- Preserves explicit
random_statevalues, consumes therandom_seedalias, and retains the historical default. - Adds eight regression cases covering random-state types, alias precedence, cloning, and stacking.
| File | Description |
|---|---|
test/automl/test_svc_clone.py |
Adds cloning, seed normalization, and stacking tests. |
flaml/automl/model.py |
Updates SVC initialization to preserve random state and remove the seed alias. |
Review effort: Balanced
Li Jiang (thinkall)
left a comment
There was a problem hiding this comment.
The constructor correction behaves correctly in focused validation: eight tests passed on Python 3.10/NumPy 1.26 and eight on Python 3.13/NumPy 2.3. The same tests detect six expected failures per stack on unmodified main. The whole-PR Low review found two coverage gaps that should be addressed before approval:
-
The stacking fixture uses
SVCEstimator().set_params(random_state=7), but the inherited setter does not update the parameters returned by FLAML'sget_params(). Probes confirm that it fits with10242048on both current and main, so the prediction-shape assertion does not exercise this regression. UseSVCEstimator(random_state=7)and assertstacking.named_estimators_["svc"].model.random_state == 7after fitting. This corroborates the existing Copilot thread; no duplicate inline issue is being opened. -
The
RandomStatecase compares onlyget_state()[1]and reads the mutable expected generator after construction/cloning. Snapshot the full state before construction, preferably after advancing the generator with a normal draw, and compare the complete state withnp.testing.assert_equal. Current full-state preservation works on both stacks, but a position-only change passes the existing key-array assertion. This is a test-oracle gap, not an observed production RNG regression.
Approval remains withheld while these findings and the independent peer-review/CI gates remain unresolved.
Posted by thinkall-agent-auto-reviewer
Signed-off-by: Aditya Kumar <adi.workspace76865@gmail.com>
|
Fixed both coverage gaps: stacking now constructs the SVC with a NumPy integer state and asserts the fitted model keeps 7. The RandomState test takes a full snapshot after a normal draw, then checks both the cloned and original generators against it. All eight tests pass; unmodified main now fails seven, including the stacking case. Black and Ruff pass. |
Li Jiang (thinkall)
left a comment
There was a problem hiding this comment.
Whole-PR review at d85e37accd51e0847c5a5e2e1100c2c3fc9c9030: both previous test-coverage findings are fixed. The RandomState oracle captures the full advanced state before construction, and the stacking test constructs the explicit seed and checks the fitted clone.
The Low skill review is clean. Targeted suites passed 16 tests across the two native stacks; the same new tests on unmodified main had 14 expected failures and 2 passes. All-files pre-commit passed. The current-head Balanced peer recommends approval, all review threads are resolved, applicable checks pass, and all current-head workflow runs completed successfully. The skipped docs gh-release job is explicitly disabled for pull requests by its verified workflow condition; no unsuccessful or pending workflow was ignored.
Approved. Review artifacts are committed only in detached local evidence worktrees and were not pushed to this PR.
Posted by thinkall-agent-auto-reviewer

Why are these changes needed?
Fixes #1678.
SVCEstimatoroverwritesrandom_stateevery time its constructor runs. That loses an explicitly configured state and can break sklearn cloning when cloning a NumPy scalar orRandomStateobject. It also leaves therandom_seedalias in the parameters passed toLinearSVC.Use the same normalization as the neighboring estimators: consume
random_seed, keep an existingrandom_state, and use the historical default only when neither was supplied.Tests
None, integer, NumPy integer andRandomStatevalues, the default andrandom_seedalias, explicitrandom_stateprecedence, and a smallStackingClassifierfit.test_model.pywas killed while running its large existing model test, so I am not claiming that suite passed.Prepared with AI assistance.
Checks