高级搜索

留言板

尊敬的读者、作者、审稿人, 关于本刊的投稿、审稿、编辑和出版的任何问题, 您可以本页添加留言。我们将尽快给您答复。谢谢您的支持!

姓名
邮箱
手机号码
标题
留言内容
验证码

面向大模型边缘部署的SwiGLU与RMSNorm算子软硬件协同优化方法研究

李赫,  周崟灏,  路卫军,  李振锋,  李莹

李赫, 周崟灏, 路卫军, 李振锋, 李莹. 面向大模型边缘部署的SwiGLU与RMSNorm算子软硬件协同优化方法研究[J]. 电子与信息学报. doi: 10.11999/JEIT260561
引用本文: 李赫, 周崟灏, 路卫军, 李振锋, 李莹. 面向大模型边缘部署的SwiGLU与RMSNorm算子软硬件协同优化方法研究[J]. 电子与信息学报. doi: 10.11999/JEIT260561
LI He, ZHOU Yinhao, LU Weijun, LI Zhenfeng, LI Ying. Software-Hardware Co-Optimization of SwiGLU and RMSNorm Operators for Edge Deployment of Large Models[J]. Journal of Electronics & Information Technology. doi: 10.11999/JEIT260561
Citation: LI He, ZHOU Yinhao, LU Weijun, LI Zhenfeng, LI Ying. Software-Hardware Co-Optimization of SwiGLU and RMSNorm Operators for Edge Deployment of Large Models[J]. Journal of Electronics & Information Technology. doi: 10.11999/JEIT260561

面向大模型边缘部署的SwiGLU与RMSNorm算子软硬件协同优化方法研究

doi: 10.11999/JEIT260561 cstr: 32379.14.JEIT260561
基金项目: 国家重点研发计划(No.E3G930C001)
详细信息
    作者简介:

    李赫:男,硕士生,研究方向为人工智能集成电路设计

    周崟灏:男,高级工程师,研究方向为集成电路设计、硬件安全

    路卫军:男,副教授,博士生导师,研究方向为超大规模集成电路设计

    李振锋:男,高级工程师,研究方向为嵌入式系统、硬件安全

    李莹:女,副研究员,研究方向为集成电路设计与验证,硬件安全

    通讯作者:

    李莹

  • 中图分类号: TN402

