arXiv:2410.00907cs.CL2024-10被引 16

用加法替代乘法,让语言模型省电95%以上

Addition is All You Need for Energy-efficient Language Models

  • 用整数加法近似浮点乘法,降低计算复杂度
  • 4位尾数精度媲美float8_e4m3,3位更优
  • 适合追求能效的推理与训练场景

大型神经网络的计算主要消耗在浮点张量乘法上。本文发现,浮点乘法可用一个高精度的整数加法器近似。我们提出线性复杂度的L-Mul算法,通过整数加法近似浮点数乘法,相比8位浮点乘法显著降低资源开销且精度更高。理论分析表明,该方法在元素级浮点张量乘法中可节省95%能耗,在点积运算中节省80%。数值实验验证了理论误差估计:4位尾数的L-Mul精度相当于float8_e4m3,3位尾数优于float8_e5m2。在自然语言理解、结构推理、数学与常识问答等任务上表现良好,直接应用于注意力机制几乎无损。将Transformer中所有浮点乘法替换为3位尾数的L-Mul,其微调与推理精度等同于使用float8_e4m3作为累加精度。

原文摘要 · Abstract (English)

Large neural networks spend most computation on floating point tensor multiplications. In this work, we find that a floating point multiplier can be approximated by one integer adder with high precision. We propose the linear-complexity multiplication L-Mul algorithm that approximates floating point number multiplication with integer addition operations. The new algorithm costs significantly less computation resource than 8-bit floating point multiplication but achieves higher precision. Compared to 8-bit floating point multiplications, the proposed method achieves higher precision but consumes significantly less bit-level computation. Since multiplying floating point numbers requires substantially higher energy compared to integer addition operations, applying the L-Mul operation in tensor processing hardware can potentially reduce 95% energy cost by element-wise floating point tensor multiplications and 80% energy cost of dot products. We calculated the theoretical error expectation of L-Mul, and evaluated the algorithm on a wide range of textual, visual, and symbolic tasks, including natural language understanding, structural reasoning, mathematics, and commonsense question answering. Our numerical analysis experiments agree with the theoretical error estimation, which indicates that L-Mul with 4-bit mantissa achieves comparable precision as float8_e4m3 multiplications, and L-Mul with 3-bit mantissa outperforms float8_e5m2. Evaluation results on popular benchmarks show that directly applying L-Mul to the attention mechanism is almost lossless. We further show that replacing all floating point multiplications with 3-bit mantissa L-Mul in a transformer model achieves equivalent precision as using float8_e4m3 as accumulation precision in both fine-tuning and inference.

能效优化浮点计算Transformer

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。