Files
obsidian/phd/papers/IMPRESS.md

140 lines
6.6 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.

# TL;DR
该工作观察到KV cache 从 SSD load 到 GPU 的开销很难被 overlapload 的时间开销占据了 TTFT 的 51%-98%。该工作的出发点是利用 attention 的稀疏性,只 load important KV cache。这就出现了两个 challengesC1: 如何决定 SSD 上的 KV cache 哪些是 important 的C2: load important KV cache 时是离散的,带宽利用不高效,基于 KV cache 的稀疏性,现有的 cache policy 也不高效。该工作利用不同 head 间 important tokens 的相似性解决 C1利用 SSD 上的 KV reorder 和 importance score based policy 解决 C2.
# Motivations
不同 tokens 对应的 KV 具有不同的重要程度,因此我们不需要 load 所有 prefix tokens 的 KV而是只 load important KV减少 IO 导致的 overhead。
# Challenges
## 现存 important KV 的判别法依然会引入巨大的 IO overhead
最 naive 的方式load 所有 KV计算 attention判断哪些是 important 的。但是既然所有 tokens 都算完了,为什么还要用 important无任何收益 ✖️
$\mathrm{attention}(Q, K, V) = \mathrm{softmax}(QK^T)V$ 的稀疏性来源于 $\mathrm{softmax}(QK^T)$ 的稀疏性,因此现有工作只 load 所有的 keys开销少了一半但仍然很大 ✖️
记录一段 prefix tokens 哪些是 important tokens下次 reuse prefix 时直接使用accuracy 不行,例如 RAG同一段 prefix tokensdocs在后面跟不同 query 时important tokens 是不一样的 ✖️
![[250228-095457.png]]
## 现有系统不能高效利用 important KV
为了高效地 disk read 和利用 PCIe现有系统会以 chunk 为单位 read。而一个 chunk 会包含 important KVs 和 unimportant KVs导致 read amplification影响性能。
现有的 KV cache manager 都是利用 LRU/LFU 这种策略,忽略了不同 KV cache 重要性的区别。可能导致不关键的 KV cache 占据着 GPU memory。降低了 important KV cache 的 hit ratio或者导致更多的 transfer 开销。
# Key Observation
## 同一 layer 不同 head 之间的 important tokens 具有相似性
对于两个 set $A, B$Jaccard Scores 用于定义相似性 $S = \frac{|A \cap B|}{|A \cup B|}$。例如下图 a相似性为 $\frac{1}{3}$,该工作通过实验 32 heads交叉的相似性都在 0.9 以上。
![[250228-164104.png]]
## 不同 important KV 的比例、不同模型的大小下都具有相似性
important KV 的比例的意思是,不同的比例 $r$,我们认为 $r \cdot \text{num\_tokens}$ 个 tokens 对应的 KV 为 important KV。
![[250228-170902.png]]
文中并没有解释、为什么只选 top 10% 的 KV 时,在后一半的 layers 中,相似度明显下降。
> Although smaller models and deeper transformer layers tend to exhibit lower similarities, they are still significantly higher than the expected value from random selection in most cases.
# Solution
## For C1, from O1
既然同一 layer 的 heads 之间的 important KV 具有相似性,可以选择部分 heads 作为探针probe heads计算它们的 important KV代表该 layer 的 important KV。
具体来说,会选取前 3 个 heads原文 claimthe choice of which three heads to use has no impact on accuracy due to the similarity作为 probe heads。load 它们的 keys计算 important tokens id set并计算它们之间的平均相似性。
如果在相似性超过 threshold则返回 3 个 tokens id set 中的其中一个,作为全局的 important tokens id set原文没说怎么在 3 个中选一个,有可能是 random 选一个,或是选择与另两个 head 的平均相似度最高的那个 head
如果相似性不足,则 fallback 到默认策略load all。实验证明只有不超过 20% 的 layers 需要 fallback。
![[250228-175702.png]]
### 神秘的超参选择
> Selecting only one probe head to determine the most important token index may introduce bias, affecting model accuracy. Using two probe heads might fail to identify the most important index through voting when disagreements arise. Therefore, we choose to use three probe heads. Increasing the number of probe heads offers minimal improvements in accuracy but increases the keys loading time, thereby extending the TTFT.
>
> ![[250228-175831.png]]
>
> $n$ prefix tokens 选择 $k$ important tokens对于两个任意的 $n$ 选 $k$ 的 token id set $A$ 和 $B$
> $$j = E(\text{Jaccard(A, B)}) = \frac{E(A \cap B)}{E(A \cup B)} = \frac{E(A \cap B)}{E(A) + E(B) - E(A \cup B)} = \frac{n \cdot \frac{k^2}{n^2}}{2k - n \cdot \frac{k^2}{n^2}} = \frac{\frac{k}{n}}{2 - \frac{k}{n}}$$
> 选择 $t = j^{\alpha}$ 作为 threshold通过实验$\alpha$ 选 0.6 最好
## For C2
### KV cache reorder
![[250301-134529.png]]
- 一个线程周期性地10 分钟)做一个 blockradix node内的 reorderreorder based on the average token importance
- 🤔 过去的 token importance 为什么能指导未来的情况?
- 不在不同 node 间 reorder 的理由:做 prefix match 时,粒度更大,会需要 load 更多的无效 KV cache导致 IO overhead
### Score-based Cache Management
每个 chunk 的分数由 access frequency 和 important tokens 的占比共同决定。
![[250301-151846.png]]
在 GPU 和 CPU 分别使用一个 min-heap 维护 score同时保证 GPU 和 CPU 上没有 overlap 的 KV但是在 disk 上会有全量 KV 的 replica减少 CPU -> disk 做 evict 时的 IO 开销
# Evaluation
## Setup
- models
OPT- 6.7B, OPT-13B, and OPT-30B
- hardware
2 * AMD EPYC 7763 CPUs (64 cores)
1 * 128 GB DRAM
1 * NVIDIA A100 GPU with 80GB HBM
1 * 2TB Intel SSD whose measured read throughput is around 5GB/s
PCIe 4.0 * 16 for GPU and CPU connection
测试时限制 GPU 上使用 10GB for prefix cacheCPU 上使用 32GB
- dataset
PIQA, RTE, COPA, and OpenBookQA
## Baseline
1. ReComp: recompute all prefix KV cache
2. AS-like: 作者自己实现的 AttentionStore
3. AS+H2O+LRU
4. AS+H2O+LFU
## Results
### Model generation quality
![[250301-155139.png]]
### TTFT
1.2x to 2.8x improvement
![[250301-155325.png]]
1.5x to 3.8x reduction in I/O time
![[250301-155822.png]]
### Ablation experiment
ITF: similarity-guided important token identification
RO: reorder
All: ITF + RO + score-based cache management
![[250301-155959.png]]
![[250301-160458.png]]
### Sensitivity Analysis
1. alpha
2. chunk size
3. dataset size: 为什么增大 dataset 后,提升效果相对减弱了?只测试到 400GB如果继续增大是不是对比起来就没有任何提升了
4. model type
![[250301-162611.png]]
# Takeaway
- 个人认为这篇工作的优点paper 写的很通顺、有很多简单的例子帮助读者 follow 它们的 idea实验做的比较详细