NoMAD-Attention:通过无乘加注意力在 CPU 上实现高效 LLM 推理
NoMAD-Attention: Efficient LLM Inference on CPUs Through Multiply-add-free Attention
AI总结:
针对 CPU 上 LLM 注意力中 MAD 运算开销大的问题,本文提出 NoMAD-Attention,用 SIMD 寄存器内查找替代 MAD,无需微调即可保持质量并将 4-bit LLaMA-7B 在 16k 上下文下最高加速 2 倍。
摘要:
由于注意力计算中存在大量代价高昂的乘加(Multiply-Add,MAD)矩阵运算,在中央处理器(CPU)上进行大语言模型推理颇具挑战。本文认为,现代 CPU 中存在一颗罕见的宝石:单指令多数据(Single-Instruction-Multiple-Data,SIMD)寄存器,它支持批量超低延迟查找。我们利用 CPU 的这一独特能力提出 NoMAD-Attention,这是一种用寄存器内查找替代 MAD 运算的高效注意力算法。通过硬件感知的算法设计,尽管 SIMD 寄存器尺寸高度受限,NoMAD-Attention 仍借助对 SIMD 寄存器的重复快速访问完成注意力分数计算。此外,NoMAD-Attention 可直接用于基于注意力的预训练 LLM,无需模型微调。实证评估表明,NoMAD-Attention 很好地保持了原始 LLM 的质量,并在 16k 上下文长度下,将 4-bit 量化的基于 LLaMA-7B 的模型最高加速 2 倍。我们的结果可在 https://github.com/tonyzhang617/nomad-dist 复现。
英文摘要:
Large language model inference on Central Processing Units (CPU) is challenging due to the vast quantities of expensive Multiply-Add (MAD) matrix operations in the attention computations. In this paper, we argue that there is a rare gem in modern CPUs, Single-Instruction-Multiple-Data (SIMD) registers, which allow for ultra-low-latency lookups in batch. We leverage this unique capability of CPUs to propose NoMAD-Attention, an efficient attention algorithm that replaces MAD operations with in-register lookups. Through hardware-aware algorithmic designs, NoMAD-Attention achieves the computation of attention scores using repeated fast accesses to SIMD registers despite their highly limited sizes. Moreover, NoMAD-Attention works with pre-trained attention-based LLMs without model finetuning. Empirical evaluations demonstrate that NoMAD-Attention maintains the quality of the original LLMs well, and speeds up the 4-bit quantized LLaMA-7B-based model by up to 2$\times$ at 16k context length. Our results are reproducible at https://github.com/tonyzhang617/nomad-dist.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。