VRAM & CUDA Tuning
Stopping CUDA Fragmentation With PYTORCH_CUDA_ALLOC_CONF
Set expandable_segments:True and max_split_size_mb:256 to eliminate false CUDA Out-of-Memory errors when nvidia-smi shows 3+ GB free.
Reclaims 1.5-3.2 GB Fragmented VRAM · Zero Perf Penalty
Why OOM Happens With 3 GB Reported Free
Switching between T5-XXL, Flux DiT, ControlNet, and tiled VAE leaves Swiss-cheese gaps in PyTorch reserved blocks. When VAE requests a contiguous 1.8 GB tensor, allocation fails.
Zero-Cost Drop-In in comfyui-launch.sh
Exporting PYTORCH_CUDA_ALLOC_CONF="expandable_segments:True,max_split_size_mb:256" lets CUDA map virtual segments into non-contiguous physical pages cleanly.
Measured Thresholds & ComfyUI Configuration Matrix
| Environment Variable | Recommended Value | Effect on ComfyUI Memory |
|---|---|---|
| PYTORCH_CUDA_ALLOC_CONF | expandable_segments:True | Maps virtual CUDA blocks instead of rigid slabs |
| max_split_size_mb | 256 | Prevents splitting large 1+ GB DiT allocations |
| CUDA_MODULE_LOADING | LAZY | Avoids loading unused cuBLAS/cuDNN kernels into VRAM |