arXiv:2505.21889cs.CL2025-05被引 2

改进提示格式,让大模型填空任务更快更省资源。

EFIM: Efficient Serving of LLMs for Infilling Tasks with Improved KV Cache Reuse

  • 设计新提示格式EFIM,提升键值缓存复用效率。
  • 实测延迟降低52%,吞吐量提升98%。
  • 适合需要频繁交互的文本补全场景。

大语言模型常用于填空类任务,这类任务需多次与相似上下文交互。为减少重复计算,跨请求键值(KV)缓存复用成为多轮服务的关键技术。但在填空任务中,提示通常由插入点前缀和后缀构成,导致前缀或后缀的缓存因另一部分增量生成而频繁失效。为此,本文提出EFIM,一种FIM的转换提示格式,以释放KV缓存复用潜力。尽管新格式解决了效率问题,却暴露了现有大模型在子词生成上的缺陷——难以准确生成不完整词汇。因此,我们引入片段分词训练方法,在数据处理阶段将文本拆分为多个片段后再进行分词。在两个代表性LLM上的实验表明,使用EFIM的模型服务可使延迟降低52%,吞吐量提升98%,同时保持原有填空能力。代码已开源:https://github.com/gty111/EFIM。

原文摘要 · Abstract (English)

Large language models (LLMs) are often used for infilling tasks, which involve predicting or generating missing information in a given text. These tasks typically require multiple interactions with similar context. To reduce the computation of repeated historical tokens, cross-request key-value (KV) cache reuse, a technique that stores and reuses intermediate computations, has become a crucial method in multi-round interactive services. However, in infilling tasks, the KV cache reuse is often hindered by the structure of the prompt format, which typically consists of a prefix and suffix relative to the insertion point. Specifically, the KV cache of the prefix or suffix part is frequently invalidated as the other part (suffix or prefix) is incrementally generated. To address the issue, we propose EFIM, a transformed prompt format of FIM to unleash the performance potential of KV cache reuse. Although the transformed prompt can solve the inefficiency, it exposes subtoken generation problems in current LLMs, where they have difficulty generating partial words accurately. Therefore, we introduce a fragment tokenization training method which splits text into multiple fragments before tokenization during data processing. Experiments on two representative LLMs show that LLM serving with EFIM can lower the latency by 52% and improve the throughput by 98% while maintaining the original infilling capability. EFIM's source code is publicly available at https://github.com/gty111/EFIM.

大模型推理缓存优化填空任务

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。