Repository navigation
Fixes for FastSurfer handles running out of GPU memory - #949
Merged
Merged
Conversation
…he OOM hint run_fastsurfer.sh and long_prepare_template.sh now take --batch_size, the name the Python modules and the OOM hint already use; --batch is kept as a deprecated alias with a warning. brun_fastsurfer.sh keeps its own --batch (task splitting), which no longer shadows the batch size flag. FastSurferCNN's run_prediction.py returned 0 after a CUDA out-of-memory error, so run_fastsurfer.sh continued without a segmentation. It now returns an error and the pipeline stops with exit code 1. The OOM hint suggests a smaller batch size only when the batch size is above 1, and now also suggests a larger --vox_size.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The changes consistently address the flag mismatch, failure status, and misleading OOM advice without identified regressions.
0 open findings
What changed in this PR
Improves GPU OOM handling and standardizes the inference batch-size flag.
Changes:
- Adds
--batch_size, retaining deprecated--batchcompatibility. - Makes FastSurferCNN OOM failures exit nonzero.
- Tailors OOM guidance to the active batch size.
| File | Description |
|---|---|
run_fastsurfer.sh |
Adds the standardized flag and deprecation warning. |
recon_surf/long_prepare_template.sh |
Supports and forwards the standardized flag. |
FastSurferCNN/utils/common.py |
Provides batch-aware OOM guidance. |
FastSurferCNN/run_prediction.py |
Returns an error after CUDA OOM. |
CerebNet/inference.py |
Supplies batch size to the OOM handler. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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
A batch-size × voxel-size sweep on an RTX 4080 SUPER (16 GB) showed three problems with how FastSurfer handles running out of GPU memory:
run_fastsurfer.sh(and so the Docker/Singularity images) only accepted--batch. The Python modules, and the OOM hint itself, use--batch_size. Following the hint gaveERROR: Flag '--batch_size' unrecognized.FastSurferCNN/run_prediction.pycaught the CUDA OOM error, printed the hint and then returned0.run_fastsurfer.shcarried on as if the step had passed, even though no segmentation was written. All 13 runs in the sweep that ran out of memory exited with code 0.--vox_sizeis the advice that actually helps there.Changes
run_fastsurfer.sh,recon_surf/long_prepare_template.sh: accept--batch_size <int>, and update the help text to match.--batchstill works but prints a deprecation warning, following the existing pattern (e.g.--run_viewagg_on).brun_fastsurfer.sh/srun_fastsurfer.shkeep their own--batch "<i>/<n>", which means task splitting. That flag used to clash with the batch size;--batch_sizecan now be passed through brun.FastSurferCNN/run_prediction.py: on a CUDA OOM, return"Segmentation failed: insufficient GPU memory.", so the script exits 1 andrun_fastsurfer.shstops withERROR: FastSurfer asegdkt segmentation failed.FastSurferCNN/utils/common.py:handle_cuda_memory_exceptiontakes an optionalbatch_size.--batch_size, a larger--vox_size, and running view aggregation on the CPU (--viewagg_device 'cpu').--vox_sizeand--viewagg_device 'cpu'.FastSurferCNN/run_prediction.py,CerebNet/inference.py: pass the batch size to the handler.Testing
Tested with the v2.6.0 image (
fastsurfer-cu126-v260.sif), with this branch mounted over/fastsurfer, on a 0.8 mm T1. All runs used--seg_only --no_cereb --no_hypothal --no_cc --no_biasfield.--vox_size 0.5 --batch_size 1asegdkt segmentation failed--vox_size 0.5 --batch_size 4--batch_sizeadvice,asegdkt segmentation failed--vox_size 1.0 --batch_size 1--vox_size 1.0 --batch 1The two shell scripts pass
bash -n. Callinghandle_cuda_memory_exceptiondirectly withbatch_size=1,8andNonelogs the expected wording for each.