KV Cache
缓存的注意力键和值,使得一次生成一个token变得经济可行。
概览
KV Cache 存储了为先前 token 已经计算好的注意力键和值,因此生成下一个 token 时无需重新计算它们。它解决了自回归生成的成本问题,否则每生成一个新 token 都要重复与整个序列成正比的计算。它之所以存在,是因为这种重复计算在推理中占主导地位,也正是它使得长对话的内存占用随其长度增长。
技术图谱
KV Cache 如何与技术栈的其他部分相连。
使用与依赖
- Prompt Caching technique Infrastructure Prompt Caching based on KV Cache High ✓ source
被用于
- SGLang tool Infrastructure KV Cache used by SGLang High ✓ source
- Speculative Decoding technique Techniques KV Cache used by Speculative Decoding High ✓ source
- Text Generation Inference tool Infrastructure KV Cache used by Text Generation Inference High ✓ source
- vLLM tool Infrastructure KV Cache used by vLLM High ✓ source