2 min read

Things llama.cpp taught me the hard way

CUDA arch flags, KV cache landing on the wrong GPU, -ub settings, swap-backed prompt caches, and when speculative decoding hurts.

Every model in my lab runs on mainline llama.cpp, built from source on each machine, one systemd service per model. These are the things that cost me hours.

Builds

  • V100 builds need -DCMAKE_CUDA_ARCHITECTURES=70 set explicitly, or they crash.
  • Every RPC node must run the same commit. Mismatched builds across a pool cause trouble.
  • Keep builds current. A month-old build was behind my repetition loops.

Memory

  • The KV cache piles onto whichever GPU has the least free VRAM. One card can OOM while the pool’s total looks fine. Watch each card, not the total.
  • -ub 512 roughly halves the working buffers and buys back context.
  • -ub 2048 plus unified memory made the 27B output gibberish. Not slow. Gibberish.
  • q8_0 KV cache looked the same as f16 to me, at half the memory.

Prompt cache and swap

Each box has a 128GB host-RAM prompt cache plus two 128GB swapfiles. When a chat gets evicted, it swaps back in instead of being re-read from scratch. On long chats that’s the difference between a quick reply and a long wait for the prompt to be processed again.

Speculative decoding

  • MTP drafts helped on the 27B, but I saw a big speed drop at very long context.
  • A DFlash draft on Muse Glimmer 30B was slower: 18 vs ~32 tok/s, ~4% accepted. Dropped.
  • Mixed V100 + P100 pools hurt draft acceptance, from ~80% to ~54%. (More)

A draft model is worth testing, not assuming.