Can Unstructured Pruning Reduce the Depth in Deep Neural Networks?
Pruning is a widely used technique for reducing the size of deep neural
networks while maintaining their performance. However, such a technique,
despite being able to massively compress deep models, is hardly able to remove
entire layers from a model (even when structured): is this an addressable task?
In this study, we introduce EGP, an innovative Entropy Guided Pruning algorithm
aimed at reducing the size of deep neural networks while preserving their
performance. The key focus of EGP is to prioritize pruning connections in
layers with low entropy, ultimately leading to their complete removal. Through
extensive experiments conducted on popular models like ResNet-18 and Swin-T,
our findings demonstrate that EGP effectively compresses deep neural networks
while maintaining competitive performance levels. Our results not only shed
light on the underlying mechanism behind the advantages of unstructured
pruning, but also pave the way for further investigations into the intricate
relationship between entropy, pruning techniques, and deep learning
performance. The EGP algorithm and its insights hold great promise for
advancing the field of network compression and optimization. The source code
for EGP is released open-source.
Zhu Liao, Victor Quétu, Van-Tam Nguyen, Enzo Tartaglione
# Can Unstructured Pruning Reduce the Depth in Deep Neural Networks?

###### Abstract

Pruning is a widely used technique for reducing the size of deep neural networks while maintaining their performance. However, such a technique, despite being able to massively compress deep models, is hardly able to remove entire layers from a model (even when structured): is this an addressable task? In this study, we introduce EGP, an innovative Entropy Guided Pruning algorithm aimed at reducing the size of deep neural networks while preserving their performance. The key focus of EGP is to prioritize pruning connections in layers with low entropy, ultimately leading to their complete removal. Through extensive experiments conducted on popular models like ResNet-18 and Swin-T, our findings demonstrate that EGP effectively compresses deep neural networks while maintaining competitive performance levels. Our results not only shed light on the underlying mechanism behind the advantages of unstructured pruning, but also pave the way for further investigations into the intricate relationship between entropy, pruning techniques, and deep learning performance. The EGP algorithm and its insights hold great promise for advancing the field of network compression and optimization. The source code for EGP is released open-source.

+
Footnote †: This paper has been accepted for publication at the Workshop on Resource Efficient Deep Learning for Computer Vision (ICCVW).

## 1 Introduction

Deep neural networks have become a cornerstone of artificial intelligence and machine learning, achieving remarkable success in a wide range of applications, from video recognition [1] and natural language processing [25] to robotics [21] and autonomous driving [2]. However, the large size of these models poses significant challenges in terms of storage, memory, and computational requirements. To address these issues, researchers have developed various techniques to reduce the size of neural networks without sacrificing their performance, including quantization [9, 26], compression [6, 24], and pruning [10, 11, 15, 16, 23].

Pruning, in particular, has emerged as a popular and effective method for reducing the number of parameters in a neural network [3, 15, 20]. The idea behind pruning is to selectively remove weights, neurons, or entire layers based on their magnitude or other criteria [7, 17, 27]. The pruned model can then be fine-tuned to recover its original performance, resulting in a smaller and more efficient network. Pruning is particularly effective for deep neural networks, which tend to be over-parameterized and therefore have many redundant or irrelevant weights.

Despite the widespread use of pruning, its underlying mechanism and the factors that contribute to its benefits are not well understood. Previous work has investigated the effects of pruning on the sparsity and connectivity patterns of neural networks [4, 5, 8], as well as its impact on the generalization performance of the pruned models [10]. Nowadays, indeed, massive study around this subject is being conducted [14, 22]. Although some works used entropy

Figure 1: Effect of unstructured pruning in ReLU-activated models: some neurons are always OFF (yellow) and others are consistently in the linear region (red). These can be removed with no impact on the performance. Some neurons are in both regions (blue). If no neuron is in both regions, the layer can be fused with the next one (it is a linear combination), and the depth can be decreased (the entire layer is removed - red cross).
to drive pruning mechanisms [13], to the best of our knowledge, no previous work has explored the relationship between pruning and the entropy of activations in the network.

In this work, we investigate the impact of unstructured pruning on the entropy of activations in the network. In the context of neural networks, entropy can provide insights into the complexity and diversity of the representations learned by the model. Leveraging this measure, we propose EGP, a strategy to drive the unstructured pruning mechanism to prune layers exhibiting low entropy. Our experiments show that unstructured pruning reduces the entropy of activations in the network (Fig. 1). This reduction in entropy suggests that pruning results in a more structured activation pattern, which may as well improve the ability of the network to generalize to new data. Interestingly, this approach overcomes the limits of structured pruning, which removes neurons persistently OFF.

