Open abhinavvsharma opened 1 year ago
Hi @abhinavvsharma. #nparams=0 means that all parameters have requires_grad=False. Torch-pruning relies on autograd for tracing and thus will not prune any layer if autograd is disabled.
Hi @VainF, thank you for your quick response!! I implemented what you said, by changing requires_grad to true after loading the model. I am able to see the value in parameters variable but the results are still the same. I am sharing the code snipper I used to change requires_grad to true. Code snippet:
for p in model.model.parameters():
p.requires_grad = True
Output of pruning:
Before Pruning: MACs=2.076926 G, #Params=0.001761 G
After Pruning: MACs=2.076926 G, #Params=0.001761 G
Have you solved this problem? @abhinavvsharma
Hi @VainF, thank you for your quick response!! I implemented what you said, by changing requires_grad to true after loading the model. I am able to see the value in parameters variable but the results are still the same. I am sharing the code snipper I used to change requires_grad to true. Code snippet:
for p in model.model.parameters(): p.requires_grad = True
Output of pruning:
Before Pruning: MACs=2.076926 G, #Params=0.001761 G After Pruning: MACs=2.076926 G, #Params=0.001761 G
you can try this,fix this line maybe solve your problem: pruned_macs, pruned_nparams = tp.utils.count_ops_and_params(model.model, example_inputs) > pruned_macs, pruned_nparams = tp.utils.count_ops_and_params(pruner.model, example_inputs)
Hello, Thank you for your contribution!
I am trying to prune a YOLOv5 Nano model by modifying the script of YOLOv7 pruning on this repository. The code is executed without any errors but the MACs before are after pruning is same and model Params is zero in both cases. It seems like the model is not actually pruned. I am sharing the code and output. The only modification needed in YOLOv7 code is the way model is loaded in YOLOv5 is
attempt_load
and for YOLOv5 there is another wrapper functionDetectMultiBackend
so, I needed to usemodel.model
instead ofmodel
.Code snippet:
Output:
When I compared the architecture of pruned model according to this code and unpruned model the only difference I see is that the BatchNorm layers are not present. What modification do I need to prune the YOLOv5 model?