Importance Estimation with Random Gradient for Neural Network Pruning
Global Neuron Importance Estimation is used to prune neural networks for
efficiency reasons. To determine the global importance of each neuron or
convolutional kernel, most of the existing methods either use activation or
gradient information or both, which demands abundant labelled examples. In this
work, we use heuristics to derive importance estimation similar to Taylor First
Order (TaylorFO) approximation based methods. We name our methods TaylorFO-abs
and TaylorFO-sq. We propose two additional methods to improve these importance
estimation methods. Firstly, we propagate random gradients from the last layer
of a network, thus avoiding the need for labelled examples. Secondly, we
normalize the gradient magnitude of the last layer output before propagating,
which allows all examples to contribute similarly to the importance score. Our
methods with additional techniques perform better than previous methods when
tested on ResNet and VGG architectures on CIFAR-100 and STL-10 datasets.
Furthermore, our method also complements the existing methods and improves
their performances when combined with them.
Suman Sapkota, Binod Bhattarai
# Importance Estimation with Random Gradient for Neural Network Pruning

###### Abstract

Global Neuron Importance Estimation is used to prune neural networks for efficiency reasons. To determine the global importance of each neuron or convolutional kernel, most of the existing methods either use activation or gradient information or both, which demands abundant labelled examples. In this work, we use heuristics to derive importance estimation similar to Taylor First Order (TaylorFO) approximation based methods. We name our methods _TaylorFO-abs_ and _TaylorFO-sq_. We propose two additional methods to improve these importance estimation methods. Firstly, we propagate _random gradients_ from the last layer of a network, thus avoiding the need for labelled examples. Secondly, we _normalize_ the gradient magnitude of the last layer output before propagating, which allows all examples to contribute similarly to the importance score. Our methods with additional techniques perform better than previous methods when tested on ResNet and VGG architectures on CIFAR-100 and STL-10 datasets. Furthermore, our method also complements the existing methods and improves their performances when combined with them.

## 1 Introduction and Background

Neural Network Pruning LeCun et al. (1989); Han et al. (2015); Gale et al. (2019); Blalock et al. (2020) is one of the methods to reduce the parameters, compute and memory requirement. This method differs significantly from knowledge distillation Hinton et al. (2015); Gou et al. (2021) where a small model is trained to produce the output of a larger model. Neural Network Pruning is performed at multiple levels; (i) weight pruning Mozer & Smolensky (1989); Han et al. (2015, 2016) removes per parameter basis while (ii) neuron/channel Wen et al. (2016); Lebedev & Lempitsky (2016) pruning removes per neuron or channel basis and (iii) block/group Gordon et al. (2018); Leclerc et al. (2018) pruning removes per a block of network such as residual block or sub-network.

Weight pruning generally achieves a very high pruning ratio getting similar performance only with a few percentages of the parameters. This allows a high compression of the network and also accelerates the network on specialized hardware and CPUs. However, weight pruning in a defined format such as N:M block-sparse helps in improving the performance on GPUs Liu & Wang (2023). Pruning network at the level of neurons or channels helps in reducing the parameters with similar performance, however, the pruning ratio is not that high. Furthermore, pruning at the level of blocks helps to reduce the complexity of the network and creates a smaller network for faster inference. All these methods can be applied to the same model as well. Furthermore, pruning and addition of neurons can bring dynamic behaviour of decreasing and increasing network capacity which has found its application in Continual or Incremental Learning settings as well as Neural Architecture Search Gordon et al. (2018); Zhang et al. (2020); Dai et al. (2020); Sapkota & Bhattarai (2022).
In this work, we are particularly interested in neuron level pruning. Apart from the benefit of reduced parameter, memory and computation, neuron/channel level pruning is more similar to a biological formulation where the neurons are the basic unit of computation. Furthermore, the number of neurons in a neural network is small compared to the number of connections and can easily be pruned by measuring the global importance LeCun et al. (1989); Hassibi et al. (1993); Molchanov et al. (2016); Lee et al. (2018); Yu et al. (2018). We focus on the global importance as it removes the need to inject bias about the number of neurons to prune in each layer. This can simplify our problem to remove less significant neurons globally which allows us to extend it to unorganized networks other than layered formulation. However, in this work, we focus only on layer-wise or block-wise architectures such as ResNet and VGG.

