Files
myWiki/concepts/snapkv.md

41 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: "SnapKV"
created: 2026-06-18
updated: 2026-06-18
type: concept
tags: ["kv-cache", "attention", "intra-head-eviction"]
sources: []
---
# SnapKV
## 定义
SnapKV (Li et al., 2024) 是一种 KV Cache 驱逐的 [[heuristic-metric]] 指标,基于累积注意力分数和观察窗口来动态识别和保留关键 token。它是 LU-KV 实验中使用的默认 intra-head 指标之一π_1
## 核心机制
1. **观察窗口**:在 prefill 阶段的最后 W 个 token 上计算注意力模式
2. **累积评分**:对每个历史 token累积其在观察窗口内的注意力权重
3. **Top-K 选择**:按累积分数排序,保留前 b 个 token
## 在 LU-KV 中的使用
LU-KV 使用 SnapKV 作为 π_1但将预算分配决策从 SnapKV 的"固定每 head 预算"提升为"基于 [[marginal-utility]] 的差异化分配"。实验表明:
- SnapKV 本身在不同 head 中的 [[optimality-gap]] 差异大
- LU-KV 将更多预算分配给 SnapKV-Oracle 对齐度高的 head
- 80% 压缩率下 LU-KV + SnapKV 显著优于 Uniform + SnapKV
## 相关概念
- [[heuristic-metric]] — SnapKV 是启发式指标的一种
- [[keydiff]] — 另一种常用 intra-head 指标
- [[intra-head-eviction]] — SnapKV 属于头内驱逐方法
- [[tang-lukv|LU-KV]] — 可兼容 SnapKV 作为 intra-head scoring 方法
## 参考
- SnapKV: LLM Knows What You are Looking for Before Generation (Li et al., 2024)
- [[tang-lukv|LU-KV]] (Tang et al., ICML 2026)