Skip to content

Commit 30dafd2

Browse files
authored
Fix downsampling memory consumption (#1325)
* Improve memory signature of mode downsampling * Reintroduce smaller buffer shape for downsampling to avoid excessive RAM consumption * Revert "Improve memory signature of mode downsampling" This reverts commit d5d82c5. * Update changelog
1 parent c85770d commit 30dafd2

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

webknossos/Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ For upgrade instructions, please check the respective _Breaking Changes_ section
1919
### Changed
2020

2121
### Fixed
22+
- Fixed excessive RAM consumption during downsampling by chunking the computation. [#1325](https://github.com/scalableminds/webknossos-libs/pull/1325)
2223

2324

2425
## [2.3.10](https://github.com/scalableminds/webknossos-libs/releases/tag/v2.3.10) - 2025-06-17

webknossos/webknossos/dataset/_downsampling_utils.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,16 @@ class InterpolationModes(Enum):
2828
MIN = 6
2929

3030

31-
def determine_buffer_shape(array_info: ArrayInfo) -> Vec3Int:
31+
def determine_downsample_buffer_shape(array_info: ArrayInfo) -> Vec3Int:
32+
# This is the shape of the data in the downsampling target magnification, so the
33+
# data that is read is up to 512³ vx in the source magnification. Using larger
34+
# shapes uses a lot of RAM, especially for segmentation layers which use the mode filter.
35+
# See https://scm.slack.com/archives/CMBMU5684/p1749771929954699 for more context.
36+
return Vec3Int.full(256).pairmin(array_info.shard_shape)
37+
38+
39+
def determine_upsample_buffer_shape(array_info: ArrayInfo) -> Vec3Int:
40+
# This is the shape of the data in the upsampling target magnification.
3241
return array_info.shard_shape
3342

3443

webknossos/webknossos/dataset/layer.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
calculate_default_coarsest_mag,
2020
calculate_mags_to_downsample,
2121
calculate_mags_to_upsample,
22-
determine_buffer_shape,
22+
determine_downsample_buffer_shape,
23+
determine_upsample_buffer_shape,
2324
downsample_cube_job,
2425
parse_interpolation_mode,
2526
)
@@ -1301,7 +1302,7 @@ def downsample_mag(
13011302
# perform downsampling
13021303
with get_executor_for_args(None, executor) as executor:
13031304
if buffer_shape is None:
1304-
buffer_shape = determine_buffer_shape(prev_mag_view.info)
1305+
buffer_shape = determine_downsample_buffer_shape(prev_mag_view.info)
13051306
func = named_partial(
13061307
downsample_cube_job,
13071308
mag_factors=mag_factors,
@@ -1506,7 +1507,7 @@ def upsample(
15061507
# perform upsampling
15071508
with get_executor_for_args(None, executor) as actual_executor:
15081509
if buffer_shape is None:
1509-
buffer_shape = determine_buffer_shape(prev_mag_view.info)
1510+
buffer_shape = determine_upsample_buffer_shape(prev_mag_view.info)
15101511
else:
15111512
buffer_shape = Vec3Int.from_vec_or_int(buffer_shape)
15121513
func = named_partial(

0 commit comments

Comments
 (0)