Our work provides a new perspective on the mechanism behind the benefits of unstructured pruning and sheds light on the relationship between entropy, pruning, and deep learning performance. These findings open up avenues for further exploration. We have also developed an entropy-based iterative pruning technology that shows promise in compressing neural networks more effectively.

Despite other works proposing entropy-based approaches to drive pruning [13, 18, 19], to the best of our knowledge, EGP is the very first entropy-driven approach that can effectively reduce the depth of a deep neural network model without harming its performance. Different from previous entropy-based pruning methods which tried to remove a certain amount of parameters or neurons inside layers, EGP tries to remove whole layers. EGP is tested on popular models for computer vision, like ResNet-18 and Swin-T, and opens the roads to a new class of pruning algorithms.

## 2 Entropy Guided Pruning

In this section, we will provide details on how we compute the entropy of the activations inside the neural network model and develop our entropy-based iterative pruning. Fig. 2 proposes an overview of the proposed entropy computing and pruning method. First, we introduce the entropy calculation method (Sec. 2.1), showing also how to handle critical cases (Sec. 2.2), and then we provide an overview of the entropy-based iterative pruning method (Sec. 2.3).

### Derivation

Let us extract the output \(\mathbf{y}_{l,i}^{\xi}\) of the \(i\)-th neuron in the \(l\)-th layer (where \(N_{l}\) is the number of neurons in the \(l\)-th layer), given as input the \(\xi\)-th sample. Let us assume the activation function \(\phi_{n}(\cdot)\) for the \(l\)-th layer is ReLU. Toward this end, we can write

\[\mathbf{y}_{l,i}^{\xi}=\text{ReLU}\left(\mathbf{z}_{l,i}^{\xi}\right), \tag{1}\]

where \(\mathbf{z}_{l,i}\) is the _post-synaptic potential_ for the \(i\)-th neuron in the \(l\)-th layer. Please note that in convolutional layers the dimensionality for \(\mathbf{y}_{l,i}^{\xi}\) is not necessarily unitary, but is proportional to the input's size \(M_{l}=K_{1,l}\times K_{2,l}\), where \(K_{1,l}\) and \(K_{2,l}\) are the dimensions for the generated feature map. We assume, for the sake of simplicity, that the size of every \(\xi\) is the same for the whole dataset \(\Xi\). We know that ReLU-activated neurons have essentially two working regions:

* an ON region, for \(z_{l,i,j}>0\);
* an OFF region, for \(z_{l,i,j}\leq 0\).

These working regions will be our possible "states". To identify the state \(s_{l,i,j}\) for the \(j\)-th feature extracted by the \(i\)-th neuron, we can apply the one-step function \(H(\cdot)\) to the post-synaptic potential, obtaining \(s_{l,i,j}^{\xi}=H(z_{l,i,j}^{\xi})\). At this point, we can obtain the frequency of the \(i\)-th neuron to be in the ON state, simply through

\[p^{\text{ON}}(l,i|\Xi)=\frac{1}{\|\Xi\|_{0}\cdot M_{l}}\sum_{\xi\in\Xi}\sum_{j }(s_{l,i,j}^{\xi}), \tag{2}\]

where \(\|\Xi\|_{0}\) is the cardinality of the dataset. Evidently, we know that in this case \(p^{\text{OFF}}(l,i|\Xi)=1-p^{\text{ON}}(l,i|\Xi)\). At this point, we can use the definition in (2) to write the entropy \(\mathcal{H}(l,i|\Xi)\):

\[\mathcal{H}(l,i|\Xi)= -\frac{1}{\log(2)}\left\{p^{\text{ON}}(l,i|\Xi)\log\left[p^{ \text{ON}}(l,i|\Xi)\right]+\right.\] \[\left.+p^{\text{OFF}}(l,i|\Xi)\log\left[p^{\text{OFF}}(l,i|\Xi) \right]\right\}. \tag{3}\]

### When the entropy goes to zero

The evaluation of the entropy proposed in (2.3) is not intended as a measure of information flowing through the given layer, but it gives us an important indication of the effective use of the ReLU non-linearity. More specifically, for the \(i\)-th neuron in the \(l\)-th layer, we will have \(\mathcal{H}(l,i|\Xi)=0\) in two possible cases:

Figure 2: Overview of the EGP approach.
* \(s^{\xi}_{l,i,j}=0,\forall j,\xi\). This case is achieved in three possible ways: either all the parameters \(\mathbf{w}_{l,i}\) of the \(i\)-th neuron are zero, or the input \(\mathbf{y}^{\xi}_{l-1}\) is zero \(\forall\xi\), or again \(z^{\xi}_{l,i,j}\leq 0,\forall j,\xi\). In these cases, the neuron's output will always be zero, and the entire neuron can be removed/pruned from the model, with no performance loss.
* \(s^{\xi}_{l,i,j}=1,\forall j,\xi\). This case is achieved if \(z^{\xi}_{l,i,j}>0,\forall j,\xi\). In this state, the \(i\)-th neuron in the \(l\)-th layer uses only the linear region, becoming a linear neuron: its contribution can be "absorbed" by the next layer (as the neuron and the next layer are a linear combination), evidencing a collapse in the neural network's depth.

