晨光
暗夜
晨光
极光
Bilingual Paper Reading · 中英对照精读

TransAxx:面向高效 Transformer 的近似计算

准大一 · 集成电路设计与集成系统 × 近似计算 × AI+芯片 —— Transformer 硬件加速精读材料
原文:arXiv:2402.07545 2024年2月12日发布 arXiv 预印本(cs.LG / cs.AR) 近似计算 × Vision Transformer × 蒙特卡洛树搜索 附英文摘要朗读音频

一、论文档案

英文标题TransAxx: Efficient Transformers with Approximate Computing
中文标题TransAxx:面向高效 Transformer 的近似计算
作者季米特里奥斯·达诺普洛斯, 乔治奥斯·泽尔瓦基斯, 季米特里奥斯·苏德里斯, 约尔格·亨克尔(机构未在素材中标注)
发布时间2024年2月12日(v1)|分类:cs.LG(机器学习)、cs.AR(硬件架构)
一句话概括Vision Transformer(ViT)很准但算力需求巨大,低功耗设备跑不动。本文提出 TransAxx:一个基于 PyTorch 的近似乘法器仿真框架,配合蒙特卡洛树搜索(MCTS)自动为每一层挑选最优近似配置并做近似感知微调,在 ImageNet 上实现了精度与功耗的大幅权衡收益。
💡 为什么选这篇给你:① 数字芯片 / DNN 加速器设计是集成电路专业的核心方向,近似计算是低功耗芯片设计的「前沿省电思路」——用一点点精度换大把功耗;② ViT 是当下最火的视觉模型架构,把「Transformer 能不能容忍近似乘法器」这个问题问得很干净;③ 工具开源、方法通用,读完可以直接上手复现,是典型的软硬件协同设计(SW/HW co-design)案例。

二、核心术语表(先扫一遍再读正文)

英文术语中文大白话解释
Vision Transformer (ViT)视觉 Transformer把图像切成小块当「词」喂给 Transformer 的视觉模型,靠自注意力理解全局关系。
approximate computing近似计算故意用不精确的算术部件(如近似乘法器)换速度与功耗,精度损失可控可接受。
approximate multiplier近似乘法器结果不完全精确、但更快更省电的乘法器,是 DNN 加速器省功耗的常用手段。
DNN acceleratorDNN 加速器专门为跑神经网络设计的硬件(ASIC/FPGA 等),把乘加运算做成流水线。
self-attention自注意力Transformer 的核心机制:每个位置与所有位置算相似度再加权求和,计算量随序列长度平方增长。
approximate-aware finetuning近似感知微调在近似硬件「已经引入误差」的前提下重新训练模型,把损失的精度补回来。
per-layer approximation逐层近似给神经网络每一层单独选不同的近似配置(混合精度式近似),比全网络统一近似更优。
Monte Carlo Tree Search (MCTS)蒙特卡洛树搜索通过随机模拟逐步扩展搜索树的决策算法,常用于 AlphaGo 等强化学习场景。
emulation framework仿真(模拟)框架在软件里模拟硬件行为的工具,不用真做芯片就能评估近似乘法器的影响。
power-accuracy trade-off精度-功耗权衡近似计算的核心矛盾:近似程度越狠越省电,但模型精度掉得越多。
quantization量化把浮点权重/激活压成低比特整数来省算力,近似计算的姊妹技术。
hardware-driven policy硬件驱动策略MCTS 搜索时用来引导方向的规则——按乘法器的功耗、面积、时延等硬件指标裁剪搜索空间。
low-power device低功耗设备手机、IoT 传感器、边缘盒子等电池或散热受限、跑不动大模型的设备。
ImageNetImageNet 数据集图像分类的「高考题」,120 万张图、1000 类,是视觉模型的标准测试场。

三、摘要中英对照(精读核心)

🎧 音频在文末,可先听一遍原文再读;每个英文句都配了逐句翻译。

摘要 Abstract

