backend: per-model kv_offload flag to keep the KV cache in host RAM

Large contexts make the KV cache huge (a 256k q4_0 cache is several GB), which
won't fit in VRAM alongside the weights. llama.cpp can't page KV to disk, but it
can keep it in system RAM via --no-kv-offload. Expose that as a per-model
kv_offload flag (default unchanged = KV in VRAM): set kv_offload=false to pass
offload_kqv=False to llama.cpp, freeing VRAM for big contexts at the cost of
slower decode (KV ops cross PCIe). Also allow the key in the admin model-config
endpoint so it's persistable from the UI.
Co-Authored-By: 's avatarClaude Opus 4.8 <noreply@anthropic.com>
parent da4359c3
......@@ -2725,7 +2725,7 @@ async def api_model_configure(request: Request, username: str = Depends(require_
"max_vram", "sdcpp_flash_attn", "sdcpp_diffusion_flash_attn", "vae_tiling",
"component_quantization", "output_crf", "force_vram_update",
"balanced_gpu_percent", "acceleration",
"cache_type_k", "cache_type_v", "turboquant", "engine", "engine_fallback",
"cache_type_k", "cache_type_v", "kv_offload", "turboquant", "engine", "engine_fallback",
"quant_backend", "kv_cache_budget_mb", "kv_cache_slots", "mmproj",
"auto_compact", "auto_compact_pct", "auto_compact_strategy",
"auto_compact_model", "suppress_reasoning"):
......
......@@ -939,6 +939,18 @@ class VulkanBackend(ModelBackend):
print(f" KV cache: type_k={_ck or 'f16'} type_v={_cv or 'f16'}"
f"{' (flash_attn on)' if _flash else ''}")
# KV-cache offload target. Default (True) keeps the KV cache in VRAM. Set
# kv_offload=false on a model to keep it in *host RAM* instead (llama.cpp
# --no-kv-offload) — frees a lot of VRAM for big contexts (a 256k KV can be
# several GB) at the cost of slower decode, since KV ops then cross PCIe.
# llama.cpp has no SSD/disk KV paging, so RAM is the only off-GPU option.
_kv_off = kwargs.get('kv_offload', _raw_cfg.get('kv_offload',
_raw_cfg.get('offload_kqv')))
if _kv_off is not None and not bool(_kv_off):
llama_kwargs['offload_kqv'] = False
print(" KV cache: offload_kqv=False — KV held in host RAM (saves VRAM, "
"slower decode)")
# Multimodal projector (mmproj): pairs a CLIP/vision projector GGUF with
# this text model so it can accept images — the llama.cpp `--mmproj`
# equivalent, which adds vision capability (e.g. gemma). Uses llama.cpp's
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment