Fixing CUDA Out-of-Memory (OOM) Errors in Local LLM Inference: Systematic Playbook
Diagnose and permanently resolve torch.cuda.OutOfMemoryError and VRAM allocation failures when running local MoE and dense LLMs on 8GB–24GB NVIDIA GPUs.
Key Technical Takeaways
- CUDA OOM errors happen in three distinct phases: model load (weights too large), prompt prefill (context/KV cache spike), or fragmented workspace buffers.
- Lowering KV cache precision from FP16 to Q8_0 or Q4_0 and capping --ctx-size is the fastest zero-hardware-cost fix.
- On Windows 11, Chrome/Edge hardware acceleration, Discord, and Wallpaper Engine routinely hold 1–2.5GB of GPU VRAM silently in the background.
- Always leave 1.0–1.5GB of VRAM headroom below your card’s nominal capacity so CUDA allocator spikes do not crash the process.
1. Identify Which Phase Triggered the OOM Crash
Not every CUDA Out-of-Memory error has the same root cause. Before blindly shrinking your model, note the exact moment the crash occurs: during startup, immediately after sending a long prompt, or midway through a long conversation.
| Crash Timing | Primary Culprit | Immediate Fix |
|---|---|---|
| During model loading | Hot VRAM budget exceeds free GPU memory | Lower --vram-budget by 1–2 GB; close browser/OBS/games |
| Immediately on long prompt | Prompt prefill batch / activation buffer spike | Reduce micro-batch size (--ubatch-size 512) and cap --ctx-size |
| Mid-conversation (turn 5+) | KV cache grew linearly past remaining VRAM | Enable --kv-cache-type q8_0 or q4_0; enable Flash Attention |
| System freeze / process killed | Host RAM exhausted by pinned expert buffers | Free system RAM or switch from Q5_K_M to Q4_K_M |
2. Reclaiming Hidden Windows 11 VRAM Consumers
Run nvidia-smi in PowerShell before starting your inference server. You will often discover that Electron apps (VS Code, Discord, Slack) and Chromium browsers collectively hold 1.2–2.2 GB of VRAM—which is almost 20% of a 12GB RTX 3060 or 4070.
- Disable "Use graphics acceleration when available" in secondary browsers if you keep 50+ tabs open while running local models.
- Turn off NVIDIA Instant Replay / ShadowPlay overlay during heavy local inference.
- On multi-monitor setups, plugging your display into the CPU integrated GPU (if available) frees an extra ~500–900 MB of VRAM on your discrete NVIDIA card.
nvidia-smi --query-compute-apps=pid,process_name,used_memory --format=csv
nvidia-smi 3. Safe Fallback Launch Profile for 12GB Cards
If you keep hitting intermittent OOM crashes, reset to a conservative baseline—8,192 context, Q8_0 KV cache, 10GB VRAM cap—verify 10 consecutive prompts pass cleanly, and then scale one parameter at a time.
Size Your Hardware Before Downloading
Calculate exact VRAM, system RAM offload, and KV cache limits — or inspect our Benchmark methodology →