当前位置:网站首页>BN折叠及其量化
BN折叠及其量化
2022-07-06 08:51:00 【cyz0202】
本文介绍量化过程中的BN折叠;
以下图片引用自 Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference
BN折叠
首先介绍BN折叠;BN折叠源自 BN模块在训练阶段和推断阶段的实现差异;
如下图所示:以conv+BN为例,图1为训练阶段的BN,图2为推断阶段的BN


可以证明这样的折叠是合理的,注意图2中的w指的是卷积核;
量化中的BN折叠
对量化来说,尤其是量化感知(伪量化),我们需要保持训练阶段的伪量化和上述图2的推断阶段的量化实现是一致的,因此对训练阶段的CONV+BN二阶段步骤进行折叠,如下图3:

图3的设计思想源自图2,基本思想是训练阶段求的EMA(即图中moment及其前后步骤)拿掉后要和图2一致;
根据图3所示BN折叠,就可以对训练阶段该折叠做后训练量化或者伪量化,如下图4

代码实现
以下代码块来自github distiller,没有完整的上下文实现,感兴趣的读者可以移步阅读

总结
- 以上简要介绍了BN折叠及其量化,思想比较巧妙,感兴趣的读者可以根据文中提到的文献进一步深入阅读,谢谢
- 理解有误的地方欢迎指正
边栏推荐
- Warning in install. packages : package ‘RGtk2’ is not available for this version of R
- Simple use of promise in uniapp
- [embedded] cortex m4f DSP Library
- Problems encountered in connecting the database of the project and their solutions
- Alibaba cloud server mining virus solution (practiced)
- Tdengine biweekly selection of community issues | phase III
- Computer graduation design PHP Zhiduo online learning platform
- Niuke winter vacation training 6 maze 2
- LeetCode:剑指 Offer 03. 数组中重复的数字
- [MySQL] multi table query
猜你喜欢
[OC]-<UI入门>--常用控件-UIButton
I-BERT
Visual implementation and inspection of visdom
Generator parameters incoming parameters
MongoDB 的安装和基本操作
After reading the programmer's story, I can't help covering my chest...
[today in history] February 13: the father of transistors was born The 20th anniversary of net; Agile software development manifesto was born
Deep analysis of C language pointer
Using C language to complete a simple calculator (function pointer array and callback function)
[sword finger offer] serialized binary tree
随机推荐
Roguelike game into crack the hardest hit areas, how to break the bureau?
优秀的软件测试人员,都具备这些能力
Leetcode: Sword finger offer 42 Maximum sum of continuous subarrays
Nacos 的安装与服务的注册
704 binary search
Esp8266-rtos IOT development
C語言雙指針——經典題型
Intel Distiller工具包-量化实现2
CSP first week of question brushing
LeetCode:673. Number of longest increasing subsequences
Purpose of computer F1-F12
Pytorch view tensor memory size
注意力机制的一种卷积替代方式
Light of domestic games destroyed by cracking
LeetCode:162. 寻找峰值
有效提高软件产品质量,就找第三方软件测评机构
Fairguard game reinforcement: under the upsurge of game going to sea, game security is facing new challenges
pytorch查看张量占用内存大小
LeetCode:498. 对角线遍历
多元聚类分析