Repository navigation
Description
This is a request for comments to define how the integration / dependence on joblib could evolve (or not evolve) in the future. There was some earlier discussion about this in #8494 and #12345
Vendoring vs defining joblib as a dependency
Currently, we are vendoring joblib under sklearn.utils.joblib. For 0.20, #11166 added the optional unvendoring of joblib using the SKLEARN_SITE_JOBLIB environment variable, then #11471 restructured the access to the vendored joblib via sklearn.utils.
The advantages of vendoring is that,
- the included version can be exactly controlled, which in particular helps ensuring that pickles will not break for a given scikit-learn version.
- we can claim that scikit-learn doesn't have any dependencies besides scipy, numpy.
- when users upgrade we are certain that the bundled dependency will also upgrade
- some of the other advantages of vendoring given e.g. as reason for bundling urllib3 as part of requests in Removed the bundled charade and urllib3. psf/requests#1812 (comment) do not apply in our case: joblib is not an implementation detail, and its use is not likely to change in the future; scikit-learn is not vendorable itself in any case because of C/Cython code, and users are likely to be using some packaging solution already to install numpy / scipy.
The disadvantages of vendoring are,
- any bug fix in vendored packages (this include joblib which itself vendors loky and cloudpickle) require a release of scikit-learn. Scikit-learn is a large package with C extensions that take much more effort to release than pure python vendored packages. As a results, scikit-learn releases happen relatively unfrequently meaning that most users will keep using vendored code with bugs that has been fixed upstream. Currently that applies to sklearn 0.20.0 and joblib 0.12.5 (although 0.12.6 has not been released yet).
- we end up owning issues related to vendored packages. Anything with a traceback that points to scikit-learn will end up on our issue tracker, even when there is nothing scikit-learn can do about the orginal issue e.g. Cloudpickle.py, the imp module is deprecated in favor of importlib #12434, Tests test_theil_sen_parallel and test_multi_output_classification_partial_fit_parallelism hang on Windows #12263 etc At the same time, some of the errors tracebacks will not be found in the trackers of the corresponding projects which breaks the usual Github workflow.
- this adds maintance overhead for scikit-learn,
- releases become dependent on joblib releases, and although it's not an issue because the joblib team is amaizing and very reactive, it's one extra constraint in our already slow release cycle and yet another thing to keep track of.
- joblib 0.12 is currently 13k lines of code -- that's a lot of code, so for any
git grepor LGTM warnings (Look at lgtm.com alerts for last couple of months #12167) will need some filtering. Also need to explain in reviews that changing vendored code is not recommended. - the 0.20.1 release will contain multiple fixes in vendored loky: do we need to document all of them in what's new, only provide a summary, link to the corresponding joblib or maybe loky release notes etc?
- vendoring is typically considered be bad by distrubution maintainers as it makes patching (for security vulnerabilities among other things) harder. In fact, numerous Linux distributions have unvendored joblib,
- Fedora
- Debian Sid (unstable) says that 0.20 is compatible with joblib > 0.9.2 which is hmm quite optimistic.
- Ubuntu Bionic also shows 0.19.1 compatible with joblib > 0.9.2
- Gentoo as previously discussed in Unbundling joblib #8494
some appear to be preserving some alias insklearn.externals.joblibsome are not.
So in practice part of out distributions channels are currently unvendoring joblib, while for for PyPi and conda we vendor it. #12350 also illustrates that actually supporting multiple joblib versions is not that much work code wise. I have not seen much issues reported by e.g. Ubuntu users due to the fact that they use an unvendored joblib.
The questions are,
- what should be done long term for
sklearn.externals.jobliband to prevent users using in in third party code (e.g. by raising some warning) ? - what is the actual range of joblib versions we could reasonably support for 0.20 : 0.11+ seems likely but possibly earlier ones would also work? What are the known issues with switching joblib versions with respect to pickle compatibility,
Memorycache consistency, and whether this can break any guarantees we currently provide. Having a good understanding of this would also help distribution maintainers. - Does it make sense to also unvendor on other distribution channels? I do believe it makes sense for conda which would only leave PyPi and the question whether the overhead we currently have is worth it (as compared to dependency say with version pinning).
Exposed joblib API
If we only used joblib internally in the code base it would be one thing. But we are also currently exposing part of the public API of joblib as part of scikit-learn API, first in sklearn.externals.joblib and since recently in sklearn.utils.{Parallel,parallel_backend,Memory,...} and suggest users use it in examples. This creates confusion for users which project implements this functionality, and corresponds to code that is not really documented in scikit-learn.
One solution could be to remove all these public joblib attributes (except for joblib.__version__) and say that to run examples users need to install joblib (independently of whether we vendor it or not internally). Currently, to run examples users are expected to install pandas, matplotlib, scikit-image but for some reason they can't install joblib. This does mean that model serialization would require joblib, and the question is when what happens when one mixes vendored and site joblib with different versions for parallel capability. Though it's a question worth considering even now: say one wants to use scikit-image with joblib and scikit-learn together which would lead to such situation.
Comments would be very appreciated.
cc @jnothman @GaelVaroquaux @amueller @ogrisel @lesteve @qinhanmin2014 @yarikoptic
Activity
jnothman commentedon Oct 23, 2018
I think joblib issues landing up in our tracker will happen anyway.
And I think you've missed a pro: when people are using different supported versions of joblib, issues will be hard to debug.
But I've not read fully yet
amueller commentedon Oct 23, 2018
I don't think that's an actual argument as it's unlikely to impact users in any way.
Unless they set
SKLEARN_SITE_JOBLIB.You missed a disadvantage: Incompatibility with site joblib.
If someone has a site joblib they might use that and the vendored joblib and that will break pickles (and will probably lead to issues if these are different versions).
I see the main disadvantage to be that we have to support multiple versions of joblib. But that's already happening right now. It means we probably want to keep supporting multiple versions in the future.
I am very strongly in favor of deprecating and removing joblib and adding it as a dependency, i.e. unvendoring on pip and conda.
I think the fact that we can have interactions with the site version of joblib is reason enough to unvendor. I don't see a compelling case for vendoring at all. All the benefits of vendoring could be achieved similarly by a pinned version dependency if that's what we want.
GaelVaroquaux commentedon Oct 24, 2018
amueller commentedon Oct 29, 2018
Roman gave several above to which I added mine. Can you be more specific?
GaelVaroquaux commentedon Oct 29, 2018
Indeed, sorry for not getting back on this. I asked this because I know that Roman is working on supporting scikit-learn on pyodide (which I think is absolutely awesome) and had difficulties with parallel computing in the process. Hence I was suspecting that he had very specific challenges. We had a lunch-time discussion on this topic, but I didn't report back here, which is bad.
Summarizing the main drawbacks
We discussed the various issues that vendoring joblib creates, touching upon the points mentionned above. Here is my summary. (Roman, I hope that I am giving a good summary, please do correct me). Bold and numbers are to ease readability, and not an indication of priority.
Roman's biggest pain is that he is patching joblib to work on pyodide. He needs to apply the patch twice, which is a drain of his resources. I think that the solution is that joblib should integrate his patch. The value of an abstraction like joblib is to make platform disappear.
A large drawback is that importing from sklearn.externals is confusing for users, and creates a havoc of joblib versions that are not explicitly understood by users. This typically happens for model persistence.
We should not encourage this behavior. The vendored joblib is for internal usage in scikit-learn and should not be exposed to users (I may be responsible for that, my bad). In particular, it should not be used for pickling.
Where I do see a problem is to expose the parallel_backend. The current solution is a hack, and is not a good option in the long term.
I believe that we should not support multiple joblib versions. The whole point of vendoring is to avoid that. I wrote the patch to be robust to variations in API, but I think that we should not go further in this direction. In my view, the SKLEARN_SITE_JOBLIB is a developers feature, only meant to test future version of joblib, and not past ones. Part of the patch that I wrote is simply the modifications that would have been necessary in the next vendoring of joblib.
Package maintainers apply their book of rules, which says that vendoring is bad, but in my experience it is more a general systematic point of view than a pragmatic one. The central reason invoked is to apply security patches, but they do this only for a very small number of critical packages, and it does not apply to our situation. Rather, package maintainers easily introduce packaging bugs: either by forgetting to update joblib (Linux distribution) or, in conda, by adding constraints between scikit-learn and specific numpy versions that do no exists (it's a major problem each time we update the environment.yml in scipy-lectures). Not blaming anyone, I used to do Debian packaging, and it's hard and valuable.
The core fear of the packager is that dead code lives in a project. Another aspect to keep in mind is that historically packagers come from Linux open-source advocates, and they try to fight depletion of developer resources due multiple developers maintaining copy-pasted code.
Having to do a scikit-learn release for bugfixes in joblib is a real drawback. In my eyes the major one that cannot be addressed.
Why vendoring is useful
To me, the importance of the vendoring of joblib is that joblib is really developed jointly with scikit-learn. Many of the evolutions of joblib are motivated directly to address bugs or performance issues in scikit-learn. In this sense, we would like to support only "future" version of joblib, and not past. The recent issues with "n_jobs=None" in the scikit-learn codebase (joblib/joblib#786) illustrates the tension that supporting older version of joblib creates.
The stakes are the following: we have been working on improving parallel computing in joblib (among other things with a dask backend). As we are moving forward with it, we find that we must make the API of joblib a bit more flexible and the scikit-learn must be adapted to use this flexibility. The goal is to have efficient distributed computing (across multiple computers) in scikit-learn. It's a strategic goal.
I asked the question about understanding the real reasons for unvendoring because I have the impression that there were multiple issues, some were more high level (ie: what we are doing is ugly), and some were very pragmatic (ie: I have a problem now). I wanted to make the difference to guide action.
Proposal: vendoring for now, revisit later
What I would like to propose is to keep the vendoring currently, because we do have a tight coupling in versions between joblib and scikit-learn: I my eyes we do not want to support older versions of joblib. We could pin the version number in our dependencies, but that's very bad practice because if several packages start doing this it leads to constraints that cannot be satisfied. Most of the problems above can be solved without too much work in the short term. I do hope that joblib will settle down, once we have a working distributing computing abstraction, but its been harder than expected.
That said, if people feel that the problems created by the vendoring add too much cost, I can understand the importance of unvendoring it. I would push for not supporting older versions in this case.
jnothman commentedon Oct 30, 2018
I think that made sense when scikit-learn 0.20 was to be shipped with joblib 0.11. But then we changed to shipping with joblib 0.12 which was not mature enough given the default loky/cloudpickle. Unless we are confident we can iron out many of the teething problems in joblib very soon, I think allowing users to adopt joblib 0.11 is a must.
GaelVaroquaux commentedon Oct 30, 2018
rth commentedon Oct 31, 2018
Thanks for the detailed summary Gael!
To be specific, that was not my main motivation. For more context, pyodide currently doesn't have ctypes, multiprocessing etc modules and because using the latest joblib inside scikit-learn would have required me to patch those inside the vendored loky, I though to try to use a site joblib 0.11 as a first step (and update later), as I didn't want to start by patching something I couldn't use anyway (just get past import errors).
That was mostly WIP, and is anyway too specific to be relevant for this discussion.
It's by no mean a criticism of joblib (or loky) -- both are great, I am a proponent of using them in other projects, and I think loky as the default backend will solve longstanding issues for users. The thing is though is that both deal with things that are a) fairly complex from an engineering perspective b) quite low level and therefore have a capacity to fail in some unexpected ways in non standard configurations. More so than the rest of the scikit-learn code base and particularly when new features are introduced.
The issue is then that the current official project position when users encounter a blocking issue with joblib is currently either to,
SKLEARN_SITE_JOBLIBmechanism that is currently considered a "developer" feature)the first two are not really great for user experience and the third is quite non standard.
Besides the ability to temporary rollback joblib one version back in case of issues, it also makes things a bit more awkward for people why know what they are doing. Say an engineer finds a bugs in loky when using scikit-learn on a production system. If everything was unvendored, in an ideal world, they would try to make a minimal example involving only joblib or loky and submit it to the corresponding issue tracker. Then when the PR with a fix is merged, they either use loky master or wait for a new loky release and they are done.
In the current situation, they would report the issue to scikit-learn, a dev there (assuming he is not part of joblib) needs to ping someone from joblib/loky to determine if the issue is genuine, then someone need to re-open the same issue in the proper issue tracker. Once it's fixed in loky, to use the stable version the engineer need to be aware of both the loky, joblib and scikit-learn release cycles (or be told that they are in sync), all the while at scikit-learn maintainers keep repeating for other users who missed the original issue "yes this was fixed upstream, and we will fix it here after we sync for the next release". There is no clean way to use loky master with anything, and to get a fix into scikit-learn one needs to wait at least a couple of months.
An example is that we keep getting issue reports about DeprecationWarnings in cloudpickle, 6 by now, even when this was fixed upstream a long time ago.
It creates latency and needless communications which is not nice for neither the user nor the maintainer. It might be more difficult to improve our release cycle speed, or PR reviews capacity, but I feel like joblib related issues are addressed quite fast but we are not currently taking advantage of it.
ogrisel commentedon Nov 9, 2018
I would also be in favor of un-vendoring joblib for a future version of scikit-learn for all the reasons @rth mentioned.
To mitigate the downside of adding such new dependencies to scikit-learn (joblib, loky and cloudpickle) we should make sure that the scikit-learn tests can work with reasonably old versions of those (that is joblib 0.11 and later for instance) as we do for numpy and scipy.
GaelVaroquaux commentedon Nov 9, 2018
jnothman commentedon Feb 26, 2019
Should we task someone with unvendoring joblib?