[GH-ISSUE #5902] Cannot modify context size through /set parameter num_ctx 8192 #3681

Closed
opened 2026-04-12 14:29:55 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @nyl199310 on GitHub (Jul 24, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/5902

What is the issue?

I'm using Ollama as backend and using OpenAI's client.chat.completions.create to send messages.
I found the logs said the input has been truncated and n_ctx=2048.
INFO [update_slots] input truncated | n_ctx=2048 n_erase=14097 n_keep=4 n_left=2044 n_shift=1022 tid="62632" timestamp=1721797206

I followed this way to set the context /set parameter num_ctx 8192. But it doesn't work, when I sent another message. the logs still said input_truncated:

INFO [update_slots] input truncated | n_ctx=2048 n_erase=14097 n_keep=4 n_left=2044 n_shift=1022 tid="62632" timestamp=1721797206
[GIN] 2024/07/24 - 13:00:49 | 200 |   42.2955085s |       127.0.0.1 | POST     "/v1/chat/completions"

I'm using the phi-3 128k. how can I use a context larger than 2048 using ollama + openai api?
Thank you.

OS

Windows

GPU

Nvidia

CPU

AMD

Ollama version

0.2.8

Originally created by @nyl199310 on GitHub (Jul 24, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/5902 ### What is the issue? I'm using Ollama as backend and using OpenAI's client.chat.completions.create to send messages. I found the logs said the input has been truncated and n_ctx=2048. `INFO [update_slots] input truncated | n_ctx=2048 n_erase=14097 n_keep=4 n_left=2044 n_shift=1022 tid="62632" timestamp=1721797206` I followed this way to set the context `/set parameter num_ctx 8192`. But it doesn't work, when I sent another message. the logs still said input_truncated: ``` INFO [update_slots] input truncated | n_ctx=2048 n_erase=14097 n_keep=4 n_left=2044 n_shift=1022 tid="62632" timestamp=1721797206 [GIN] 2024/07/24 - 13:00:49 | 200 | 42.2955085s | 127.0.0.1 | POST "/v1/chat/completions" ``` I'm using the phi-3 128k. how can I use a context larger than 2048 using ollama + openai api? Thank you. ### OS Windows ### GPU Nvidia ### CPU AMD ### Ollama version 0.2.8
GiteaMirror added the bug label 2026-04-12 14:29:55 -05:00
Author
Owner

@rick-github commented on GitHub (Jul 24, 2024):

Add "options": { "num_ctx": 8192} to the call you are making to the API. Alternatively,, create a new model with the default context size that you want:

ollama show --modelfile phi3:14b-medium-128k-instruct-q4_K_M > Modelfile

Edit the Modelfile and add

PARAMETER num_ctx 8192

Create the new model:

ollama create phi3:14b-medium-128k-instruct-8k-q4_K_M -f Modelfile
<!-- gh-comment-id:2247127874 --> @rick-github commented on GitHub (Jul 24, 2024): Add `"options": { "num_ctx": 8192}` to the call you are making to the API. Alternatively,, create a new model with the default context size that you want: ``` ollama show --modelfile phi3:14b-medium-128k-instruct-q4_K_M > Modelfile ``` Edit the Modelfile and add ``` PARAMETER num_ctx 8192 ``` Create the new model: ``` ollama create phi3:14b-medium-128k-instruct-8k-q4_K_M -f Modelfile ```
Author
Owner

@royjhan commented on GitHub (Jul 30, 2024):

As @rick-github mentioned, "options": { "num_ctx": 8192} can be set if using an ollama api. However, if using an oai compat api @nyl199310, the second approach is the only viable method right now (creating a new model with default num_ctx. The oai endpoint does not include a field for setting context length, so you can't pass in an argument for it right now. This is on our radar but no specific timeline for other methods at this time

<!-- gh-comment-id:2258978147 --> @royjhan commented on GitHub (Jul 30, 2024): As @rick-github mentioned, "options": { "num_ctx": 8192} can be set if using an ollama api. However, if using an oai compat api @nyl199310, the second approach is the only viable method right now (creating a new model with default num_ctx. The oai endpoint does not include a field for setting context length, so you can't pass in an argument for it right now. This is on our radar but no specific timeline for other methods at this time
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#3681