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

how to calculate the macs after prune? #2313

Open
machengjie321 opened this issue May 8, 2023 · 2 comments
Open

how to calculate the macs after prune? #2313

machengjie321 opened this issue May 8, 2023 · 2 comments
Labels

Comments

@machengjie321
Copy link

🚀 Descirbe the improvement or the new tutorial

I use torch.nn.utils.prune as prune to prune the model, then I use torchprofile.profile_macs() to calculate the macs of Pruned_model, but I find the macs will be increase before prune.remove() to make the pruning permanent. it is normal because additional calculate wil be weight * mask.
but after I use prune.remove() to make the pruning permanent, the macs calculated by torchprofile.profile_macs() still same as the model befor prune.
2023-05-08_17-01-34

Existing tutorials on this topic

No response

Additional context

No response

@svekars
Copy link
Contributor

svekars commented May 8, 2023

Hi @machengjie321, which to tutorial are you having trouble with?

@machengjie321
Copy link
Author

Hi @machengjie321, which to tutorial are you having trouble with?
I have trouble in this:
https://pytorch.org/tutorials/intermediate/pruning_tutorial.html?highlight=torch%20nn%20utils%20prune
image
prune can compress models by reducing the number of parameters.
I want calculate the macs(flops) of model after prune, so I use the torchprofile.profile_macs() to calculate it, but after I use prune.remove() to make the pruning permanent, the macs calculated by torchprofile.profile_macs() still same as the model befor prune.
I found some possible answers in the other responses:
‘Pruning allows for impressive theoretical reduction of models sizes and complexity. However it usually offers little practical benefits as it is most often limited to just zeroing out weights, without actually removing the pruned filters/weights. This precludes from actual advantages provided by sparsification methods.’pytorch/pytorch#59835

I initially thought that the macs of the pruned model would be less than the unpruned model, but since it is not actually removing the pruned filters/weights, the macs obtained using torchprofile.profile_macs() is same as the model prune.

Is there any way can make the macs of pruned model is less than the unpruned model, Such as if I convert the pruned model into a sparse form, can the macs of model be reduced?

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

2 participants