arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2406.02657cs.CLcs.AIcs.LG
收藏

Block Transformer:面向快速推理的全局到局部语言建模

Block Transformer: Global-to-Local Language Modeling for Fast Inference

KAIST AI(韩国科学技术院人工智能学院);LG AI Research(LG人工智能研究院);Google DeepMind(谷歌DeepMind)

Namgyu Ho, Sangmin Bae, Taehyeon Kim, Hyunjik Jo, Yireun Kim, Tal Schuster, Adam Fisch, James Thorne, Se-Young Yun

AI总结:

针对自注意力推理的KV缓存瓶颈问题,提出分层全局到局部的Block Transformer架构,低层粗粒度全局注意力降开销、高层细粒度局部注意力保精度,实现同等性能下10-20倍的推理吞吐量提升。

摘要:

我们提出了Block Transformer(块变换器),将分层全局到局部建模引入自回归变换器,以缓解自注意力带来的推理瓶颈。自注意力需要在每个解码步骤从内存中检索所有先前序列的键值(KV)缓存以获取上下文信息,这在批量推理期间导致两个主要瓶颈:首先,首个token的生成存在显著延迟,因为必须先处理整个提示的信息以预填充KV缓存;其次,后续token的计算受限于获取整个KV缓存的高内存I/O需求,该需求随序列长度线性增长,整体产生二次方级的内存读取量。\n我们设计Block Transformer以策略性地降低这些成本,将粗粒度性与局部性整合到全局到局部的一体化架构中:在低层,我们将token聚合为固定大小的块,以粗粒度细节在整个序列上应用注意力,在捕获全局上下文的同时最小化KV缓存开销;在高层,我们在每个块内应用注意力以解码单个token,通过轻量级的局部KV缓存建模细粒度细节。\n我们从头预训练了普通变换器和Block Transformer,实验证明,在困惑度和零样本任务性能相当的情况下,Block Transformer的推理吞吐量达到普通变换器的10–20倍。代码可在https://github.com/itsnamgyu/block-transformer获取。

英文摘要:

We introduce the Block Transformer which adopts hierarchical global-to-local modeling to autoregressive transformers to mitigate the inference bottlenecks associated with self-attention. Self-attention requires the key-value (KV) cache of all previous sequences to be retrieved from memory at every decoding step to retrieve context information, leading to two primary bottlenecks during batch inference. First, there is a significant delay in obtaining the first token, as the information of the entire prompt must first be processed to prefill the KV cache. Second, computation of subsequent tokens is bottlenecked by the high memory I/O demand of fetching the entire KV cache, which grows linearly with sequence length, incurring quadratic memory reads overall. We design the Block Transformer to strategically mitigate these costs, by incorporating coarsity and locality into an integrated global-to-local architecture. At the lower layers, we aggregate tokens into fixed size blocks to apply attention across the entire sequence at coarse-grained detail, to capture the global context while minimizing KV cache overhead. At upper layers, we apply attention within each block to decode individual tokens, to model fine-grained details with a lightweight local KV cache. We pretrain vanilla and Block Transformers from scratch and demonstrate that Block Transformers reach 10--20x inference throughput compared to vanilla transformers with equivalent perplexity and zero-shot task performance. Code is available at https://github.com/itsnamgyu/block-transformer.

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

↑