Sphere
Log in Join

Ollama 0.3.12 keeps unloading models on 8GB laptop — num_gpu and keep_alive

## What tipped me off

I run Ollama 0.3.12 on an old 8GB laptop with a 4GB GTX 1650 and a Ryzen 5 5600H. It is my good-enough box for summarising meeting notes while I am on the couch. Every single prompt took 25-30 seconds of nothing first, then flew. Classic sign the model was being loaded fresh each time.

ollama ps made it obvious:

NAME           ID           SIZE   PROCESSOR       UNTIL
llama3.1:8b 91ab72b7c9e0 4.7GB 19% GPU/CPU 4 minutes from now

Nineteen percent GPU meant it was offloading barely anything to the 1650 and doing the rest on that poor CPU.

## Why it was doing that

Ollama auto-guesses num_gpu based on free VRAM at load time. With 4GB and the desktop compositor holding ~600MB, it decided the 8B in Q4 would not fully fit and dumped most layers to system memory. It is a safe guess, not a smart one. The model is 4.7GB, so it never fit entirely anyway; the real question is which layers are worth keeping on the GPU.

I pushed it too far once and got this:

Error: model requires more system memory (5.2 GiB) than is available (4.8 GiB)

So there is a real ceiling. You cannot just set num_gpu 999 and walk away.

## Pinning it in a Modelfile

I made a derived model instead of fighting the CLI every time:

FROM llama3.1:8b
PARAMETER num_gpu 20
PARAMETER num_ctx 4096
PARAMETER num_threads 6

Then:

ollama create llama3.1-local -f Modelfile
ollama run llama3.1-local

ollama ps after that showed 100% GPU with 20 layers offloaded, and first-token latency dropped from about 28s to 3s. Still not fast, but no longer insulting. I also switched from the default 8b tag to llama3.1:8b-instruct-q4_K_M at one point, which is slightly smaller and a bit sharper for the short summarisation prompts I actually use.

## keep_alive is the other half

Ollama unloads idle models after five minutes by default, which is terrible for an interactive tool you pick up and put down. Set it explicitly:

curl http://localhost:11434/api/generate -d '{"model":"llama3.1-local","prompt":"hi","keep_alive":"24h","stream":false}'

Or pass --keepalive 24h to ollama run for a one-off session. Note that keep_alive is per request through the API, so if your client forgets to send it, the model goes back to the five-minute timer. That caught me for a day because my little Python wrapper was only sending model and prompt.

## What went wrong

I originally set num_threads 12 because the 5600H reports 12 threads. Worse. This chip has 6 physical cores and 12 threads, and SMT contention was hurting more than helping; 6 gave better tokens/sec than 12. Took me an embarrassingly long time to try the smaller number. I also tried forcing num_gpu 24, which fit but left the machine swapping, so 20 is the sweet spot here.

Anyway, pinned num_gpu, num_ctx 4096, six threads, long keep_alive. If you have a similar low-VRAM setup and found a better split, tell me which layers you offloaded.