面向Arm CPU上LLM推理的高度优化内核与细粒度码本
Highly Optimized Kernels and Fine-Grained Codebooks for LLM Inference on Arm CPUs
AI总结:
本文提出面向Arm CPU的高度优化内核和分组非均匀码本量化方法,通过分摊权重解包成本、优化数据布局与解压缩路径,显著提升LLM推理效率,在4位量化下实现提示处理3-3.2倍、自回归解码2倍的加速。
摘要:
大型语言模型(LLMs)已经改变了我们对语言理解和生成的思考方式,吸引了研究者和开发者的广泛关注。然而,由于LLMs前所未有的规模和资源需求,部署LLM进行推理一直是一个重大挑战。虽然将模型权重量化到亚字节精度已成为缓解内存压力的有前景的解决方案,但LLM量化中常用的分组量化格式具有显著的计算开销和资源密集型的反量化过程。因此,较高比例的计算指令并不执行乘法,即不执行实际工作,这使得它们不适合满足部署在通用CPU上的LLM所需的延迟要求。在这项工作中,我们提出了一组高度优化的内核,以加速LLM推理并释放CPU的全部潜力,特别是Arm CPU。这些内核将加载操作数的成本和权重解包的成本分摊到多个输出行上。同时,我们引入了优化的交错分组数据布局用于权重,以及解压缩路径优化以减少不必要的操作和反量化开销,同时最大化向量和矩阵乘法运算的使用,显著提高了MAC运算的效率。此外,我们提出了一种基于分组非均匀码本的量化方法,用于LLM的超低精度量化,以更好地匹配其权重分布中的非均匀模式,在令牌生成过程中展示了比最先进方法更好的吞吐量,同时确保更好的质量。将这些改进应用于4位LLM,与基于LLaMA.cpp的解决方案相比,在Arm CPU上提示处理速度提升了3-3.2倍,自回归解码速度提升了2倍。优化后的内核可在https://github.com/ggerganov/llama.cpp获取。
英文摘要:
Large language models (LLMs) have transformed the way we think about language understanding and generation, enthralling both researchers and developers. However, deploying LLMs for inference has been a significant challenge due to their unprecedented size and resource requirements. While quantizing model weights to sub-byte precision has emerged as a promising solution to ease memory pressure, the group quantization formats commonly used for LLM quantization have significant compute overheads and a resource-intensive dequantization process. As a result, a higher proportion of compute instructions do not perform multiplies, i.e., real work, rendering them unsuitable for meeting the required latency requirements for LLMs deployed on commodity CPUs. In this work, we propose a set of highly optimized kernels to accelerate LLM inference and unleash the full potential of CPUs, particularly Arm CPUs. These kernels amortize the cost of loading the operands and the cost of weight unpacking across multiple output rows. This, along with the introduction of an optimized interleaved group data layout for weights and decompression path optimizations to reduce unnecessary operations and dequantization overhead while maximizing the use of vector and matrix multiply operations, significantly improves the efficiency of MAC operations. Furthermore, we present a groupwise non-uniform codebook-based quantization method for ultra-low-precision quantization of LLMs to better match non-uniform patterns in their weight distributions, demonstrating better throughput during token generation while ensuring better quality than the state-of-the-art. Applying these improvements to 4-bit LLMs results in a 3-3.2x improvement in prompt processing and a 2x improvement in autoregressive decoding on Arm CPUs, compared to LLaMA.cpp-based solution. The optimized kernels are available at https://github.com/ggerganov/llama.cpp.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。