EN · 原文
Vision Transformer (ViT) models which were recently introduced by the transformer architecture have shown to be very competitive and often become a popular alternative to Convolutional Neural Networks (CNNs).
CN · 翻译
由 Transformer 架构引入的视觉 Transformer(ViT)模型表现非常能打,常常成为卷积神经网络(CNN)的流行替代方案
EN · 原文
However, the high computational requirements of these models limit their practical applicability especially on low-power devices.
CN · 翻译
然而,这类模型极高的计算需求限制了它们的实际应用,尤其是在低功耗设备上。
EN · 原文
Current state-of-the-art employs approximate multipliers to address the highly increased compute demands of DNN accelerators but no prior research has explored their use on ViT models.
CN · 翻译
当前最先进的工作用近似乘法器应对 DNN 加速器急剧增长的算力需求,但此前没有研究探索过它们在 ViT 模型上的应用
EN · 原文
In this work we propose TransAxx, a framework based on the popular PyTorch library that enables fast inherent support for approximate arithmetic to seamlessly evaluate the impact of approximate computing on DNNs such as ViT models.
CN · 翻译
本文提出 TransAxx——一个基于流行 PyTorch 库的框架,它原生、快速地支持近似算术,从而无缝评估近似计算对 ViT 这类 DNN 的影响
EN · 原文
Using TransAxx we analyze the sensitivity of transformer models on the ImageNet dataset to approximate multiplications and perform approximate-aware finetuning to regain accuracy.
CN · 翻译
借助 TransAxx,我们分析了 Transformer 模型在 ImageNet 数据集上对近似乘法的敏感性,并通过近似感知微调把精度补回来。
EN · 原文
Furthermore, we propose a methodology to generate approximate accelerators for ViT models. Our approach uses a Monte Carlo Tree Search (MCTS) algorithm to efficiently search the space of possible configurations using a hardware-driven hand-crafted policy.
CN · 翻译
此外,我们提出一套为 ViT 模型生成近似加速器的方法论:用蒙特卡洛树搜索(MCTS)配合硬件驱动的定制策略,高效搜索可能的配置空间。
EN · 原文
Our evaluation demonstrates the efficacy of our methodology in achieving significant trade-offs between accuracy and power, resulting in substantial gains without compromising on performance.
CN · 翻译
评估证明了该方法在精度与功耗之间实现显著权衡的有效性——在不牺牲性能的前提下获得可观的收益

关键词 Keywords:Approximate Computing 近似计算 | Vision Transformer 视觉 Transformer | Monte Carlo Tree Search 蒙特卡洛树搜索 | Hardware Acceleration 硬件加速

四、引言精选(为什么这个问题重要)

① 背景:ViT 很准,但算力贵到低功耗设备跑不动

EN · 原文
Deep Learning (DL) has achieved remarkable success in a vast range of applications such as image processing, where it has emerged as one of the most powerful and accurate techniques.
CN · 翻译
深度学习(DL)在图像处理等大量应用中取得了巨大成功,已成为最强大、最准确的技术之一
EN · 原文
However, ViT models are very computationally expensive due to their large number of parameters and the self-attention mechanism used in their architecture. Their high computational demands have limited their applicability on resource-constrained devices.
CN · 翻译
然而,ViT 模型因为参数量大自注意力机制而计算非常昂贵,其高计算需求限制了它们在资源受限设备上的适用性。

② 近似计算是已知答案,但没人试过 Transformer

EN · 原文
The utilization of approximate computing has demonstrated potential in enhancing the efficiency of deep learning models by reducing their computational complexity and memory demands [1].
CN · 翻译
近似计算已被证明有潜力通过降低计算复杂度与内存需求来提升深度学习模型的效率 [1]。
EN · 原文
It involves trading off a small amount of accuracy in DNNs for significant gains in speed and power efficiency by using inexact arithmetic components in place of their accurate counterparts [2, 3, 4].
CN · 翻译
它的做法是:用不精确的算术部件替换精确部件,拿 DNN 的一点点精度换取速度与功耗效率的大幅提升 [2, 3, 4]。
EN · 原文
Although, approximate computing has emerged as a promising approach to improve the efficiency of DNNs, no prior research has investigated its exploitation and applicability on transformers.
CN · 翻译
尽管近似计算已成为提升 DNN 效率的有前途的方法,但此前没有任何研究考察过它在 Transformer 上的应用与可行性。

