666DZY666 / micronet

micronet, a model compression and deploy lib. compression: 1、quantization: quantization-aware-training(QAT), High-Bit(>2b)(DoReFa/Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference)、Low-Bit(≤2b)/Ternary and Binary(TWN/BNN/XNOR-Net); post-training-quantization(PTQ), 8-bit(tensorrt); 2、 pruning: normal、regular and group convolutional channel pruning; 3、 group convolution structure; 4、batch-normalization fuse for quantization. deploy: tensorrt, fp32/fp16/int8(ptq-calibration)、op-adapt(upsample)、dynamic_shape
MIT License
2.2k stars 478 forks source link

向大佬请教量化模型保存的问题 #22

Open Rishiber opened 4 years ago

Rishiber commented 4 years ago

想问一下大佬,就是模型压缩数据对比那张表中的Size(MB)是怎么出来的,得到的模型pth文件大小确实不变,我看您之前的回复说可以通过脚本提取量化模型参数以txt文件形式保存吗?但是那个模型Size是怎么衡量的呢,谢谢!

666DZY666 commented 4 years ago

这里的压缩率目前是手动算的,BN参数这里做了融合,所以不需要计算,只算卷积参数就行。量化模型的大小是(模型参数量 * 每个参数bits / 8)Bytes,再用这个和之前的未量化模型比较得出压缩率

fxwfzsxyq commented 4 years ago

用了bn_folding.py里面的量化,保存量化后的模型参数,为啥模型还是和原来一样大,是我理解错了么 @666DZY666@Rishiber

ghost commented 4 years ago

用了bn_folding.py里面的量化,保存量化后的模型参数,为啥模型还是和原来一样大,是我理解错了么 @666DZY666@Rishiber

hi 我也用了bn_folding.py里面的量化,模型还是和以前一样大,你这个问题解决了吗?或许咱俩可以交流一下。18729264891@163.com

fxwfzsxyq commented 4 years ago

看了一下,我觉得应该是虽然把一些参数量化成二值了,但是保存的的时候矩阵的大小是没变的,所以体积也不变

