mirror of
https://github.com/ollama/ollama-python.git
synced 2026-07-21 09:05:23 -04:00
Understanding Variable Response Times from a Local Mistral Model #42
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @fentresspaul61B on GitHub (Feb 28, 2024).
Hello,
Thank you for the great package, I have been exploring it, and considering using this as a way to host an LLM on my companies Linux server. Our overarching goal was to move away from using the OpenAI API, due to its long and varying response times from the API, and host an open source LLM on our own machine. It seems that Ollama may work for this use case.
However, after doing some initial prompts with the Mistral model, I started to notice the response times were not consistent. I am currently running the code on a CPU on our Linux server (so I did not expect fast response times); however, I did expect consistent response times. From what I understand, the Ollama python packages uses the models that are downloaded to your machine, and therefore are running offline, on that machine, not in the cloud by a third party server (correct me if I am wrong here).
I was surprised to see my first initial responses have around 60 second response time, and then that response time drop down to 10 and 7 seconds, when using the exact same prompt. This behavior is reminds me of cold starts when using serverless infra, but again, I am assuming that this is a local offline model.
I also waited a few minutes, and re ran the script, and got the initial 1 minute response time, then 5 second response times again, so it seems like there some type of initialization or cold start?
Here is the code (hiding the prompt), simply taken from your README.
Response for exact same input:
Some Questions
Thanks again,
Paul
@mxyng commented on GitHub (Mar 1, 2024):
The high timing on the first run is because Ollama needs to load the model into (GPU) memory. Subsequent requests take roughly the same amount of time. There will still be some variance since the outputs will be different. You can set
options={'temperature': 0}for reproducible result and more consistent timings.By default, the model gets unloaded after 5 minutes. Once the model gets unloaded, the next request needs to load the model back into memory. You can change this behaviour by setting
keep_alive, e.g.ollama.chat(model='...', messages=[...], keep_alive=...).keep_alivecan be either a duration (60s, 5m, 1h) or a number (in seconds). Negativekeep_alive,-1, will keep the model in memory indefinitely@fentresspaul61B commented on GitHub (Mar 5, 2024):
Thank you for the response. That hopefully will resolve the loading/ cold start issue. I am still trying to understand how these different parts work together.
I was wondering if you could help me with this question that I originally proposed:
"From what I understand, the Ollama python packages uses the models that are downloaded to your machine, and therefore are running offline, on that machine, not in the cloud by a third party server (correct me if I am wrong here)."
@mxyng commented on GitHub (Mar 5, 2024):
This is mostly correct. This library implements a Python interface to the Ollama API. As such, it requires a running Ollama instance which can be local (same machine) or remote (hosted by you or someone you trust). The default configurations assume local (127.0.0.1:11434 to be precise). This Ollama instance is responsible for downloading and running models.