Repository navigation
Conversation
|
Thank you for opening your first pull request to scikit-learn! 🎉 To help get your contribution reviewed, please make sure that:
|
12d9098 to
52aba9d
Compare
Fixes a race condition and silent data corruption when ArgKmin or RadiusNeighbors are invoked concurrently across threads on OpenBLAS built with OpenMP. Overlapping threadpoolctl context manager lifecycles prematurely restored global BLAS thread counts while concurrent GEMM operations were still running. We introduce _RefcountedBLASLimit to ensure the limit remains pegged at 1 until all concurrent tasks exit. Closes scikit-learn#31884
52aba9d to
16cc7f9
Compare
|
Thank you! I think however an easier solution is to upgrade |
|
Thank you for your work but threadpoolctl 3.7 fixes the issue and is now the default version people get when installing scikit-learn (including very old versions like 1.2), so we're not going to make the effort to review and maintain this fix, sorry. |
Reference Issues/PRs
Fixes #31884
What does this implement/fix? Explain your changes.
When calling
ArgKmin64.compute()orRadiusNeighbors64.compute()concurrently across threads (e.g. usingjoblib.Parallel(backend="threading")), numerical corruption occurs in environments running OpenBLAS compiled with the OpenMP threading layer.The root cause is overlapping
threadpoolctlcontext manager lifecycles:threadpoolctlchanges process-global C state (openblas_set_num_threads). When Thread A exits itscompute()block, it prematurely restores the thread limit back to default (e.g. 12) while concurrent threads are still running_gemmoperations, corrupting OpenBLAS's non-reentrant static packing buffers.This PR introduces
_RefcountedBLASLimitinsklearn.utils.parallel. It reference-counts concurrent entries across threads so the BLAS thread limit stays pinned to 1 as long as any reduction is active, and only restores the original thread count once the last concurrent thread exits.Any other comments?
_RefcountedBLASLimitintest_parallel.py.test_pairwise_distances_reduction.py.