当前位置:网站首页>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折叠及其量化,思想比较巧妙,感兴趣的读者可以根据文中提到的文献进一步深入阅读,谢谢
- 理解有误的地方欢迎指正
边栏推荐
- Deep analysis of C language data storage in memory
- LeetCode:162. 寻找峰值
- LeetCode:387. 字符串中的第一个唯一字符
- Image, CV2 read the conversion and size resize change of numpy array of pictures
- C语言双指针——经典题型
- marathon-envs项目环境配置(强化学习模仿参考动作)
- Sublime text using ctrl+b to run another program without closing other runs
- 注意力机制的一种卷积替代方式
- Swagger setting field required is mandatory
- LeetCode:836. 矩形重叠
猜你喜欢

多元聚类分析

C语言双指针——经典题型

Navicat premium create MySQL create stored procedure

ESP8266-RTOS物联网开发

Swagger setting field required is mandatory

Problems in loading and saving pytorch trained models

I-BERT

704 binary search

Roguelike game into crack the hardest hit areas, how to break the bureau?

Computer cleaning, deleted system files
随机推荐
LeetCode:劍指 Offer 42. 連續子數組的最大和
Leetcode: Sword finger offer 48 The longest substring without repeated characters
LeetCode:394. String decoding
R language uses the principal function of psych package to perform principal component analysis on the specified data set. PCA performs data dimensionality reduction (input as correlation matrix), cus
Alibaba cloud server mining virus solution (practiced)
I-BERT
LeetCode:221. Largest Square
LeetCode:673. 最长递增子序列的个数
注意力机制的一种卷积替代方式
Notes 01
Intel Distiller工具包-量化实现3
TP-LINK enterprise router PPTP configuration
pytorch查看张量占用内存大小
Purpose of computer F1-F12
UML diagram memory skills
Mongodb installation and basic operation
R language ggplot2 visualization: place the title of the visualization image in the upper left corner of the image (customize Title position in top left of ggplot2 graph)
可变长参数
Nacos 的安装与服务的注册
LeetCode:221. 最大正方形