← Blog/Ollama Ignoring num_ctx? What Is Actually Happening
deep-dive
Runyard Team
@runyard_dev
7 min read

Tags

#ollama#num_ctx#context#troubleshooting#local-llm
Runyard.dev — Find AI Models That Run on Your Hardware

Ollama Ignoring num_ctx? What Is Actually Happening

Where raising num_ctx starts pushing layers to the CPU
Raising it works. Raising it too far moves you onto the CPU.

You paste a long document, the model answers as though it only saw the end, and nothing errors. That is not the model being stupid — it is truncation, and it is silent by design.

Why it happens

Ollama has historically defaulted to a small context window. Anything longer than that gets cut from the front before the model ever sees it. No warning, no error, just a model answering a question it was only shown half of.

How to change it, properly

Per session, in the interactive prompt:

sessionbash
/set parameter num_ctx 8192

Permanently, in a Modelfile — this is the one that survives restarts:

Modelfilebash
FROM llama3.1:8b
PARAMETER num_ctx 8192

# then:
# ollama create mymodel -f Modelfile

And through the API, where it goes in the options object on each request:

request.jsonjson
{
  "model": "llama3.1:8b",
  "prompt": "...",
  "options": { "num_ctx": 8192 }
}

The trap on the other side

Raising num_ctx works, and raising it too far quietly costs you the GPU. On a 12 GB card running a 14B model at Q4_K_M:

  • num_ctx 2048 — all 40 layers on the GPU.
  • num_ctx 4096 — all 40.
  • num_ctx 8192 — all 40, with about 7.96 GB of budget left.
  • num_ctx 16384 — 31 of 40. The other nine move to system RAM.

So the honest advice is not 'set it as high as it goes'. It is: set it to the smallest value that holds your actual prompts. 8192 covers most chat and code work. Go higher only when you genuinely feed long documents, and expect to give up either speed or model size to do it.

Checking it took effect

verify.shbash
ollama show mymodel --parameters
# num_ctx should be listed

ollama ps
# PROCESSOR should read 100% GPU, not a split

Every figure here is computed the same way the calculators do it: weights are parameters times bits-per-weight divided by eight, plus a KV-cache term for your context, plus about a gigabyte of runtime overhead. Usable memory is roughly 90% of nameplate on a discrete card.

Find the largest num_ctx that keeps every layer on your card.

Size your num_ctx

RUNYARD.DEV

Hardware-aware AI model discovery. Know exactly what runs on your machine — before you download.

© 2026 RUNYARD.DEV — All rights reserved.

Built for local AI.

Tools

Try Runyard

Find AI models that fit your exact hardware. Enter your specs and get a ranked list instantly.

Newsletter