{
  "schema_version": "1.0",
  "id": "T-478f4e489d6a",
  "url": "https://gpuatlas.top/articles/T-478f4e489d6a/",
  "title": "llama.cpp 的 KV cache 能量化吗，应该怎么选？",
  "summary": "llama.cpp缓存可按K/V分别评估量化，先核对模式支持，再比较长文细节、峰值和完整时间。",
  "language": "zh-Hans",
  "category": {
    "id": "c-09",
    "name": "框架配置与故障",
    "url": "https://gpuatlas.top/categories/c-09/"
  },
  "topics": [
    {
      "id": "framework-5c58ce0020",
      "name": "llama.cpp",
      "kind": "framework",
      "description": "用 GGUF 在本机运行模型时，GPU layers 和 CPU 卸载怎么分配？先平衡显存占用与生成速度。",
      "url": "https://gpuatlas.top/topics/framework-5c58ce0020/"
    },
    {
      "id": "task-dce84928dd",
      "name": "量化",
      "kind": "task",
      "description": "权重变小以后，速度和效果会怎样变化？这里收录量化格式选择、运行支持及显存不足时的取舍。",
      "url": "https://gpuatlas.top/topics/task-dce84928dd/"
    }
  ],
  "body_text": "llama.cpp可以评估KV量化，但权重量化不自动决定缓存位宽。先看当前版本cache-type-k和cache-type-v支持的类型，再核对模型、FlashAttention与拆分模式，K和V也不能默认采用相同条件。\n\n固定缓存说明中，部分量化V路径需要FlashAttention，实验tensor模式另有缓存限制。单卡或layer可用的配置不能直接搬过去，版本变化后也需复核，不能把旧命令永久套用。\n\n先判断峰值是否主要来自缓存。权重加载已经失败时，改KV未必触及主要问题；缓存降位也不会缩小基础权重或消除临时张量。理论位宽只影响部分数据，块、比例尺和元数据使实际下降比例不同。\n\n固定权重和长度，先用默认或较高精度缓存建基线，再改一种受支持类型。样本包含短题、最长日常材料和数字或代码细节，记录正确、错引、重复与截断，不能只看有文字返回。\n\n多卡测试应逐卡看峰值，同时比较输入处理、首字和完整等待，缓存省空间也可能付出内核或转换成本。长材料里的数字或代码一旦退步，就回到基线复查，不能仅凭显存下降采用新类型。把当前版本、K/V类型和拆分模式与结果绑定，最终保留能完成这项长文任务的缓存配置。",
  "published_at": null,
  "modified_at": "2026-11-26T15:00:32.276655+00:00",
  "evidence": {
    "type": "documentation_and_conditional_estimates",
    "hardware_tested": false,
    "note": "资料解释与条件估算，非硬件实测。"
  },
  "sources": [
    {
      "id": "llamacpp-multigpu",
      "url": "https://raw.githubusercontent.com/ggml-org/llama.cpp/master/docs/multi-gpu.md",
      "retrieved_at": "2026-11-25T09:52:45.997121+00:00"
    },
    {
      "id": "llamacpp-server",
      "url": "https://raw.githubusercontent.com/ggml-org/llama.cpp/master/tools/server/README.md",
      "retrieved_at": "2026-11-25T09:52:45.997121+00:00"
    },
    {
      "id": "transformers-kv-cache",
      "url": "https://raw.githubusercontent.com/huggingface/transformers/main/docs/source/en/kv_cache.md",
      "retrieved_at": "2026-11-25T10:07:29.175278+00:00"
    }
  ],
  "revision_note": "更新使用说明与操作示例；非硬件实测。",
  "representations": {
    "html": "https://gpuatlas.top/articles/T-478f4e489d6a/",
    "json": "https://gpuatlas.top/data/articles/T-478f4e489d6a.json",
    "markdown": "https://gpuatlas.top/data/articles/T-478f4e489d6a.md"
  }
}
