You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add ability to override joblib backend for scikit-learn estimators #8804
Some calls to Parallel in scikit-learn hardcode what joblib backend to use. It would be nice if these could be overridden to use a different backend using the parallel_backend contextmanager. This would allow optionally using the dask.distributed backend in more places, which may provide speedups (see comment here).
One way to do this would be to check if there's a globally set backend (as set by the context manager) and use that, otherwise use the specified fallback. This might look like:
fromsklearn.externals.joblib.parallelimport_backenddefactive_backend_or(default):
"""If there is an active joblib backend use that, otherwise use the default"""returngetattr(_backend, 'backend_and_jobs', (default, None))[0]
# Use the active backend if set, otherwise use "threading"Parallel(backend=active_backend_or("threading"))(...)
I'm not sure if this is a fix that should be implemented in scikit-learn or in joblib. Opening this for discussion.
Reacted by Roman Yurchak, M. Long, Caio Augusto Araújo Oliveira, Franck Charras and Isaac Joseph
One problem that I see is that when the backing is threading, the code
can safely assume that there is shared memory, and use it. This is no
longer the case with other backend.
In your benchmark: did you check that the results were the same in the
different backends, or did you only compare the run-time? I don't
remember if random forest use a shared memory or not.
One problem that I see is that when the backing is threading, the code can safely assume that there is shared memory, and use it. This is no longer the case with other backend.
That is a good point though, and would need to be considered when determining what can have overridable backends.
Should outer_backend have priority over inner_backend?
I don't think so, as that wouldn't allow internal code to ensure using threading. For the case of RandomForest we could allow fit to use any backend, but predict would require threading (my benchmark found that distributing predict was slower anyway, which makes sense because of the low overhead of predict).
On 29 Apr 2017 1:56 am, "Jim Crist" ***@***.***> wrote:
In your benchmark: did you check that the results were the same in the
different backends, or did you only compare the run-time?
I'm not sure exactly what to compare for trees, but they have the same
score, and the following passes (for RandomForestClassifier):
for t1, t2 in zip(distributed_res.estimators_, threading_res.estimators_):
np.testing.assert_array_equal(t1.tree_.value, t2.tree_.value)
That is a good point though, and would need to be considered when
determining what can have overridable backends.
Should outer_backend have priority over inner_backend?
I don't think so, as that wouldn't allow internal code to ensure using
threading. For the case of RandomForest we could allow fit to use any
backend, but predict would require threading (my benchmark found that
distributing predict was slower anyway, which makes sense because of the
low overhead of predict).
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#8804 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEz6-pytxxwJWKCUWev4jtC4gdq-icxks5r0gwhgaJpZM4NKmzc>
.
If we were to do that, my preference would be that Parallel backends are not overridable by default, and we set allow_override=True for calls that are known to work fine under non-shared memory backends.
For moving forward on this, is this something that should be an issue/PR to joblib instead of here?
I think that the notion of overrides is going to be challenging to do in
a non fragile way.
Maybe we should have a semantics in the way we specify the backends. To
give an example, what the threading backend provides is shared memory,
what it doesn't provide is parallel computing for gil.
A semantic specification might look like "backend='nogil,shared_mem'",
which would say that the code needs shared mem, but doesn't need
gil-level parallelism.
Another dimension to look at would be whether the operations are expected
to be very short or not.
Hmmm, that's an interesting idea. I will say that as a novice joblib user, I find the concept of a default backend and whether that backend can/cannot be swapped out to be simpler than a set of semantic requirements (probably simpler to implement too). It's not immediately clear to me what nogil means here (could mean either that my function releases the gil or that I want to compute in processes to avoid the gil?). I will cede to your judgement here though.
It's not immediately clear to me what nogil means here (could mean
either that my function releases the gil or that I want to compute in
processes to avoid the gil?).
I agree that the semantics should be made clear in documentation. I also
agree that better wording must be explored.
The question is rather: are these the good axis to explore?
Ping @ogrisel, @aabadie, @lesteve
I think it would be good to allow users to directly specify what the input
to joblib is if they want to override it. That way they can call upon
documentation from both sklearn, joblib, and other packages built on joblib
to try to understand what is happening better. In sklearn documentation we
would want to specify why we chose what we did, for example that
'threading' is useful for trees, but not for estimators that don't release
the GIL.
Is there anything I can do to help expedite this issue? If I was to make an example PR showing what I think should be done, should I submit it here or joblib? Would that be a good next step?
Should this be closed? PR ( #11166 ) allows optional use of a different joblib and PR ( joblib/joblib#602 ) solved the shared memory constraint. Were there other outstanding issues?
Activity
lesteve commentedon Apr 28, 2017
Now I am wondering why using a context manager only overrides the default backend (when not specified explicitly) and not all of them.
In other words:
Should
outer_backendhave priority overinner_backend?Ping @ogrisel, I seem to remember we chatted about related things but I don't remember the outcome of the discussion.
GaelVaroquaux commentedon Apr 28, 2017
lesteve commentedon Apr 28, 2017
That's a good point actually and this is going to be a problem since #8672, which was merged around a month ago relies on the threading backend. In https://github.com/scikit-learn/scikit-learn/pull/8672/files#diff-65dc1c804f310acfd90f5ea83286065cR387 the function that was passed into
Parallelhas side-effects and this only works becausebackend='threading'.jcrist commentedon Apr 28, 2017
I'm not sure exactly what to compare for trees, but they have the same score, and the following passes (for
RandomForestClassifier):That is a good point though, and would need to be considered when determining what can have overridable backends.
I don't think so, as that wouldn't allow internal code to ensure using threading. For the case of
RandomForestwe could allow fit to use any backend, butpredictwould require threading (my benchmark found that distributingpredictwas slower anyway, which makes sense because of the low overhead of predict).jnothman commentedon Apr 29, 2017
jcrist commentedon May 1, 2017
If we were to do that, my preference would be that
Parallelbackends are not overridable by default, and we setallow_override=Truefor calls that are known to work fine under non-shared memory backends.For moving forward on this, is this something that should be an issue/PR to joblib instead of here?
GaelVaroquaux commentedon May 1, 2017
jcrist commentedon May 1, 2017
Hmmm, that's an interesting idea. I will say that as a novice joblib user, I find the concept of a default backend and whether that backend can/cannot be swapped out to be simpler than a set of semantic requirements (probably simpler to implement too). It's not immediately clear to me what
nogilmeans here (could mean either that my function releases the gil or that I want to compute in processes to avoid the gil?). I will cede to your judgement here though.GaelVaroquaux commentedon May 1, 2017
jmschrei commentedon May 5, 2017
jcrist commentedon May 22, 2017
Is there anything I can do to help expedite this issue? If I was to make an example PR showing what I think should be done, should I submit it here or joblib? Would that be a good next step?
jnothman commentedon May 22, 2017
jcrist commentedon May 23, 2017
See joblib/joblib#524.
jmschrei commentedon May 24, 2017
This is a really neat addition, thanks for the link. I'll be watching it.
Use backend hints rather than hardcoding
Use backend hints rather than hardcoding
jakirkham commentedon Jul 2, 2018
Should this be closed? PR ( #11166 ) allows optional use of a different
jobliband PR ( joblib/joblib#602 ) solved the shared memory constraint. Were there other outstanding issues?GaelVaroquaux commentedon Jul 2, 2018
I am not convinced: right now specifying the backend with system joblib will work only if scikit-learn is "unvendored".
jnothman commentedon Feb 5, 2019
cmarmo commentedon Dec 16, 2021
@GaelVaroquaux, @ogrisel, joblib is no longer distributed with scikit-learn, right? Shall this is issue be closed now? Thanks!
thomasjpfan commentedon Jun 30, 2022
I think this issue can be closed now. As noted in the dask-ml docs,
parallel_backendcan be used to switch the parallel backend to "dask".