HowDoesAIDoThat?

Questions / practical answer

Why does Ollama run out of memory when I increase the context window?

A larger context adds runtime memory beyond the model weights. Check the actual allocation, remove competing work and verify a separate smaller-context profile before changing hardware.

By HowDoesAIDoThatSources checked 12 October 2026

A bigger context needs more than the model weights

Increasing Ollama's context window can push a previously working local model beyond available memory. The runtime needs space for the model, working buffers and context-related cache. Parallel requests and other loaded models can add pressure. A model's advertised maximum context is a capability limit, not a promise that your computer can run it at that size.

First check the allocation actually used, isolate one local model and try a smaller context. These instructions were checked against documentation on 12 October 2026; we have not installed, run or benchmarked this configuration.

1. Record the failure and the loaded model

Use your existing Ollama installation and confirm the CLI connects to your own local server. Test a downloaded local model; an entry in the model list can also represent a cloud model. Our local-or-cloud answer covers that distinction.

Open a terminal and run:

ollama --version
ollama ls
ollama ps

Record any client/server version mismatch, the exact model tag, its ID, the error message and which application made the request. The CLI reference explains the list and running-model commands.

Read CONTEXT for the loaded allocation and PROCESSOR for CPU/GPU placement. 100% GPU, 100% CPU and a split describe where the model is loaded; they are not a live GPU-utilisation percentage. The context guide shows both columns. If loading failed, there may be no row to inspect: keep the failure and server log instead.

2. Find where the context setting comes from

Check the app's context slider, the server's OLLAMA_CONTEXT_LENGTH, the model's Modelfile and the requesting application's settings. An API client can supply options.num_ctx; an interactive session can use /set parameter num_ctx 4096, as documented in the FAQ. Changing a server default is insufficient if a client requests its own value.

Do not assume a single universal default. Current documentation gives different defaults in different places, and settings depend on the version and route. Verify the actual running allocation instead. Environment changes must reach the Ollama server process and may require its documented restart; changing a terminal variable does not necessarily reconfigure an already running desktop app or service.

Also separate context from output length. num_ctx configures the context window; num_predict limits generated tokens. A shorter requested answer does not, by itself, reduce a large configured context allocation. See the Modelfile parameter reference.

3. Remove competing work before comparing

Pause your own chat apps, coding agents and background requests. Run ollama ps again. For each unused model you recognise, replace UNUSED_MODEL_TAG below with its exact tag:

ollama stop UNUSED_MODEL_TAG
ollama ps

Check that it disappears. This unloads the model; it does not delete its downloaded files. Do not stop a shared service's model while someone else is using it.

Ollama's concurrency documentation explains that parallel requests increase context-related allocation. OLLAMA_NUM_PARALLEL controls per-model parallel processing; multiple resident models are another consideration. Check inherited server settings if you previously raised concurrency. Testing one request does not prove a configuration will fit under several simultaneous requests. Increasing the queue limit is not a memory fix.

4. Create a separate, smaller-context test profile

Use an exact local tag from ollama ls; replace YOUR_MODEL_TAG below. In a text editor, save this as Modelfile.context-check, without an added .txt extension:

FROM YOUR_MODEL_TAG
PARAMETER num_ctx 4096
PARAMETER num_predict 64

Here 4096 is a diagnostic example, not a guaranteed fit or a recommendation for every task. Use a previously working smaller value if known, within your model's supported limits. The 64-token output cap keeps this simple comparison short.

Choose an unused name instead of context-check if it already exists, then run these from the file's folder:

ollama create context-check -f ./Modelfile.context-check
ollama show --modelfile context-check
ollama run context-check "Explain RAM in one sentence."
ollama ps

The official Modelfile instructions support deriving a named configuration from an existing model. This does not retrain it. Inspect the shown parameters and the running CONTEXT; do not treat successful creation as successful inference. Stop if Ollama unexpectedly starts downloading a missing base model and check your tag.

Keep the same short prompt while varying only context. Return to a fresh conversation in your usual app, select the test profile and remove any larger context override. Recheck allocation there too. A profile that works through the CLI can still fail when another client requests different settings.

5. Save the working evidence and choose the next change

Immediately after a successful request, retain the original Modelfile and save these records in your test folder:

ollama ps > context-check-running.txt
ollama show --modelfile context-check > context-check-export.Modelfile

Open both files to confirm their contents. Keep your model ID, version, hardware, prompt, errors and observed memory alongside them. Reopen the saved Modelfile in your editor before later changes; its exported paths can be specific to that installation. The CLI implementation supports the shown commands; none has been executed for this article.

If reducing context works, use only the material needed for the task. A smaller window may trim useful history: preserve your chat or document separately. If it still fails, consult Ollama's troubleshooting logs and hardware support. Driver/backend problems and insufficient capacity need different fixes.

Model-weight quantisation and K/V-cache quantisation are separate choices. Inspect the cache guidance before advanced changes; support and output effects vary. A supported smaller model or weight variant is another option: compare its answers on your actual task. Buying more memory or hosted compute may help a larger workload, but confirm compatibility, full runtime requirements, costs and data handling first. There is no universal model-size-to-VRAM table that replaces those checks.

Sources

Primary references checked 12 October 2026. This explanation is not a benchmark of a particular model or computer.