๐ŸŒฑโšก
GPU Garden
Terminal CLI Triage & Memory Guides
Launch Matchmaker โ†’
CLI Error Fix Status: Triage Verified

Fix torch.OutOfMemoryError: Allocation on device 0 would exceed allowed memory in ComfyUI (FLUX & Wan 2.1)

comfyui-allocation-on-device ยท Immediate Memory Rescue
Exact Terminal Stderr / Flag Signature
torch.OutOfMemoryError: Allocation on device 0 would exceed allowed memory

Root Cause & Memory Allocation Mechanics

Modern flow-matching Diffusion Transformers have three distinct memory phases inside a ComfyUI execution graph: (1) Text Conditioning (`T5-XXL` at `9.8 GB` FP16 or `UMT5-XXL` at `11.4 GB` FP16), (2) Iterative Latent Denoising (`12Bโ€“14B DiT` weights plus cross-attention activation maps), and (3) Spatial/Temporal VAE Decoding. On Windows 11, if ComfyUI's smart memory manager miscalculates free VRAM because Desktop Window Manager (DWM) or a web browser is holding 1.2 GB, either Windows silently spills tensors into slow shared system RAM (dropping speed by 10x) or `--cuda-malloc` throws `Allocation on device 0 would exceed allowed memory` during the final VAE upscaling convolution.

Exact CLI Remediation Commands

Ollama Resolution
# Unload any background Ollama LLMs stealing VRAM before running ComfyUI!
ollama stop $(ollama ps | awk 'NR>1 {print $1}')
Llama.cpp Resolution
# Launch ComfyUI with explicit VRAM reserve and PyTorch expandable segments
export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True
python main.py --reserve-vram 1.5 --use-sage-attention

# For 8GBโ€“12GB GPUs, force lowvram weight streaming:
python main.py --lowvram --reserve-vram 1.0
vLLM Resolution
# In ComfyUI workflow nodes:
# 1. Use 'Load Diffusion Model (weight_dtype: fp8_e4m3fn)' or 'Unet Loader (GGUF)'
# 2. Load 't5xxl_fp8_e4m3fn.safetensors' in DualCLIPLoader
# 3. Replace 'VAE Decode' with 'VAE Decode (Tiled)' (tile_size=256 or 512)
Option 1: Hardware Upgrade

Upgrade VRAM on Amazon

If software quantization cannot bridge your memory deficit, explore 16GBโ€“24GB GPUs.

Option 2: Cloud Rental (On-Demand)

Rent Cloud GPUs on RunPod & Vast.ai

Eliminate local VRAM limits immediately by running large workloads on 80GB A100 or H100 pods.

Frequently Asked Questions

Why does ComfyUI crash right at the end of a FLUX or Wan 2.1 render?

The final step of any diffusion workflow is `VAE Decode`, which decompresses compact latents into uncompressed 32-bit RGB pixel tensors. Using `VAE Decode (Tiled)` processes the frame in 256x256 or 512x512 sub-blocks, cutting peak VAE VRAM by 75%.

Did leaving Ollama or LM Studio open in the system tray cause my ComfyUI OOM?

Yes! By default, Ollama keeps the last-used LLM loaded in VRAM for 5 minutes (`OLLAMA_KEEP_ALIVE=5m`). Run `ollama ps` and `ollama stop ` before starting heavy ComfyUI video renders.

Verify Your Hardware Memory Math

Use the GPU Garden Matchmaker to calculate exact KV-cache footprints and avoid future OOM crashes.

Open Interactive Calculator โ†’