question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong number of workers reported by effective_n_jobs

See original GitHub issue

I 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:

https://github.com/joblib/joblib/blob/1753c3bcb1d8430439ce48a1ef4e866166f34296/joblib/_parallel_backends.py#L232-L235

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:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
glemaitrecommented, Jan 3, 2020

Let’s try to implement @glemaitre in a PR

Not me but the solution 😃

Shall I do it?

I can do it with a unit test.

0reactions
GaelVaroquauxcommented, Jan 3, 2020
Let's try to implement @glemaitre in a PR

Not me but the solution 😃

I would so much like to have @glemaitre in joblib. It would be a major feature!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found