arXiv:2502.01770cs.LGcs.AI2025-02被引 2

用二值化键值对加速长序列Transformer,性能损失小、功耗降八成。

Hamming Attention Distillation: Binarizing Keys and Queries for Efficient Long-Context Transformers

  • 将注意力中的键和查询二值化为±1向量,改用汉明距离计算替代点积。
  • 在GLUE上仅损失1.78%,图像分类损失2.5%,远优于现有二值化方法。
  • 适合追求低功耗部署的长文本处理场景,尤其硬件加速环境。

预训练的长上下文Transformer模型因计算与内存开销大,难以大规模部署。本文提出汉明注意力蒸馏(HAD),通过将注意力机制中的键和查询二值化为{-1, +1}向量,并以高效的汉明距离替代点积运算,显著降低计算开销。同时引入注意力矩阵稀疏化,剪除低影响激活,进一步减少长序列处理成本。尽管采用激进压缩策略,其保留了强表示能力,在多项任务中表现优于已有二值化Transformer。在GLUE、ImageNet和QuALITY等任务上验证,性能接近标准模型。在自定义硬件模拟中,相较标准注意力实现79%面积缩减和87%功耗降低,仅损失1.78%(GLUE)和2.5%(ImageNet)性能,显著优于当前最优二值化方案(分别9.08%和12.14%损失)。

原文摘要 · Abstract (English)

Pre-trained transformer models with extended context windows are notoriously expensive to run at scale, often limiting real-world deployment due to their high computational and memory requirements. In this paper, we introduce Hamming Attention Distillation (HAD), a novel framework that binarizes keys and queries in the attention mechanism to achieve significant efficiency gains. By converting keys and queries into {-1, +1} vectors and replacing dot-product operations with efficient Hamming distance computations, our method drastically reduces computational overhead. Additionally, we incorporate attention matrix sparsification to prune low-impact activations, which further reduces the cost of processing long-context sequences. \par Despite these aggressive compression strategies, our distilled approach preserves a high degree of representational power, leading to substantially improved accuracy compared to prior transformer binarization methods. We evaluate HAD on a range of tasks and models, including the GLUE benchmark, ImageNet, and QuALITY, demonstrating state-of-the-art performance among binarized Transformers while drastically reducing the computational costs of long-context inference. \par We implement HAD in custom hardware simulations, demonstrating superior performance characteristics compared to a custom hardware implementation of standard attention. HAD achieves just $\mathbf{1.78}\%$ performance losses on GLUE compared to $9.08\%$ in state-of-the-art binarization work, and $\mathbf{2.5}\%$ performance losses on ImageNet compared to $12.14\%$, all while targeting custom hardware with a $\mathbf{79}\%$ area reduction and $\mathbf{87}\%$ power reduction compared to its standard attention counterpart.

Transformer优化二值化长序列处理低功耗

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