Hi all,
I am trying to prune my pytroch model based on the tutorial [here]. (https://pytorch.org/tutorials/intermediate/pruning_tutorial.html)
However, the size of the model doesn’t reduce (even with 40 % pruning).
Original Size:
Size (MB): 6.623636
Pruned model size
Size (MB): 6.623636
The link to my code can be found here -
moreover when I prune the bias as well I get the following error -
import torch.nn.utils.prune as prune
for name, module in model.named_modules():
# prune 40% of connections in all 2D-conv layers
if isinstance(module, torch.nn.Conv2d):
prune.l1_unstructured(module, name='weight', amount=0.4)
prune.l1_unstructured(module, name='bias', amount=0.3)
prune.remove(module, 'weight')
prune.remove(module, 'bias')
# prune 40% of connections in all linear layers
elif isinstance(module, torch.nn.Linear):
prune.l1_unstructured(module, name='weight', amount=0.4)
prune.l1_unstructured(module, name='bias', amount=0.4)
prune.remove(module, 'weight')
prune.remove(module, 'bias')
ERROR -
File "/Users/raghavgurbaxani/Desktop/DI PA /EAST-Pytorch/try_pruning.py", line 143, in main
prune.l1_unstructured(module, name='bias', amount=0.3)
File "/opt/anaconda3/lib/python3.7/site-packages/torch/nn/utils/prune.py", line 886, in l1_unstructured
L1Unstructured.apply(module, name, amount)
File "/opt/anaconda3/lib/python3.7/site-packages/torch/nn/utils/prune.py", line 536, in apply
return super(L1Unstructured, cls).apply(module, name, amount=amount)
File "/opt/anaconda3/lib/python3.7/site-packages/torch/nn/utils/prune.py", line 167, in apply
default_mask = torch.ones_like(orig) # temp
TypeError: ones_like(): argument 'input' (position 1) must be Tensor, not NoneType
@Michela could you help out on whats going wrong here ?