fix: prevent CPU OOM on large batches by reducing memory fragmentation#50
Open
pxl-pshr wants to merge 1 commit into
Open
fix: prevent CPU OOM on large batches by reducing memory fragmentation#50pxl-pshr wants to merge 1 commit into
pxl-pshr wants to merge 1 commit into
Conversation
When processing large frame batches (1200+ frames at 1456x768), the node crashes with a CPU OOM error even on systems with 191GB RAM. The root cause is memory fragmentation from thousands of small tensor allocations over long-running inference loops, not insufficient total memory. Changes: - Pre-allocate contiguous output tensors instead of appending to lists - Free images_pt and normalized_images early to reduce peak memory - Lazily allocate ray tensors to handle variable model output resolutions - Use in-place operations (clamp_, zero_) to avoid extra tensor copies - Delete intermediate tensors immediately after processing - Reconstruct RGB output from original input instead of keeping a copy alive - Helper functions now accept both tensors and lists (backward compatible) Tested with 1200 frames at 1456x768 on a system with 191GB RAM. Previously crashed; now completes successfully.
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
When processing large frame batches (1200+ frames at 1456×768), the node crashes with a CPU OOM error (
DefaultCPUAllocator: not enough memory: you tried to allocate 16102195200 bytes) even on systems with plenty of RAM (tested with 191GB). The root cause is memory fragmentation from thousands of small tensor allocations accumulated over long-running inference loops (~59 minutes), not insufficient total memory.Changes
depth_out,conf_out,sky_out,ray_origin_out,ray_dir_out) instead of appending to Python lists — eliminates thousands of small allocations and the subsequenttorch.cat()copiesimages_ptandnormalized_imagesearly to reduce peak memory (~32GB freed during inference)clamp_(),zero_()) to avoid extra tensor copiesdel depth_out, etc.) immediately after processing into final formimagesinput instead of keepingimages_ptalive for the entire loopprocess_tensor_to_image,process_tensor_to_mask) now accept both pre-allocated tensors and lists (backward compatible)Test plan
keep_model_size=Trueoption