让我们看看我第一次得到的结果。这是我的模型的一个卷积层,我只显示了11个滤波器的权重(113x3带channel=1)。
所以我想知道"TORCH.NN.UTILS.PRUNE.L1_UNSTRUCTURED“是如何工作的,因为火把网站上说修剪了最低的L1-范数单位,但据我所知,L1-范数剪枝是一种过滤剪枝方法,它剪枝整个过滤器,使用这个方程式来细化最低的过滤器值,而不是修剪单个权重。所以我有点好奇这个函数是如何工作的?
以下是我的剪枝代码
parameters_to_prune = (
(model.input_layer[0], 'weight'),
(model.hidden_layer1[0], 'weight'),
(model.hidden_layer2[0], 'weight'),
(model.output_layer[0], 'weight')
)
prune.global_unstructured(
parameters_to_prune,
pruning_method=prune.L1Unstructured,
amount = (pruned_percentage/100),
)发布于 2021-12-14 09:52:11
nn.utils.prune.l1_unstructured实用程序并不会修剪整个过滤器,它会像您在工作表中看到的那样,对单个参数组件进行修剪。这是低范数的组件被蒙住了。
下面是一个很小的例子,在下面的注释中讨论过:
>>> m = nn.Linear(10,1,bias=False)
>>> m.weight = nn.Parameter(torch.arange(10).float())
>>> prune.l1_unstructured(m, 'weight', .3)
>>> m.weight
tensor([0., 0., 0., 3., 4., 5., 6., 7., 8., 9.], grad_fn=<MulBackward0>)https://stackoverflow.com/questions/70346398
复制相似问题