Repository navigation
Conversation
|
Any idea if the failures for the debian build are deterministic and related to this PR? Can you try to push an empty commit to trigger a new CI run? |
I agree, but it's good to draft this here to test that this is does not cause regressions when running the full scikit-learn test suite. You can also push an empty commit with the |
There was a problem hiding this comment.
Thanks for the PR. I think we should consolidate some experimental results with various runtimes (different blas and openmp implementations and configuration on different platforms and distribution channels) either here or in a gist/side repo to assess the robustness of this proof of concept.
I will push a few scripts with high level use cases in a gist.
| # pools, or choosing a better BLAS library. | ||
| with _get_threadpool_controller().limit( | ||
| limits=max(joblib.cpu_count() // self.n_jobs, 1) | ||
| ): |
There was a problem hiding this comment.
In the final version would rather like to find a way to avoid calling this context manager if the backend is not a threading backend.
[free-threaded]
Done, we'll see how it goes. But also... does anyone actually do 32-bit these days? |
|
I guess it's plausible that I broke Debian. This is gonna be fun debugging, I can already tell 😁 |
It's a useful proxy to catch some pyodide problems :) |
| # Given this limitation, algorithms that cannot saturate all cores | ||
| # should having documentation suggesting either sticking to process | ||
| # pools, or choosing a better BLAS library. | ||
| # TODO don't do this on process pools: |
There was a problem hiding this comment.
You can use git commit --allow-empty -m "Trigger [free-threaded] CI" if you don't want to change a file.
|
Some progress on the 32-bit Debian failures: they only happen when tests are run with pytest-xdist with more than one worker, e.g. this fails much like CI: but these succeed: |
|
Digging a bit deeper, it's not so much pytest-xdist as, I believe, that as a result of constraining workers these tests calculate a result two ways: with multiple OpenBLAS threads, and a single OpenBLAS thread. Fundamentally, many operations cannot be guaranteed to give the same answer, given floating point isn't commutative. So for example the There is question is why 32-bit is causing this to be so much more different. And I think it's worth filing a bug fore. However: this is a pre-existing problem. As far as I can tell, if you run code under 32-bit you will get somewhat different results depending on the number of OpenBLAS threads. So a hypothetical user on a 4-core 32-bit machine will get different results than a user on a 1-core 32-bit machine. All this branch does is expose that to a test, it's not creating a new problem. Also it's not clear to me if this is even relevant to WASM (does NumPy use OpenBLAS there, and does OpenBLAS use web workers?). I have also spent quite a lot of time digging into this, and I don't want to spend more, since the payoff is pretty low (it's a preexisting problem for the least-popular target platform). So I suggest:
@ogrisel had a chance to come up with some relevant high-level benchmarks? |
|
Oh and looks like pyodide has no threads so inconsistent behavior is not really relevant there for now. |
| with _get_threadpool_controller().limit( | ||
| limits=max(joblib.cpu_count() // self.n_jobs, 1) | ||
| ): | ||
| return super().__call__(iterable_with_config_and_warning_filters) |
There was a problem hiding this comment.
This needs to handle the case where the result is lazy (an iterable) rather than synchronous (all results immediately available as a list).
❌ Linting issuesThis PR is introducing linting issues. Here's a summary of the issues. Note that you can avoid having linting issues by enabling You can see the details of the linting issues under the
|
|
Running with the given benchmark in the gist, with:
Then:
This suggests there's still some oversaturation happening somewhere, that this branch isn't catching... |
|
I think what's happening is nested Parallel, so in this case thread pools starting (overly large) thread pools in their worker threads. Solving this probably requires switching This probably means this prototype needs to be implemented in a branch in |
|
Work has moved to joblib. |
This is a sketch of what a fix for #34070 might look like.
You can enable thread pools globally by setting an environment variable
SKLEARN_THREADING=1(this was added just for experimentation purposes, it's not intended to be merged.)The changes in
parallel.pythen prevent oversaturation (tested with OpenBLAS pthreads and OpenBLAS OpenMP variants). Plausibly these changes should be done upstream injoblib, rather than here.