An out-of-memory error in Ollama is not one error. The message tells you who ran out of what: the NVIDIA driver refusing an allocation (cudaMalloc failed: out of memory), Ollama’s scheduler refusing before it even starts (model requires more system memory (X GiB) than is available (Y GiB)), or the model not fitting fully on the GPU (unable to load full model on GPU). Read the message first, because the fix follows from it.
Related guide: How to Fix Ollama When the Server Is Not Running
Step 1: free memory that is already used
Run ollama ps and look at what is loaded. Unload anything you do not need with ollama stop <model> — the Ollama FAQ says this unloads a model immediately. Models also unload themselves after 5 minutes idle by default, so a model that loaded fine an hour ago and fails now is often just competing with something still resident. Close other GPU programs too; a game or a browser with hardware acceleration can hold gigabytes of VRAM.
Step 2: shrink what the model asks for
If freeing memory is not enough, shrink the request. The cheapest levers, in order, are: lower the context window (a Modelfile PARAMETER num_ctx 512, or the OLLAMA_CONTEXT_LENGTH environment variable — the FAQ says the default context is 4096 tokens); offload fewer layers to the GPU (PARAMETER num_gpu 20, or 0 for CPU only); and set OLLAMA_KV_CACHE_TYPE=q8_0, which the FAQ says uses about half the memory of the default f16 cache with a very small loss in precision. If the weights alone exceed VRAM, none of these will save you: use a smaller model or a smaller quantization such as Q4_K_M.
Step 3: check the logs before retrying
Read the server log for the exact line — the FAQ points to the troubleshooting docs for logs. If the log says the load failed and Ollama reduced the automatic context and retried once, that is Ollama telling you the context was the problem. Retry with the smaller context set explicitly, and confirm with ollama ps that the model loads and shows the processor split you expect.
Expected result. We checked the Ollama FAQ for the 5-minute keep-alive default, ollama stop, the concurrent-request settings and the KV cache quantization types, and the linked guides for the exact error strings and the order of fixes. We did not run this software ourselves for this guide, so no output here is a recorded result; steps marked UNTESTED were checked against the sources below, not run.
Limits
These fixes trade quality or speed for memory: a smaller context forgets earlier turns sooner, fewer GPU layers run slower, and a smaller quantization answers less precisely. If the model plus its context genuinely exceeds your hardware, no setting makes it fit — you need a smaller model. We did not reproduce any of these errors, so the error strings are quoted from the sources, not from a run on this machine.
Sources
- Ollama FAQ — models kept in memory for 5 minutes by default; ollama stop unloads a model; OLLAMA_MAX_LOADED_MODELS, OLLAMA_NUM_PARALLEL and OLLAMA_MAX_QUEUE defaults; Flash Attention and OLLAMA_KV_CACHE_TYPE q8_0/q4_0
- Ollama out-of-memory errors — cudaMalloc failed, model requires more system memory than is available, unable to load full model on GPU; levers: unload, cap loaded models, shrink num_ctx, quantize the KV cache, push layers off the GPU
- Ollama CUDA out-of-memory guide — lower num_ctx, offload fewer layers with PARAMETER num_gpu, or set OLLAMA_NUM_PARALLEL=1
Checked 2026-11-28.
