From 0ff28758b3a5e9dc0149a93d87677dd0585590c1 Mon Sep 17 00:00:00 2001 From: Jesse Gross Date: Thu, 20 Mar 2025 10:35:19 -0700 Subject: [PATCH] ollamarunner: Provide mechanism for backends to report loading progress This enables the runner to report progress back to the Ollama server, both for showing status to the user and also to prevent the server from killing the runner if it thinks things have stalled. Most of the infrastructure was already there, this extends it to be available to the backends. --- ml/backend.go | 4 ++++ runner/ollamarunner/runner.go | 3 +++ 2 files changed, 7 insertions(+) diff --git a/ml/backend.go b/ml/backend.go index c63c73d46..66eb37f78 100644 --- a/ml/backend.go +++ b/ml/backend.go @@ -60,6 +60,10 @@ type CacheConfig struct { // BackendParams controls how the backend loads and executes models type BackendParams struct { + // Progress is a callback function that allows reporting percentage completion + // of model loading + Progress func(float32) + // NumThreads sets the number of threads to use if running on the CPU NumThreads int diff --git a/runner/ollamarunner/runner.go b/runner/ollamarunner/runner.go index 443b34b05..90eb0de62 100644 --- a/runner/ollamarunner/runner.go +++ b/runner/ollamarunner/runner.go @@ -783,6 +783,9 @@ func Execute(args []string) error { } params := ml.BackendParams{ + Progress: func(progress float32) { + server.progress = progress + }, NumThreads: *threads, NumGPULayers: *numGPULayers, MainGPU: *mainGPU,