Skip to content

key value kv caching mistral transformers xformers | Towards Data Science

Published: at 00:51

关键字: KV-Caching, Mistral, Attention, Prefill, Decode

概述: 本文深入探讨了 Mistral 模型中使用的 KV-Caching 技术,解释了为什么大型语言模型(LLM)的首次 token 生成时间(TTFT)较长,而后续 token 生成速度很快。文章详细介绍了 KV-Caching 的原理,即通过存储先前计算的 key 和 value 向量来避免冗余计算,从而显著提高解码效率。文章还阐述了 Mistral 模型中预填充(Prefill)和解码(Decode)两个阶段的工作原理,以及如何利用 xFormers 库生成注意力掩码。通过具体的例子和图示,文章清晰地展示了 KV-Caching 在实际应用中的运作方式,以及它如何大幅减少计算量,从而加速 LLM 的推理过程。

分节阅读:

相关工具:

参考文献:

  1. Mistral Codebase: https://github.com/mistralai/mistral-inference/tree/main
  2. xFormers Codebase: https://github.com/facebookresearch/xformers
  3. Umar Jamil’s excellent overview of Mistral: https://www.youtube.com/watch?v=UiX8K-xBUpE

原文链接: https://towardsdatascience.com/deep-dive-into-kv-caching-in-mistral-7e0cea8409a1

source: https://towardsdatascience.com/deep-dive-into-kv-caching-in-mistral-7e0cea8409a1


Previous Post
Fine-Tune Llama 3.1 Ultra-Efficiently with Unsloth | by Maxime Labonne | Towards Data Science
Next Post
Practical Tips for Finetuning LLMs Using LoRA (Low-Rank Adaptation)