③ 难点:ViT 对近似误差更敏感,且无法解析预测

EN · 原文
predicting the exact impact of an approximate multiplier on the accuracy of a ViT model is highly challenging and cannot be analytically determined. Information distortion of the self-attention map of ViTs, which involves a large number of operations, may lead to large errors being introduced by lower precision [9].
CN · 翻译
预测一个近似乘法器对 ViT 模型精度的确切影响极具挑战、无法解析求出。ViT 的自注意力图信息失真涉及大量运算,低精度可能引入很大的误差 [9]。
EN · 原文
DNNs can often become sensitive to approximation [10] and hence, approximation-aware retraining is required to recover the error introduced by approximation [10, 6, 12].
CN · 翻译
DNN 往往对近似很敏感 [10],因此需要近似感知的重训练来挽回近似引入的误差 [10, 6, 12]。

④ TransAxx 的定位:给硬件设计师的「试算器」

EN · 原文
In this paper, we present TransAxx, a fast emulation framework of approximate multipliers in ViT models. TransAxx is developed on top of PyTorch and can run on Nvidia GPUs.
CN · 翻译
本文提出 TransAxx——一个在 ViT 模型中快速仿真近似乘法器的框架,构建在 PyTorch 之上,可在 Nvidia GPU 上运行。
EN · 原文
In brief, if a hardware designer has produced a deterministic approximate multiplier, they can use TransAxx to assess the accuracy of ViT models when run on accelerators using this approximate multiplier.
CN · 翻译
简单说:硬件设计师做出一个近似乘法器后,用 TransAxx 就能评估使用该乘法器的加速器上 ViT 模型的精度表现。
💡 这是全文最有味道的一句“Although, approximate computing has emerged as a promising approach to improve the efficiency of DNNs, no prior research has investigated its exploitation and applicability on transformers.”——CNN 上玩熟了的近似计算,搬到 Transformer 上就是全新问题:自注意力会把小误差放大,谁都不能拍胸脯说「没事」。

五、论文贡献(3 个要点)

EN · 原文
1. A fast emulation framework for ViT. The objective of TransAxx is to streamline and accelerate seamlessly, for the first time, the process of simulating popular ViT models on approximate hardware. It acts as a seamless PyTorch plugin that can be enabled by the user without obstructing the natural flow of the DL framework.
CN · 翻译
1. 面向 ViT 的快速仿真框架。TransAxx 的目标是首次无缝、高效地在近似硬件上仿真主流 ViT 模型;它是一个可一键启用的PyTorch 插件,不打扰深度学习框架的正常流程。
EN · 原文
2. Approximation-aware (re)training support. It can efficiently handle all popular ViT models and perform approximate inference supporting mixed approximation (per-layer) as well. Additionally, a calibrated post-training quantization and approximate re-training is also supported for further accuracy improvement.
CN · 翻译
2. 近似感知(重)训练支持。它能高效处理所有主流 ViT 模型,支持混合近似(逐层)的近似推理;此外还支持校准的后训练量化近似重训练,进一步提升精度。
EN · 原文
3. Hardware-driven MCTS search. Specifically, we developed a Monte Carlo Tree Search (MCTS) based method (which is often used as component in RL tasks) along with a dynamic hardware-driven policy to reduce the search process.
CN · 翻译
3. 硬件驱动的 MCTS 搜索。我们开发了基于蒙特卡洛树搜索(MCTS)的方法(常用于强化学习任务),配合动态硬件驱动策略来缩减搜索过程。

六、结论中英对照

