Wrong number of workers reported by effective_n_jobs
See original GitHub issueI want to highlight something which looks weird to me (not sure yet if this is a bug). I made a snippet which is a pattern that we use in scikit-learn.
from joblib import Parallel, delayed, effective_n_jobs, parallel_backend
from joblib.parallel import get_active_backend
def func(x):
return x ** 2
class Klass:
def __init__(self, n_jobs=None):
self.n_jobs = n_jobs
def func(self, x):
n_jobs = effective_n_jobs(self.n_jobs)
print(
f"Number of effective jobs found: {effective_n_jobs(self.n_jobs)}"
)
backend, backend_n_jobs = get_active_backend()
print(
f"Current backend used: {backend}"
)
print(
f"Number of jobs in the backend: {backend_n_jobs}"
)
return Parallel(n_jobs=n_jobs)(delayed(func)(i) for i in x)
n_jobs = 4
with parallel_backend("threading", n_jobs=n_jobs):
r = Klass().func(range(10))
Number of effective jobs found: 1
Current backend used: <joblib._parallel_backends.ThreadingBackend object at 0x7f946468d810>
Number of jobs in the backend: 4
If I am not wrong, one would expect to make the Parallel
call with n_jobs=4
. However, effective_n_jobs
will report n_jobs=1
due to:
I would have expected parallel_backend
to overwrite the number of jobs if not specified in the estimator but I am not sure about it.
NB: found during investigating https://github.com/scikit-learn/scikit-learn/issues/15978
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
ED313528.pdf - ERIC
rising. While roughly 30% of the semi-skilled and unskilled workers are functional- ly illiterate, the number of professional jobs contiaues to increase as ......
Read more >S archand youth - Search Institute
mailing a large number of surveys and communications to potential respondents. ... and resources on positive youth development to youth workers in a...
Read more >Bosses, you're wrong: Remote workers are more productive ...
Remote and hybrid workers reported higher productivity levels than their fully in-office peers, the Slack Future Forum finds.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Not me but the solution 😃
I can do it with a unit test.
I would so much like to have @glemaitre in joblib. It would be a major feature!