Files
myWiki/concepts/beam-shared-kv-caching.md

31 lines
1.1 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: "Beam-Shared KV Caching"
created: 2026-06-28
updated: 2026-06-28
type: concept
tags: [generative-recommendation, inference-optimization, kv-cache]
sources: [GR4AD]
---
# Beam-Shared KV Caching
Beam-Shared KV Caching 是 [[GR4AD]] 提出的束搜索推理优化技术,通过沿序列维度组织束来共享编码器 KV 缓存。
## 问题
在束搜索中,解码器的每步需要对 $B$ 个束分别计算注意力——每个束需要独立的 KV 缓存。标准实现中,$B$ 个束产生 $B$ 份完整 KV 缓存副本per-step KV 读取复杂度为 $O(B \cdot L)$,其中 $L$ 是序列长度。
## 方案
将所有束沿序列维度拼接,多个束共享**同一份编码器 KV 缓存**。注意力计算中束间通过适当的掩码隔离互注意力但编码器部分完全共享。per-step KV 读取复杂度降至 $O(L)$。
## 效果
- 消除冗余的内存访问
- 对束搜索的吞吐量有显著贡献
- 配合 TopK Pre-Cut先并行选 $k$ 个候选人,再做全局 top-$k$ 选择)进一步减少搜索空间
## 参考
- [[GR4AD]]
- [[dynamic-beam-serving|DBS]]