Repository navigation
Modify mean chunk functions to return dicts rather than arrays - #4513
Conversation
These functions return two array chunks each: 1. The sum of the array 2. The counts of the array We need to return these as a single intermediate value. Previously we did this by constructing an empty numpy array and then assigning into it. This doesn't work as well with numpy-like arrays like cupy and sparse. Now we return a dict containing two arrays. This is nice in a few ways, but does mean that we need to replicate the `concatenate=` functionality within our chunk aggregation and combine functions, which can be tricky. This commit fails to do it correctly, but may be a good start. After this we would like to implement the same fix for other functions, notably the `moment_*` functions in this same reductions.py file. Fixes dask#4481
| total = _concatenate2(totals, axes=axis).sum(axis=axis, **kwargs) | ||
|
|
||
| return divide(total.sum(dtype=dtype, **kwargs), | ||
| n.sum(dtype=dtype, **kwargs), dtype=dtype) |
There was a problem hiding this comment.
Found the mistake, you're calling .sum() twice for both total and n. Get rid of one and you should be good to go!
|
By the way, @mrocklin if you want to get your commit fixed and merge it, feel free to leave |
|
If you like I'm also happy to hand this entire commit to you to finish up
if you're interested :)
…On Thu, Feb 21, 2019 at 7:05 AM Peter Andreas Entschev < ***@***.***> wrote:
By the way, @mrocklin <https://github.com/mrocklin> if you want to get
your commit fixed and merge it, feel free to leave moment_* to me, I just
found out it's the next one in line for Dask-GLM+CuPY.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4513 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AASszL8B-HVZPYIAEILdEMsnVJ3dt9Kiks5vPrXPgaJpZM4bEV_j>
.
|
|
I don't mind taking it over, but the fix is to literally remove the double |
|
Pushed. @jakirkham if you're around to review that would be welcome. |
|
Thinking about extending this to moment, it looks like there is a little bit of a challenge here: empty = empty_lookup.dispatch(type(n))
M = empty(n.shape + (order - 1,), dtype=dtype)
for o in range(2, order + 1):
M[..., o - 2] = _moment_helper(Ms, ns, inner_term, o, sum, kwargs)Here we construct an empty array and then assign into it. Instead, we might construct many arrays and then concatenate them together. xs = [_moment_helper(Ms, ns, inner_term, o, sum, kwargs) for o in range(2, order + 1)]
M = np.stack(x2, axis=-1)(I might have the axis= keyword above wrong. Also depending on the shape of the output of cc @pentschev |
|
@mrocklin that might work, but couldn't that cause a potential performance issue? I guess the stacked blocks will all remain different memory blocks, right? My concern is more on the case if stacking doesn't cause all the blocks to be moved to a single memory block, thus involving allocation and copy. |
|
And also, I'd like to point out that this will still require a lookup for empty_like, which is simple to add. |
I suspect that the data at this stage of the computation will probably be pretty small (it has already gone through a reduction along at least one axis), so I'm not too concerned about performance.
I think that we can avoid this. We no longer construct an empty array and then assign into it. Instead we create many arrays and then call |
|
Nevermind, you're right, I misinterpreted your suggestion on how to do the stacking. I will work on it, thanks for the suggestions. |
This is a follow-up on dask#4513.
|
Merging this later today if there are no further comments |
|
Nope, not merging. Adding a failing test. We still use To be honest I'm hoping that @pentschev is able to come up with a solution that I'll be able to steal here :) |
I just tried this new test you added and it fails also in current master (i.e., before the changes in this PR). I think this is something we could (maybe even should) tackle in a different issue? |
This is a follow-up on #4513.
|
I think this is good to be merged now @mrocklin |
This is a follow-up on dask#4513.
…4513) These functions return two array chunks each: 1. The sum of the array 2. The counts of the array We need to return these as a single intermediate value. Previously we did this by constructing an empty numpy array and then assigning into it. This doesn't work as well with numpy-like arrays like cupy and sparse. Now we return a dict containing two arrays. This is nice in a few ways, but does mean that we need to replicate the `concatenate=` functionality within our chunk aggregation and combine functions, which can be tricky. This commit fails to do it correctly, but may be a good start. After this we would like to implement the same fix for other functions, notably the `moment_*` functions in this same reductions.py file. Fixes dask#4481
These functions return two array chunks each:
We need to return these as a single intermediate value.
Previously we did this by constructing an empty numpy array and then
assigning into it. This doesn't work as well with numpy-like arrays
like cupy and sparse.
Now we return a dict containing two arrays. This is nice in a few ways,
but does mean that we need to replicate the
concatenate=functionality within our chunk aggregation and combine functions, which
can be tricky. This commit fails to do it correctly, but may be a good
start.
This is also somewhat suboptimal in a distributed setting because we no longer get special-cased handling of numpy arrays like we used to. The scheduler will probably miscount the number of bytes that these objects hold and will probably not use ideal serialization and compression. I think that this is probably ok because they're likely to be small, but it's worth pointing out.
After this we would like to implement the same fix for other functions,
notably the
moment_*functions in this same reductions.py file.Fixes #4481
Help or ideas with this would be welcome. cc @pentschev @jakirkham
flake8 dask