KV Cache Tip

#1
by kotyKD - opened

I got everything set up on my RTX 3080 10GB (the Prism fork of Llama.cpp), but I noticed the KV cache was using a ton more than it should. I then noticed this line:

0.02.389.608 I srv    load_model: initializing, n_slots = 4, n_ctx_slot = 32000, kv_unified = 'true'

I added "-np 1" to my command, and it went way down. In my opinion, the default should be -np 1, or at most 2. 4 seems high considering this is intended for low VRAM devices. If you want specific numbers, lmk, but it went from about 9.5GB total VRAM (including desktop) to ~7.8GB.

Thanks for the report. We added a Known issues note to the model card recommending -np 1 for single-user servers on GPUs with limited VRAM. The four automatic slots share a unified KV cache. If you have the exact build, launch command, and CUDA buffer allocation lines from both runs, those would help us identify which buffers account for the difference.

You can also offload vision to CPU with --no-mmproj-offload
Slower image ingestion but saves VRAM.

With -np 1 you can save a bit more VRAM by setting -b to the same value as -ub since it goes wasted with just one slot.

You can save more vram by offloading some laers on cpu:

Ternary-Bonsai-2.5-27B-Q2_0.gguf: 4.0 GiB VRAM · 5.8 GiB RAM (32K · F16 · ngl 25) — Simulate on whichllmmodel.com

Sign up or log in to comment