Files
nexus/wiki/concepts/KV-Cache.md

24 lines
860 B
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.
# KV Cache
## Metadata
- **Type**: Concept
- **Category**: AI/LLM/Inference Optimization
## Definition
KV CacheKey-Value Cache是 Transformer 模型推理优化中的关键技术。KKey和 VValue是由每个 token 的向量化后通过线性变换得到的两类向量用于注意力机制计算。KV Cache 将这些历史 K/V 保存下来,使得后续步骤不需要重复计算,从而加速推理。
## Details
- **K 和 V 的来源**: 每个 token 的向量化结果通过线性变换得到
- **作用**: 避免重复计算,提高推理效率
- **局限性**: KV Cache 随上下文长度、层数、头数、维度线性增长,是推理中的主要显存开销之一
- **优化方案**: vLLM 的 PagedAttention 将 KV Cache 切分为固定大小的块管理
## Related Concepts
- [[vLLM]]
- [[PagedAttention]]
- [[LLM]]