Repository navigation
fix(ollama): stop reloading the model on every run - #268
Merged
Merged
Conversation
Kit loads an Ollama model with a warmup request to /api/generate. This request always sent num_gpu and main_gpu: -1 and 0 from the flag defaults in the CLI, and from setSDKDefaults in the SDK. Kit sends the chat requests to the OpenAI-compatible /v1 endpoint, without GPU options. Since Ollama 0.30.0, main_gpu 0 is no longer the same as no main_gpu. Ollama loads the model again when the runner options of a request differ from those of the loaded model. So the warmup loaded the model again, and the first chat request loaded it once more. With Ollama 0.40.14, each one-shot run loaded the model twice. BuildProviderConfig now sets NumGPU and MainGPU only when num-gpu-layers or main-gpu is set explicitly: with a flag, a KIT_* variable or the config file. It already works this way for the sampling parameters. setSDKDefaults no longer registers defaults for the two keys, because a viper default makes IsSet return true. Both changes are necessary: without the defaults, the old code would send num_gpu 0, which puts all layers on the CPU. With an explicit main-gpu, Ollama still loads the model again for the chat requests, because the /v1 endpoint has no field for runner options. TestBuildProviderConfigGPUFlags checks the CLI flags. TestOllamaWarmupGPUOptions checks the options of the warmup request. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Matthias G. Eckermann <mge@suse.com>
|
Connected to Huly®: KIT-269 |
The lint job (golangci-lint, modernize/newexpr) flagged the int32Ptr helper in the new test. Since Go 1.26, new accepts an expression, so the test table now uses new(int32(N)) directly, as other tests in the repository do. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Matthias G. Eckermann <mge@suse.com>
Contributor
|
@coderabbitai review |
Action performed
|
formatInt32Ptr was the only function in this change without a doc comment. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Matthias G. Eckermann <mge@suse.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #265.
Kit loads an Ollama model with a warmup request to /api/generate. This
request always sent num_gpu and main_gpu: -1 and 0 from the flag
defaults in the CLI, and from setSDKDefaults in the SDK. Kit sends the
chat requests to the OpenAI-compatible /v1 endpoint, without GPU
options.
Since Ollama 0.30.0 (ollama/ollama#16031), main_gpu is a pointer in the
runner options, so main_gpu 0 is no longer the same as no main_gpu.
Ollama loads the model again when the runner options of a request
differ from those of the loaded model (needsReload in server/sched.go).
So the warmup loaded the model again, and the first chat request loaded
it once more.
BuildProviderConfig now sets NumGPU and MainGPU only when num-gpu-layers
or main-gpu is set explicitly: with a flag, a KIT_* variable or the
config file. It already works this way for the sampling parameters.
setSDKDefaults no longer registers defaults for the two keys, because a
viper default makes IsSet return true. Both changes are necessary:
without the defaults, the old code would send num_gpu 0, which puts all
layers on the CPU.
Known limit: with an explicit --main-gpu, Ollama still loads the model
again for the chat requests, because the /v1 endpoint has no field for
runner options. On master, this happens on every run. A main_gpu set as
a model parameter (PARAMETER main_gpu N in a Modelfile) applies to all
requests and causes no reloads.
Testing:
same results with and without the change, plus the new tests. All
packages pass, except TestSetParentLinkErrorKeepsLock in
internal/session: it fails on master too when the tests run as root.
if either of the two changes is missing.
Model loads with Ollama 0.40.14 on CPU and a tiny GGUF test model,
counted as llama-server starts in the server log:
kit --model ollama/tiny "hello", per runkit --main-gpu 0 --model ollama/tiny "hello", per runSummary by CodeRabbit