PSA: check your served context length — Ollama gave me 4k for a model declaring 40960

#22
by SatoshiAkiyama - opened

Not a problem with the model — a serving-layer issue that had me attributing
weeks of results to the model itself, so posting in case anyone else is in the
same position.

On ollama 0.32.9, ollama show qwen3:14b reports a context length of 40960.
Load it with nothing specified and ollama ps reports:

NAME         ID              SIZE      PROCESSOR    CONTEXT    UNTIL
qwen3:14b    bdbd181c33f2    9.6 GB    100% GPU     4096       4 minutes from now

No num_ctx in the Modelfile, no OLLAMA_CONTEXT_LENGTH set. 16GB card, which
puts it in the 4k tier described on Ollama's context-length page.

It does not error. Send a prompt longer than that and you get HTTP 200,
prompt_eval_count 2050, and an answer built from whatever survived.
Truncation takes the front, so the system prompt, your formatting rules and
the earlier turns of a conversation are what disappear first. It reads exactly
like a model that stops following instructions on long inputs.

With a needle on the first line of a ~7.9k-token prompt, the reply quoted a
fragment from a filler line near the end instead. Adding "num_ctx": 16384 to
the request, same prompt, it answers correctly.

Some models on the same server return a clear HTTP 400 for the identical
request instead of truncating. I couldn't work out what separates them: it
isn't model size (a stock Qwen3-4B truncates the same way this one does), it
isn't the declared context length, and it isn't ollama create — a derivative
built from a Modelfile containing nothing but FROM qwen3:14b behaves
identically to its parent.

Quickest check

Read prompt_eval_count in the API response and compare it with how many
tokens you actually sent. It's the number evaluated, not the number submitted.
ollama ps also shows the CONTEXT column on builds that have it.

Script that runs the comparison for you (standard library only, no
dependencies), plus a longer writeup:
https://github.com/Bigbonus/ollama-context-window-check

python check_context.py qwen3:14b

Reported upstream as https://github.com/ollama/ollama/issues/17889.

Happy to compare notes if anyone else has hit this — particularly if you can
tell me why the truncated count is 2050 when the allocated window is 4096. It
reproduces across models and prompts and I have no explanation for it.

Sign up or log in to comment