Files
myWiki/concepts/offline-profiling.md

59 lines
2.3 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: "Offline Profiling (LU-KV)"
created: 2026-06-18
updated: 2026-06-18
type: concept
tags: ["kv-cache", "deployment", "profiling"]
sources: ["https://arxiv.org/abs/2602.08585"]
---
# Offline Profiling
## 定义
Offline Profiling离线分析/标定)是 LU-KV 中的三阶段数据驱动协议,用于在实际推理前预计算每个 attention head 的最优预算配置。它将理论上需要未来解码信息的 [[oracle-importance]] 评估搬到了离线阶段,使在线推理只需查表。
## 三阶段协议
### 阶段 1上下文生成Context Generation
构造一个合成长上下文 C_syn约 4,000 tokens通常为 AI 生成的中文小说节选,与评测集无重叠,模拟真实的 KV Cache 状态。
### 阶段 2Oracle 计算Oracle Computation
- 生成 M = 30 个多样化查询 Q = {q_1, ..., q_M},分别针对不同信息片段
- 对每个 q_i通过**全注意力解码**full-attention decoding计算 ground-truth Oracle 重要性 I_{l,h,j}
- 全注意力解码在 profiling 中可接受(离线),但在生产推理中不可行
### 阶段 3Profile 聚合Profile Aggregation
- 在密集的全局压缩率网格 ρ ∈ [0, 1] 上求解每个查询的最优配置 r*_{l,h}(q_i; ρ)
- 取平均得到最终静态 profileΦ(π)(ρ)_{l,h} = (1/M) Σ r*_{l,h}(q_i; ρ)
- Φ(π) 成为一个**查表**:给定目标全局压缩率 σ_target → 返回每个 head 的最优局部压缩率
## 关键经验发现
> 各 head 的最优局部-全局压缩率在不同任务间高度稳定。
如图 2b 所示,问答、长上下文检索等不同场景下的最优压缩率配置高度一致——这意味着**一个静态 profile 可跨任务迁移**。
## 在线使用
```
1. Lookup: {r_{l,h}} ← Φ(π)(σ_target)
2. Budgeting: b_{l,h} = floor((1 - r_{l,h}) * T)
3. Eviction: 每个 head 独立保留 top-b_{l,h} tokens
```
额外开销可忽略(仅查表 + 整数计算)。
## 相关概念
- [[oracle-importance]] — Profiling 阶段 2 的 ground truth
- [[global-combinatorial-optimization]] — Profiling 阶段 3 求解的优化问题
- [[convex-hull-relaxation]] — 使 profiling 中的优化高效可解的技巧
## 参考
- [[tang-lukv|LU-KV]] (Tang et al., ICML 2026) — 附录 F.2 有迁移性分析