Skip to content

n_jobs support details in docs #2453

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Alexsandruss
Copy link
Contributor

@Alexsandruss Alexsandruss commented Apr 25, 2025

Description

Adds a doc page for n_jobs specifics of sklearnex.


Checklist to comply with before moving PR from draft:

PR completeness and readability

  • I have reviewed my changes thoroughly before submitting this pull request.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation to reflect the changes or created a separate PR with update and provided its number in the description, if necessary.
  • Git commit message contains an appropriate signed-off-by string (see CONTRIBUTING.md for details).
  • I have added a respective label(s) to PR if I have a permission for that.
  • I have resolved any merge conflicts that might occur with the base branch.

Testing

  • I have run it locally and tested the changes extensively.
  • All CI jobs are green or I have provided justification why they aren't.
  • I have extended testing suite if new functionality was introduced in this PR.

Performance

N/A

@Alexsandruss Alexsandruss marked this pull request as ready for review April 25, 2025 17:00
Copy link

codecov bot commented Apr 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Flag Coverage Δ
azure ?
github 71.96% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

see 41 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@@ -0,0 +1,46 @@
.. Copyright 2025 Intel Corporation
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines +25 to +30
* `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|
* |sklearnex| doesn't use `joblib` for parallelism in patched estimators and functions
* The only low-level parallelism library used by |sklearnex| is oneTBB (through oneDAL)
* The `threading` parallel backend of `joblib` is not supported by |sklearnex|
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* `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|
* |sklearnex| doesn't use `joblib` for parallelism in patched estimators and functions
* The only low-level parallelism library used by |sklearnex| is oneTBB (through oneDAL)
* The `threading` parallel backend of `joblib` is not supported by |sklearnex|
* `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|.
* |sklearnex| doesn't use `joblib` for parallelism in patched estimators and functions.
* The only low-level parallelism library used by |sklearnex| is oneTBB (through oneDAL).
* The `threading` parallel backend of `joblib` is not supported by |sklearnex|.

* The only low-level parallelism library used by |sklearnex| is oneTBB (through oneDAL)
* The `threading` parallel backend of `joblib` is not supported by |sklearnex|

The only exception is multiclass LogisticRegression, which uses `joblib` for parallelism across classes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The only exception is multiclass LogisticRegression, which uses `joblib` for parallelism across classes.
The only exception is multiclass LogisticRegression, which uses :external+joblib:doc:`joblib <index>` for parallelism across classes.

(perhaps it could be added in the substitutions list)

while |sklearn| enables it for selected estimators only
* `n_jobs` estimator parameter sets the number of threads used by the underlying |oneDAL|
* |sklearnex| doesn't use `joblib` for parallelism in patched estimators and functions
* The only low-level parallelism library used by |sklearnex| is oneTBB (through oneDAL)
Copy link
Contributor

Choose a reason for hiding this comment

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

There's also multi-threading from the MKL side.

The only exception is multiclass LogisticRegression, which uses `joblib` for parallelism across classes.

|sklearnex| follows the same rules as |sklearn| for
`the calculation of the 'n_jobs' parameter value <https://scikit-learn.org/stable/glossary.html#term-n_jobs>`_.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
`the calculation of the 'n_jobs' parameter value <https://scikit-learn.org/stable/glossary.html#term-n_jobs>`_.
`the calculation of the 'n_jobs' parameter value <https://scikit-learn.org/stable/glossary.html#term-n_jobs>`__.

Link is repeated, single underscore makes it a named reference, which can cause with repetitions that change the name.

Comment on lines +22 to +23
|sklearnex| supports the `n_jobs <https://scikit-learn.org/stable/glossary.html#term-n_jobs>`_ parameter
of the original |sklearn| with the following differences:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
|sklearnex| supports the `n_jobs <https://scikit-learn.org/stable/glossary.html#term-n_jobs>`_ parameter
of the original |sklearn| with the following differences:
|sklearnex| supports the `n_jobs <https://scikit-learn.org/stable/glossary.html#term-n_jobs>`_ parameter
of the original |sklearn|, with the following differences:

Environment variables such as `OMP_NUM_THREADS`, `MKL_NUM_THREADS`, `OPENBLAS_NUM_THREADS`, and others used by
low-level parallelism libraries are recognized by `joblib` and therefore can be used as hints by |sklearnex|.

To track the actual number of threads used by sklearnex's estimators,
Copy link
Contributor

Choose a reason for hiding this comment

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

There's also the MKL debug variable, and now the oneDAL debug variable.

|sklearnex| follows the same rules as |sklearn| for
`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`),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
When Scikit-learn's utilities with built-in parallelism are used (for example, `GridSearchCV` or `VotingClassifier`),
When Scikit-learn's utilities with built-in parallelism are used (for example, :obj:`sklearn.model_selection.GridSearchCV` or :obj:`sklearn.model_selection.VotingClassifier`),

`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`.
Copy link
Contributor

Choose a reason for hiding this comment

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

I wasn't aware that such a system existed. Could you provide a link to the code where this happens?

* `n_jobs` estimator parameter sets the number of threads used by the underlying |oneDAL|
* |sklearnex| doesn't use `joblib` for parallelism in patched estimators and functions
* The only low-level parallelism library used by |sklearnex| is oneTBB (through oneDAL)
* The `threading` parallel backend of `joblib` is not supported by |sklearnex|
Copy link
Contributor

Choose a reason for hiding this comment

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

What does it mean "not supported by sklearnex"? What happens for example if you run an sklearn metaestimator (like BaggingClassifier) using that joblib backend with an sklearnex estimator inside?

@david-cortes-intel
Copy link
Contributor

Thanks for adding these explanations. But it's still missing important pieces of information and leaves several questions unanswered:

  • It's missing the threading part of MKL, the static linkage part, and how it interacts with environment variables, n_jobs parameter, inner_max_num_threads parameter, and threadpoolctl configurations.
  • It doesn't mention how the threading works when put under a threadpoolctl context.
  • The explanation is unclear about what ends up happening with the number of threads when using environment variables in addition to passing n_jobs as parameter.
  • Could mention what happens with n_jobs in GPU mode.
  • There's a difference in the threading configuration logic between daal4py and sklearnex, which this doc could also mention.
  • It doesn't cover the part about some configurations being global, which is quite relevant when using python-based multi-threading.
  • It could mention that the TBB threading doesn't automatically avoid nested parallelism when used in conjunction with OpenMP (which sklearn uses) and/or with joblib or python threads.
  • Some estimators perform better when not using all threads - for example, linear regression is faster on LNL laptops when not using low-power E-cores. Perhaps could mention these sort of things here as they are relevant.

@icfaust
Copy link
Contributor

icfaust commented May 26, 2025

@Alexsandruss make sure to merge main for latest CI checks on docs

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.

3 participants