Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some questions about quantization #85

Open
Desmond-97 opened this issue Feb 19, 2022 · 9 comments
Open

Some questions about quantization #85

Desmond-97 opened this issue Feb 19, 2022 · 9 comments

Comments

@Desmond-97
Copy link

您好,我在量化RepVGG到INT8时遇到一些问题:
完全按照您在README中提到的量化流程,先插入BN后QAT量化,掉点非常严重。以大模型(b3g4)为例,在ImageNet分类任务上量化后仅有20左右的accuracy。
但假如将https://github.com/DingXiaoH/RepVGG/blob/ce669bad170bf5d7c2a9eb060e90f39e7e109130/quantization/repvgg_quantized.py#L50代码修改为:` torch.quantization.fuse_modules(m, ['conv'], inplace=True)`
可以直接运行QAT量化,则掉点只有2.7%,调参后掉点大约1.7%。(参数为epochs=20 batch_size:与训练时bs保持一致 lr=1e-3 weight_decay=55e-6)
但对于分类任务而言量化后掉点也有点多,不知道这样做是否正确?请问您有其他量化方法的见解吗?

@twmht
Copy link

twmht commented Apr 18, 2022

@Desmond-97

有任何進展嗎

@Desmond-97
Copy link
Author

@twmht
我后来尝试直接用PTQ量化效果会好很多,TensorRT实现PTQ量化,用交叉熵做校准loss,RepVGG_A0模型在ImageNet分类任务上掉点仅0.16%。
我后来思考QAT量化掉点多的原因可能是:在QAT阶段用的模型是融合后的单分支推理模型,用这个模型进行QAT的finetune会使得模型退化,类似VGG的精度。但我并没有尝试用训练阶段模型进行QAT量化。

@blueardour
Copy link

@Desmond-97

你这边尝试的结论是否是:
对于QAT量化,以RepVGG方式训练的全精度模型初始化,fintune融合后的单分支模型,效果非常差。但是对于这个融合后的单分支模型,直接用PTQ算法,量化精度几乎没损失?

也就是说RepVGG训练出来的模型不适合QAT的量化,只要用PTQ就行了~~

@twmht
Copy link

twmht commented Apr 28, 2022

可以試試把 repvgg 的模型弄得更小一點,看做 PTQ 精度會不會掉?

@Desmond-97
Copy link
Author

@blueardour

是的 但我的实验不够完备,可以在实践的时候再尝试一下~

@hobbitlzy
Copy link

hobbitlzy commented Apr 30, 2022

@Desmond-97 请问你在做PTQ的时候有再用insert_bn吗?我发现直接convert后的单路repvgg的网络参数范围比较大,导致量化误差也大。

@twmht
Copy link

twmht commented Apr 30, 2022

@hobbitlzy

你 PTQ 用 TensorRT 的還是哪個 framework?

@hobbitlzy
Copy link

hobbitlzy commented Apr 30, 2022

我是用的有一篇工作BRECQ里边的PTQ。用的fake quantization。

@Desmond-97
Copy link
Author

@hobbitlzy 没有用insert_bn。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants