Ollama out of memory? Load failures, mid-reply CUDA crashes and 'requires more system memory' need different fixes. Fix them in this exact order.
An Ollama out-of-memory error is one of three problems. 'unable to allocate CUDA0 buffer' or 'cudaMalloc failed' at load means the weights, KV cache and compute buffer don't fit in VRAM. A crash seconds into a reply means a buffer grew after loading. 'model requires more system memory' means free RAM, not VRAM, ran out. Fix VRAM errors by shrinking the quant, num_ctx and parallel slots first, then flash attention, KV quantization and num_gpu.
- 4k under 24 GiB VRAM, 32k at 24 to 48 GiB, 256k at 48+
- OLLAMA_NUM_PARALLEL x context length
- f16 (default), q8_0 (~1/2), q4_0 (~1/4); needs flash attention
- OLLAMA_GPU_OVERHEAD, in bytes per GPU
Key takeaways
- Read the error before touching settings. Load-time VRAM failures, mid-generation crashes and the 'requires more system memory' refusal have different causes and different first fixes.
- Weights are rarely the whole story. In one GitHub report the allocation that failed was a 4.9 GiB compute buffer, reserved after 27.8 GiB of weights already fit.
- Context and parallel slots multiply. Ollama's FAQ says required memory scales with OLLAMA_NUM_PARALLEL times the context length, and the default context jumps to 32k on 24 to 48 GiB cards.
- num_gpu is the manual override. Lowering the number of offloaded layers fixed load failures in two GitHub reports, at the cost of speed.
- 'Requires more system memory' is a RAM check. Unload idle models with ollama stop, and in Docker check how much memory the container can actually see.
“Ollama out of memory” is not one error. It is three, and the fix for one can do nothing for another. Before you change a setting, find out which one you have: the message in the client, plus the server log, tells you whether VRAM ran out while loading, VRAM ran out while generating, or system RAM was too short for Ollama to even try.
Everything below comes from Ollama’s documentation, its source code, or GitHub issues where the logs show the cause. Where a fix is a community report rather than documented behavior, it says so.
What does each Ollama out-of-memory error mean?
Each message points at a different memory pool and a different moment, so read it before anything else. Ollama’s troubleshooting page lists where the server log lives: ~/.ollama/logs/server.log on macOS, journalctl -u ollama on Linux with systemd, docker logs <container> in Docker, and %LOCALAPPDATA%\Ollama\server.log on Windows.
| Error text | When it happens | Memory pool | Typical cause |
|---|---|---|---|
unable to allocate CUDA0 buffer / unable to allocate ROCm0 buffer | While loading | VRAM | Weights, KV cache and compute buffer together exceed the card |
cudaMalloc failed: out of memory | Usually while loading | VRAM | Same, often on the last allocation, the compute buffer |
CUDA error: out of memory, then error reading llm response in the client | Seconds into a reply | VRAM | A buffer grew after load; little headroom left |
model requires more system memory (X GiB) than is available (Y GiB) | Before loading | System RAM | Free RAM is short: other models, apps, page cache, or a container limit |
ollama ps shows a split such as 48%/52% CPU/GPU | After loading | Both | Not an error: the model spilled to RAM and runs slowly |
The last row is the quiet version of the problem. If the model loads but ollama ps shows a CPU/GPU split, you are not crashing, you are just slow; that diagnosis lives in Ollama not using GPU.
Why does Ollama run out of memory when the model file fits?
Because the GPU holds three things, and the model file is only one of them. Ollama allocates the weights, then the KV cache for the whole context window, then a compute buffer for the forward pass. The KV cache grows linearly with context, and the compute buffer is allocated last, so it is often the allocation that fails.
Issue #11202 shows the arithmetic clearly. A user with two 32 GB AMD MI50s loaded a 671B model with 8 of 62 layers on the GPUs. The log shows 28,426.68 MiB of weights and 1,280 MiB of KV cache on the first card, then a failed attempt to reserve 5,030 MiB more for the compute graph: cudaMalloc failed: out of memory. Ollama had asked one card to hold about 33.9 GiB.
Since September 2025, Ollama’s new engine measures memory before loading instead of estimating it. The announcement says this “significantly reduced crashes due to out of memory issues” and that ollama ps now matches nvidia-smi. At launch it applied to models on the new engine, such as gpt-oss, gemma3 and qwen3, with llama3.x and qwen3-coder listed as “coming soon.” If an older model family still crashes, it may still be on the estimate path, and updating Ollama is a reasonable first step.
Why does memory run out after the model loaded fine?
Usually because the context or the number of parallel slots is larger than you think, or because the card had no slack for allocations made during generation.
Two settings multiply each other. Ollama’s FAQ says “required RAM will scale by OLLAMA_NUM_PARALLEL * OLLAMA_CONTEXT_LENGTH”, and its example is a 2k context with 4 parallel requests becoming 8k. OLLAMA_NUM_PARALLEL defaults to 1 in the current source, so check whether your service file or a tutorial set it higher.
The default context is also not fixed. The context length docs set it by VRAM: 4k under 24 GiB, 32k from 24 to 48 GiB, and 256k at 48 GiB or more. Ollama’s own pages disagree with each other here: the FAQ still says 4096 and the Modelfile reference says 2048. The source code matches the VRAM-based rule. Clients add their own value on top: in a Continue issue about Llama 3.1 8B, the maintainer’s fix for an Ollama memory error was to lower Continue’s contextLength, because Continue’s default can be higher than other tools’. How each client sets it is covered in Ollama context length.
Mid-reply crashes also come from having no headroom at all. In issue #6382, a 70B model loaded on a 16 GB Tesla P100 with 29 of 81 layers offloaded, then crashed within seconds of each prompt. A maintainer suggested fewer GPU layers and flash attention; the reporter’s other model, gemma2, ran once num_gpu was lowered.
We build CandorNo GPU? Use a hosted model
Uncensored AI, right in your browser.
Candor runs open models with refusals removed, so it answers the questions other assistants deflect. New accounts get free credits, no card needed.
Try Candor freeWhich settings fix Ollama out of memory errors, in what order?
Start with the levers that cost nothing in speed, and finish with the ones that trade speed for fit. An Ollama maintainer posted a mitigation list in issue #8597; this order rearranges it by cost and adds the two levers that come before any setting.
- Use a smaller quant or a smaller model. A Q4_K_M instead of Q8_0 roughly halves the weights. It is the only lever that shrinks the biggest block. Sizing by GPU is in local LLM hardware requirements.
- Lower the context. Set
num_ctxper request orOLLAMA_CONTEXT_LENGTHon the server. Going from 32k to 8k cuts the KV cache by three quarters. - Set
OLLAMA_NUM_PARALLEL=1. Each extra slot reserves its own context; how the slots work is in OLLAMA_NUM_PARALLEL. - Turn on flash attention. The FAQ says Ollama enables it automatically where the backend supports it, and
OLLAMA_FLASH_ATTENTION=1forces it. It “can significantly reduce memory usage as the context size grows.” - Quantize the KV cache.
OLLAMA_KV_CACHE_TYPE=q8_0uses about half the memory of the f16 default with a “very small” precision loss;q4_0uses about a quarter. It only applies with flash attention on, and it is global for all models. Trade-offs are in KV cache quantization. - Reserve headroom with
OLLAMA_GPU_OVERHEAD. The source describes it as “Reserve a portion of VRAM per GPU (bytes)”. The maintainer’s example is536870912for 512 MiB. Ollama then plans around a smaller card, which leaves room for buffers that grow. - Offload fewer layers with
num_gpu. This works every time, but the layers that move to the CPU run at RAM speed. - Unload other models.
ollama stop <model>frees a model now.OLLAMA_MAX_LOADED_MODELScaps how many stay loaded; the FAQ gives a default of 3 per GPU.
On Linux with NVIDIA cards the same maintainer list also mentions GGML_CUDA_ENABLE_UNIFIED_MEMORY=1, which lets CUDA spill into system memory instead of failing. Expect it to be slow.
The server-wide settings go in the environment of ollama serve:
OLLAMA_NUM_PARALLEL=1 \
OLLAMA_FLASH_ATTENTION=1 \
OLLAMA_KV_CACHE_TYPE=q8_0 \
OLLAMA_CONTEXT_LENGTH=8192 \
OLLAMA_GPU_OVERHEAD=536870912 \
ollama serveOn a systemd install, put the same lines in systemctl edit ollama as Environment= entries and restart the service.
How do you control GPU layers with num_gpu?
num_gpu is the number of model layers Ollama offloads to the GPU, and setting it overrides Ollama’s own placement. In the API types it defaults to -1, meaning “set dynamically.” The Modelfile reference doesn’t document it, but a maintainer in issue #6382 gave three ways to set it:
# interactive session
ollama run qwen3:32b
>>> /set parameter num_gpu 40
# per request
curl http://localhost:11434/api/generate -d '{"model":"qwen3:32b","prompt":"hi","options":{"num_gpu":40}}'
# baked into a model
printf 'FROM qwen3:32b\nPARAMETER num_gpu 40\n' > Modelfile
ollama create qwen3-32b-40gpu -f ModelfileTo pick a number, read the load line in the server log, which says something like offloaded 8/62 layers to GPU, and start a few layers below it. The MI50 user in #11202 went from 8 to 6 layers and the model loaded at 78% and 87% use on the two cards. Each layer you remove makes generation slower, so stop as soon as it loads with a little slack.
num_gpu is not a fix for a GPU that isn’t detected. If ollama ps says 100% CPU, that is a discovery problem, covered in Ollama not using GPU.
What if you are out of system RAM rather than VRAM?
Then the message is model requires more system memory (X GiB) than is available (Y GiB), and the fixes are about RAM. Ollama compares what the model needs against free memory before it starts the runner, and returns an HTTP 500 if it doesn’t fit.
- Unload what is already loaded. Models stay in memory for 5 minutes after use by default (FAQ). Run
ollama ps, thenollama stopanything idle, or sendkeep_alive: 0with requests you don’t need cached. - Check what “available” means on your box. In issue #13556, llama3.3 (a 39.6 GiB Q4_K_M file) ran once in Docker and then failed with “requires more system memory (39.4 GiB) than is available (30.0 GiB)”. A contributor traced it to how Ollama counts used memory inside containers, linked a fix on a personal fork, and the issue was still open in February 2026. Lowering the context didn’t help that reporter.
- Swap is not free memory you want. An Ollama maintainer noted in #6382 that Ollama counts swap in its memory check, which is how a 39 GB model on 16 GB of VRAM and 23 GB of RAM ends up thrashing instead of failing cleanly.
- Unified memory machines blur the line. On an NVIDIA Jetson Thor with 122.8 GiB shared memory, a forum user running gpt-oss:120b in the official container got “requires more system memory (61.4 GiB) than is available (36.4 GiB)” with no process accounting for the used memory. NVIDIA suggested a cache-cleaning script, which helped only partly.
What do developers report in practice?
The pattern across GitHub reports is that the estimate, not the hardware, is often what fails, and that num_gpu is the fix that consistently works.
- Big model, two cards, compute buffer overflow. The MI50 report above is the clearest log: weights fit, the 4.9 GiB compute buffer did not, and
PARAMETER num_gpu 6fixed it (#11202). - Context as the trigger. On a 12 GB RTX 4070, one user saw
CUDA error: out of memoryintermittently atnum_ctx2048 and every time at 4096 or higher, on a 2024 Ollama release (#3460). - ROCm is less predictable. An 8 GB Radeon user hit
unable to allocate ROCm0 bufferwith deepseek-r1:14b after upgrading from 0.6.5 to 0.7.0. Loweringnum_gputo 9 and raisingOLLAMA_GPU_OVERHEADdid not help, while llama.cpp alone used nearly the full 8 GB. The maintainer wrote that “it’s not clear to me why the OOM occurred” (#10784). If you are on AMD and the levers don’t move anything, try an older or newer Ollama release and post a debug log. - Containers miscount RAM. The llama3.3 Docker report above failed only on its second run (#13556).
- Enterprise hardware isn’t immune. The maintainer’s mitigation list in #8597 was written for a user with four 46 GB L40S cards and 384 GB of RAM loading DeepSeek-R1.
Treat these as community reports on specific versions. Ollama’s memory code has changed several times since, so the version you run matters as much as the setting.
FAQ
How do I fix “CUDA out of memory” in Ollama?
Lower the context (num_ctx or OLLAMA_CONTEXT_LENGTH), set OLLAMA_NUM_PARALLEL=1, and use a smaller quant. If it still fails, enable flash attention with a q8_0 KV cache, reserve headroom with OLLAMA_GPU_OVERHEAD, then reduce num_gpu.
What does “cudaMalloc failed: out of memory” mean in Ollama?
A CUDA or ROCm allocation for the model failed because VRAM was full. In logged cases it is often the compute buffer, allocated after the weights and KV cache, so a model whose file fits can still fail. Lower the context or offload fewer layers.
What does “model requires more system memory than is available” mean?
Ollama checked free system RAM before loading and found too little. Unload idle models with ollama stop, close memory-heavy apps, lower the context, and in Docker check the container’s memory limit.
Does Ollama use system RAM when VRAM runs out?
Yes, if it plans for it: Ollama puts fewer layers on the GPU and runs the rest on the CPU, which ollama ps shows as a CPU/GPU split. A crash happens when its plan underestimates what the GPU needs, which is why num_gpu and OLLAMA_GPU_OVERHEAD exist.
Does flash attention reduce Ollama memory use?
Yes. The FAQ says it can significantly reduce memory use as context grows, and it is required before OLLAMA_KV_CACHE_TYPE takes effect.
We build CandorSkip the setup
Want an uncensored model without hosting one?
Candor (candorai.dev) is an uncensored AI chat app that runs in your browser: it answers the questions mainstream assistants dodge, on health, money, law and work, without the lecture. New accounts get free credits, no card needed.
Facts from candorai.dev, checked Nov 10, 2026. Candor never changes how we rank or review models. Disclosure.
Sources (10)
- FAQ: parallel requests, flash attention, K/V cache quantization, keep_alive, Ollama documentation
- Context length, Ollama documentation
- Troubleshooting: server logs and debug variables, Ollama documentation
- Modelfile reference, Ollama documentation
- envconfig/config.go: OLLAMA_GPU_OVERHEAD, OLLAMA_NUM_PARALLEL, OLLAMA_CONTEXT_LENGTH, ollama/ollama
- New model scheduling (exact memory measurement), Ollama blog, September 2025
- Unable to allocate CUDA0 buffer, maintainer's OOM mitigation list, ollama/ollama issue #8597
- Ollama overcommiting GPU memory with large models, ollama/ollama issue #11202
- cuda error out of memory, ollama/ollama issue #6382
- model requires more system memory on subsequent runs, ollama/ollama issue #13556
Written by Refusal Rate editors from papers, model cards, official docs and pricing pages. Anything we ran ourselves is labeled as our own test, with the hardware and settings. Our method.