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
from_array performance when no name is provided #3946
The performance of from_array seems to be seriously affected when no name is provided.
I understand that in the documentation you mention that setting name to false is (fast), but I think the default should be changed to False. Edit: I think perhaps a more stark warning should be provided and the information that @martindurant can be linked in the comment.
For example, the asarray function doesn't even provide a name argument. this means that using asarray is guaranteed to be slow. da.asarray is used in at least a few places like empty_like which make that function take for ever....
I have a feeling the whole array module will feel different with that default changed
from dask import array as da
import numpy as np
import dask
print(dask.__version__)
print(np.__version__)
# For python to load up dask array for fair benchmarks
_ = da.asarray(np.zeros(2))
shape = (50, 1024, 1024)
# This takes Wall time 170 ms
%time a = np.ones(shape=shape)
# This takes wall time 500 ms!!
%time _ = da.asarray(a)
# This takes wall time 400 us, that is more like it!
%time _ = da.from_array(a, chunks=-1, name=False)
# This takes 500 ms !!!
%time b = da.from_array(a, chunks=-1)
# This takes 500ms!!
%time da.empty_like(a)
# This takes 100 us! much more like it
%time da.empty_like(b)
but I think the default should be changed to False.
Defaults are tricky things. They need to be optimized over many different use cases. Splitting large in-memory numpy arrays into a dask arrays is actually a pretty rare workload overall. More often large dask arrays come into being from being loaded directly from files/network or are otherwise generated in a way where we can create their name without hashing all of their data (filename, last modification time, etc..) However when these arrays interact with Numpy arrays those numpy arrays are more often quite small, and hashing them by default to avoid repeated work in complex algorithms is a very useful feature that can significantly improve performance.
The cost to people accelerating Numpy workloads is unfortunate. I don't disagree that it would be good to avoid this somehow, but based on current use it's not clear that changing the default is strictly a good idea.
I get it.
This was definitely done intentionally.
Maybe a separate bug for the use of asarray in the *like functions is
appropriate. Really only the metadata needs to be extracted.
Finally, maybe the introduction of a name parameter to asarray would help
overcome the immediate issues for those transitioning from numpy arrays.
On Tue, Sep 4, 2018 at 9:21 PM Matthew Rocklin ***@***.***> wrote:
but I think the default should be changed to False.
Defaults are tricky things. They need to be optimized over many different
use cases. Splitting large in-memory numpy arrays into a dask arrays is
actually a pretty rare workload overall. More often large dask arrays come
into being from being loaded directly from files/network or are otherwise
generated in a way where we can create their name without hashing all of
their data (filename, last modification time, etc..) However when these
arrays interact with Numpy arrays those numpy arrays are more often quite
small, and hashing them by default to avoid repeated work in complex
algorithms is a *very* useful feature that can significantly improve
performance.
The cost to people accelerating Numpy workloads is unfortunate. I don't
disagree that it would be good to avoid this somehow, but based on current
use it's not clear that changing the default is strictly a good idea.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#3946 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAFfmCrX0es3J0pmYF2Q7PmoU0IPqVISks5uXycogaJpZM4WZ77d>
.
It is worth pointing out that for arrays, the default hash uses python's standard sha1, but if you happen to have cityhash, xxhash or murmurhash installed (all available with pip), then you can get a large-factor speedup in the tokenisation step. You may consider that a separate point, but perhaps it is useful.
FYI the *_like functions don't actually generate any arrays until computation occurs. So hashing for them proceeds through a different path. Doubt that adding a name parameter is needed in that case.
For the asarray checks in those functions? That sounds like a good idea. Alternatively we could rely completely on duck typing there and drop the asarray calls. That may cause some breakage for users relying on asarray to be called for them, but we could mitigate this with a decent exception message and users can fix the issue pretty easily.
Activity
mrocklin commentedon Sep 5, 2018
Defaults are tricky things. They need to be optimized over many different use cases. Splitting large in-memory numpy arrays into a dask arrays is actually a pretty rare workload overall. More often large dask arrays come into being from being loaded directly from files/network or are otherwise generated in a way where we can create their name without hashing all of their data (filename, last modification time, etc..) However when these arrays interact with Numpy arrays those numpy arrays are more often quite small, and hashing them by default to avoid repeated work in complex algorithms is a very useful feature that can significantly improve performance.
The cost to people accelerating Numpy workloads is unfortunate. I don't disagree that it would be good to avoid this somehow, but based on current use it's not clear that changing the default is strictly a good idea.
hmaarrfk commentedon Sep 5, 2018
martindurant commentedon Sep 5, 2018
It is worth pointing out that for arrays, the default hash uses python's standard sha1, but if you happen to have cityhash, xxhash or murmurhash installed (all available with pip), then you can get a large-factor speedup in the tokenisation step. You may consider that a separate point, but perhaps it is useful.
mrocklin commentedon Sep 5, 2018
Adding a name parameter makes sense.
hmaarrfk commentedon Sep 5, 2018
I guess that will start to depart from the numpy API.
Seem like you could:
nameparameter to asarrayasarraycallfrom_arraywithname=FalseI'm not sure if that will invoke the same loss in hashing for the algorithms you mentioned.
hmaarrfk commentedon Sep 8, 2018
@mrocklin I could add a PR to add a
nameparameter toasarray.How would this affect the performance of
*_likewhen callingasarraywith the parametername=Falsefor the use cases you mentioned?mrocklin commentedon Sep 9, 2018
hmaarrfk commentedon Sep 9, 2018
So the added parameter should have to be added to the functions
*_likeas well?mrocklin commentedon Sep 9, 2018
jakirkham commentedon Sep 9, 2018
FYI the
*_likefunctions don't actually generate any arrays until computation occurs. So hashing for them proceeds through a different path. Doubt that adding anameparameter is needed in that case.mrocklin commentedon Sep 9, 2018
mrocklin commentedon Sep 9, 2018
jakirkham commentedon Sep 9, 2018
For the
asarraychecks in those functions? That sounds like a good idea. Alternatively we could rely completely on duck typing there and drop theasarraycalls. That may cause some breakage for users relying onasarrayto be called for them, but we could mitigate this with a decent exception message and users can fix the issue pretty easily.hmaarrfk commentedon Sep 9, 2018
the only thing I can think of is:
doesn't have the array interface.
we would need a function that is like:
Set name=False in array foo_like functions
Set name=False in array foo_like functions (#4116)
hmaarrfk commentedon Oct 23, 2018
Thanks @mrocklin !!
mrocklin commentedon Oct 23, 2018