In this work we will be looking for both: while the first is expected, and known to rise in high pruning regimes [3, 23], the second one is more surprising, but can potentially lead to similar gains as those obtained with pruning.

It is possible to extend the proposed formulation to other activations, like the sigmoid and GeLU (we will test on Swin-T in Sec. 3).

### Entropy-based iterative pruning

As our target is to reduce the depth of deep neural networks by removing zero-entropy layers, we implement iterative pruning based on the entropy of different layers to get more layers with entropy zero.

Let us set the percentage of parameters to be pruned at each pruning iteration as \(\zeta\), and the total weight parameters of the considered \(L\) layers in the model as \(\|\theta\|_{0}\). Then, in each pruning iteration, the number of weight parameters to be pruned \(\|\theta\|_{0}^{\text{pruned}}\) is given by

\[\|\theta\|_{0}^{\text{pruned}}=\zeta\cdot\|\theta\|_{0}. \tag{4}\]

After calculating the entropy of each neuron belonging to the \(l\)-th layer, we can calculate an average entropy for it, simply through

\[\hat{\mathcal{H}}(l|\Xi)=\frac{1}{N_{l}}\sum_{i}\mathcal{H}(l,i|\Xi). \tag{5}\]

We would like to route the magnitude pruning algorithm towards removing more parameters in layers where the entropy is low. This is because manifesting a low entropy is a symptom of not necessarily requiring a non-linear activation in these layers, and for such reason, these layers are the most promising to remove. However, we know that \(\mathcal{H}(l,i|\Xi)\geq 0\forall l,i,\Xi\): this means that, when having \(\hat{\mathcal{H}}(l|\Xi)=0\Leftrightarrow\mathcal{H}(l,i|\Xi)=0\forall i\). When this happens, we know that we are able to completely remove such a layer, and we no longer need to prune it.

In order to increase the number of layers with zero entropy, more pruning should be applied to layers with lower entropy (more likely to reach zero entropy). Simultaneously, to minimize the impact on model performance, more pruning should be done on smaller magnitude weights. To achieve both goals, we propose a _pruning irrelevance_ meter \(\mathcal{I}_{l}\) for the \(l\)-th layer

\[\mathcal{I}_{l}=\hat{\mathcal{H}}(l|\Xi)\cdot\frac{1}{\|\theta_{l}\|_{0}}\sum _{i}|\theta_{l,i}|, \tag{6}\]

where \(\|\theta_{l}\|_{0}\) is the cardinality of the non-zero weights in the \(l\)-th layer. Effectively, the larger this value is, the least we are interested in removing parameters from it. However, we are very interested in removing parameters from layers having very low pruning irrelevance: for such reason, we define the complementary measure of _pruning relevance_