EN · 原文
In this paper we introduced TransAxx, an end-to-end framework built on top of PyTorch library, that is designed for seamless and fast evaluation and re-training of approximate Vision Transformers. TransAxx is accelerated by leveraging GPU hardware without significant overhead compared with the native execution.
CN · 翻译
本文介绍了 TransAxx——构建在 PyTorch 之上的端到端框架,用于对近似 Vision Transformer 进行无缝、快速的评估与重训练。TransAxx 借助 GPU 硬件加速,相比原生执行的额外开销很小
EN · 原文
Additionally, we introduce a novel methodology for searching the design space of approximate ViT models using a hardware-driven MCTS-based algorithm. Our findings demonstrate the capability to achieve substantial gains in both accuracy and power, according to the preferences of the designer, all within a short timeframe.
CN · 翻译
此外,我们提出用硬件驱动的 MCTS 算法搜索近似 ViT 模型设计空间的新方法论。结果表明:按设计者的偏好,在短时间内就能在精度与功耗两方面都获得可观的收益。
EN · 原文
Towards contributing fundamentally in the software-hardware ecosystem, TransAxx will be made available open-source.
CN · 翻译
为了给软硬件生态系统做出根本性贡献,TransAxx 将开源发布

七、编者解读:这篇论文到底讲了什么(大白话版)

  1. 问题:ViT 模型准确率高,但参数量大、自注意力算起来特别费电,手机、IoT 芯片这类低功耗设备跑不动。硬件界早就在用「近似乘法器」给 CNN 加速器省电,但没人试过它对 ViT 好不好使。
  2. 做法:先造一把「尺子」——TransAxx 在 PyTorch 里直接模拟近似乘法器的行为,把 ViT 跑在近似硬件上的精度损失量出来;再用 MCTS 自动搜索:每一层该用哪种近似乘法器(有的层敏感、有的层皮实),搜完再用近似感知微调把精度补回来。
  3. 结果:在 ImageNet 上,精度与功耗可以「按需调节」——想要多省电、愿意掉多少精度,都能在短时间内找到对应配置,获得显著收益而不牺牲整体性能。
  4. 最值钱的观点:自注意力机制会把近似误差「放大并传播」——所以 ViT 的近似配置不能一刀切,必须逐层搜索 + 重训练;这也解释了为什么「先仿真、后搜索、再微调」三步缺一不可。
  5. 工程意义:硬件设计师不用等芯片流片,先用 TransAxx 就能知道自己的近似乘法器在真实模型上值多少钱;这套「软件仿真 + 自动搜索」流程正是软硬件协同设计(SW/HW co-design)的标准打法。
🎯 对保研的启示:这篇论文是「软硬件协同设计」的绝佳范例——算法团队负责容错(微调补精度),硬件团队负责省电(近似乘法器),中间用仿真框架和搜索算法把两边接起来。复试时能讲清「我这边做什么、那边做什么、接口在哪」,比只背模型名强得多。

八、给准大一的阅读路线图 & 延伸方向

📖 怎么读这篇论文(三遍法)

  1. 第一遍(10 分钟):只读摘要和术语表,回答三个问题——问题是什么(ViT 太费算力)?方法是什么(近似乘法器 + MCTS 搜索 + 微调)?结果是什么(精度-功耗大幅权衡)?
  2. 第二遍(20 分钟):读引言 + 结论,重点体会「为什么 ViT 比 CNN 更难容忍近似」以及「仿真框架存在的意义」。
  3. 第三遍(30 分钟):读方法文字部分(TransAxx 架构、MCTS 搜索、近似感知微调),跳过公式和实验表格细节,只看文字描述;遇到不懂的术语回查术语表。

🚀 这个方向你能延伸做什么

九、英文摘要朗读(练听力用)

先盲听一遍→再看对照稿→再听一遍。目标是听出每个术语(Vision Transformer、approximate multipliers、Monte Carlo Tree Search、ImageNet)和「no prior research」这个关键否定。