arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2404.09529cs.LGcs.AIcs.CL
收藏

Prepacking:一种实现大语言模型快速预填充与吞吐量提升的简单方法

Prepacking: A Simple Method for Fast Prefilling and Increased Throughput in Large Language Models

University of California, Los Angeles(加利福尼亚大学洛杉矶分校)

Siyan Zhao, Daniel Israel, Guy Van den Broeck, Aditya Grover

AI总结:

针对大语言模型预填充阶段因批次提示词长度差异大、填充操作浪费计算的问题,提出Prepacking方法,通过装箱算法打包不同长度提示词并调整注意力掩码与位置编码,显著提升预填充的速度与内存效率。

摘要:

在基于Transformer的大语言模型(LLM)推理过程中,预填充(prefilling)是指在自回归生成前,为提示词中的输入令牌计算键值(KV)缓存的操作。当输入提示词长度较长时,预填充会给解码时间带来显著开销。本研究指出了预填充的以下缺陷:对于批次内提示词长度差异较大的情况,将序列填充至最大长度的标准做法会造成大量计算浪费。随着LLM越来越多地支持更长的上下文长度(最高可达1000万令牌),批次内提示词的长度差异会更加显著。为解决这一问题,我们提出了Prepacking,这是一种简单却有效的预填充计算优化方法。为避免填充令牌上的冗余计算,Prepacking将不同长度的提示词组合成一条序列,并使用装箱算法(bin-packing algorithm)将多条序列打包成紧凑的批次。随后该方法修改注意力掩码与位置编码,从而在单条序列中为多个提示词计算多个预填充的KV缓存。在包含不同长度提示词的标准精选数据集上,我们在多种基础模型配置与推理服务场景中,对比Huggingface中默认的基于填充的预填充计算方式,取得了显著的速度与内存效率提升。

英文摘要:

During inference for transformer-based large language models (LLM), prefilling is the computation of the key-value (KV) cache for input tokens in the prompt prior to autoregressive generation. For longer input prompt lengths, prefilling will incur a significant overhead on decoding time. In this work, we highlight the following pitfall of prefilling: for batches containing high-varying prompt lengths, significant computation is wasted by the standard practice of padding sequences to the maximum length. As LLMs increasingly support longer context lengths, potentially up to 10 million tokens, variations in prompt lengths within a batch become more pronounced. To address this, we propose Prepacking, a simple yet effective method to optimize prefilling computation. To avoid redundant computation on pad tokens, prepacking combines prompts of varying lengths into a sequence and packs multiple sequences into a compact batch using a bin-packing algorithm. It then modifies the attention mask and positional encoding to compute multiple prefilled KV-caches for multiple prompts within a single sequence. On standard curated dataset containing prompts with varying lengths, we obtain a significant speed and memory efficiency improvements as compared to the default padding-based prefilling computation within Huggingface across a range of base model configurations and inference serving scenarios.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