-
Notifications
You must be signed in to change notification settings - Fork 184
Add doc page about n_jobs
#2768
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
base: main
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests.
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
doc/sources/parallelism.rst
Outdated
| `the calculation of the 'n_jobs' parameter value <https://scikit-learn.org/stable/glossary.html#term-n_jobs>`__. | ||
|
|
||
| When Scikit-learn's utilities with built-in parallelism are used (for example, `GridSearchCV` or `VotingClassifier`), | ||
| |sklearnex| tries to determine the optimal number of threads per job using hints provided by `joblib`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you point to the code where this happens? How does it detect that it is running under joblib? (they have multiple threading backends).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| def get_suggested_n_threads(n_cpus): |
If several instances of sklearnex are run via joblib, n_threads is equal to number of cpu / number of instances
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I played a bit with it, and from what I can tell, it works under both joblib jobs and threadpool contexts. Including contexts that only limit BLAS like this:
threadpoolctl.threadpool_limits(limits=2, user_api='blas').. which actually contradicts some of the other points here:
|sklearnex| threading doesn't automatically avoid nested parallelism when used in conjunction with OpenMP and/or with joblib or python threads.
|
Thanks for looking into it. A couple points from the earlier PR:
|
|
|
||
| * `n_jobs` parameter is supported for all estimators patched by |sklearnex|, | ||
| while |sklearn| enables it for selected estimators only. | ||
| * `n_jobs` estimator parameter sets the number of threads used by the underlying |oneDAL|. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * `n_jobs` estimator parameter sets the number of threads used by the underlying |oneDAL|. | |
| * `n_jobs` estimator parameter sets the number of threads used by the underlying |onedal|. |
Macros are case-sensitive.
| * If `n_jobs` is not specified |sklearnex| uses all available threads whereas |sklearn| is single-threaded by default. | ||
|
|
||
| |sklearnex| follows the same rules as |sklearn| for | ||
| `the calculation of the :term:`n_jobs` parameter value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| `the calculation of the :term:`n_jobs` parameter value. | |
| the calculation of the :term:`n_jobs` parameter value. |
| |sklearnex| follows the same rules as |sklearn| for | ||
| `the calculation of the :term:`n_jobs` parameter value. | ||
|
|
||
| When Scikit-learn's utilities with built-in parallelism are used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| When Scikit-learn's utilities with built-in parallelism are used | |
| When |sklearn|'s utilities with built-in parallelism are used |
| |sklearnex| threading doesn't automatically avoid nested parallelism when used in conjunction with OpenMP and/or with joblib or python threads. | ||
|
|
||
| To track the actual number of threads used by estimators from the |sklearnex|, | ||
| set the `DEBUG` :ref:`verbosity setting <verbose>`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not see any log with the number of threads when doing this.
Example:
import os
os.environ["SKLEARNEX_VERBOSE"] = "DEBUG"
import numpy as np
from sklearnex.linear_model import Ridge
from sklearn.model_selection import GridSearchCV
rng = np.random.default_rng(seed=123)
X = rng.standard_normal(size=(100,10))
y = rng.standard_normal(X.shape[0])
Ridge().fit(X, y)DEBUG:sklearnex: Assigned method '<host_backend>.linear_model.regression.train' to 'BaseLinearRegression.train'
DEBUG:sklearnex: Assigned method '<host_backend>.linear_model.regression.infer' to 'BaseLinearRegression.infer'
DEBUG:sklearnex: Assigned method '<host_backend>.linear_model.regression.model' to 'BaseLinearRegression.model'
DEBUG:sklearnex: Assigned method '<host_backend>.linear_model.regression.partial_train_result' to 'BaseIncrementalLinear.partial_train_result'
DEBUG:sklearnex: Assigned method '<host_backend>.linear_model.regression.partial_train' to 'BaseIncrementalLinear.partial_train'
DEBUG:sklearnex: Assigned method '<host_backend>.linear_model.regression.finalize_train' to 'BaseIncrementalLinear.finalize_train'
DEBUG:sklearnex: Assigned method '<host_backend>.logistic_regression.classification.train' to 'LogisticRegression.train'
DEBUG:sklearnex: Assigned method '<host_backend>.logistic_regression.classification.infer' to 'LogisticRegression.infer'
DEBUG:sklearnex: Assigned method '<host_backend>.logistic_regression.classification.model' to 'LogisticRegression.model'
INFO:sklearnex: sklearn.linear_model.Ridge.fit: running accelerated version on CPU
DEBUG:sklearnex: Dispatching function 'linear_model.regression.train' with policy <onedal._onedal_py_host.host_policy object at 0x7fb689e02770> to Backend(<module 'onedal._onedal_py_host' from '/home/dcortes/repos/scikit-learn-intelex/onedal/_onedal_py_host.cpython-311-x86_64-linux-gnu.so'>, is_dpc=False, is_spmd=False)
|
|
||
| When Scikit-learn's utilities with built-in parallelism are used | ||
| (for example, :obj:`sklearn.model_selection.GridSearchCV` or :obj:`sklearn.model_selection.VotingClassifier`), | ||
| |sklearnex| tries to determine the optimal number of threads per job using hints proded by `joblib`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| |sklearnex| tries to determine the optimal number of threads per job using hints proded by `joblib`. | |
| |sklearnex| tries to determine the optimal number of threads per job using hints proded by :mod:`joblib` / ``threadpoolctl``. |
Seems to work with both.
Description
Add doc update regarding
n_jobsparameter. Contains content from #2453 and addresses comments from there.Checklist:
Completeness and readability
Testing