[pytorch] model pruning model pruning

torch.nn.utils.prune is a toolkit for pytorch to prune the model. It module.named_buffers()limits , and then uses the prune.remove function to prune. Generally speaking, pruning parameters with smaller values parameters, the performance of the model will not change much.

However, it should be noted that what this article introduces is non-structural pruning, that is, the parameters that are cut to 0 will be iteratively updated after the model is retrained. For structural pruning, the method in this article is not applicable. It is recommended to use github Some of the above libraries are implemented.

global pruning

Without using torch.nn.utils.prune, customize a pruning function:


# sparsity: 剪枝比例
def pruning(model, sparsity=0.3,</

Guess you like

Origin blog.csdn.net/weixin_42468475/article/details/130047834