Repository navigation
Stream n4_biasfield instead of scaling its memory with the image - #216
Merged
Merged
Conversation
With ZarrNii's separable interpolation and level-by-level pyramid writes (khanlab/zarrnii#271), n4_biasfield's peak memory follows threads x chunk size: ~0.4 GB per thread for 256^3 chunks. Request a fixed 96 GB (12 GB per .ims dask worker) instead of 128 GB + 0.5x the image. Write the .ims temp zarr to the job's tmpdir, without a pyramid, since only level 0 is read back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eometry zarrnii 0.22.0 includes khanlab/zarrnii#271 (bounded memory for the map_blocks bias field apply and the pyramid write) and the fix for OME-Zarr writes losing voxel size, origin and units with ome-zarr-py >= 0.18 (khanlab/zarrnii#272). The lock moves ome-zarr from 0.18.0 to 0.21.0, adding transformnd and array-api-compat, updating ome-zarr-models to 1.8.1, and moving pydantic back to 2.12.5. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #215. Requires zarrnii 0.22.0, which includes khanlab/zarrnii#271.
Cause
I measured the steps of
n4_biasfield.pyone at a time on F1A1Te4 at levels 2 and 1, with 16 threads per worker and 18 GB per worker:map_blocksback end built a float64 coordinate grid for each block, about 52 bytes per voxel. That is 0.8 GB per 256³ block for each of a worker's 16 threads. At level 1 this reproduced theKilledWorkeron_fused_blockseen on the first cluster attempt..imstemp zarr: not a cause. It peaked at 3 GB at level 1, and/tmpon the nodes is local disk.khanlab/zarrnii#271 fixes all three, with separable interpolation, a pyramid written one level at a time, and the low-resolution arrays passed into the graph once.
KilledWorkerOn the cluster with this PR's request (128 threads, 96 GB), for the apply + pyramid stage:
Both succeeded on the first attempt. Including the
.imsconversion, the jobs took 4 min 23 s and 41 min 49 s. Slurm's MaxRSS (65 GB and 98 GB) also counts page cache from writing to the node's local disk, and the jobs were not memory-limited.That is about 0.4 GB per thread for 256³ chunks, regardless of image size. At level 2, outputs match 0.21.6 to within float32 precision. The only exception was 2 of 2.4 billion voxels at the mask's 0.5 threshold.
Changes
n4_biasfieldmemory: a fixed 96 GB, multiplied by the attempt, instead ofscaled_mem_mb(128000, 500). dask splits the job's memory across its workers, so a 16-thread.imsworker gets 12 GB. It peaked at 5.4 GB at level 0, well below dask's 80% pause threshold. For the 563 GB subject at level 0 this goes from 409 GB to 96 GB..imstemp zarr: written toresources.tmpdir, with only level 0, since nothing reads its lower levels.Before merging
zarrniipin andpixi.lock. The lock also moves ome-zarr from 0.18.0 to 0.21.0, addstransformndandarray-api-compat, updatesome-zarr-modelsto 1.8.1, and moves pydantic back to 2.12.5. With the new lock,n4_biasfield.pyran on F1A1Te4 at level 3, and its output kept the input's shape, voxel size, units and affine.Notes
0b45135), OME-Zarr outputs written through ZarrNii have had no voxel size, origin or units (OME-Zarr writes lose voxel size, origin and units with ome-zarr-py >= 0.18 zarrnii#272, write_image() silently ignores coordinate_transformations (and axis units) since 0.18.0 ome/ome-zarr-py#710). zarrnii 0.22.0 fixes this, so this PR fixes it for new outputs. OME-Zarr outputs written since0b45135still have the wrong geometry and need to be regenerated.to_ome_zarr. Rules whose requests were raised because workers paused (compute_filtered_regionprops,signed_distance_transform) could be re-benchmarked after the release.🤖 Generated with Claude Code