Repository navigation
Replace dill with cloudpickle - #865
Conversation
dask.multiprocessing. this commit: test with dill
There was a problem hiding this comment.
For what objects were we hitting a recursion limit? Ideally nothing we do is this heavily nested.
There was a problem hiding this comment.
@mrocklin I am investigating a bit more about what is going on in the test cases that hit the recursion limit.
Running the tests on my laptop (on py27 and py35) I cannot reproduce the recursionlimit errors, so I am temporarily adding more info to the exceptions such that I can get a better idea of what is happening with these tests in travis. I'll post a comment when I have more info.
There was a problem hiding this comment.
I have narrowed this down a little bit. For example in dask/bag/tests/test_bag.py::test_fold FAILED the object that is failing to pickle is
['bag-33', (<built-in function reduce>, <method 'union' of 'set' objects>, [('bag-32', 0), ('bag-32', 1), ('bag-32', 2)]), {('bag-32', 0): set([0, 1]), ('bag-32', 1): set([2, 3]), ('bag-32', 2): set([4])}, <AutoProxy[Queue] object, typeid 'Queue' at 0x4497110>, <function _process_get_id at 0x34eb410>, False]
I went ahead and tried pickling the items in this list, and found that the one that causes the recursion error is:
(<built-in function reduce>, <method 'union' of 'set' objects>, [('bag-32', 0), ('bag-32', 1), ('bag-32', 2)])
I did the same for the other failing tests, and found that the objects that hit the recursion limit are:
dask/bag/tests/test_bag.py::test_fold FAILED:
(<built-in function reduce>, <method 'union' of 'set' objects>, [('bag-32', 0), ('bag-32', 1), ('bag-32', 2)])dask/bag/tests/test_bag.py::test_distinct FAILED:
(<built-in function apply>, <method 'union' of 'set' objects>, [('bag-34', 2), ('bag-34', 1), ('bag-34', 0)])dask/bag/tests/test_bag.py::test_from_filenames_large FAILED:
(<method 'decode' of 'str' objects>, (<function textblock at 0x2157e60>, '/tmp/tmpju03wI.', 200, 300, None), 'utf-8')dask/bag/tests/test_bag.py::test_from_filenames_encoding FAILED:
(<method 'decode' of 'str' objects>, (<function textblock at 0x2157e60>, '/tmp/tmpTsLX9O.', 0, 100, None), 'gb18030')dask/bag/tests/test_bag.py::test_from_filenames_large_gzip FAILED:
(<method 'decode' of 'str' objects>, (<function textblock at 0x2157e60>, '/tmp/tmpKXpz29.gz', 500, 600, 'gzip'), 'utf-8')
There was a problem hiding this comment.
That's quite odd. None of those strike me as particularly troublesome.
There was a problem hiding this comment.
It seems like the probem occurs for method descriptor objects:
Python 2.7.10 |Continuum Analytics, Inc.| (default, Oct 19 2015, 18:04:42)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import cloudpickle, pickle
>>> cloudpickle.dumps(set.union)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/pmd/anaconda3/envs/python2/lib/python2.7/site-packages/cloudpickle/cloudpickle.py", line 602, in dumps
cp.dump(obj)
File "/home/pmd/anaconda3/envs/python2/lib/python2.7/site-packages/cloudpickle/cloudpickle.py", line 111, in dump
raise pickle.PicklingError(msg)
pickle.PicklingError: Could not pickle object as excessively deep recursion required.
>>> cloudpickle.dumps(str.decode)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/pmd/anaconda3/envs/python2/lib/python2.7/site-packages/cloudpickle/cloudpickle.py", line 602, in dumps
cp.dump(obj)
File "/home/pmd/anaconda3/envs/python2/lib/python2.7/site-packages/cloudpickle/cloudpickle.py", line 111, in dump
raise pickle.PicklingError(msg)
pickle.PicklingError: Could not pickle object as excessively deep recursion required.
>>> pickle.dumps(set.union)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/pmd/anaconda3/envs/python2/lib/python2.7/pickle.py", line 1374, in dumps
Pickler(file, protocol).dump(obj)
File "/home/pmd/anaconda3/envs/python2/lib/python2.7/pickle.py", line 224, in dump
self.save(obj)
File "/home/pmd/anaconda3/envs/python2/lib/python2.7/pickle.py", line 306, in save
rv = reduce(self.proto)
File "/home/pmd/anaconda3/envs/python2/lib/python2.7/copy_reg.py", line 70, in _reduce_ex
raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle method_descriptor objects
>>> def f(x):
... return set.union(x)
...
>>> cloudpickle.dumps(f)
'\x80\x02ccloudpickle.cloudpickle\n_fill_function\nq\x00(ccloudpickle.cloudpickle\n_make_skel_func\nq\x01ccloudpickle.cloudpickle\n_builtin_type\nq\x02U\x08CodeTypeq\x03\x85q\x04Rq\x05(K\x01K\x01K\x02KCU\rt\x00\x00j\x01\x00|\x00\x00\x83\x01\x00Sq\x06N\x85q\x07U\x03setq\x08U\x05unionq\t\x86q\nU\x01xq\x0b\x85q\x0cU\x07<stdin>q\rU\x01fq\x0eK\x01U\x02\x00\x01q\x0f))tq\x10Rq\x11]q\x12}q\x13\x87q\x14Rq\x15}q\x16N}q\x17tR.'
>>> def g(x):
... return str.decode(x)
...
>>> cloudpickle.dumps(g)
'\x80\x02ccloudpickle.cloudpickle\n_fill_function\nq\x00(ccloudpickle.cloudpickle\n_make_skel_func\nq\x01ccloudpickle.cloudpickle\n_builtin_type\nq\x02U\x08CodeTypeq\x03\x85q\x04Rq\x05(K\x01K\x01K\x02KCU\rt\x00\x00j\x01\x00|\x00\x00\x83\x01\x00Sq\x06N\x85q\x07U\x03strq\x08U\x06decodeq\t\x86q\nU\x01xq\x0b\x85q\x0cU\x07<stdin>q\rU\x01gq\x0eK\x01U\x02\x00\x01q\x0f))tq\x10Rq\x11]q\x12}q\x13\x87q\x14Rq\x15}q\x16N}q\x17tR.'
>>>
|
I found that the switch to Win32 python 3.5 with
|
|
It looks like the the |
|
Whoa, that's a surprising limitation. Hrm, we could consider choosing the serialization library based on the python version and system platform. |
|
I may be onto something. Using the |
|
Very cool. |
|
Looks like I may have found a better solution to the |
|
Oh cool. That is indeed much nicer |
|
@mrocklin Should I squash all commits in to a single one in this case as well? Let me know if you think there is anything pending for this request to be complete. |
|
Looks good to me. Merging in 12 hours if no comments |
|
Excited about this, |
Replace dill with cloudpickle
|
This is in. Thanks @PedroMDuarte ! |
| def _dumps(x): | ||
| return cloudpickle.dumps(x, protocol=pickle.HIGHEST_PROTOCOL) | ||
|
|
||
| _loads = pickle.loads |
There was a problem hiding this comment.
Not sure if this was intentionally meant to be pickle or if this should actually be cloudpickle. Assumed the latter and added PR ( #3180 ) to change it. However if I assumed incorrectly, please feel free to let me know. Would be good to understand why if this was intentional.
|
Cloudpickle produces bytestrings that are unpicklable with the pickle
module.
…On Tue, Feb 20, 2018 at 3:23 PM, jakirkham ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In dask/multiprocessing.py
<#865 (comment)>:
> +else:
+ import copyreg
+
+def _reduce_method_descriptor(m):
+ return getattr, (m.__objclass__, m.__name__)
+
+# type(set.union) is used as a proxy to <class 'method_descriptor'>
+copyreg.pickle(type(set.union), _reduce_method_descriptor)
+
+import pickle
+import cloudpickle
+
+def _dumps(x):
+ return cloudpickle.dumps(x, protocol=pickle.HIGHEST_PROTOCOL)
+
+_loads = pickle.loads
Not sure if this was intentionally meant to be pickle or if this should
actually be cloudpickle. Assumed the latter and added PR ( #3180
<#3180> ) to change it. However if I
assumed incorrectly, please feel free to let me know. Would be good to
understand why if this was intentional.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#865 (review)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AASszLHlZ0UnhVIA3Yqqi7dK4kIrw7Hoks5tWykKgaJpZM4Gvhdh>
.
|
|
Not sure I follow. We are already using |
In [1]: import pickle, cloudpickle
In [2]: pickle.loads is cloudpickle.loads
Out[2]: True |
|
I see. Still wouldn't it be better to be explicit? Just in case |
|
No preference on my end
…On Tue, Feb 20, 2018 at 4:16 PM, jakirkham ***@***.***> wrote:
I see. Still wouldn't it be better to be explicit? Just in case
cloudpickle ever changed the behavior.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#865 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AASszN9TYq6uuSa1FInhGqJ1NuLTFwGRks5tWzZBgaJpZM4Gvhdh>
.
|
WIP for #847
cloudpickle.test_dataframe_series_are_dillableuses itdillandcloudpickleatdask/multiprocessing.py. Other tests wheredillwas imported now usemultiprocessing._dumpsandmultiprocessing._loads.__globals__:dask/tests/test_multiprocessing.py::test_pickle_globals.dilland passes withcloudpicklecloudpickleintroduced regressions in some tests for Python <= 3.3dask/bag/core.py::dask.bag.core.Bag.distinct FAILED(failed in Python:2.7 only)dask/bag/tests/test_bag.py::test_fold FAILEDdask/bag/tests/test_bag.py::test_distinct FAILEDdask/bag/tests/test_bag.py::test_from_filenames_large FAILEDdask/bag/tests/test_bag.py::test_from_filenames_encoding FAILEDdask/bag/tests/test_bag.py::test_from_filenames_large_gzip FAILEDPicklingError: Could not pickle object as excessively deep recursion required.dask/multiprocessing.pythat fixes the recursion errors seen so far: ifdumpsfails the recursion limit is increased by a factor of 2 andcloudpickletries again.I appreciate any feedback on this WIP. Thanks!