------------------ 原始邮件 ------------------ 发件人: "the-god-of-liang"<notifications@github.com>; 发送时间: 2020年5月14日(星期四) 下午4:19 收件人: "666DZY666/model-compression"<model-compression@noreply.github.com>; 抄送: "snake"<2441124901@qq.com>; "Comment"<comment@noreply.github.com>; 主题: Re: [666DZY666/model-compression] 向大佬请教量化模型保存的问题 (#22)

用了bn_folding.py里面的量化,保存量化后的模型参数,为啥模型还是和原来一样大,是我理解错了么 @666DZY666@Rishiber

hi 我也用了bn_folding.py里面的量化,模型还是和以前一样大,你这个问题解决了吗?或许咱俩可以交流一下。18729264891@163.com

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

ghost commented 4 years ago

您做的还是那个二值量化是吗?我是在做IAO 8bits量化,然后按照二值量化那边的实例改过来的,发现保存量化以后的模型还是浮点数

王良

邮箱:18729264891@163.com |

签名由 网易邮箱大师 定制

在2020年05月14日 16:47,fxwfzsxyq 写道:

看了一下,我觉得应该是虽然把一些参数量化成二值了,但是保存的的时候矩阵的大小是没变的,所以体积也不变

------------------ 原始邮件 ------------------ 发件人: "the-god-of-liang"<notifications@github.com>; 发送时间: 2020年5月14日(星期四) 下午4:19 收件人: "666DZY666/model-compression"<model-compression@noreply.github.com>; 抄送: "snake"<2441124901@qq.com>; "Comment"<comment@noreply.github.com>; 主题: Re: [666DZY666/model-compression] 向大佬请教量化模型保存的问题 (#22)

用了bn_folding.py里面的量化,保存量化后的模型参数,为啥模型还是和原来一样大,是我理解错了么 @666DZY666@Rishiber

hi 我也用了bn_folding.py里面的量化,模型还是和以前一样大,你这个问题解决了吗?或许咱俩可以交流一下。18729264891@163.com

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

fxwfzsxyq commented 4 years ago

没有在搞了,之前做了一下剪枝和量化,目前做项目没时间搞,我也是刚接触这个

------------------ 原始邮件 ------------------ 发件人: "the-god-of-liang"<notifications@github.com>; 发送时间: 2020年5月14日(星期四) 下午4:54 收件人: "666DZY666/model-compression"<model-compression@noreply.github.com>; 抄送: "snake"<2441124901@qq.com>; "Comment"<comment@noreply.github.com>; 主题: Re: [666DZY666/model-compression] 向大佬请教量化模型保存的问题 (#22)

您做的还是那个二值量化是吗?我是在做IAO 8bits量化,然后按照二值量化那边的实例改过来的,发现保存量化以后的模型还是浮点数

王良

邮箱:18729264891@163.com |

签名由 网易邮箱大师 定制

在2020年05月14日 16:47,fxwfzsxyq 写道:

看了一下,我觉得应该是虽然把一些参数量化成二值了,但是保存的的时候矩阵的大小是没变的,所以体积也不变

------------------&nbsp;原始邮件&nbsp;------------------ 发件人: "the-god-of-liang"<notifications@github.com&gt;; 发送时间: 2020年5月14日(星期四) 下午4:19 收件人: "666DZY666/model-compression"<model-compression@noreply.github.com&gt;; 抄送: "snake"<2441124901@qq.com&gt;; "Comment"<comment@noreply.github.com&gt;; 主题: Re: [666DZY666/model-compression] 向大佬请教量化模型保存的问题 (#22)

用了bn_folding.py里面的量化,保存量化后的模型参数,为啥模型还是和原来一样大,是我理解错了么 @666DZY666@Rishiber

hi 我也用了bn_folding.py里面的量化,模型还是和以前一样大,你这个问题解决了吗?或许咱俩可以交流一下。18729264891@163.com

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

ghost commented 4 years ago

好吧,我现在就差这一个评价指标就做完了

王良

邮箱:18729264891@163.com |

签名由 网易邮箱大师 定制

在2020年05月14日 17:00,fxwfzsxyq 写道:

没有在搞了,之前做了一下剪枝和量化,目前做项目没时间搞,我也是刚接触这个

------------------ 原始邮件 ------------------ 发件人: "the-god-of-liang"<notifications@github.com>; 发送时间: 2020年5月14日(星期四) 下午4:54 收件人: "666DZY666/model-compression"<model-compression@noreply.github.com>; 抄送: "snake"<2441124901@qq.com>; "Comment"<comment@noreply.github.com>; 主题: Re: [666DZY666/model-compression] 向大佬请教量化模型保存的问题 (#22)

您做的还是那个二值量化是吗?我是在做IAO 8bits量化,然后按照二值量化那边的实例改过来的,发现保存量化以后的模型还是浮点数

王良

邮箱:18729264891@163.com |

签名由 网易邮箱大师 定制

在2020年05月14日 16:47,fxwfzsxyq 写道:

看了一下,我觉得应该是虽然把一些参数量化成二值了,但是保存的的时候矩阵的大小是没变的,所以体积也不变

------------------&nbsp;原始邮件&nbsp;------------------ 发件人: "the-god-of-liang"<notifications@github.com&gt;; 发送时间: 2020年5月14日(星期四) 下午4:19 收件人: "666DZY666/model-compression"<model-compression@noreply.github.com&gt;; 抄送: "snake"<2441124901@qq.com&gt;; "Comment"<comment@noreply.github.com&gt;; 主题: Re: [666DZY666/model-compression] 向大佬请教量化模型保存的问题 (#22)

用了bn_folding.py里面的量化,保存量化后的模型参数,为啥模型还是和原来一样大,是我理解错了么 @666DZY666@Rishiber

hi 我也用了bn_folding.py里面的量化,模型还是和以前一样大,你这个问题解决了吗?或许咱俩可以交流一下。18729264891@163.com

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

mjanddy commented 4 years ago

好吧,我现在就差这一个评价指标就做完了 | | 王良 | | 邮箱:18729264891@163.com | 签名由 网易邮箱大师 定制 在2020年05月14日 17:00,fxwfzsxyq 写道: 没有在搞了,之前做了一下剪枝和量化,目前做项目没时间搞,我也是刚接触这个 ------------------ 原始邮件 ------------------ 发件人: "the-god-of-liang"<notifications@github.com>; 发送时间: 2020年5月14日(星期四) 下午4:54 收件人: "666DZY666/model-compression"<model-compression@noreply.github.com>; 抄送: "snake"<2441124901@qq.com>; "Comment"<comment@noreply.github.com>; 主题: Re: [666DZY666/model-compression] 向大佬请教量化模型保存的问题 (#22) 您做的还是那个二值量化是吗?我是在做IAO 8bits量化,然后按照二值量化那边的实例改过来的,发现保存量化以后的模型还是浮点数 | | 王良 | | 邮箱:18729264891@163.com | 签名由 网易邮箱大师 定制 在2020年05月14日 16:47,fxwfzsxyq 写道: 看了一下,我觉得应该是虽然把一些参数量化成二值了,但是保存的的时候矩阵的大小是没变的,所以体积也不变 ------------------&nbsp;原始邮件&nbsp;------------------ 发件人: "the-god-of-liang"<notifications@github.com&gt;; 发送时间: 2020年5月14日(星期四) 下午4:19 收件人: "666DZY666/model-compression"<model-compression@noreply.github.com&gt;; 抄送: "snake"<2441124901@qq.com&gt;; "Comment"<comment@noreply.github.com&gt;; 主题: Re: [666DZY666/model-compression] 向大佬请教量化模型保存的问题 (#22) 用了bn_folding.py里面的量化,保存量化后的模型参数,为啥模型还是和原来一样大,是我理解错了么 @666DZY666@Rishiber hi 我也用了bn_folding.py里面的量化,模型还是和以前一样大,你这个问题解决了吗?或许咱俩可以交流一下。18729264891@163.com — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

你好,我想问一下,关于这个量化后的模型再次加载时候会多出来一些key值,这些是怎么处理的呢?

czczmr commented 1 year ago

量化后文件保存格式还是float32,甚至由于添加了某些量化信息,模型还会变大。需要用对应的平台推理后模型的大小才会变成int8的模型大小。比如paddle使用paddlelite把模型导出成nb文件,nb文件的大小就体现出差异性了。