Fix CUDA Out of Memory When Running Ollama and ComfyUI Together
By default, Ollama keeps local LLM weights (such as qwen3.5:9b or llama3) resident in NVIDIA VRAM for 5 minutes after every chat prompt (keep_alive=5m). If you trigger an image generation in ComfyUI during that window on an 8 GB or 12 GB GPU, the two processes collide. Unload the active Ollama model or pass keep_alive: 0 to the Ollama HTTP API before starting diffusion sampling.
1. Exact Terminal Error Signature & Stack Trace
If your standalone ComfyUI, Ollama, or Python terminal outputs the following error on Windows 10/11 x64 or Linux x64:
ggml_cuda_host_malloc: failed to allocatePinned memory
torch.cuda.OutOfMemoryError: CUDA out of memory. GPU 0 has 12.00 GiB total capacity; 4.85 GiB free (Ollama runner holding 5.6 GiB)
2. Root Cause in Standalone Python, ComfyUI, or Ollama
[Verified] On a 12 GB GPU, an 8B-9B quantized LLM in Ollama occupies 5.5 GB to 6.5 GB of VRAM alongside KV-cache buffers. When ComfyUI subsequently attempts to allocate 6.8 GB for FLUX.1-schnell Q4_K_S plus 1.2 GB for text encoders, total demand reaches ~15 GB, causing either a hard CUDA OOM crash or severe WDDM PCIe paging.
3. Manual CLI Fix for Standalone Users (100% Free Utility)
Run the following commands in your terminal or update your launch configuration to resolve the issue immediately in a standalone installation:
# Option A: Inspect and unload the active Ollama model via the local HTTP API (port 11434) using keep_alive=0:
curl http://127.0.0.1:11434/api/ps
curl http://127.0.0.1:11434/api/generate -d '{"model": "qwen3.5:9b", "keep_alive": 0}'
# Option B: Set OLLAMA_KEEP_ALIVE=0 in your environment variables so weights unload right after each chat reply.
4. How Logen 1.4.0 Prevents This Error Automatically
Logen 1.4.0 coordinates Ollama and ComfyUI natively inside one process supervisor. In Project-Linked AI Chat, Logen uses Ollama to plan and refine your visual prompt, then automatically unloads the LLM weights from VRAM before handing the prompt to ComfyUI for diffusion sampling. Your GPU is never forced to hold both engines in VRAM at the same time.
Supported platforms: Windows 10/11 x64 (Logen-1.4.0-Setup.exe) and Linux x64 (Logen-1.4.0.AppImage, Logen-1.4.0-amd64.deb). macOS is not supported.
5. Check Your GPU & Model Memory Headroom
Calculate Exact Dedicated VRAM Headroom on Windows 10/11 & Linux x64
Select your NVIDIA graphics card, diffusion model, operating system, and target resolution to compute deterministic peak VRAM usage before you download weights.
Formula: Dedicated_VRAM (12.0 GB) – [Weights (6.8 GB) + Encoder (1.2 GB) + VAE Buffer (0.9 GB) + OS Reserve (1.5 GB)] = +1.60 GB available headroom.
6. Troubleshooting FAQ: Fix CUDA Out of Memory When Running Ollama and ComfyUI Together
How do I see how much GPU VRAM Ollama is currently holding?
Query http://127.0.0.1:11434/api/ps or check the Ollama status output. It lists every loaded model, its size in GB, the percentage split between CPU and GPU, and the remaining time until keep_alive expires.
Does setting OLLAMA_KEEP_ALIVE=0 delete my downloaded model from disk?
No. keep_alive=0 only unloads the model weights from graphics card RAM (VRAM) back to idle after generating a response. The model file remains saved on your SSD.
How does Logen 1.4.0 choose which Ollama model to install for my GPU?
During first-launch onboarding, Logen's Setup Wizard checks your NVIDIA VRAM tier: it selects qwen3.5:9b for GPUs under 8 GB, qwen3.5:35b-a3b (MoE with ~3B active parameters) for 8 GB to 16 GB GPUs, and qwen3.5:27b for 16 GB+ cards.
7. Related Local AI & ComfyUI Error Guides
- Fix torch.cuda.OutOfMemoryError in ComfyUI on 8GB and 12GB NVIDIA GPUs (VRAM & OOM)
- Fix Prompt Outputs Failed Validation: DualCLIPLoader / VAELoader Not Found in ComfyUI (Missing Nodes & Checkpoints)
- Fix AssertionError: Torch Not Compiled with CUDA Enabled on Windows 10/11 (Python & CUDA Environment)
- Fix Cannot Import ComfyUI-GGUF Module: No Module Named 'gguf' (Missing Nodes & Checkpoints)
- Fix Windows 10/11 WDDM Shared GPU Memory Slowdown (Why FLUX Drops from 25s to 4 Minutes) (VRAM & OOM)
- Fix Error: connect ECONNREFUSED 127.0.0.1:11434 (WinError 10061) in Local AI Apps (Ollama & Background Services)
- Fix Black Image or NaN Tensor Output When Decoding FLUX VAE in ComfyUI (VAE & Precision Errors)
- Fix dlopen(): error loading libfuse.so.2 When Launching AppImage on Ubuntu 22.04 / 24.04 (Linux Desktop & Packaging)
- Fix OutOfMemoryError During 4x RealESRGAN 4K Upscaling in ComfyUI (VRAM & OOM)
Checking hardware compatibility? Browse the Local AI GPU & VRAM Compatibility Index or explore Logen 1.4.0 Desktop Studio.
Generate with FLUX.1-schnell, FLUX.2 [klein] 4B & Z-Image-Turbo in a self-healing desktop studio.
Logen 1.4.0 manages ComfyUI and Ollama automatically on your NVIDIA GPU with zero monthly fees.