Software-Hardware Co-Optimization of SwiGLU and RMSNorm Operators for Edge Deployment of Large Models

  • 摘要: 当前大模型的端侧部署应用中,非线性算子已逐步成为性能瓶颈。因此针对SwiGLU与RMSNorm两类高频算子,开展算法与硬件协同的优化方法研究。为解决SwiGLU中SiLU激活计算复杂、硬件代价较高的问题,提出基于分布感知分段建模与2n多项式斜率拟合的近似方法,并设计两级区间判定数据通路以降低电路复杂度;针对RMSNorm,提出词元(token)级重叠流式架构,通过多bank缓冲、选择性压缩与倒数平方根指数补偿等方式实现统计路径与缩放路径的解耦。基于TinyLlama-1.1B的算法评估与FPGA实现结果表明,所提方法在保持模型性能可用的同时,能够显著降低非线性算子的资源开销与功耗,适用于大模型端侧部署场景。
  • 图  1  基于DASA点选取的SiLU近似构建过程。

    图  2  包含两级区间判定SiLU近似的SwiGLU硬件架构(以N=16为例)。

    注:Tk(k=1,…,15)为按升序排列的分段阈值;Gj(j=0,…,3)为第j个组内阈值集合精度为S-INT8;j和i分别表示一级组号和最终分区号,采用U2和U4格式。输入输出则都为S-INT8。S/U分别表示有符号/无符号整数。

    图  3  RMSNorm的流式硬件架构

    注:输入、输出均为128 bit数据流,每拍包含16个补码S-INT8数据,并采用valid-ready-last握手。平方统计结果为32 bit, inv_rms采用16 bit Q2.14格式;3个轮转FIFO的单Bank深度均为32×128 bit。

    1  $ \text{SwiGLU(g)=(SiLU(X*}{\text{W}}_{\text{g}})\odot\text{(X*}{\text{W}}_{\text{u}})){\text{W}}_{\text{o}} $

     输入:量化预输入激活$ \mathrm{X }=\left\{{\mathrm{x}}_{\mathrm{t}}\right\} $,分区数N,截断区间
     [$ {\mathrm{x}}_{\min },{\mathrm{x}}_{\max } $],幂指数范围[${\mathrm{e}}_{\min},{\mathrm{e}}_{\max}$],$ {\mathrm{W}}_{\text{gate}} $, $ {\mathrm{W}}_{\text{up}} $, $ {\mathrm{W}}_{\text{down}} $
     输出:分区集合$ {\{\tau }_{\mathrm{i}}\} $,分区近似参数集合$ \{{\hat{\mathrm{a}}_{\mathrm{i}}},{\hat{\mathrm{b}}_{\mathrm{i}}}\} $, Y
      阶段1:
      1: $ {\text{x}}_{\text{clip}}\leftarrow\text{Clip(}{\text{x}}_{\min },{\text{x}}_{\max }\text{,X)} $
      2: $ \hat{\text{F}}({\mathrm{x}})\leftarrow\text{EmpiricalCDF(}{\text{x}}_{\text{clip}}) $
      3: $ {{\mathrm{for}}\; {\mathrm{i}}\leftarrow 0 \;{\mathrm{to}}\; {\mathrm{N}}\; {\mathrm{do}}} $
      4:  $ {\text{I}}_{\text{i}},[{\tau}_{\text{i}},{\tau}_{\text{i+1}})\leftarrow\hat{\text{F}}\text{(x)} $
      5: end for
      阶段2:
      6: $ {\text{S}}_{\text{DASA}}\leftarrow \varnothing $
      7: $ \text{for}\;{\text{e}}_{1},{\text{e}}_{2}\leftarrow {\text{e}}_{\min }\;\text{to}\;{\text{e}}_{\max }\;\text{do} $
      8:  $ \text{for}\;{\text{s}}_{1},{\text{s}}_{2}\in{{-1,0,1} \;{\mathrm{do}}} $
      9:   $ {{{\mathrm{a}}\leftarrow{\mathrm{s}}}}_{1}{2}^{{{\text{e}}_{1}}}+{\text{s}}_{2}{2}^{{{\text{e}}_{2}}} $
      10: $ {\text{S}}_{\text{DASA}}\leftarrow {\text{S}}_{\text{DASA}}\cup\text{{a}} $
      11: end for
      12: end for
      13: $ {{\mathrm{for}}\; {\mathrm{i}}\leftarrow 0 \;{\mathrm{to}}\; {\mathrm{N}}\; {\mathrm{do}}} $
      14: $ {\text{I}}_{\text{i}},{\xi}_{\text{i}}\leftarrow[{\tau}_{\text{i}},{\tau}_{\text{i+1}}) $
      15: $ {\text{N}}_{\text{i}}\leftarrow\text{KNearest(}{\text{x}}_{\text{clip}}\cap{\text{I}}_{\text{i}},{\xi}_{\text{i}}) $
      16: $ \text{for each a }\in{\text{S}}_{\text{DASA}}\;\text{do} $
      17:  $ {{{\mathrm{b}} \leftarrow {\mathrm{f}}(}{{\xi}_{\text{i}}}{) - {\mathrm{a}}\cdot\xi}}_{\text{i}} $
      18:  $ {{\mathrm{E}}({\mathrm{a}})\leftarrow \displaystyle\sum {\mathrm{[f(x)}}-({\mathrm{a}}\cdot{\mathrm{x+b}})}{]}^{2} $
      19:  $ {{{\mathrm{if E(a}}) <{\mathrm{E}}}}_{\text{i}}\;\text{then} $
      20:   $ {\text{E}}_{\text{i}},\hat{{\text{a}}_{\text{i}}},\hat{{\text{b}}_{\text{i}}}\leftarrow\text{E(a),a,b} $
      21:  end if
      22: end for
      23: end for
      阶段3:
      24: $ \text{g}\leftarrow{\text{W}}_{\text{gate}}\text{X, u}\leftarrow{\text{W}}_{\text{up}}\text{X} $
      25: $ {{\mathrm{h}}}\leftarrow({\hat{\text{a}}_{\text{i}}}\text{g}+\hat{{\text{b}}_{\text{i}}}) \odot $u
      26: $ \text{Y}\leftarrow{\text{W}}_{\text{down}}\text{h} $
      27: Return Y
    下载: 导出CSV

    2  RMSNorm(x)

     输入:输入激活向量X,稳定项$ \mathrm{\epsilon } $,仿射权重$ \gamma $
     输出:归一化输出激活值Y
      阶段1:
      1: $ \text{for i}\leftarrow {\text{0 to C do}} $
      2:  $ {\text{A}}_{\text{i}}\leftarrow \text{UnsignedAbs(}{\text{X}}_{\text{i}}) $
      3:  $ {\text{X}}_{\text{ci}},{\text{S}}_{\text{i}}\leftarrow \text{SC(}{\text{A}}_{\text{i}}) $
      4:  $ {\text{S}}_{\text{qi}}\leftarrow ({\text{X}}_{\text{ci}}\cdot{\text{X}}_{\text{ci}})<<(2{\text{S}}_{\text{i}}) $
      5:  $ {\text{Ex}}^{2}\leftarrow {\text{Ex}}^{2}+{\text{S}}_{\text{qi}} $
      6: $ \text{end for} $
      $ \text{阶段2} $:
      7: $ {\text{Ex}}^{2}\leftarrow {\text{Ex}}^{2}{\text{Ex}}^{2}\cdot\text{1/C} $
      8: $ \text{u} \leftarrow {\text{Ex}}^{2}{+ \epsilon } $
      9: $ {\text{p}} \leftarrow {\mathrm{LOD(u); k }}\leftarrow {\mathrm{p}}-{\mathrm{F}}+1; {\mathrm{m}} \leftarrow {\mathrm{u}}\cdot 2^\wedge (-{\mathrm{k}})$
      $\triangleright{\mathrm{u}}={\mathrm{m}}\cdot{2}^{\text{k}}{,{\mathrm{m}}\in[0.5,1)} $
      10: $ \text{idx} \leftarrow {\text{Map(m)}} $
      11: $ {\text{y}}_{0}\leftarrow \text{LUT(idx)} \quad \triangleright {\text{y}}_{0}\approx \text{1/sqrt(m)} $
      12: $ {\mathrm{t}} \leftarrow \text{floor(k/2),r} \leftarrow {\mathrm{k}} - {\mathrm{2t}} $
      13: $ \text{inv}\_\text{rms} \leftarrow {\text{y}}_{0}\cdot{2}^{\text{(-t)}}\cdot\text{(1/sqrt(2)}{)}^{\text{r}} $
      $ \text{阶段3} $:
      14: $ {\text{for i}} \leftarrow \text{0 to C do Stage2} $
      15:  $ {\text{Y}}_{\text{i}}\leftarrow {\text{X}}_{\text{i}}\text{· inv}\_\text{rms} $
      16:  $ {\mathrm{if}}\; \gamma \text{is used then} $
      17:   $ {\text{Y}}_{\text{i}}\leftarrow {\gamma}_{\text{i}}\cdot{\text{Y}}_{\text{i}} $
      18:  $ \text{end if} $
      19: end for
      20: return Y
    下载: 导出CSV

    表  1  RMSNorm硬件流水调度示意

    T0 T1 T2 T3 T4 T5 T6 T7
    FIFO 0 W(A) R(A) W(D) R(D) ···
    FIFO 1 W(B) R(B) W(E) R(E) ···
    FIFO 2 W(C) R(C) W(F) R(F)
    E(x2) A B C D E F G H
    INV A B C D E F G
    Scale A B C D E F
    注:A、B、…表示连续输入的不同token;Ti表示流水调度时刻;W/R分别表示token在FIFO中的写入与回读;E(x2)、INV和Scale分别表示平方统计、倒数平方根生成和逐元素缩放三个阶段。
    下载: 导出CSV

    表  2  TinyLlama-1.1B 在不同算子部署设置下的算法级评估结果。

    RunprecisionWikitext
    (ppl)
    Hellaswag
    (acc)
    PIQA
    (acc)
    BoolQ
    (acc)
    ARC-Easy
    (acc)
    Stability
    mean
    Stability
    std
    fp32fp327.1990.5700.7190.6000.4180.5760.107
    int8int87.2360.5680.7140.6040.4090.5730.109
    int8+swigluint87.8520.5500.6750.6160.3560.5490.120
    int8+rmsnormint87.3370.5760.7200.6000.4400.5840.099
    int8+hwint89.0970.5440.6390.6100.3040.5240.131
    注:PPL(困惑度)是衡量语言模型对文本预测能力的指标,数值越低,说明模型对文本的预测越准确。ACC(准确率)是模型预测结果中正确样本占总样本的比例,数值越高代表模型的预测正确率越高。
    下载: 导出CSV

    表  3  完整SwiGLU与RMSNorm算子在基线实现和优化实现下的硬件开销与功耗对比

    算子 实现 LUT FF DSP BRAM 总功耗(W) 动态功耗(W)
    SwiGLU base 27590 1323 145 9 1.083 0.997
    opt 17063 1310 91 9 0.572 0.487
    Δ –38.2% –0.98% –37.2% - –47.2% –51.2%
    RMSNorm base 5660 4917 16 2 0.269 0.138
    opt 1976 938 17 6 0.158 0.027
    Δ –65.1% –80.9% +6.3% +4 –41.3% –80.4%
    下载: 导出CSV
  • [1] VASWANI A, SHAZEER N, PARMAR N, et al. Attention is all you need[C]. Proceedings of the 31st International Conference on Neural Information Processing Systems, Long Beach, USA, 2017: 6000–6010.
    [2] PENG Tianfan, XIA Tianhua, QIN Jiajun, et al. HAAN: A holistic approach for accelerating normalization operations in large language models[C]. 2025 Design, Automation & Test in Europe Conference (DATE), Lyon, France, 2025: 1–7. doi: 10.23919/DATE64628.2025.10993005.
    [3] ZHANG Jiawen, CHEN Kejia, HE Lipeng, et al. Activation approximations can incur safety vulnerabilities even in aligned LLMs: Comprehensive analysis and defense[C]. Proceedings of the 34th USENIX Conference on Security Symposium, Seattle, USA, 2025: 18.
    [4] WANG Wenxun, ZHOU Shuchang, SUN Wenyu, et al. SOLE: Hardware-software co-design of Softmax and LayerNorm for efficient transformer inference[C]. 2023 IEEE/ACM International Conference on Computer Aided Design (ICCAD), San Francisco, USA, 2023: 1–9. doi: 10.1109/ICCAD57390.2023.10323725.
    [5] KIM R, LEE D, KIM J, et al. Hardware accelerator for approximation-based Softmax and layer normalization in transformers[J]. Electronics, 2025, 14(12): 2337. doi: 10.3390/electronics14122337.
    [6] 刘海莹, 乔瑞秀, 陈刚, 等. 一种高效的Softmax函数计算方法及硬件电路[J]. 微电子学与计算机, 2024, 41(2): 91–100. doi: 10.19304/J.ISSN1000-7180.2023.0141.

    LIU Haiying, QIAO Ruixiu, CHEN Gang, et al. An efficient calculation method and implementation of Softmax function[J]. Microelectronics & Computer, 2024, 41(2): 91–100. doi: 10.19304/J.ISSN1000-7180.2023.0141.
    [7] GERBER I. Attention is not all you need: The importance of feedforward networks in transformer models[EB/OL]. https://arxiv.org/abs/2505.06633, 2025.
    [8] KOCA N A, DO A T, and CHANG C H. Accuracy-preserving layer normalization approximations for efficient transformer hardware accelerators[C]. IEEE International Symposium on Circuits and Systems (ISCAS), London, United Kingdom, 2025: 1–5. doi: 10.1109/ISCAS56072.2025.11044257.
    [9] FINI E, SHUKOR M, LI Xiujun, et al. Multimodal autoregressive pre-training of large vision encoders[C]. Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, Nashville, USA, 2025: 9641–9654. doi: 10.1109/CVPR52734.2025.00901.
    [10] TANASE A V and PELICAN E. Supernova: Achieving more with less in transformer architectures[EB/OL]. https://arxiv.org/abs/2507.15773, 2025.
    [11] GRAEF N, CLAPP M, and WASIELEWSKI A. Flash normalization: Fast RMSNorm for LLMs[EB/OL]. https://arxiv.org/abs/2407.09577v1, 2024.
    [12] PARK J, SHIN G, and YOO H. Implementation of Activation Functions using various approximation methods[C]. 2024 21st International SoC Design Conference (ISOCC), Sapporo, Japan, 2024: 175–176. doi: 10.1109/ISOCC62682.2024.10762658.
    [13] BASTERRETXEA K, TARELA J M, and DEL CAMPO I. Approximation of sigmoid function and the derivative for hardware implementation of artificial neurons[J]. IEE Proceedings - Circuits, Devices and Systems, 2004, 151(1): 18–24. doi: 10.1049/ip-cds:20030607.
    [14] XIE Yusheng, RAJ A N J, HU Zhendong, et al. A twofold lookup table architecture for efficient approximation of activation functions[J]. IEEE Transactions on Very Large Scale Integration (VLSI) Systems, 2020, 28(12): 2540–2550. doi: 10.1109/TVLSI.2020.3015391.
    [15] HUANG Jianxin, WU Yuling, ZHUANG Mingyong, et al. High-precision and efficiency hardware implementation for GELU via its internal symmetry[J]. Electronics, 2025, 14(9): 1825. doi: 10.3390/electronics14091825.
    [16] SERHIIENKO P, SERGIYENKO A, TELENYK S, et al. Calculation of the sigmoid activation function in FPGA using rational fractions[C]. 24th International Conference on Computational Science (ICCS 2024), Malaga, Spain, 2024: 146–157. doi: 10.1007/978-3-031-63778-0_11.
    [17] XIANG Maoyang and WANG Bo. DAPA: Distribution aware piecewise activation functions for on-device transformer inference and training[C]. Proceedings of the 63rd ACM/IEEE Design Automation Conference, Long Beach, USA, 2026: 236. doi: 10.1145/3770743.3804274.
    [18] KARP A H and MARKSTEIN P. High-precision division and square root[J]. ACM Transactions on Mathematical Software, 1997, 23(4): 561–589. doi: 10.1145/279232.279237.
    [19] SAHA S and XU Lanyu. Vision transformers on the edge: A comprehensive survey of model compression and acceleration strategies[J]. Neurocomputing, 2025, 643: 130417. doi: 10.1016/j.neucom.2025.130417.
    [20] KANG Yiwen and WANG Dong. Hardware-oriented approximations of Softmax and RMSNorm for efficient Transformer inference[J]. Micromachines, 2026, 17(1): 84. doi: 10.3390/mi17010084.
    [21] 李天阳, 张帆, 王松, 等. 基于FPGA的卷积神经网络和视觉Transformer通用加速器[J]. 电子与信息学报, 2024, 46(6): 2663–2672. doi: 10.11999/JEIT230713.

    LI Tianyang, ZHANG Fan, WANG Song, et al. FPGA-based unified accelerator for convolutional neural network and vision transformer[J]. Journal of Electronics & Information Technology, 2024, 46(6): 2663–2672. doi: 10.11999/JEIT230713.
    [22] 贺煜凯, 谢童欣, 朱振华, 等. 面向商用存算一体架构矩阵乘算子协同优化策略研究[J]. 电子与信息学报, 2025, 47(9): 3187–3197. doi: 10.11999/JEIT250364.

    HE Yukai, XIE Tongxin, ZHU Zhenhua, et al. Collaborative optimization strategies for matrix multiplication-accumulation operators on commercial processing-in-memory architectures[J]. Journal of Electronics & Information Technology, 2025, 47(9): 3187–3197. doi: 10.11999/JEIT250364.
  • 加载中
图(3) / 表(5)
计量
  • 文章访问数:  13
  • HTML全文浏览量:  2
  • PDF下载量:  0
  • 被引次数: 0
出版历程
  • 修回日期:  2026-11-02
  • 录用日期:  2026-11-02
  • 网络出版日期:  2026-11-11

目录

    /

    返回文章
    返回