VainF / Torch-Pruning

[CVPR 2023] Towards Any Structural Pruning; LLMs / SAM / Diffusion / Transformers / YOLOv8 / CNNs
https://arxiv.org/abs/2301.12900
MIT License
2.59k stars 318 forks source link

Error while calculating importance score #114

Open shadowpa0327 opened 1 year ago

shadowpa0327 commented 1 year ago

Description

Hi! Currently, I try to apply MagnitudePruner onto my model with tp.importance.MagnitudeImportance as importance metrics. There result in some error while calculating score as shown below:

 File "/usr/local/lib/python3.8/dist-packages/torch_pruning/pruner/algorithms/metapruner.py", line 160, in step
    self.prune_global()
  File "/usr/local/lib/python3.8/dist-packages/torch_pruning/pruner/algorithms/metapruner.py", line 244, in prune_global
    imp = self.estimate_importance(group, ch_groups=ch_groups)
  File "/usr/local/lib/python3.8/dist-packages/torch_pruning/pruner/algorithms/metapruner.py", line 166, in estimate_importance
    return self.importance(group, ch_groups=ch_groups)
  File "/usr/local/lib/python3.8/dist-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/torch_pruning/importance.py", line 65, in __call__
    if (w.shape[0] != group_imp[0].shape[0]):  
IndexError: list index out of range

I have traced part of the code, it seems that group_imp is empty, can you provide me some tips to debug? Thank you!

Reference

Model I try to prune: https://github.com/datvuthanh/HybridNets

VainF commented 1 year ago

Hi @shadowpa0327, the importance module may not be always robust for all models. we will investigate the issue further to improve its reliability. Thank you for the issue.

If it is an emergency to prune this model, you can quickly implement your own importance estimator following the tutorial provided in this link: https://github.com/VainF/Torch-Pruning/blob/master/tutorials/1%20-%20Customize%20Your%20Own%20Pruners.ipynb.

shadowpa0327 commented 1 year ago

Thanks for the timely response! I will give it a try and try to figure the factor behind this error. If you needed I can also provide a script to reproduce this issue.