Fast decision path
- Capture evidence: copy the complete
torch.cuda.OutOfMemoryErrorsentence and note the failing node. - Check current GPU users: run
nvidia-smi. Close unrelated applications or duplicate ComfyUI processes, not arbitrary system tasks. - Retest batch 1: this separates workflow viability from batch pressure.
- Reduce pixel count: lower width and height together. Record the last successful size.
- Use the stage-specific change: tiled VAE decode for a decode-stage peak; supported offload/memory flags for model/sampling pressure.
Read the PyTorch OOM sentence
| Field | What it tells you | Do not conclude |
|---|---|---|
| Tried to allocate | The next failed allocation, not the entire workload requirement. | Adding exactly that amount guarantees success. |
| Total capacity | Usable capacity reported for that device. | All of it is available to ComfyUI. |
| Free | Free memory at the failure instant. | It was equally low throughout the run. |
| Process memory in use | Memory owned by the process, including non-PyTorch use. | Every byte is a model weight. |
| Allocated by PyTorch | Live tensor allocations tracked by PyTorch. | Clearing the cache frees live tensors. |
| Reserved but unallocated | Allocator-reserved blocks not currently holding tensors. | Any nonzero value proves fragmentation. |
Fix by failing stage
Model loading
Verify that the workflow is not loading duplicate checkpoints, diffusion models, text encoders or ControlNets. For FLUX, start from the official workflow and use its documented FP8 option when memory is constrained. ComfyUI also exposes --lowvram and offload controls; exact availability depends on your version.
Sampling / KSampler
Set batch to 1, remove optional ControlNets or high-resolution stages, then reduce width and height. Restore one optional component at a time after a successful baseline.
VAE decode
A workflow can finish sampling and still fail while converting latents to pixels. Use tiled VAE decode when appropriate or lower final dimensions. Changing CFG is not a direct memory fix for this stage.
Preview generation
ComfyUI documents --preview-method none as a way to disable previews. This is useful only when preview work contributes to the peak.
Video workflows
Frame count, temporal models, decode and upscaling can create separate peaks. Establish a successful short, low-resolution run before scaling duration or dimensions.
Supported memory controls, in order
- Close competing GPU workloads. Confirm with
nvidia-smi. - Batch 1 and fewer pixels. This is the most portable test.
- Tiled VAE decode or model-specific low-memory workflow.
- Disable previews:
--preview-method none. - Reserve headroom: ComfyUI exposes
--reserve-vram; choose a measured value rather than copying one blindly. - Try
--lowvramor supported offload options. Expect speed trade-offs. --cpulast. Official ComfyUI documentation describes it as very slow.
When allocator fragmentation is plausible
First compare reserved-but-unallocated memory with total capacity. A material reserved pool plus repeated variable-size workloads can justify testing PyTorch’s expandable segments allocator. Current PyTorch documentation uses PYTORCH_ALLOC_CONF; PYTORCH_CUDA_ALLOC_CONF remains a backward-compatible alias.
# Example experiment; compare a fresh baseline before keeping it PYTORCH_ALLOC_CONF=expandable_segments:True python main.py
Do not use allocator tuning as the first answer when the process simply holds more live tensors than the GPU can fit.
Verification checklist
- The same workflow completes twice from a fresh start.
- The successful dimensions, batch, frames and optional models are recorded.
nvidia-smishows expected processes only.- No new NaN, VAE, missing-model or shape error replaces the OOM.
- The chosen memory flag exists in the installed ComfyUI version.