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

flops and parameters question about slim pruner #1846

Closed
chaos1992 opened this issue Dec 11, 2019 · 9 comments
Closed

flops and parameters question about slim pruner #1846

chaos1992 opened this issue Dec 11, 2019 · 9 comments

Comments

@chaos1992
Copy link

nni Environment:

  • nni version: 1.2
  • nni mode(local|pai|remote): local
  • OS: ubuntu18.04
  • python version: 3.7
  • is conda or virtualenv used?: conda
  • is running in docker?: no

Q1:
After running slim_pruner_torch_vgg19.py (I set epoch to 5 for testting quickly and other config is default), I compare the size of vgg19_cifar10.pth with pruned_vgg19_cifar10.pth. I find their size are both 78321KB and their test time are also nearly. I don't think it's normal and I think pruned_vgg19_cifar10.pth should be smaller and faster than vgg19_cifar10.pth.
How can I use slim_pruner correctly?

Q2:
So I try to use torchstate.stat(model, (3, 32, 32)) in other to get flops and parameters , but it has an error: AttributeError: Can't get attribute 'vgg' on <module 'main' from ...>

As the statement in docs/en_US/Compressor/SlimPruner.md, after slim pruner, the model's parameters is reduced from 20.04M to 2.03M.

Model Error(paper/ours) Parameters Pruned
VGGNet 6.34/6.40 20.04M
Pruned-VGGNet 6.20/6.26 2.03M 88.5%

How can I get the model's parameters and flops?

Looking forward to your reply, thanks!

@tanglang96
Copy link
Contributor

Q1:
Currently, our pruning implementation is masking the parameters with zeros but not directly removing them, the compressed model can be obtained by manually constructing the compact model(such as Conv2d(3,32,3)->Conv2d(3,16,3)) and inheriting the unmasked weights.

Q2:
Same to Q1, we only mask parameters but not remove them, the parameters count in our docs is computed from a new constructed compact model which inherits the pruned model parameters.

@chaos1992
Copy link
Author

@tanglang96 thanks for your reply! Could you please release the code that can obtain the new constructed compact model?

@QuanluZhang
Copy link
Contributor

@chaos0625 we are working on it, and will release the code soon.

@chaos1992
Copy link
Author

@tanglang96 @QuanluZhang thanks for your work, I expect that you will release the whole code because it's not completely for now.
Thanks nni team again!

@leckie-chn
Copy link
Contributor

add @Cjkkkk to track this.

@marsggbo
Copy link
Contributor

marsggbo commented Jan 3, 2020

@tanglang96 @QuanluZhang thanks for your work, I expect that you will release the whole code because it's not completely for now.
Thanks nni team again!

Hello, do you solve the problem? If so, could you please share your code? Thanks!

@chaos1992
Copy link
Author

@marsggbo not yet

@QuanluZhang
Copy link
Contributor

@marsggbo @chaos0625 we will provide an Alpha version for this feature in v1.4

@QuanluZhang
Copy link
Contributor

@chaos1992 @marsggbo model speedup has been supported in v1.4, please refer to this doc and this example. Note that it is still in an Alpha version

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

No branches or pull requests

8 participants