Repository navigation
dask.array: Don't use dummy expansion for trim_internal in overlapped - #3964
Conversation
|
Note to self. I guess i need to specify the partial arguments as kwargs for python 2.7 to take them in. |
|
Except for the Python 2 errors things here seems sensible to me. @jakirkham might find this PR interesting. @hmaarrfk if I recall correctly you have a small benchmark where this showed significant speed improvement. Would you might including a small example as a comment in this PR? We might also include the speed difference in the commit message. |
|
2.7 bug is fixed in #3966 |
BenchmarkAdapted from #3947 (comment)
To illustrate the problem, I define a convenience function that implements the trim logic at the end of Benchmark: from dask import array as da
from dask.array.overlap import (coerce_boundary,
coerce_depth,
trim_internal,
trim_overlap,
add_dummy_padding)
shape=(150, 1024, 1024)
chunks=(-1, 512, 512)
dtype='float32'
z = da.zeros(shape=shape, chunks=chunks, dtype=dtype).persist()
# convenience function, inverse of da.overlap.overlap
# logic taken from map_overlap (before this patch)
def trim(x, depth, boundary=None):
boundary2 = coerce_boundary(x.ndim, boundary)
depth2 = coerce_depth(x.ndim, depth)
x2 = add_dummy_padding(x, depth2, boundary2)
return trim_internal(x2, depth2)
# Call once to force python to load all the necessary modules
_ = trim(z, 10, boundary='nearest').persist()
%time _ = trim(z, 10, boundary='none').persist()
%time _ = trim(z, 10, boundary='nearest').persist()
%time _ = trim_overlap(z, 10, boundary='none').persist()
%time _ = trim_overlap(z, 10, boundary='nearest').persist()
%time _ = trim(z, 10, boundary='none').persist()
%time _ = trim(z, 10, boundary='nearest').persist()
%time _ = trim_overlap(z, 10, boundary='none').persist()
%time _ = trim_overlap(z, 10, boundary='nearest').persist()Results:
Computation graphTrimming with 'nearest'trim(z, 10, boundary='nearest').visualize()Trimming with 'none'trim(z, 10, boundary='none').visualize()cc: @jni Much to my surprise, this speeds up boundary='nearest' as well. |
|
Also cc'ing @emmanuelle |
… computations Fixes dask#3947
950e328 to
80629e0
Compare
|
oh i didnt see that you had merged into my branch i guess i rebased and forced pushed... |
|
@mrocklin do you have any insight as to why this sped up |
|
To be honest I don't have great recall over this part of the codebase. You
may be the world expert right now :)
…On Sun, Sep 9, 2018 at 11:49 AM, Mark Harfouche ***@***.***> wrote:
@mrocklin <https://github.com/mrocklin> do you have any insight as to why
this sped up normal bdy conditions too? 30ms -> 2ms
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3964 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AASszLb_ezBvo_JZe06nymf75TOjcbZvks5uZTiKgaJpZM4WgAmU>
.
|
|
What do you want to do with the function Pads an array which has 'none' as the boundary type.
Used to simplify trimming arrays which use 'none'.
>>> import dask.array as da
>>> x = da.arange(6, chunks=3)
>>> add_dummy_padding(x, {0: 1}, {0: 'none'}).compute() # doctest: +NORMALIZE_WHITESPACE
array([..., 0, 1, 2, 3, 4, 5, ...])Had you done any changes to it before I erased yours? Also, the results of that benchmark still baffle me. I thought that it was serialization thing where because I defined the function from the REPL dask was having a hard time making the bytecode for it. Unfortunately, even if I move the old and new code into the benchmark script, I get the same results :S. I even modified it with: def trim(x, depth, boundary=None):
boundary2 = coerce_boundary(x.ndim, boundary)
depth2 = coerce_depth(x.ndim, depth)
x2 = add_dummy_padding(x, depth2, boundary2)
if boundary == 'nearest':
print('got here')
assert x is x2
return trim_internal(x2, depth2)and in fact, nearest just passes x2 as x, so I'm really confused. |
|
I wouldn't trust the 30ms -> 2ms speedup. Trying a few different combination out, I think There is definitely some memory issues (page faulting), that are causing the 30ms number to appear. A best case time of 2ms can be achieved on The 500 ms number seems consistent. |
Looking at your code above it looks like you never create a Dask.distributed If you wanted to see how this would function with separate processes, you would run the following two lines: from dask.distributed import Client
client = Client()But for your case where you're looking to accelerate computations on small datasets on a single computer the in-process ThreadPool is likely to be a much better solution. |
|
Right thanks for pointing that out. Still I don't undertand the huge difference in performance from 30ms to 2ms for operations that should effective call the dask infrastructure and a graph with no-ops |
|
You might find these mechanisms helpful to help figure out what's going on:
http://dask.pydata.org/en/latest/understanding-performance.html
…On Sun, Sep 9, 2018 at 5:51 PM, Mark Harfouche ***@***.***> wrote:
Right thanks for pointing that out.
Still I don't undertand the huge difference in performance from 30ms to
2ms for operations that should effective call the dask infrastructure and a
graph with no-ops
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3964 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AASszGYRb3voNAhSxQ_hyEnvIxl-t5PBks5uZY1bgaJpZM4WgAmU>
.
|
|
@jakirkham and @hmaarrfk you two might want to trade reviewing each others' PRs at #3958 and #3964 |
|
@jakirkham I've added a new api function |
Sorry for the delay in response. Yes, we handle API docs manually. I think that there is a section in the array api docs that is about overlapped. Presumably this would go there. |
|
If there are no further comments on this I plan to merge this at the end of the day. |
|
Did you want me to add things to the docs first? or were you going to do it? |
|
@jakirkham if you're around before then to look at things that would be welcome |
I don't plan to do this, no. I'm somewhat busy with other things. I just wanted to make sure that this PR didn't linger for too long. If you have time to add docs that would be welcome. |
|
Just a ping. I think I added the required info to the docs. Let me know if you need anything else. |
|
Sorry to be absent here. I'll try to look, but unfortunately can't promise anything before Friday. If other people are happy with this, would encourage you to move ahead without me. |
|
OK, I'm going to go ahead and merge. Retroactive reviewing would still be welcome @jakirkham if you have time. |
|
Thanks for the work here @hmaarrfk . It's nice to see someone take on performance for in-memory use cases. |


… computations
Fixes #3947
flake8 dask