动态调整批次,让大模型推理效率提升1.75倍
BATON: Enhancing Batch-wise Inference Efficiency for Large Language Models via Dynamic Re-batching
- 通过动态重批处理,避免新增查询带来的空闲计算
- 不增加资源消耗,实现近零空闲计算
- 适合高并发大模型服务场景,如ChatGPT类应用
大语言模型(LLM)的推理需要对不同查询进行多轮前向计算,传统批量推理难以高效处理。现有方法虽将批处理细化到迭代级,但需复制所有非线性层,导致资源占用增加且新查询预填充引发空闲计算。为此,本文提出BATON,一种动态调整处理批次的高效批量推理方案。其核心为:1)通过向量对齐与新注意力掩码生成,使新查询插入无需额外资源;2)利用预填充与解码分离机制,将新查询的键值缓存嵌入现有批次,消除预填充带来的空闲计算。实验表明,相比最先进方案Orca,BATON在查询处理上最多提升1.75倍。
原文摘要 · Abstract (English)
The advanced capabilities of Large Language Models (LLMs) have inspired the development of various interactive web services or applications, such as ChatGPT, which offer query inference services for users. Unlike traditional DNN model, the inference of LLM entails different iterations of forward computation for different queries, which result in efficiency challenges for existing run-to-completion batch-wise inference. Hence, some methods refine batch-wise inference to iteration-level by duplicating all nonlinear layers of LLM. However, this approach not only increases resource usage but also introduces idle computations to the batch due to the prefilling of newly added queries. Therefore, we propose BATON, an efficient batch-wise LLM inference scheme by dynamically adjusting processing batch, which can achieve near-zero idle computations without incurring additional resource consumption. To do so, BATON 1) shapes the vectors involved in the inference of the newly inserted query and processing batch to align dimensions and generates a new attention mask based on vector shaping to ensure inference correctness, which enables query inserting without consuming additional resource; 2) embeds prefilled Keys and Values of the new query into the KV_Cache of the processing batch by leveraging the prefilling and decoding separation mechanism, eliminating idle computations to the batch introduced by the prefilling process of the new query. Experimental results show that compared to the state-of-the-art solution Orca, BATON improves query processing by up to 1.75 times.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。