Home/Error Wiki/ComfyUI CUDA OOM
ComfyUI / PyTorch / CUDA

ComfyUI CUDA out of memory

A useful fix depends on where memory peaked. Preserve the first OOM line and its numbers before restarting; the last traceback frame alone is not enough.

Evidence reviewed 2026-08-01. This page is ad-free while the error wiki is under quality review.

Fast decision path

  1. Capture evidence: copy the complete torch.cuda.OutOfMemoryError sentence and note the failing node.
  2. Check current GPU users: run nvidia-smi. Close unrelated applications or duplicate ComfyUI processes, not arbitrary system tasks.
  3. Retest batch 1: this separates workflow viability from batch pressure.
  4. Reduce pixel count: lower width and height together. Record the last successful size.
  5. Use the stage-specific change: tiled VAE decode for a decode-stage peak; supported offload/memory flags for model/sampling pressure.

Paste the log into the local decoder →

Read the PyTorch OOM sentence

FieldWhat it tells youDo not conclude
Tried to allocateThe next failed allocation, not the entire workload requirement.Adding exactly that amount guarantees success.
Total capacityUsable capacity reported for that device.All of it is available to ComfyUI.
FreeFree memory at the failure instant.It was equally low throughout the run.
Process memory in useMemory owned by the process, including non-PyTorch use.Every byte is a model weight.
Allocated by PyTorchLive tensor allocations tracked by PyTorch.Clearing the cache frees live tensors.
Reserved but unallocatedAllocator-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

  1. Close competing GPU workloads. Confirm with nvidia-smi.
  2. Batch 1 and fewer pixels. This is the most portable test.
  3. Tiled VAE decode or model-specific low-memory workflow.
  4. Disable previews: --preview-method none.
  5. Reserve headroom: ComfyUI exposes --reserve-vram; choose a measured value rather than copying one blindly.
  6. Try --lowvram or supported offload options. Expect speed trade-offs.
  7. --cpu last. 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-smi shows 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.

Screen the scenario or parse OOM telemetry →

Primary sources