Previous works show that global importance estimation can be computed using one or all of forward/activation Hu et al. (2016), parameter/weight Han et al. (2015b) or backward/gradient Wang et al. (2020); Lubana and Dick (2020); Evici et al. (2022) signals. Some of the previous techniques use Feature Importance propagation Yu et al. (2018) or Gradient propagation Lee et al. (2018) to find the neuron importance. Taylor First Order approximation based methods use both activation and gradient information for pruning Molchanov et al. (2016, 2019). There are also works that improve pruning with Taylor Second Order approximations Singh and Alistarh (2020); Yu et al. (2022); Chen et al. (2022). Although there are methods using forward and backward signals for pruning at initialization Wang et al. (2020), we limit our experiment to the pruning of trained models for a given number of neurons.

In this work, we derive a similar importance metric to Taylor First Order (Taylor-FO) approximations Molchanov et al. (2016, 2019) but from heuristics combining both forward and backward signals. The forward signal, namely the activation of the neuron, and the backward signal, the gradient or the random gradient of the output. We also compare the pruning accuracy with a different number of data samples and find that our method performs better than the previous works in most settings. Furthermore, our method of using the random gradient signal on the last layer and gradient normalization is also applicable to previous methods, showing that our approach improves performance on previous methods as well.

## 2 Motivation and Our Method

Previous works on global importance based post-training pruning of neurons focus on using forward and backward signals. Since most of these methods are based on Taylor approximation of the change in loss after the removal of a neuron or group of parameters, these methods require input and target value for computing the importance.

We tackle the problem of pruning from the perspective of overall function output without considering the loss.

**Forward Signal:** The forward signal is generally given by the pre-activation (\(x_{i}\)). If a pre-activation is zero, then it has no impact on the output of the function, i.e. the output deviation with respect to the removal of the neuron is zero. If the incoming connection of a neuron is zero-weights, then the neuron can be simply removed, i.e. it has no significance. If the incoming connection is non-zero then the neuron has significance. Forward signal takes into consideration how data affects a particular neuron.

**Backward Signal:** The backward signal is generally given by back-propagating the loss. If the outgoing connection of the neuron is zeros, then the neuron has no significance to the function even if it has positive activation. The gradient(\(\delta x_{i}\)) provides us with information on how the function or loss will change if the neuron is removed.

**Importance Metric:** Combining the forward and backward signal we can get the influence of the neuron on the loss or the function for given data. Hence, the importance metric (\(I_{i}\)) of each neuron (\(n_{i}\)) for dataset of size \(M\) is given by \(I_{i}=\frac{1}{M}\sum_{n=1}^{M}x_{i}.\delta x_{i}\), where \(x_{i}\) is the pre-activation and \(\delta x_{i}\) is its gradient. It fulfils the criterion that importance should be low if incoming or outgoing connections are zeros and higher otherwise.

**Problem 1:** This importance metric is similar to Taylor-FO Molchanov et al. (2016). However, analysing this, we find that this method produces low importance if the gradient is negative, which
to our application is a problem as the function will be changed significantly, even if it lowers the loss. Hence, we make the importance positive either by using the absolute value or the squared value. This gives rise to two of our methods namely:

**Taylor-FO-abs : \(I_{i}=\frac{1}{M}\sum_{n=1}^{M}|x_{i}.\delta x_{i}|\)****Taylor-FO-sq : \(I_{i}=\frac{1}{M}\sum_{n=1}^{M}\left(x_{i}.\delta x_{i}\right)^{2}\)****Problem 2:** The goal of neuron removal is to make the least change in the loss value, which requires the label to calculate the loss. However, according to our intuition, the goal should be to make the least change in the output of the function. Having the least change in the function implicitly fulfils the objective of previous methods to have the least change in the loss. This removes the need to have labels for pruning. Furthermore, viewing from the backward signal, the slope/gradient of the output towards the correct label should not be the requirement, as data points getting the same output as the target will not produce any gradient and hence deemed insignificant by previous methods.

