Files
gpu-broker/docs/DESIGN.md
T

2.6 KiB

gpu-broker design (2026-11-11)

Why

yveltal has two GPUs (GTX 1060 6 GB = GPU 0, GTX 1080 8 GB = GPU 1) shared by Jellyfin (NVENC transcodes), Immich ML, a native Ollama (dogebot, music-genres, AFFiNE) and a llama.cpp router container. Nothing coordinates them: on 2026-11-11 a 15 GB model didn't fit and Ollama quietly ran 20% of it on the CPU, which (with AudioMuse) helped overheat arceus. The user wants work to use the GPUs whenever possible, queue when they are busy, and fall back to the CPU (capped) instead of waiting forever.

Approach (user picked "option 2 on top of option 1", 2026-11-11)

Option 1, rules (base):

  • Fixed homes: Jellyfin and Immich ML on GPU 0; LLMs prefer GPU 1 (they may use both).
  • Ollama: idle models unload (keep-alive 10 min), at most 2 loaded.
  • Models that can never fit (> 14 GB, e.g. gemma4-26b) are CPU-only by rule, never half-loaded.

Option 2, a small GPU scheduler on yveltal:

  • gpu-broker daemon: samples VRAM per GPU (nvidia-smi, every 2 s), hands out leases (client, priority, VRAM needed, max wait). Grants the GPU with room; otherwise the request waits in a priority queue (realtime > interactive > batch, FIFO within a priority). After max wait it answers "CPU" when the caller allows a CPU fallback. A per-GPU reserve (GPU 0: 1.5 GB) keeps room for Jellyfin transcodes, which can't ask first. Leases expire unless renewed.
  • gpu-broker ollama-proxy: listens where Ollama used to (:11434); Ollama moves to 127.0.0.1:11435. Inference requests for a model that isn't loaded ask for a lease (interactive, size from Ollama's model list + 20% for context); on "CPU" the request is forwarded with num_gpu: 0, num_thread: 4. Already-loaded models pass straight through.
  • gpu-run: wrapper for batch jobs: gpu-run --vram 3000 --priority batch -- cmd. Sets CUDA_VISIBLE_DEVICES to the granted GPU, or "" plus a CPU cap (systemd-run CPUQuota=400%) on CPU fallback; renews the lease while the command runs and releases it on exit.
  • API with an OpenAPI spec (oapi-codegen), like media-preload. /metrics for Prometheus.

Alternatives not taken: rules only (no queue); GPUStack/LocalAI (LLM-only, heavy).

Non-goals (v1)

  • No per-request GPU pinning inside Ollama (it places models itself; the broker only gates).
  • llama.cpp router: leases only, no CPU fallback (its presets are GPU presets). Later.
  • AudioMuse stays masked (thermal) and is CPU-only anyway.

Constraints

  • Thermal: CPU fallback is always capped (4 threads / CPUQuota 400%); arceus has a thermal guard.
  • Go, static binary, OpenAPI, mise, TDD (scheduler logic is pure and clock-injected).