Add memory guard to emerging_hotspots public API (#1274)#1276
Open
brendancol wants to merge 1 commit intomainfrom
Open
Add memory guard to emerging_hotspots public API (#1274)#1276brendancol wants to merge 1 commit intomainfrom
brendancol wants to merge 1 commit intomainfrom
Conversation
The numpy and cupy backends each materialise three full (T, H, W) cubes (float32 input copy, gi_zscore float32, gi_bin int8) plus small H*W temporaries with no memory check. A (100, 20000, 20000) input projected to about 480 GB. Add _available_memory_bytes() and _check_memory() helpers and call the guard from the public API for non-dask inputs. Dask paths process per-chunk via map_blocks/map_overlap and do not need the cube guard. Same pattern as #1231, #1240, #1263, #1264.
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.
Summary
_available_memory_bytes()and_check_memory(n_times, ny, nx)helpers toxrspatial/emerging_hotspots.pyand calls them from the public API so the numpy and cupy backends raiseMemoryErrorbefore allocating when the projected(T, H, W)cube would exceed 50% of available RAMmap_blocksandmap_overlappaths process per-chunk and do not materialise the full cubeWhy
Pre-fix, the public API only validated
ndimandshape[0] >= 2. A(100, 20000, 20000)input ran straight into about 480 GB of allocations on the numpy path with no warning. Same pattern as #1231, #1229, #1240, #1236, #1241, #1263, and #1264.Found during the emerging_hotspots security sweep (
/sweep-security).Test plan
TestMemoryGuardcover: numpy guard trips, numpy guard passes when budget is ample, cupy guard trips, dask guard is skipped, error message surfaces shape and projected GB.claude/sweep-security-state.jsonupdated with the emerging_hotspots entry recording the fix and a deferred MEDIUM finding (public API does not call_validate_raster())Closes #1274