Open WeiCL7777 opened 1 year ago
我这里基本遇到pruner = tp.pruner.MetaPruner就会有如上报错,不知道是不是torch版本问题,希望请教作者,谢谢
I have got the same problem even with the example in the wiki:
import torch
from torchvision.models import resnet18
import torch_pruning as tp
model = resnet18(pretrained=True)
# Importance criteria
example_inputs = torch.randn(1, 3, 224, 224)
imp = tp.importance.TaylorImportance()
ignored_layers = []
for m in model.modules():
if isinstance(m, torch.nn.Linear) and m.out_features == 1000:
ignored_layers.append(m) # DO NOT prune the final classifier!
iterative_steps = 5 # progressive pruning
pruner = tp.pruner.MagnitudePruner(
model,
example_inputs,
importance=imp,
iterative_steps=iterative_steps,
ch_sparsity=0.5, # remove 50% channels, ResNet18 = {64, 128, 256, 512} => ResNet18_Half = {32, 64, 128, 256}
ignored_layers=ignored_layers,
)
TypeError Traceback (most recent call last)
2 frames
/usr/local/lib/python3.10/dist-packages/torch_pruning/pruner/algorithms/scheduler.py in
TypeError: unsupported operand type(s) for *: 'float' and 'NoneType'
My torch version is : 2.0.1+cu118
i looked through the code and the issue seems to be that the latest version does not support channel_sparsity
"ch_sparsity is deprecated in v1.3.0. Please use pruning_ratio."
using pruning_ratio instead fixes the problem
Hi all, there is a bug with ch_sparsity. We will fix it today and release a new version.
Caused by this typo:
Fixed in the latest release. Thanks for the issue!
您好,请问在运行基于Torch-Pruning实现MagnitudePruner的实验中,出现如上报错该怎么解决?谢谢。似乎是torch_pruning代码里面的错误,实在不知道如何解决 ---> [19] pruner = tp.pruner.MetaPruner( [20] model, [21] example_inputs, # 用于分析依赖的伪输入 [22] importance=imp, # 重要性评估指标 [23] iterative_steps=iterative_steps, # 迭代剪枝,设为1则一次性完成剪枝 [24] ch_sparsity=0.5, # 目标稀疏性,这里我们移除50%的通道 ResNet18 = {64, 128, 256, 512} => ResNet18_Half = {32, 64, 128, 256} [25] ignored_layers=ignored_layers, # 忽略掉最后的分类层 [26 )
File [~/anaconda3/envs/py/lib/python3.9/site-packages/torch_pruning/pruner/algorithms/scheduler.py:3], in(.0)
2 def linear_scheduler(pruning_ratio_dict, steps):
----> 3 return [((i) / float(steps)) * pruning_ratio_dict for i in range(steps+1)]
TypeError: unsupported operand type(s) for *: 'float' and 'NoneType'