Home / use case

llama-sleep: park GPU models in RAM so llama-swap switches in about 2 seconds

At a glance
Hardware
Hardware in the write-up: NVIDIA RTX 3060 12 GB on PCIe 3.0 x16, 125 GB DDR4, Fedora 44, driver 615.71
Models & engines
Software: llama-swap v263 and llama.cpp b11552 (CUDA 13) in one container; models Gemma 4 12B QAT and Gemma 4 26B A4B QAT (UD-Q4_K_XL)
12B used about 7.9 GiB GPU memory; 26B used 11.1–11.3 GiB with some expert weights on the CPU
llama-sleep is a single ~7 MB Go binary built without cgo; NVIDIA GPUs and Linux only, driver 570 or later for the checkpoint path described
Key gotcha
A parked model keeps as much host RAM as it used on the GPU.

What they built

On Robert Zaage's home server an RTX 3060 12 GB runs a Gemma 4 12B voice assistant and a Gemma 4 26B model for long automation inputs; each fills the GPU alone, so llama-swap was stopping one llama-server and starting the other for every job.

A baseline swap between two GPU-filling 26B processes took 10.3 seconds and threw away the voice model's cached system prompt of about 8,000 tokens, which delayed the first spoken word by another 6–7 seconds after a cold reload.

llama-sleep is a small MIT Go wrapper that becomes the model's cmd and cmdStop: it holds requests (including health checks) until the model is awake, parks idle models into host RAM with the CUDA driver checkpoint API, and wakes the requested model when llama-swap starts it again.

Setup

  • Hardware in the write-up: NVIDIA RTX 3060 12 GB on PCIe 3.0 x16, 125 GB DDR4, Fedora 44, driver 615.71
  • Software: llama-swap v263 and llama.cpp b11552 (CUDA 13) in one container; models Gemma 4 12B QAT and Gemma 4 26B A4B QAT (UD-Q4_K_XL)
  • 12B used about 7.9 GiB GPU memory; 26B used 11.1–11.3 GiB with some expert weights on the CPU
  • llama-sleep is a single ~7 MB Go binary built without cgo; NVIDIA GPUs and Linux only, driver 570 or later for the checkpoint path described

How it works

  1. Point llama-swap macros at `llama-sleep serve ... --` for cmd and `llama-sleep sleep` for cmdStop so the wrapper owns the listen port and the real llama-server sits behind a Unix socket or internal port.
  2. Use `--idle` (5s in the example) so a quiet model parks in the background before the next swap needs the GPU.
  3. Tune cold starts separately with a fixed layer split such as `--n-cpu-moe 14` for the 26B if you still need cold loads; parking wakes do not depend on that probe.
  4. Optionally enable multi-size transparent huge pages (16 KB–1 MB) under `/sys/kernel/mm/transparent_hugepage` so host buffers fault in fewer pages during park/wake copies.

Results & numbers

  • With parking, background idle, and wake-on-start, the remaining critical path around the copy shrank to about 82 ms; most of a ~1.9 s wake was the GPU↔host copy.
  • End-to-end swap between two 26B models fell from 10.3 s to about 2.1 s, and with mTHP to about 1.7 s; swap back to the 12B voice model reached about 1.1 s with mTHP.
  • A 9,589-token prompt sent again after a round-trip swap was answered with 9,588 tokens taken from cache and only one token processed, instead of re-prefilling all 9,589 after a cold start.

Gotchas

  • A parked model keeps as much host RAM as it used on the GPU.
  • If a request arrives while a park is still running, the swap waits; with 8-second gaps the author measured 3.2–5.3 s instead of 2.1 s on 4 KB pages.
  • Suspending CUDA without holding requests can crash: a parked llama-server still returns /health 200, and llama-swap can forward traffic mid-restore.
  • Freezing the container hangs restore because the CUDA restore thread is frozen too.
“Most of the time a swap took was overhead around the model, not the model itself.”— Robert Zaage

Do it yourself

  1. Install llama-swap and a CUDA llama-server build that can load your GGUF models.
  2. Build or download llama-sleep and wire each model's cmd/cmdStop macros to `llama-sleep serve` / `llama-sleep sleep` as in the article.
  3. Confirm an idle model parks after `--idle` and that a request for the other model wakes it without a full weight reload.
  4. If park/wake copies are slow, try multi-size transparent huge pages and re-measure time to first token at the client.
macros:
  "serve": llama-sleep serve --name ${MODEL_ID} --listen 127.0.0.1:${PORT} --idle 5s --
  "sleep": llama-sleep sleep --name ${MODEL_ID} --stop-pid ${PID}
models:
  "gemma-26b": { cmd: "${serve} llama-server ...", cmdStop: "${sleep}" }
Source: zaage.IT · Published 2026-11-05 · Added 2026-11-07. This write-up summarizes the original source; see it for full details.

Similar setups

Running 80 GB MoE models on two 16 GB GPUs with llama.cpp 1.0

Gancho Stoychev measured five llama.cpp 1.0 settings one at a time on his homelab box with two RTX 5060 Ti 16 GB cards, running Qwen3.8-Flash-Next and DeepSeek V4 Flash, each about 80 GiB.

DEV Community (Gancho Stoychev) · 2026-11-25

A local eve agent on a 4B model that keeps its pending approval through kill -9

@VarunChopr17597 ran Vercel's open-source eve 1.1 agent framework against Qwen3.5-4B on llama.cpp on a CPU-only Linux box, with no Vercel account, and tested whether a tool waiting for human approval survives the server being killed.

X (@VarunChopr17597) · 2026-11-20

Serving a local model on Kubernetes on your own laptop with kind and Ollama

Alex Jones wrote a tested guide to running Ollama in a kind cluster on CPU, Intel Arc, NVIDIA and AMD, then using the served model with k8sgpt to explain cluster failures without any data leaving the machine.

axjns.dev · 2026-11-09

A Baroque music events calendar fed by a local Qwen agent on a home llama.cpp server

A data scientist serves small models with llama.cpp from a 16 GB RTX 4060 Ti box on his home network, and a LangChain agent on it finds upcoming concerts for his wife's Bavarian Baroque events calendar.

Andreas Kaempf (FastDataScience.eu) · 2026-11-04