APE:通过自适应并行编码实现更快、更长的上下文增强生成
APE: Faster and Longer Context-Augmented Generation via Adaptive Parallel Encoding
AI总结:
针对上下文增强生成(CAG)中重新编码上下文导致的计算负担问题,提出自适应并行编码(APE)方法,通过预计算缓存上下文KV状态并对齐注意力分布,在保留性能的同时实现4.5倍加速并支持更长上下文。
摘要:
上下文增强生成(CAG)技术(包括RAG和ICL)需要高效结合多个上下文来生成用户查询的响应。将这些上下文直接作为序列输入,会因每个请求都重新编码组合后的上下文选择而带来巨大计算负担。为此,我们探索了并行编码的潜力,通过独立预计算并缓存每个上下文的KV状态。该方法在推理时可直接加载缓存状态,同时通过跨上下文位置复用容纳更多上下文。但由于注意力分布错位,直接应用并行编码会导致性能显著下降。为实现高效且有效的CAG,我们提出自适应并行编码($\textbf{APE}$),引入共享前缀、注意力温度和缩放因子,使并行编码的分布与序列编码对齐。在RAG和ICL任务上的结果表明,APE在相同输入下能保留98%和93%的序列编码性能,同时分别优于并行编码3.6%和7.9%。它还能扩展到多轮CAG,有效并行编码数百个上下文。效率评估显示,对于128K长度的上下文,APE通过减少28倍的预填充时间,实现端到端4.5倍的加速。
英文摘要:
Context-augmented generation (CAG) techniques, including RAG and ICL, require the efficient combination of multiple contexts to generate responses to user queries. Directly inputting these contexts as a sequence introduces a considerable computational burden by re-encoding the combined selection of contexts for every request. To address this, we explore the promising potential of parallel encoding to independently pre-compute and cache each context's KV states. This approach enables the direct loading of cached states during inference while accommodating more contexts through position reuse across contexts. However, due to misalignments in attention distribution, directly applying parallel encoding results in a significant performance drop. To enable effective and efficient CAG, we propose Adaptive Parallel Encoding ($\textbf{APE}$), which brings shared prefix, attention temperature, and scaling factor to align the distribution of parallel encoding with sequential encoding. Results on RAG and ICL tasks demonstrate that APE can preserve 98% and 93% sequential encoding performance using the same inputs while outperforming parallel encoding by 3.6% and 7.9%, respectively. It also scales to many-shot CAG, effectively encoding hundreds of contexts in parallel. Efficiency evaluation shows that APE can achieve an end-to-end 4.5$\times$ speedup by reducing 28$\times$ prefilling time for a 128K-length context.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。