Skip to content
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

FEA parallel_config context manager to allow more fine-grained control #1392

Merged
merged 19 commits into from Apr 26, 2023

Conversation

jeremiedbb
Copy link
Contributor

@jeremiedbb jeremiedbb commented Feb 16, 2023

Fixes #912
Fixes #979
related to #1376

adds a new context_manager parallel_config that should be used in place of parallel_backend. It exposes more parameters and does not enforce setting a backend.

It allows to do something like:

from joblib.parallel import parallel_config
from joblib.memory import Memory
from joblib import Parallel, delayed
 
with parallel_config(prefer="threads", n_jobs=3):
    res = Parallel(verbose=100)(delayed(lambda :1)() for _ in range(10))
 
# [Parallel(n_jobs=3)]: Using backend ThreadingBackend with 3 concurrent workers.
# [Parallel(n_jobs=3)]: Done   1 tasks      | elapsed:    0.0s
# [Parallel(n_jobs=3)]: Done   2 tasks      | elapsed:    0.0s
# [Parallel(n_jobs=3)]: Done   3 tasks      | elapsed:    0.0s
# [Parallel(n_jobs=3)]: Done   4 tasks      | elapsed:    0.0s
# [Parallel(n_jobs=3)]: Done   5 tasks      | elapsed:    0.0s
# [Parallel(n_jobs=3)]: Done   6 out of  10 | elapsed:    0.0s remaining:    0.0s
# [Parallel(n_jobs=3)]: Done   7 out of  10 | elapsed:    0.0s remaining:    0.0s
# [Parallel(n_jobs=3)]: Done   8 out of  10 | elapsed:    0.0s remaining:    0.0s
# [Parallel(n_jobs=3)]: Done  10 out of  10 | elapsed:    0.0s remaining:    0.0s
# [Parallel(n_jobs=3)]: Done  10 out of  10 | elapsed:    0.0s finished

It's using the threading backend instead of the default loky, with 3 jobs instead of the default 1.

The config parameters of the context are used only if they are not explicitely set in Parallel. It makes us forced to use sentinels for the default values, adding a little bit of complexity.

TODO

  • raise an error if backend constructor params are set but backend is left to None
  • add tests

@codecov
Copy link

codecov bot commented Feb 16, 2023

Codecov Report

Patch coverage: 97.12% and project coverage change: -0.03 ⚠️

Comparison is base (41b70ff) 94.78% compared to head (4aa3509) 94.75%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1392      +/-   ##
==========================================
- Coverage   94.78%   94.75%   -0.03%     
==========================================
  Files          44       44              
  Lines        7207     7306      +99     
==========================================
+ Hits         6831     6923      +92     
- Misses        376      383       +7     
Impacted Files Coverage Δ
joblib/_utils.py 95.45% <83.33%> (-4.55%) ⬇️
joblib/test/test_parallel.py 96.20% <97.34%> (+0.12%) ⬆️
joblib/parallel.py 97.24% <97.75%> (+0.17%) ⬆️
joblib/__init__.py 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@tomMoral tomMoral left a comment

Choose a reason for hiding this comment

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

From a quick scan, the setup looks nice :)
Just a few first comments.

joblib/parallel.py Outdated Show resolved Hide resolved
joblib/parallel.py Show resolved Hide resolved
joblib/parallel.py Show resolved Hide resolved
Copy link
Contributor

@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.

To me, this is a valuable contribution for users. Thank you, @jeremiedbb.

Here is a review from an outsider (I am starting getting around joblib).

joblib/_utils.py Outdated Show resolved Hide resolved
joblib/parallel.py Outdated Show resolved Hide resolved
joblib/parallel.py Outdated Show resolved Hide resolved
joblib/parallel.py Show resolved Hide resolved
@jeremiedbb jeremiedbb changed the title [WIP] FEA parallel_config context manager to allow more fine-grained control FEA parallel_config context manager to allow more fine-grained control Feb 17, 2023
joblib/parallel.py Show resolved Hide resolved
joblib/parallel.py Show resolved Hide resolved
joblib/parallel.py Show resolved Hide resolved
joblib/parallel.py Show resolved Hide resolved
joblib/parallel.py Outdated Show resolved Hide resolved
joblib/parallel.py Outdated Show resolved Hide resolved
joblib/parallel.py Outdated Show resolved Hide resolved
joblib/parallel.py Show resolved Hide resolved
joblib/parallel.py Show resolved Hide resolved
joblib/parallel.py Outdated Show resolved Hide resolved
joblib/parallel.py Outdated Show resolved Hide resolved
joblib/parallel.py Outdated Show resolved Hide resolved
@ogrisel
Copy link
Contributor

ogrisel commented Apr 19, 2023

@jeremiedbb There are a few conflicts to resolve after the merge of the return_generator branch but it does not look too complicated.

Copy link
Contributor

@tomMoral tomMoral left a comment

Choose a reason for hiding this comment

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

I did a pass but the code looks super nice!! Good job @jeremiedbb :)

joblib/parallel.py Show resolved Hide resolved
joblib/test/test_parallel.py Outdated Show resolved Hide resolved
joblib/parallel.py Outdated Show resolved Hide resolved
joblib/parallel.py Outdated Show resolved Hide resolved
joblib/parallel.py Outdated Show resolved Hide resolved
joblib/parallel.py Outdated Show resolved Hide resolved
joblib/parallel.py Show resolved Hide resolved
joblib/parallel.py Outdated Show resolved Hide resolved
joblib/parallel.py Outdated Show resolved Hide resolved
joblib/parallel.py Outdated Show resolved Hide resolved
Copy link
Contributor

@tomMoral tomMoral left a comment

Choose a reason for hiding this comment

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

LGTM! thanks @jeremiedbb for making this :)

@tomMoral tomMoral merged commit ebacd8c into joblib:master Apr 26, 2023
16 checks passed
@trendelkampschroer
Copy link

Thanks a lot for this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pass verbose through parallel_backend Pass max_nbytes through parallel_backend
6 participants