用小模型预估大模型的键值缓存,显著缩短首个输出的生成时间。
KV Prediction for Improved Time to First Token
- 引入辅助小模型预测基模型的键值缓存,避免重复计算。
- 在TriviaQA上相对准确率提升15%~50%,HumanEval代码生成提升30%。
- 适用于边缘设备加速推理,尤其适合对响应速度要求高的场景。
基于Transformer的语言模型推理从提示处理步骤开始,该步骤生成首个输出标记并存储后续生成所需的键值缓存(KV cache)。当提示长度或批大小增加时,此过程在边缘设备上的千亿参数模型上可能耗时数十秒,严重影响用户体验。为降低首个输出的生成时间(即“首次标记时间”,TTFT),本文提出一种名为KV Prediction的新方法。该方法使用一个小型辅助模型处理提示,生成基模型所用键值缓存的近似值。该近似缓存随后与基模型结合进行自回归生成,无需再次查询辅助模型。实验表明,该方法在效率-准确率权衡上达到帕累托最优。在TriviaQA数据集上,不同TTFT FLOPs预算下相对准确率提升15%至50%;在HumanEval Python代码补全任务中,固定TTFT FLOPs预算下准确率最高提升30%。此外,在Apple M2 Pro CPU上的基准测试也验证了该方法在实际硬件上的速度提升。代码已开源:https://github.com/apple/corenet/tree/main/projects/kv-prediction。
原文摘要 · Abstract (English)
Inference with transformer-based language models begins with a prompt processing step. In this step, the model generates the first output token and stores the KV cache needed for future generation steps. This prompt processing step can be computationally expensive, taking 10s of seconds or more for billion-parameter models on edge devices when prompt lengths or batch sizes rise. This degrades user experience by introducing significant latency into the model's outputs. To reduce the time spent producing the first output (known as the ``time to first token'', or TTFT) of a pretrained model, we introduce a novel method called KV Prediction. In our method, a small auxiliary model is used to process the prompt and produce an approximation of the KV cache used by a base model. This approximated KV cache is then used with the base model for autoregressive generation without the need to query the auxiliary model again. We demonstrate that our method produces a pareto-optimal efficiency-accuracy trade-off when compared to baselines. On TriviaQA, we demonstrate relative accuracy improvements in the range of $15\%-50\%$ across a range of TTFT FLOPs budgets. We also demonstrate accuracy improvements of up to $30\%$ on HumanEval python code completion at fixed TTFT FLOPs budgets. Additionally, we benchmark models on an Apple M2 Pro CPU and demonstrate that our improvement in FLOPs translates to a TTFT speedup on hardware. We release our code at https://github.com/apple/corenet/tree/main/projects/kv-prediction .
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。