Topic 4 of 5 · 4 min read
Diagnosing slow local inference
Goal: Read a slow run's log and system stats and name the cause of the slowdown.
When a local model is slow, the log and a few system stats usually name the cause within a minute; guessing at flags wastes hours. Most slowdowns are one of five things, and each leaves a trace.
Check yourself · 1 of 3
A local model suddenly runs at a fraction of its usual speed, with no error. The log says 0 layers were offloaded. What is the most likely cause?
Why it matters
Local runners fail quietly. If the GPU backend is missing, the model still runs, just on the CPU, and nothing crashes. You only notice that it is "slow". Looking at evidence first tells you whether to change a flag, a build or the hardware.
The five usual suspects
- Silent CPU fallback. The binary was built without the right backend (CUDA, Metal, Vulkan), or the GPU is not visible. Clues: the load log says zero layers offloaded, GPU memory in
nvidia-smistays near empty while the CPU sits at 100 %. - Partial offload. The log shows fewer layers on the GPU than the model has, because the model, cache and buffers did not fit. See the offload topic.
- Memory swapping. The model plus cache is larger than free RAM, so the OS swaps pages to disk. Clues:
free -hshows swap in use,vmstatshows swap-in and swap-out activity, and generation speed is erratic or extremely low. - Thermal or power throttling. Fast at first, then slower as the chip heats up or the laptop switches to battery. Clues: clock speeds fall during a long run in
nvidia-smior the OS monitor. - Oversized context. A very long prompt or a huge
-cmakes prompt processing slow and eats memory that pushes layers off the GPU.
A diagnosis routine
- Read the startup log for the backend line and the layers offloaded line.
- Watch GPU memory and utilization during a run.
- Check RAM, swap and other processes using the GPU.
- Repeat a short benchmark and a long one to see whether speed falls over time.
Before and after
Weak: "It got slow, try a smaller model." That ignores a log line saying offloaded 0/33 layers to GPU.
Better: the log shows 0 layers offloaded. The binary was a CPU-only build, so install a build with the GPU backend. Same model, same flags.
What goes wrong
- Fixing the wrong layer. Retuning flags on a CPU-only build changes nothing.
- Missing another tenant. A browser or another model server already holds half the VRAM.
- Blaming the model. A model that was fast yesterday and slow today usually points at the system, not the weights.
- Testing too briefly. Throttling shows only in runs long enough to heat the chip.
Examples
Reading a startup log
llama_model_load: offloaded 0/33 layers to GPU
system_info: n_threads = 8 | CUDA = 0 | AVX2 = 1
Zero layers offloaded and no CUDA in the build line. This is a CPU-only binary: reinstall or rebuild with the GPU backend. Changing -ngl will not help until then.
Swap hiding in plain sight
$ free -h
total used free
Mem: 16Gi 15Gi 120Mi
Swap: 8Gi 5.2Gi 2.8Gi
A model that needs more than the available RAM pushes 5 GB into swap, so each token waits on disk. Use a smaller quant, a shorter context or close other programs.
Key points
- A missing GPU backend does not crash; the model runs on the CPU and is simply slow.
- The startup log shows the backend and how many layers were offloaded.
- Swap activity in free or vmstat means the model plus cache exceeds free RAM.
- Throttling shows as clock speeds falling during a long run, so benchmark for long enough to see it.
- Another process holding GPU memory can push layers to the CPU without any error.
Common mistakes
- Retuning flags before checking the log for the backend and offloaded layers.
- Assuming a slow run means the model is too big, when the GPU is not being used at all.
- Ignoring other processes that already hold GPU or system memory.
- Benchmarking for seconds, which hides thermal throttling.
Check yourself · 2 of 3
free -h shows nearly all RAM used and several GB of swap in use while a model generates at an erratic, very low speed. What does this indicate?
Check yourself · 3 of 3
A laptop benchmark shows 40 tokens per second for the first minute, then 22 for the rest of a 10-minute run on battery. Which check best confirms the cause?
Practice items, not counted towards your mastery.
Start here
- llama-bench (llama.cpp) (opens in a new tab)DocsFree
The standard tool for repeatable prompt and generation speed numbers, with options for offload, flash attention and repetitions.
- llama.cpp server README (opens in a new tab)DocsFree
Lists the flags for context size, GPU layers, KV cache types, flash attention and draft models.
- llama.cpp (opens in a new tab)ToolFree
The runtime behind many local tools; build instructions show which backends (CUDA, Metal, Vulkan) a binary includes.