Figure 1: The number of neurons pruned vs Accuracy plot for (left) ResNet-54 and (right) VGG19 for various data sizes (DS). Methods: tayloro Molchanov et al. (2016), Molchanov_BN and Molchanov_group Molchanov et al. (2019) are the baselines while tayloro_sq and tayloro_abs are _our methods_. rand represents use of random gradient and norm represents use of gradient magnitude normalization.
Alternatively, we test the hypothesis that any _random gradient_ should work fine, and the gradient should be _normalized_ to the same magnitude (of \(1\)). Doing so makes the contribution of each data point equal for computing the importance. We find that the use of random gradient also produces similar pruning performance as shown in Experiment Section Figure 1and 2 supporting our hypothesis.

Our method of using random gradient can be applied to all the previous methods using gradient signal from output to compute the importance. The implication can be useful in the setting of unsupervised pruning, where a network can be pruned to target datasets without labels. The application of this method can be significant for settings such as Reinforcement Learning, where the input data is abundant but the label is scarce.

**Similarity to Molchanov-BN pruning:** Our method is similar to Molchanov - Batch Norm pruning Molchanov et al. (2019) as both of our methods perform neuron/channel level pruning using forward and backward signals.

Molchanov-BN has Importance given by \(I_{i}=\sum(\gamma_{i}.\delta\gamma_{i}+\beta_{i}.\delta\beta_{i})^{2}\), where \(\gamma,\beta_{i}\) represents the scaler and bias terms of BN and \(\delta\gamma\) and \(\delta\beta\) represents their gradient respectively. If we consider \(\beta=0\) then \(I_{i}=\sum(\gamma_{i}.\delta\gamma_{i})^{2}\). If we consider the input of batch-norm to be \(x_{i}\) and output after scaling to be \(y_{i}=x_{i}.\gamma_{i}\) then the gradient \(\delta\gamma_{i}=\delta y_{i}.x_{i}\) and the overall importance is \(I_{i}=\sum(\gamma_{i}.\delta y_{i}.x_{i})^{2}\).

In our case, we take the importance \(I_{i}=\sum(x_{i}.\delta x_{i})^{2}\). Considering the value with respect to \(\delta y_{i}\), we get our importance to be \(I_{i}=\sum x_{i}.\gamma.\delta y_{i}\). Which differs only by the constant shift term \(\beta\). It turns out that our method produces better accuracy for ResNet style architecture. However, in VGG architecture, our pruning method performs better than Molanchonov-BN and is competitive or better than Molanchonov-WeightGroup when tested in various settings.

## 3 Experiments

**Procedure:** First, we compute the importance score for each neuron/channel on a given dataset. Secondly, we prune the \(P\) least important neurons of total \(N\) by importance metric (\(I\)) given by different methods. We measure the resulting accuracy and plot with the number of neurons pruned. We test for Taylor method Molchanov et al. (2016, 2019), and on two of our methods. The pruning is performed on the training dataset and accuracy is measured on the test dataset.

Furthermore, to test the performance of different methods on different dataset sizes, we test for \(D\) data points of total \(M\) data points on all the datasets and architectures. The total dataset size for CIFAR-100 is 50K and for STL-10 is 5K.

**CIFAR-100:** We test the pruning performance of different methods on CIFAR-100 Krizhevsky et al. (2009) dataset for dataset size \(D\in[2,10,103,50K]\) as shown in the Figure 1 2. We test the model for Resnet-20, ResNet-56 and VGG-19.

**STL-10:** ResNet-18 model used on STL-10 Coates et al. (2011) dataset is finetuned on Imagenet pretrained model. We test the pruning performance of different methods on the STL-10 dataset for dataset size \(D\in[2,71,595,5K]\) as shown in Figure 2.

## 4 Conclusion

In this paper, we improve on previously proposed Taylor First Order based pruning methods Molchanov et al. (2019) by using random gradients and by normalizing the gradients. We show that our techniques improve on the previous methods as well as our own variation. The knowledge that these methods allow for pruning with random gradient backpropagation is the main contribution of our work.
Figure 2: The number of neurons pruned vs Accuracy plot for (left) ResNet-20 on CIFAR-100 and (right) ReNet-18 on STL-10 dataset for various data sizes (DS). Methods: tayloro Molchanov et al. (2016), Molchanov_BN and Molchanov_group Molchanov et al. (2019) are the baselines while tayloro_sq and tayloro_abs are _our methods_. rand represents use of random gradient and norm represents use of gradient magnitude normalization.