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

模型剪枝后的速度问题 #70339

Open
dsdsknfsk opened this issue Dec 19, 2024 · 4 comments
Open

模型剪枝后的速度问题 #70339

dsdsknfsk opened this issue Dec 19, 2024 · 4 comments
Assignees
Labels

Comments

@dsdsknfsk
Copy link

dsdsknfsk commented Dec 19, 2024

请提出你的问题 Please ask your question

我们把torch的mmedetction框架上的一个目标检测模型(gfl)和它的剪枝模型(压缩约45%,结构性剪枝)都转成了paddle模型。(使用的是ppdetction框架,只用作推理)
具体的转换方法:
将torch上的模型权重和形状复制到paddle上
问题:
转换后模型的准确率MAP和torch大致相同,因此初步判断代码逻辑应该没有问题。但是在COCO数据集上测的FPS指标上,用PyTorch框架下跑原模型fps(每秒处理图像帧数)是23,压缩后(压缩约50%)模型fps是29,和预期相符。但是转Paddle后,在相同的环境和配置下,原模型和压缩后模型fps都是22,总体是下降。而且随着batchsize增加会进一步下降,下面的表格展示了具体的指标,请问这是为什么?。同时压缩后的模型和原模型之间的差异性也没有了。请问剪枝后模型需要额外的GPU设置才能加速吗。
补充:
关于paddle压缩后的模型和原模型之间的差异性这一点,我们在CPU上做了实验(即使用CPU推理,不使用GPU),剪枝后的模型FPS约为0.26,而未剪枝模型的FPS约为0.12,此时二者有明显的差异。
问题概括:
1.例如在一个卷积层上,剪枝前的形状是[256, 64, 1, 1],剪枝后是[134, 38, 1, 1],为什么模型的运算效率并没有提升呢?
2.随着batchsize增加FPS(衡量速度的指标)会下降,FLOPS(运算量)增大
一些具体的指标如下
1734591369992

@dsdsknfsk
Copy link
Author

dsdsknfsk commented Dec 19, 2024

剪枝前的部分参数shape如下:
backbone.conv1.conv1.conv.weight:[64, 3, 7, 7]
backbone.conv1.conv1.norm.weight:[64]
backbone.conv1.conv1.norm.bias:[64]
backbone.conv1.conv1.norm._mean:[64]
backbone.conv1.conv1.norm._variance:[64]
backbone.res2.res2a.branch2a.conv.weight:[64, 64, 1, 1]
backbone.res2.res2a.branch2a.norm.weight:[64]
backbone.res2.res2a.branch2a.norm.bias:[64]
backbone.res2.res2a.branch2a.norm._mean:[64]
backbone.res2.res2a.branch2a.norm._variance:[64]
与之对应的剪枝后的部分参数shape如下:
backbone.conv1.conv1.conv.weight:[56, 3, 7, 7]
backbone.conv1.conv1.norm.weight:[56]
backbone.conv1.conv1.norm.bias:[56]
backbone.conv1.conv1.norm._mean:[56]
backbone.conv1.conv1.norm._variance:[56]
backbone.res2.res2a.branch2a.conv.weight:[40, 56, 1, 1]
backbone.res2.res2a.branch2a.norm.weight:[40]
backbone.res2.res2a.branch2a.norm.bias:[40]
backbone.res2.res2a.branch2a.norm._mean:[40]
backbone.res2.res2a.branch2a.norm._variance:[40]

@FeixLiu
Copy link
Contributor

FeixLiu commented Dec 19, 2024

@zoooo0820 辛苦帮忙看下推理剪枝的问题

@dsdsknfsk
Copy link
Author

@zoooo0820 能否解答一下

@sealoongleft
Copy link

兄弟我也用了coco数据集,你哪个机构的,可以加个联系方式吗,以后有机会合作

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

No branches or pull requests

3 participants