You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
sklearn.cluster.OPTICS uses all cores when minkowski's p=2 #21786
minkowski with p=2 relies on BLAS functions to compute the distances which is multithreaded.
n_jobs only controls joblib based parallelism. Other sources of parallelism will likely try to use as many cores as possible. It also happens when we call numpy or scipy functions that rely on BLAS: parallelism is handled by the BLAS library linked.
So I don't think it's a bug, but maybe a lack of documentation.
If you really want to use at most 2 cores, you need to set the env var OPENBLAS_NUM_THREADS or MKL_NUM_THREADS depending on your blas. You can find out what blas is linked by running python -m threadpoolctl -i sklearn
You can also limit the number of threads programmatically with threadpoolctl:
fromthreadpoolctlimportthreadpool_limitswiththreadpool_limits(limits=2, user_api="blas"):
# your code here
Thanks @jeremiedbb , I feel like we need a clear documentation about these with links to them from virtually everywhere, so that people can figure out how to limit/use their resources as they want.
I think our n_jobs explanation can also be improved. We make no explicit mention of BLAS or openmp threads there, and only have a link to glossary, which then has a link to our parallelism docs. I think this information should be available in a bit more direct and explicit way to the users.
Activity
adrinjalali commentedon Nov 25, 2021
Could you please reproduce with scikit-learn 1.0.1, and also paste a reproducible code, which can be copy pasted to reproduce the issue?
szperajacyzolw commentedon Nov 25, 2021
Running it with scikit-learn 1.0.1 gives the same result in terms of cores usage
Below version works just fine:
adrinjalali commentedon Nov 25, 2021
Could you please instead of a loading a csv, use a synthetic dataset, or a dataset fetched by
fetch_openml, so that we can run and test it?szperajacyzolw commentedon Nov 26, 2021
Here I have created synthetic set similar to what I have used in real scenario.
adrinjalali commentedon Nov 29, 2021
maybe @jeremiedbb would have an idea?
jeremiedbb commentedon Nov 29, 2021
minkowski with p=2 relies on BLAS functions to compute the distances which is multithreaded.
n_jobs only controls joblib based parallelism. Other sources of parallelism will likely try to use as many cores as possible. It also happens when we call numpy or scipy functions that rely on BLAS: parallelism is handled by the BLAS library linked.
So I don't think it's a bug, but maybe a lack of documentation.
If you really want to use at most 2 cores, you need to set the env var
OPENBLAS_NUM_THREADSorMKL_NUM_THREADSdepending on your blas. You can find out what blas is linked by runningpython -m threadpoolctl -i sklearnYou can also limit the number of threads programmatically with
threadpoolctl:adrinjalali commentedon Nov 29, 2021
Thanks @jeremiedbb , I feel like we need a clear documentation about these with links to them from virtually everywhere, so that people can figure out how to limit/use their resources as they want.
szperajacyzolw commentedon Nov 29, 2021
Thank you @jeremiedbb for insightful explanation!
glemaitre commentedon Nov 29, 2021
I would retag this issue as documentation. I was going to propose to have an entry in the FAQ but we already have it:
https://scikit-learn.org/stable/faq.html#why-does-my-job-use-more-cores-than-specified-with-n-jobs
So, the part of the documentation that could be improved would be the following:
https://scikit-learn.org/stable/computing/parallelism.html#parallelism
where we could have some usage of
threadpooltctl.adrinjalali commentedon Nov 29, 2021
I think our
n_jobsexplanation can also be improved. We make no explicit mention of BLAS or openmp threads there, and only have a link to glossary, which then has a link to our parallelism docs. I think this information should be available in a bit more direct and explicit way to the users.