Skip to content

MNT use new threadpoolctl API (global threadpool controller) #21206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Oct 8, 2021

Conversation

jeremiedbb
Copy link
Member

@jeremiedbb jeremiedbb commented Sep 30, 2021

The new API of threadpoolctl allows to not look for the shared libraries at each call to threadpool_(limits/info). The idea is that in scikit-learn the BLAS and OpenMP libraries are loaded during the import and won't change during the lifetime of a program using sklearn. It means that we can reuse their handlers for all subsequent call to threadpoolctl.

The goal is to reduce some unnecessary overhead, which can be as high as check_array in some extreme situations like in #20254 when running neighbors prediction on a single test sample.

@jjerphan could you try the new threadpoolctl api in your PR, via the fixes introduced in this PR ?
It's already available in the master branch of https://github.com/joblib/threadpoolctl
You should now import threadpool_limits from utils._threadpoolctl_fixes.

This PR is in draft state. Its current purpose is to check that the new api solves the perf issues in sklearn. Then, if it does, we'll need to release a new version of threadpoolctl before considering merging this.

@jjerphan
Copy link
Member

@jjerphan could you try the new threadpoolctl api in your PR, via the fixes introduced in this PR ?

I will have a look now.

Copy link
Member

@ogrisel ogrisel left a comment

Choose a reason for hiding this comment

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

Looks great. Maybe you could expand the comment a bit by stating the expected per-call overhead with and without the dynamic libraries lookups.

Copy link
Member

@jjerphan jjerphan left a comment

Choose a reason for hiding this comment

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

All good for #20254, LGTM!

@jeremiedbb jeremiedbb marked this pull request as ready for review October 1, 2021 15:31
@jeremiedbb
Copy link
Member Author

threadpoolctl 3.0.0 has been released. This PR is ready for review

@ogrisel
Copy link
Member

ogrisel commented Oct 4, 2021

To avoid merging code that isn't used or tested, could you please make KMeans use it instead of calling threadpoolctl.threadpool_limit directly?

@ogrisel ogrisel merged commit 1cab25c into scikit-learn:main Oct 8, 2021
@thomasjpfan
Copy link
Member

Since there is a performance benefit, what do you think of updating the required version for threadpoolctl to 3.0 in scikit-learn 1.1?

@glemaitre glemaitre mentioned this pull request Oct 23, 2021
10 tasks
glemaitre pushed a commit to glemaitre/scikit-learn that referenced this pull request Oct 23, 2021
samronsin pushed a commit to samronsin/scikit-learn that referenced this pull request Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants