---
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://framesfield.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
title: "Fix ComfyUI CUDA Out of Memory on 12GB–16GB GPUs"
description: "Switch BF16 checkpoints to FP8/GGUF Q4_K_M/NVFP4, drop batch_size to 1, swap VAEDecode for VAEDecodeTiled, and launch ComfyUI with --lowvram + PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True alongside 32–64GB system RAM."
canonical: "https://framesfield.com/fixes/comfyui-cuda-out-of-memory-16gb-gpu"
---

# Fix ComfyUI CUDA Out of Memory on 12GB–16GB GPUs

> Switch BF16 checkpoints to FP8/GGUF Q4_K_M/NVFP4, drop batch_size to 1, swap VAEDecode for VAEDecodeTiled, and launch ComfyUI with --lowvram + PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True alongside 32–64GB system RAM.

- **Canonical URL:** https://framesfield.com/fixes/comfyui-cuda-out-of-memory-16gb-gpu
- **Category:** ComfyUI & Local GPU
- **Error Signature:** `torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 2.40 GiB (GPU 0; 15.99 GiB total capacity; 14.82 GiB already allocated)`
- **Last Verified:** 2026-12-01

## Observed Symptom

ComfyUI crashes with torch.OutOfMemoryError while loading Wan 2.2, LTX-2, Qwen-Image 20B, or FLUX on a 12GB–16GB RTX desktop card—often right after sampling reaches 100% during final VAEDecode.

## Technical Root Cause

Default unquantized BF16 checkpoints plus 8B–11B text encoders (T5-XXL, Qwen2.5-VL) demand 24–42 GB VRAM, and non-tiled VAEDecode or batch_size > 1 creates a massive temporary tensor spike at the final step.

## Under the Hood

A 14B–20B diffusion model stored in 16-bit BF16 consumes 28–40 GB before a single pixel latent is allocated. On 12GB–16GB consumer cards (RTX 4070 Ti, 4080, 5080, 4060 Ti 16G), running modern open-weight video and typography models cleanly requires three coordinated reductions: (1) quantizing diffusion weights to FP8 (`e4m3fn`), GGUF `Q4_K_M`, or `NVFP4`; (2) offloading heavy text encoders into 32–64 GB of system RAM via `--lowvram`; and (3) preventing PyTorch memory fragmentation with `PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True`.

If your workflow completes all 20 sampling steps cleanly and crashes right at 99%, the diffusion UNet is NOT the culprit—the untiled `VAEDecode` node is trying to decode the entire 81-frame or 2048px latent tensor in one shot. Swapping `VAEDecode` for `VAEDecodeTiled` (`tile_size: 512`) and keeping `batch_size = 1` cuts peak decode VRAM by more than half with zero loss in quality.

## Before vs. After

### Broken (OOM-Prone Setup (BF16 + Default Launch + Untiled VAEDecode))

```
python main.py   # Loads 28GB BF16 weights + T5-XXL on GPU + batch_size=4 + VAEDecode -> CRASH
```

### Verified Fix (Stable 12–16GB Studio Launch (Expandable Segments + --lowvram + Tiled VAE))

```
export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True
python main.py --lowvram --preview-method auto
# Inside graph: FP8/GGUF Q4_K_M checkpoint + batch_size=1 + VAEDecodeTiled (tile_size=512)
```

Offloading text encoders to system RAM after prompt encoding frees 8–12 GB of VRAM exclusively for quantized diffusion and tiled VAE decoding.

## Copy-Paste Fix (launch-comfyui-16gb.sh)

```bash
# 1. Check live GPU VRAM usage and close competing Chromium/Blender GPU tabs first
nvidia-smi --query-gpu=name,memory.used,memory.free,memory.total --format=csv

# 2. Launch ComfyUI cleanly with CPU text-encoder offload & allocator tuning for 12GB–16GB cards
export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True
python main.py --lowvram --preview-method auto

# Required graph adjustments inside ComfyUI when running <= 16GB VRAM:
# - Swap BF16 diffusion weights -> FP8 (flux1-schnell-fp8 / qwen-image-fp8), GGUF Q4_K_M (Wan 2.2), or NVFP4 (LTX-2)
# - Set EmptyLatent batch_size = 1 (queue 4 sequential jobs instead of batch_size=4)
# - Replace VAEDecode with VAEDecodeTiled (tile_size: 512, overlap: 64) for 720p video & 4K stills
# - Keep >= 32GB–64GB system RAM free so T5-XXL / Qwen2.5-VL offloads cleanly without OS swap thrashing
```

## Step-by-Step Resolution

1. **Match quantization format strictly to your VRAM tier:** Check /tools/vram-calculator: 12GB–16GB cards require GGUF Q4_K_M for Wan 2.2 A14B, NVFP4 for LTX-2 19B, and FP8/GGUF for Qwen-Image 20B and FLUX.
2. **Drop batch_size to 1 and swap VAEDecode for VAEDecodeTiled:** Peak VRAM spikes hardest during the final VAE decode step. Decoding tiled latents (tile_size: 512) with batch_size=1 prevents sudden 99%-complete OOM crashes.
3. **Launch with --lowvram and PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True:** Offloading 8B–11B text encoders into 32–64GB system RAM frees 8–12 GB of VRAM exclusively for sampling and prevents memory fragmentation errors.

## Verification Check (Monitor Peak VRAM Headroom During a Render Pass)

```bash
nvidia-smi --query-gpu=memory.used,memory.total,utilization.gpu --format=csv -l 2
```

**Expected healthy output:**

```text
13420 MiB, 16376 MiB, 99 %   # Peaks safely ~2–3 GB below 16 GB ceiling without OOM
```

## Prevention Guardrails

1. **Close hardware-accelerated browser tabs and Resolve/Blender before batching:** Chrome, Slack, and NLE timelines silently reserve 1.5–3.0 GB of GPU VRAM—often the exact margin separating a smooth 16GB render from OOM.
2. **Never render native 1920×1080 video latents on 16GB cards:** Always diffuse cleanly at 1280×704 (81 frames) and upscale to 1080p in FFmpeg afterward.
3. **Audit hardware fit before downloading 20GB+ checkpoints:** Verify your GPU VRAM and system RAM against /tools/vram-calculator before pulling large BF16 files.

## FAQs

### Why does ComfyUI still crash on 16GB VRAM if I only have 16GB of system RAM?

Offloading text encoders (T5-XXL or Qwen2.5-VL) moves 8–15 GB of weights into system RAM. Running 16GB system RAM triggers disk swap or OS OOM kills—32GB to 64GB system RAM is strongly recommended for local ComfyUI.

### Does batch_size=1 produce worse image quality than batch_size=4?

No. Generating 4 sequential images at batch_size=1 yields identical mathematical quality while using roughly 60% less peak VRAM.

### Does VAEDecodeTiled leave visible square seams in rendered images or video?

When configured with tile_size: 512 and overlap: 64, tiled decoding blends tile borders smoothly with virtually undetectable seams while slashing peak decode memory.

### What if I only have an 8GB laptop GPU and want to run Wan 2.2 video?

Use Apache 2.0 FLUX.1 Schnell (NF4) locally on 8GB for opening stills, and rent an on-demand 24GB cloud GPU (~$0.55/hr) or use metered Runway Gen-4 Turbo ($0.25/5s) for video animation.

### Should I use --lowvram or --novram on a 12GB–16GB NVIDIA card?

Start with `--lowvram`, which streams individual diffusion blocks efficiently while keeping sampling fast. Reserve `--novram` strictly as an emergency fallback on 8GB cards when `--lowvram` still hits OOM, as `--novram` increases render duration 2x–3x.
