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
performance of map_overlap with boundary='none' is hindered by add_dummy_padding #3947
map_overlap provides a few boundary conditions. The performance of the 'none' boundary condition is seriously affected when the array is trimmed since dummy_padding is added to the array which forces a whole copy of the array.
To illustrate the problem, I define a convenience function that implements the trim logic at the end of map_overlap.
Benchmark:
fromdaskimportarrayasdafromdask.array.overlapimport (coerce_boundary,
coerce_depth,
trim_internal,
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_overlapdeftrim(x, depth, boundary=None):
boundary2=coerce_boundary(x.ndim, boundary)
depth2=coerce_depth(x.ndim, depth)
x2=add_dummy_padding(x, depth2, boundary2)
returntrim_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(z, 10, boundary='none').persist()
%time_=trim(z, 10, boundary='nearest').persist()
%time_=trim(z, 10, boundary='none').persist()
%time_=trim(z, 10, boundary='nearest').persist()
Results:
'nearest' finishes in 30 ms
'none' finishes in 500 ms
Computation graph
Trimming with 'nearest'
trim(z, 10, boundary='nearest').visualize()
Trimming with 'none'
trim(z, 10, boundary='none').visualize()
This is very likely the issue I was seeing in Issue #3938
I agree that in my case it is "all boundary", but you may only want to overlap in a specific dimensions (a use case that was envisioned in map_overlap) in which case the trim functionality, that you would assume should be a no-op in those dimensions, is actually coming at a big cost. this is probably not true.
I think the logic of add_dummy_padding can be moved in chunk.trim (or whatever function actually returns the sliced array), to allow the slicing to be aware of the boundary condition. map_blocks can pass block_info to the trimming function so that it becomes aware what block is being trimmed.
the slicing can then check if
If it is located on boundary.
If that boundary was originally passed as 'none'.
Then it can choose to slice the axis as :, overlap:, overlap:-overlap or :-overlap accordingly.
On Tue, Sep 4, 2018 at 9:52 PM, Mark Harfouche ***@***.***> wrote:
I agree that in my case it is "all boundary", but you may only want to
overlap in a specific dimensions (a use case that was envisioned in
map_overlap) in which case the trim functionality, that you would assume
should be a no-op in those dimensions, is actually coming at a big cost.
I think the logic of add_dummy_padding can be moved in chunk.trim (or
whatever function actually returns the sliced array), to allow the slicing
to be aware of the boundary condition. map_blocks can pass block_info to
the trimming function so that it becomes aware what block is being trimmed.
the slicing can then check if
1. If it is located on boundary.
2. If that boundary was originally passed as 'none'.
Then it can choose to slice the axis as :, overlap:, overlap:-overlap or
:-overlap accordingly.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#3947 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AASszBphJjX2ZjaplIbRUymuPRfytjvcks5uXy5ogaJpZM4WZ9SP>
.
PR #3950 implemented the "solution" where the logic is moved down to chunk.trim but I'm not convinced that it is the best solution. I mostly wrote it so I could benchmark my own work without incurring large memory copies and to learn about block_info.
My specific issue with PR #3950 is that chunk.trim now needs knowledge of options that are coming from higher level code. This makes the api of chunk.trim very cluttered.
I think a better solution would be to somehow:
Allow chunk.trim to handle asymmetric trimming
Call chunk.trim with the appropriate trimming parameters on each axis.
For now, chunk.trim supports different trimmings on a per axis level, but doesn't support asymmetric trimming.
I can probably help implement this, but I would need guidance on the correct choice for the API of chunk.trim:
Maybe: axes could take:
An iterable of tuples. The inner tuple would be trim_front, trim_back. trim_back would have to be a positive number or None
If the iterable returns a non-iterable, then it assumes symmetric slicing.
If axis is a single value, symmetric trimming on all axes is assumed.
I think that it doesn't matter that much. We can make some new function like chunk.trim that is only used in this context. This inner function doesn't have to be public API.
Activity
mrocklin commentedon Sep 5, 2018
It looks like it only affects the outer boundary chunks, but I suspect that in your case that this is the entire array.
Do you have a recommendation on how to improve the implementation?
hmaarrfk commentedon Sep 5, 2018
I agree that in my case it is "all boundary", but you may only want to overlap in a specific dimensions (a use case that was envisioned inthis is probably not true.map_overlap) in which case thetrimfunctionality, that you would assume should be a no-op in those dimensions, is actually coming at a big cost.I think the logic of
add_dummy_paddingcan be moved inchunk.trim(or whatever function actually returns the sliced array), to allow the slicing to be aware of the boundary condition.map_blockscan passblock_infoto the trimming function so that it becomes aware what block is being trimmed.the slicing can then check if
Then it can choose to slice the axis as
:,overlap:,overlap:-overlapor:-overlapaccordingly.First implementation of fast trimming for boundary='none'
mrocklin commentedon Sep 5, 2018
hmaarrfk commentedon Sep 5, 2018
PR #3950 implemented the "solution" where the logic is moved down to
chunk.trimbut I'm not convinced that it is the best solution. I mostly wrote it so I could benchmark my own work without incurring large memory copies and to learn aboutblock_info.My specific issue with PR #3950 is that
chunk.trimnow needs knowledge of options that are coming from higher level code. This makes the api ofchunk.trimvery cluttered.I think a better solution would be to somehow:
chunk.trimto handle asymmetric trimmingchunk.trimwith the appropriate trimming parameters on each axis.For now,
chunk.trimsupports different trimmings on a per axis level, but doesn't support asymmetric trimming.I can probably help implement this, but I would need guidance on the correct choice for the API of
chunk.trim:Maybe:
axescould take:trim_front,trim_back.trim_backwould have to be a positive number orNonemrocklin commentedon Sep 5, 2018
I think that it doesn't matter that much. We can make some new function like chunk.trim that is only used in this context. This inner function doesn't have to be public API.
dask.array: Don't use dummy expansion for trim_internal in overlapped…
dask.array: Don't use dummy expansion for trim_internal in overlapped…
dask.array: Don't use dummy expansion for trim_internal in overlapped (…