\[\mathcal{R}_{l}=\left\{\begin{array}{cc}\frac{\sum_{j}\mathcal{I}_{j}}{ \mathcal{I}_{l}}&\mathcal{I}_{l}\neq 0\\ 0&\mathcal{I}_{l}=0.\end{array}\right. \tag{7}\]

Finally, in order to assess the exact amount of parameters to be removed at the \(l\)-th layer we resort to a softmax smoothening, according to

\[\|\theta_{l}\|_{0}^{\text{pruned}}=\|\theta\|_{0}^{\text{pruned}}\cdot\frac{ \exp[\mathcal{R}_{l}-\max_{k}(\mathcal{R}_{k})]}{\sum_{j}\exp[\mathcal{R}_{j}- \max_{k}(\mathcal{R}_{k})]}. \tag{8}\]

If the number of parameters pruned assigned to a specific layer exceeds its remaining parameter count, then prune all parameters of that layer. Afterward, distribute the remaining number of pruning parameters to other layers following the methods outlined in (6) and (8).

## 3 Experiments

In this section, we present our empirical results obtained on three different very common setups. We have performed our experiments on an NVIDIA GeForce RTX 2080 GPU and developed the code using PyTorch 1.13.1.

Figure 3: Distributions of neuron states per layer for ResNet-18 trained on CIFAR-10 with 98.4% of pruned parameters for EGP. In blue neurons having non-zero entropy, in orange always OFF, and in red always ON.
Footnote 1: We acknowledge this choice is computationally extensive and unnecessary with optimal hyper-parameter optimization: our objective here is not to be efficient at train time but to highlight neurons with zero entropy.

**Setup.** We present results for ResNet-18 and Swin-T trained on CIFAR-10 and Tiny-ImageNet (Tint-INet). While for ResNet-18 ReLU is the non-linearity for the layers, in Swin-T the non-linear activation adopted is GELU. We adopt the same baseline training strategy as in [12]. Specifically for Swin-T, we prune just the GELU-activated layers (which are, for this model, 12). For all the sparse configurations, we set \(\zeta=0.5\).1

Footnote 1: We acknowledge this choice is computationally extensive and unnecessary with optimal hyper-parameter optimization: our objective here is not to be efficient at train time but to highlight neurons with zero entropy.

**Results.** The main results are reported in Table 1. Here, we compare a vanilla iterative magnitude pruning strategy with EGP. It appears evident that plugging EGP as a scaling factor to drive the pruning process effectively removes entire layers from the model. Evidently, with a higher sparsity, a performance drop naturally occurs; however, the gap in performance between vanilla pruning and EGP (for the same sparsity) remains consistently narrow. We provide, in Fig. 3, a visualization of the activation distributions for CIFAR-10 at 98.4% sparsity for EGP. Interestingly, we observe that one layer only (#12) can be removed with traditional pruning approaches, while others (like #14), having also neurons in the ON state, would be overlooked: this shows the effectiveness of EGP and potentially opens the road to a new class of pruning algorithms.

**Ablation study.** We propose here an ablation study on the effectiveness of EGP. Table 2 compares training from scratch a model with some layers removed to the same following EGP: we observe that in all cases EGP exhibits better Top-1 performance. Especially for Swin-T trained on Tiny-ImageNet, this architecture/dataset combination does not provide good results as the smaller model should be also pre-trained on a large dataset like the vanilla one. This phenomenon suggests that EGP enhances accessibility to rare, compressed states of the deep model.

## 4 Conclusion

In this work, we have investigated the impact of unstructured pruning on the entropy of activations in DNNs. Our preliminary experiments on ReLU and GELU-activated models show that our pruning strategy, EGP, drives a consistent part of the neurons in the model to either ON or OFF regions. Unstructured pruning can provide a structured activation pattern and yes, it can reduce the model's depth! Our results provide new insights into the mechanisms behind the benefits of pruning and open avenues for further

\begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Model** & **Dataset** & **Lay. rem.** & **Method** & **Top-1** \\ \hline \multirow{4}{*}{Resnet-18} & \multirow{2}{*}{CIFAR-10} & \multirow{2}{*}{5/17} & from scratch & 91.10 \\  & & & EGP & **92.18** \\ \cline{2-4}  & & & from scratch & 37.72 \\  & & & EGP & **39.80** \\ \hline \multirow{4}{*}{Swin-T} & \multirow{2}{*}{CIFAR-10} & \multirow{2}{*}{5/12} & from scratch & 61.00 \\  & & & EGP & **90.41** \\ \cline{2-4}  & & & from scratch & 0.50 \\ \cline{1-1}  & & & EGP & **71.48** \\ \hline \hline \end{tabular}
\end{table}
Table 2: Performance of entropy-based pruned model and reinitialized model.

\begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Model** & **Dataset** & **Lay. rem.** & **Method** & **Top-1** \\ \hline \multirow{4}{*}{Resnet-18} & \multirow{2}{*}{CIFAR-10} & \multirow{2}{*}{5/17} & from scratch & 91.10 \\  & & & EGP & **92.18** \\ \cline{2-4}  & & & EGP & 37.72 \\ \cline{2-4}  & Tiny-ImageNet & 4/17 & from scratch & 37.72 \\  & & & EGP & **39.80** \\ \hline \multirow{4}{*}{Swin-T} & \multirow{2}{*}{CIFAR-10} & \multirow{2}{*}{5/12} & from scratch & 61.00 \\  & & & EGP & **90.41** \\ \cline{2-4}  & & & EGP & 0.50 \\ \cline{1-1} \cline{2-4}  & Tiny-ImageNet & 1/12 & from scratch & 0.50 \\ \cline{1-1}  & & & EGP & **71.48** \\ \hline \hline \end{tabular}
\end{table}
Table 2: Performance of entropy-based pruned model and reinitialized model.
exploration into the relationship between entropy, pruning, and deep learning performance.

Future work can explore the applicability of our findings to other activation functions and architectures as well as the design of a regularization function explicitly enforcing low entropy to favor the model's compressibility. Exploring the impact of pruning on the dynamics of the optimization process and the interpretability of the resulting models could lead to a better understanding of the mechanisms behind the benefits of pruning.

**Acknowledgements.** The research leading to these results has received funding from the project titled "PC6-FITNESS" in the frame of the program "PEPR 5G et Reseaux du futur". Zhu Liao is funded by China Scholarship Council (CSC).
