Skip to content

MNT Test for thread safety contract: inference methods shouldn't modify the estimator - #34729

Merged
ogrisel merged 34 commits into
scikit-learn:mainfrom
itamarst:test-thread-safety-contract
Nov 30, 2026
Merged

ogrisel merged 34 commits into
scikit-learn:mainfrom
itamarst:test-thread-safety-contract

Conversation

@itamarst

@itamarst itamarst commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Prerequisite for #34596

One can imagine being more thorough (what if some code does self.x = list(x), as Pipeline does?) but it's a start.

I went ahead and fixed the relatively small number of failures.

@github-actions github-actions Bot removed the CI:Linter failure The linter CI is failing on this PR label Aug 11, 2026
@itamarst

itamarst commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Update: I've hopefully fixed the failing tests.

One was just noise from KDTree/BallTree stats, which are actually thread-safe (and deprecated).

The other appears to be a real bug: somehow SplineTransformer.transform is mutating bsplines_. I couldn't figure out how, but a deepcopy fixed, so that's in as a workaround. If a reviewer can spot the place where things get mutated (I think it's BSpline.t from some debugging) that'd be better.

@cakedev0
cakedev0 self-requested a review October 2, 2026 14:38

@cakedev0 cakedev0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Here is a partial review with the help of AI.

Some things can be fixed/improved, but nothing critical.

AI add a few more legit-looking items I haven't checked yet, so I haven't included them yet in this review.

Comment thread sklearn/utils/estimator_checks.py Resolved
Comment thread sklearn/neighbors/_binary_tree.pxi.tp Resolved
Comment thread sklearn/preprocessing/_polynomial.py Resolved
Comment thread sklearn/utils/estimator_checks.py Resolved
Comment thread sklearn/utils/estimator_checks.py Resolved
Comment thread sklearn/utils/estimator_checks.py Resolved
Comment thread sklearn/utils/estimator_checks.py Resolved

@cakedev0 cakedev0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

End of my review.

Comment thread sklearn/utils/estimator_checks.py Resolved
Comment thread sklearn/utils/estimator_checks.py Resolved
@cakedev0 cakedev0 added this to Labs Oct 5, 2026
@itamarst

Copy link
Copy Markdown
Contributor Author

OK, done.

@itamarst
itamarst requested a review from cakedev0 October 14, 2026 11:00

@cakedev0 cakedev0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, nice work, thanks!

@cakedev0 cakedev0 added Waiting for Second Reviewer First reviewer is done, need a second one! free-threading PRs and issues related to support for free-threaded CPython (a.k.a. nogil or no-GIL, PEP 703) labels Oct 14, 2026
@ev-br

ev-br commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

The other appears to be a real bug: somehow SplineTransformer.transform is mutating bsplines_. I couldn't figure out how, but a deepcopy fixed, so that's in as a workaround. If a reviewer can spot the place where things get mutated (I think it's BSpline.t from some debugging)

Came here from the upstream issue, scipy/scipy#26600, and the upstream's position is scipy/scipy#26600 (comment).

The BSpline code has been doing these internal copies "forever", thus changing it is not straightforward for backwards compat, and I'm not immediately convinced that it's a BSpline bug, FWIW.

cakedev0 added a commit to cakedev0/my-scikit-learn-backlog that referenced this pull request Nov 3, 2026
todo: move [sklearn#35216](scikit-learn/scikit-learn#35216) from Now to Waiting, the test was already there, approved by lesteve with auto-merge
add: Trees: get [sklearn#34554](scikit-learn/scikit-learn#34554) merged (recursion PDP on categorical features; approved)
add: Threads: review [sklearn#34729](scikit-learn/scikit-learn#34729) (inference methods don't modify the estimator; ev-br on the SplineTransformer mutation)
todo: lucyleeow approved [sklearn#35215](scikit-learn/scikit-learn#35215)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cakedev0 added a commit to cakedev0/my-scikit-learn-backlog that referenced this pull request Nov 3, 2026
done: HGB: get [sklearn#35216](scikit-learn/scikit-learn#35216) merged (binning crash on all-missing features, fixes [sklearn#35164](scikit-learn/scikit-learn#35164)), merged before I removed it
done: Trees: get [sklearn#34554](scikit-learn/scikit-learn#34554) merged (recursion PDP on categorical features)
drop: Threads: answer lesteve on [sklearn#35105](scikit-learn/scikit-learn#35105) (RFC deprecate `pre_dispatch`)
drop: Maintenance: follow up on [sklearn#35209](scikit-learn/scikit-learn#35209) (newton-cg test failing on the macOS x86_64 wheels)
drop: Benchmarks: review [benchmarks#142](probabl-ai/scikit-learn-benchmarks#142) (cuML benchmark config)
drop: Threads: review [sklearn#34729](scikit-learn/scikit-learn#34729) (inference methods don't modify the estimator)
drop: Linear: [sklearn#34793](scikit-learn/scikit-learn#34793) (Ridge centering trick for cholesky), benchmarks in [benchmarks#115](probabl-ai/scikit-learn-benchmarks#115) and [benchmarks#31](probabl-ai/scikit-learn-benchmarks#31)
drop: Upstream: sklearnex reports [sklearnex#3402](uxlfoundation/scikit-learn-intelex#3402), [sklearnex#3377](uxlfoundation/scikit-learn-intelex#3377), [sklearnex#3220](uxlfoundation/scikit-learn-intelex#3220)
drop: Upstream: [data-apis/array-api#976](data-apis/array-api#976) (why `stable=True` is the default for `xp.sort`)
drop: Upstream: dpnp reports [IntelPython/dpnp#3149](IntelPython/dpnp#3149) and [IntelPython/dpnp#3148](IntelPython/dpnp#3148)
drop: Threads: [sklearn#34736](scikit-learn/scikit-learn#34736) (oversubscription in `pairwise_distances`), out of the reported findings item
drop: KMeans: benchmarks [benchmarks#154](probabl-ai/scikit-learn-benchmarks#154), [benchmarks#160](probabl-ai/scikit-learn-benchmarks#160), [OpenBLAS#6105](OpenMathLib/OpenBLAS#6105) and [sklearn#17334](scikit-learn/scikit-learn#17334), out of the [sklearn#35193](scikit-learn/scikit-learn#35193) item
todo: move [joblib#1899](joblib/joblib#1899), [sklearn#35261](scikit-learn/scikit-learn#35261) and [sklearn#35053](scikit-learn/scikit-learn#35053) from Reviews to Now, [sklearn#35181](scikit-learn/scikit-learn#35181) to the top of Waiting (by hand in 03835dd)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the size/M label Nov 4, 2026

@ogrisel ogrisel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Pending review comments of a partial review I started but never finished.

Comment thread sklearn/preprocessing/_polynomial.py Resolved
Comment thread sklearn/utils/estimator_checks.py Resolved
Comment thread sklearn/utils/estimator_checks.py Resolved
Comment thread sklearn/utils/estimator_checks.py Resolved
@ogrisel

ogrisel commented Nov 23, 2026

Copy link
Copy Markdown
Member

@itamarst the new test fails but other than that, LGTM.

@itamarst

Copy link
Copy Markdown
Contributor Author

And some merge conflicts, looks like. I'll take a look, thank you.

@itamarst

Copy link
Copy Markdown
Contributor Author

I fixed the test and merged forward.

Since this adds what is technically a public API (a new estimator check), should it be FEAT instead of MNT?

@ogrisel
ogrisel merged commit 99aac4f into scikit-learn:main Nov 30, 2026
39 checks passed
@github-project-automation github-project-automation Bot moved this from PR waiting for reviews to Done in Labs Nov 30, 2026
csadorf added a commit to NVIDIA/cuml that referenced this pull request Dec 1, 2026
## Summary

Fixes the 10 failures in the nightly-dependency wheel tests.

- Keeps the upstream inference-state check active by recording opaque
GPU objects by identity in its per-attribute diagnostics. The
whole-estimator comparison and production serialization stay unchanged.
scikit-learn/scikit-learn#34729
- Routes extra `LogisticRegression.fit` keywords to scikit-learn for
callback metadata routing and validation. Fits that only use the
existing arguments stay eligible for GPU execution.
- Tests metadata consumption through the public API for both
`MetadataRequest` and `MetadataRouter`, while retaining the exact
request checks on older versions.
scikit-learn/scikit-learn#34137

## Validation

Rebuilt cuML locally and ran `test_core.py` and
`test_estimator_proxy.py` on an RTX PRO 6000: 392 passed on scikit-learn
`1.10.dev0`, and 388 passed on `1.9.1`.

Closes #8976
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

free-threading PRs and issues related to support for free-threaded CPython (a.k.a. nogil or no-GIL, PEP 703) module:utils size/M Waiting for Second Reviewer First reviewer is done, need a second one!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants