diff --git a/deploy/gpu-broker-ollama-proxy.service b/deploy/gpu-broker-ollama-proxy.service new file mode 100644 index 0000000..ab02f6b --- /dev/null +++ b/deploy/gpu-broker-ollama-proxy.service @@ -0,0 +1,14 @@ +# Sits on Ollama's usual port (:11434); Ollama itself moves to 127.0.0.1:11435 (ollama.service.d/gpu-broker.conf). +[Unit] +Description=gpu-broker: Ollama proxy (lease before a model loads, CPU fallback when GPUs are busy) +After=gpu-broker.service ollama.service +Wants=gpu-broker.service + +[Service] +ExecStart=/usr/local/bin/gpu-broker ollama-proxy --listen 0.0.0.0:11434 --upstream http://127.0.0.1:11435 --broker http://127.0.0.1:8130 --max-wait 1m --cpu-threads 4 --prefer 1 +DynamicUser=yes +Restart=always +RestartSec=2 + +[Install] +WantedBy=multi-user.target diff --git a/deploy/gpu-broker.service b/deploy/gpu-broker.service new file mode 100644 index 0000000..da0e839 --- /dev/null +++ b/deploy/gpu-broker.service @@ -0,0 +1,13 @@ +# GPU scheduler on yveltal (gitea ziadarafat/gpu-broker). API on 127.0.0.1:8130, /metrics. +[Unit] +Description=gpu-broker: GPU leases, priority queue, CPU fallback +After=nvidia-persistenced.service + +[Service] +ExecStart=/usr/local/bin/gpu-broker serve --listen 127.0.0.1:8130 --reserve 0=1500 +DynamicUser=yes +Restart=always +RestartSec=2 + +[Install] +WantedBy=multi-user.target diff --git a/deploy/ollama-gpu-broker.conf b/deploy/ollama-gpu-broker.conf new file mode 100644 index 0000000..56138bc --- /dev/null +++ b/deploy/ollama-gpu-broker.conf @@ -0,0 +1,7 @@ +# /etc/systemd/system/ollama.service.d/gpu-broker.conf (gpu-broker design, option 1 rules) +[Service] +# The gpu-broker Ollama proxy now owns :11434 +Environment="OLLAMA_HOST=127.0.0.1:11435" +# Idle models give their VRAM back after 10 minutes; at most two models loaded +Environment="OLLAMA_KEEP_ALIVE=10m" +Environment="OLLAMA_MAX_LOADED_MODELS=2" diff --git a/internal/server/server.go b/internal/server/server.go index 20175a8..abc3279 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -82,7 +82,9 @@ func (h handlers) ReleaseLease(_ context.Context, r api.ReleaseLeaseRequestObjec func (h handlers) Status(_ context.Context, _ api.StatusRequestObject) (api.StatusResponseObject, error) { st := h.s.Status() - out := api.Status200JSONResponse{TtlS: int(h.ttl / time.Second)} + out := api.Status200JSONResponse{ + TtlS: int(h.ttl / time.Second), Gpus: []api.GpuStatus{}, Leases: []api.LeaseInfo{}, Waiting: []api.WaitInfo{}, + } for _, g := range st.GPUs { out.Gpus = append(out.Gpus, api.GpuStatus{Index: g.Index, TotalMb: g.TotalMB, UsedMb: g.UsedMB, ReserveMb: g.ReserveMB, FreeMb: g.FreeMB}) } diff --git a/internal/server/server_test.go b/internal/server/server_test.go index 968563f..655bf56 100644 --- a/internal/server/server_test.go +++ b/internal/server/server_test.go @@ -117,3 +117,11 @@ func TestMetricsShowFreeVRAMPerGPU(t *testing.T) { } } } + +func TestEmptyListsAreArraysNotNull(t *testing.T) { + c, _ := start(t, 0, 0) + r, _ := c.StatusWithResponse(context.Background()) + if !strings.Contains(string(r.Body), `"leases":[]`) || !strings.Contains(string(r.Body), `"waiting":[]`) { + t.Fatalf("%s", r.Body) + } +}