Skip to content

Add option to control rechunking in reshape - #6753

Merged
jsignell merged 6 commits into
dask:masterfrom
TomAugspurger:reshape-rechunk-special-2
Jan 14, 2021
Merged

jsignell merged 6 commits into
dask:masterfrom
TomAugspurger:reshape-rechunk-special-2

Conversation

@TomAugspurger

Copy link
Copy Markdown
Member

Builds on top of #6748, so a WIP for now. Just pushing this to show the docs to aid in review over there.

In da.reshape, there's a tradeoff between

  1. The chunking of "slow-moving" axes (specifically whether they all have chunksize=1)
  2. The amount of communication / merging done in the reshape

This adds a keyword to control that tradeoff. The default merge_chunks=True is the current behavior and is backwards compatible.

Here's a render of the new docs

array-reshaping

When the slow-moving (early) axes in `.reshape` are all size 1, then we
can avoid an intermediate rechunk which could cause memory issues.

```
00 01 | 02 03   # a[0, :, :]
----- | -----
04 05 | 06 07
08 09 | 10 11

=============

12 13 | 14 15   # a[1, :, :]
----- | -----
16 17 | 18 19
20 21 | 22 23

-> (3, 4)

00 01 | 02 03
----- | -----
04 05 | 06 07
08 09 | 10 11
----- | -----
12 13 | 14 15
----- | -----
16 17 | 18 19
20 21 | 22 23
```

xref dask#5544, specifically the examples
given in dask#5544 (comment).
Adds a keyword to reshape to control merge / rechunking. See the
documentation for an explanation.
@TomAugspurger
TomAugspurger marked this pull request as draft October 20, 2020 14:22
@TomAugspurger
TomAugspurger marked this pull request as ready for review November 5, 2020 18:49
Comment thread dask/array/reshape.py
an integer, then the result will be a 1-D array of that length.
One shape dimension can be -1. In this case, the value is
inferred from the length of the array and remaining dimensions.
merge_chunks : bool, default True

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsignell do you have thoughts on this API? Does merge_chunks=True feel like a good description of what is done on master today? I see a couple alternatives:

  • merge_intermediate_chunks: Make it a bit clearer when things are getting merged.
  • rechunk_leading_axes=False/True: Flip the logic to make it opt-in rather than opt-out.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it flipped, but rechunk_leading_axes feels long. This feels kind of like split_every=1 or something, but maybe reusing that kwarg is too confusing. Maybe split_chunks would work?

@jsignell

Copy link
Copy Markdown
Member

I am fine with merging this as-is and seeing how it goes. Does that work for you @TomAugspurger?

@TomAugspurger

Copy link
Copy Markdown
Member Author

Works for me :)

@jsignell
jsignell merged commit 1a52a0c into dask:master Jan 14, 2021
abduhbm pushed a commit to abduhbm/dask that referenced this pull request Jan 19, 2021
* Avoid rechunking in reshape with chunksize=1

When the slow-moving (early) axes in `.reshape` are all size 1, then we
can avoid an intermediate rechunk which could cause memory issues.

```
00 01 | 02 03   # a[0, :, :]
----- | -----
04 05 | 06 07
08 09 | 10 11

=============

12 13 | 14 15   # a[1, :, :]
----- | -----
16 17 | 18 19
20 21 | 22 23

-> (3, 4)

00 01 | 02 03
----- | -----
04 05 | 06 07
08 09 | 10 11
----- | -----
12 13 | 14 15
----- | -----
16 17 | 18 19
20 21 | 22 23
```

xref dask#5544, specifically the examples
given in dask#5544 (comment).

* fix conditioni

* remove breakpoint comment

* API: Added merge_chunks to reshape

Adds a keyword to reshape to control merge / rechunking. See the
documentation for an explanation.

* update images
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants