arXiv Vanity renders academic papers from arXiv as responsive web pages so you don’t have to squint at a PDF. Read this paper on arXiv.org.

# Joint Multi-Dimension Pruning

Zechun Liu
HKUST

&Xiangyu Zhang
MEGVII Technology

&Zhiqiang Shen
CMU

&Zhe Li              Yichen Wei
MEGVII Technology

&Kwang-Ting Cheng
HKUST

&Jian Sun
MEGVII Technology

This work is done when Zechun Liu interns at MEGVII Technology. Corresponding author.
###### Abstract

We present joint multi-dimension pruning (named as JointPruning), a new perspective of pruning a network on three crucial aspects: spatial, depth and channel simultaneously. The joint strategy enables to search a better status than previous studies that focused on individual dimension solely, as our method is optimized collaboratively across the three dimensions in a single end-to-end training. Moreover, each dimension that we consider can promote to get better performance through colluding with the other two. Our method is realized by the adapted stochastic gradient estimation. Extensive experiments on large-scale ImageNet dataset across a variety of network architectures MobileNet V1&V2 and ResNet demonstrate the effectiveness of our proposed method. For instance, we achieve significant margins of 2.5% and 2.6% improvement over the state-of-the-art approach on the already compact MobileNet V1&V2 under an extremely large compression ratio.

## 1 Introduction

Network pruning has been acknowledged as one of the most effective model compression methods for adapting heavy models to the resource-limited devices he2017channelpruning; slimmable; networkslimming. The pruning methods evolved from unstructured weight pruning guo2016dynamic; han2015learning to structured channel pruning ding2019centripetal; zhuang2018discrimination with the purpose of more hardware-friendly implementation.

With the increasing demand of highly compressed models, merely pruning the channel dimension becomes insufficient to strike a good computation-accuracy trade-off. Some previous studies begin to seek compression schemes besides the channel dimension. For example, OctaveConv chen2019drop proposed to manually reduce the spatial redundancy in feature maps. MobileNet howard2017mobilenets scales down the input image’s spatial size for reducing the computational overhead. Besides the spatial dimension, depth is also a dimension worth exploring crowley2018closer. These three dimensions (i.e., channel, spatial, depth) are inter-related: A reduction in the network depth can enable using larger feature maps or more channels under the same computational constraint; An alteration in the spatial size will affect the optimal channel pruning scheme. To this end, manually set the spatial size and network depth while only adjust the layer-wise channel pruning strategy leads to sub-optimal solutions. It is of high significance to automatically allocate computational resource among three dimensions with a unified consideration.

However, jointly pruning channels together with the spatial and depth dimension is challenging and some difficulties are always underestimated. The first challenge is that most of the pruning algorithms are developed based on the unique property of the channel dimension, for instance, removing channels with small weight L1 norms networkslimming; yang2018netadapt. Such approaches are inflexible and can hardly generalize to other dimensions, especially the spatial dimension. The second challenge stems from the overladen search space within the three integrated dimensions, since the potential choices of these dimensions are numerically consecutive integers. Therefore, the previous enumerate-based methods are always computationally prohibitive or under-optimized.

To resolve the aforementioned limitations and derive a decent solution, we propose the JointPruning that considers three dimensions (channel, spatial, depth) simultaneously. In contrast to previous pruning methods that mainly focus on exploring the correlation between channels (e.g., the redundancy), we formulate this problem by defining channel numbers associating with the spatial and depth into an integrated space through a configuration vector. Within this joint space, we can not only mine the relationships inside a single dimension, but also find relatively optimal options across three dimensions by optimizing this configuration vector. That is to say, we consider the global reciprocity between the three aspects and model joint pruning with the defined pruning configuration vector specifying layer-wise channel numbers, spatial size, and the network depth. This circumvents the algorithmic dependency on the exclusive properties in the channel dimension.

As there is no explicit function between the loss function of the pruned network and its configuration vector (i.e., it is non-differentiable to the pruning configuration), also considering the efficiency of optimization, we propose to use stochastic gradient estimation to approximate the gradient w.r.t. configuration vectors. We first convert the loss function to an expectation of the loss of configuration vectors sampled from a Gaussian distribution around the original vector. Then we utilize the log likelihood trick sutton2000policy to obtain the gradient of expectation as an approximation to the underlying gradient. We further design weight sharing mechanism for evaluating the loss of configuration vectors without training each corresponding pruned network from scratch. With alternatively updating weights and configuration vector, the proposed JointPruning can automatically learn the global pruning configuration across three dimensions.

We show the effectiveness of JointPruning on MobileNet V1/V2 and ResNet structures. It achieves up to higher accuracy than MobileNet V1/V2 baselines under FLOPs constraint. Moreover, JointPruning is friendly to tackle channels in shortcuts and also supports multiple resource constraints. It can automatically adapt the pruning scheme according to the underlying hardware specialty and different circumstances due to its larger potential options. Under CPU latency constraint, JointPruning achieves comparable or higher results with less searching time than advanced adaptation based ChamNet dai2018chamnet. When targeting at GPU latency, it surpasses MobileNet V1/V2 baselines with more than 3.9% and 2.4% improvement under an extremely large compression ratio.

Contributions:

We reveal the perspective that joint pruning neural network in three dimensions (i.e., channel, spatial and depth) is crucial for striking a good accuracy-computation trade-off. We define pruning configuration as a vector specifying the spatial size, network depth and layer-wise channel numbers, and formulate joint pruning as optimizing the configuration vector.

We propose to use stochastic gradient estimation w.r.t. the configuration vector for efficient optimization. This strategy inherits the high efficiency advantage of the gradient descent algorithm meanwhile overcomes the non-differentiability in the configuration vectors.

We design weight sharing strategy to avoid training individual pruned network from scratch, and an alternative updating strategy to jointly optimize weights and configuration vectors, which further facilitates optimization.

The proposed JointPruning can flexibly incorporate different resource constraints including FLOPs and hardware latency. It outperforms traditional pruning algorithms with less human efforts and achieved higher results than state-of-the-art model adaptation methods with less optimization time.

## 2 Related Work

Model compression is recognized as an effective approach for efficient deep learning han2015deep; wu2019efficient. The categories of model compression expands from pruning he2017channelpruning; chin2019legr; huang2018data, quantization zhuang2019effective; zhuang2019training, to compact network architecture design ma2018shufflenet; zhang2018shufflenet; howard2017mobilenets; sandler2018mobilenetv2. Our approach is most related to pruning.

Pruning and Model Adaptation Early works lecun1990optimal; hassibi1993optimal; guo2016dynamic prune individual redundant weights and recent studies focus on removing the entire kernel networkslimming; luo2017thinet to produce structured pruned networks. While traditional pruning involves massive human participation in determining the pruning ratio, AutoML-based methods with reinforcement learning he2018amc, a feedback loop yang2018netadapt or a meta network liu2019metapruning can automatically decide the best pruning ratio. In those pruning methods, the optimization space is confined to channels only. Intuitively, a higher compression ratio and better trade-off can be obtained through jointly reducing channel, spatial and depth dimensions. So far, only a few works address the joint adaptation across three dimensions. EfficientNet tan2019efficientnet focuses on scales all dimensions of depth/width/resolution with a single compound coefficient. The coefficient is obtained by grid search. ChamNet dai2018chamnet uses the Gaussian process to predict the accuracy of compression configurations in three dimensions. Despite their high accuracy, grid search or Gaussian process requires training hundreds of networks from scratch, which are with high computational cost. Instead, we propose to model the joint pruning as optimizing the numerical values of architecture configurations (i.e., channel, depth and spatial), which enables to use a stochastic gradient estimation w.r.t. the configuration vector in optimization, and further improves the efficiency greatly.

Gradient Estimation Gradient estimation is initially proposed for optimizing non-differentiable objectives nesterov2017random. Reinforcement learning (RL) algorithms often utilize gradient estimation to update the policy williams1992simple; o2016combining; gu2017interpolated; lillicrap2015continuous; beyer2002evolution; salimans2017evolution; back1991survey. We customize a relaxation of the objective function and use the log likelihood trick to calculate the estimated gradient silver2014deterministic. Different from these algorithms designed for the typical RL tasks, such as Atari and MuJoCo, our approach focuses on optimizing the network configuration and assumes the policy function to be a Gaussian distribution, which can better approximate the actual gradient and is free of hyper-parameters. Furthermore, we utilize the Lipchitz continuous property of the neural networks w.r.t. the configuration vectors. Such that we adopt a progressively shrinking Gaussian window for obtaining more accurate gradient estimations, and use an alternative paradigm for updating configuration vectors and the weight parameters.

Neural Architecture Search and Parameter Sharing Different from pruning tasks, which aims to find a compressed model through adjusting the numerical values in architecture configurations, NAS are targeting at choosing the best options zoph2018learning; real2018regularized; tan2018mnasnet; xie2018snas and/or connections xie2019exploring. Although a few NAS studies include two or three channel number choices in their search space wu2018fbnet; cai2018proxylessnas, they enumerate these choice as independent nodes. The gradient-based neural architecture search (NAS) adopts Straight Through Estimation cai2018proxylessnas or probabilistic relaxation liu2018darts, which models choices as independent and is essentially unsuitable for continuous numerical choices in the pruning configuration. While proposed JointPruning tailored for this task utilizes the consecutiveness in the numerical values, and is thus more effective. Parameter sharing is studied in NAS. Our parameter-sharing scheme is inspired by the practice in one-shot architecture search guo2019single; stamoulis2019single; bender2018understanding; cai2019once. Different from the operation-level sharing mechanism designed for independent operations, proposed weight sharing adopts a matrix-level sharing, which is specialized for a more efficient sharing among the consecutive channel/spatial/depth choices. The details of our algorithm are described in Sec. 3.

## 3 Methodology

To solve the pruning problem in three dimensions, we define the pruned networks with the corresponding unique architecture configuration vectors:

 vconf={c,s,d}, (1)

where denotes the number of channels in each layer, c = , is the total number of layers, denotes the spatial size of the input image to the network and denotes the network depth.

We formulate the JointPruning as a constrained optimization problem over the configuration vector. The objective is to minimize the loss under a given resource constraint:

 minimize L(v,w) (2) subject to  C(v)

where refers to the loss function of the neural network, is the weight parameters, is the computational cost given the network configuration and denotes the target resource constraint (i.e., FLOPs or latency). We merge the resource constraint as a regularization term in the error function as follows:

 E(v,w)=L(v,w)+ρ||C(v)−constraint||2, (4)

where is the positive regularization coefficient. Consequently, the goal is to find the architecture configuration vector that minimizes the error function :

 v=argminv(E) (5)

However, it is computationally prohibitive to obtain the error through enumerating the configuration vectors and training each corresponding pruned network from scratch. To tackle this, we propose the gradient estimation method to approximate the steepest gradient descent direction of the configuration vector that minimizes the error, and also customize a weight sharing mechanism to further enhance the optimization efficiency. We detail our gradient estimation method and the weight sharing mechanism in Section 3.1 and Section 3.2, respectively.

### 3.1 Stochastic Gradient Estimation for Configuration Vectors

Since the error function is naturally non-differentiable with respect to the configuration vectors, we propose gradient estimation to approximate the underlying gradients. Inspired by rechenberg1994evolutionsstrategie; yi2009stochastic; sehnke2010parameter, we conduct the gradient estimation by relaxing the objective error function to the expectation of with configuration vector obeying a distribution .

 E(v)≈Ev∼pθ(v)E(v), (6)

where the distribution is parameterized by . To simplify the expression, we omit the in the term . In previous works, is chosen to be a function of . Instead, and considering the relaxation purpose is for obtaining precise gradient estimation w.r.t. the configuration vector , we simplify the probability distribution to be an isotropic multivariate gaussian distribution:

 pμ(v)∼N(μ,σ), (7)

with the mean being the current configuration vector and the deviation set to . Consequently, the approximation to the objective function can be written as:

 E(μ)≈Ev∼N(μ,σ)E(v)=En∼N(0,σ)E(μ+n), (8)

where denotes the random multidimensional Gaussian noise added to the current configuration vector. This approximation holds because the neural network is Lipschitz continuous with respect to , i.e., there exists a positive real constant such that:

 ||E(μ+n)−E(μ)||

In configuration vector optimization, is confined to small variation values, i.e., . Therefore, the alteration in the error function is bounded within . In experiments, we observe the constant to be diminutive within a local region around the current configuration vector and thus the variation is tolerable.

With this approximation to the error function, we can derive the estimated gradient following the commonly adopted log likelihood trick in reinforcement learning:

 ∇μEv∼N(μ,σ)E(v) =Ev∼N(μ,σ)[E(v)∇μlog(p(v;μ))] (10) =Ev∼N(μ,σ)[E(v)∇μ(log(1σ√2πe−12(v−μσ)2))] (11) =Ev∼N(μ,σ)[E(v)v−μσ2] (12) =1σ2En∼N(0,σ)[E(μ+n)n]. (13)

Thus, the gradient of can be estimated by the configuration vector stochastically sampled around the current vector under a gaussian distribution :

 ∇μEv∼N(μ,σ)E(v)≈1σ2M∑i=1E(μ+ni)ni, (14)

where is the total number of samples. An intuitive interpretation of this gradient estimation approach is: by weighting the variation directions with the corresponding error, the gradient direction can be approximated with the variation direction that has the lower expected error. Then the configuration vector is updated with the estimated gradient:

 μ′=μ−α∇μE(v), (15)

where denotes the update rate, and the geometric meaning of is the center configuration vector for adding Gaussian variations. The resulting algorithm iteratively executes the following two steps: (1) stochastic sampling of the architecture configuration vectors and evaluate the corresponding errors; (2) integrating the evaluations to estimate the gradient and update the configuration vector.

### 3.2 Weight Sharing

In the aforementioned stochastic gradient estimation paradigm, one crucial issue that remains unsolved is how to obtain the error evaluation of the configuration vector. Recall that the error is a function of and : . To evaluate the configuration vector(), the weights() in the corresponding pruned network need to be trained. However, it would be too computationally prohibitive to train each pruned network from scratch. To address this, we customize a parameter-sharing mechanism to share the weights for different architectures varying in the channel, spatial and depth configurations.

The parameter-sharing mechanism is illustrated in Figure 1. For spatial dimension, decreasing the input image resolution will reduce the feature map size in the network, as Figure 1(a). This does not require any modification in the weight kernels and thus all the network weights are shared when adjusting the spatial resolution. To prune the channels, we follow liu2019metapruning to keep the first channels of feature maps in the original network and crop the weight tensors correspondingly, as shown in Figure 1(b). To reduce depth, we adopt block dropping. That is keeping the first blocks and skipping the rest of the blocks, as Figure 1(c). Combining these three dimensions, we come up with the joint parameter-sharing mechanism as illustrated in Figure 1(d). With this mechanism, we only need to train one set of weights in the weight-shared network and evaluate the error of different pruning configuration vectors with corresponding weights cropped from this network.

### 3.3 Alternatively Update Weights and Configuration Vectors

For training the weights in the shared network, the optimization goal is set to minimize the error concerning the expectation of a bunch of configuration vectors. The objective is defined as:

 minwEv∼N(μ,σ)E(v,w) (16)

To optimize this objective function, we inject noise to the configuration vectors during weight training. That is, in each weight training iteration, the configuration vectors is randomly sampled from .

After training the weights for one epoch, we use the stochastic gradient estimation to estimate the gradient w.r.t. the and take a step in the variable space to decline the error:

 minμEv∼N(μ,σ)E(v,w) (17)

We alternatively optimize the weights and the architecture configuration vectors and meanwhile decrease the deviation till convergence. With the error function well approximated by its smoothed version , we can obtain the optimized configuration vector to be the mean of the configuration vector distributions (i.e., ) of the final model. The optimization pipeline is detailed in Algorithm 1.

## 4 Experiments

In this section, we begin by introducing our experiment settings in Sec. 4.1. Then, we explain the configuration vector settings in Sec. 4.2. Thirdly, we show the comparison between our method and the state-of-the-arts on various architectures and under different resource constraint metrics in Sec. 4.3. Lastly, we visualize two of the pruned networks obtained by our algorithm in Sec. 4.4.

### 4.1 Experiment Settings

Dataset All experiments are conducted on the ImageNet 2012 classification dataset russakovsky2015imagenet. For optimizing the configuration vector, we randomly split the original training set into two subsets: 50,000 images for validation (50 images for each class) and use the rest as the training set. After the architecture hyperparameters are optimized, we train the corresponding architecture from scratch using the original training/validation dataset split, following the practice in cai2018proxylessnas; wu2018fbnet.

Training We alternatively optimize the configuration vector and weights with an outer loop of 75 iterations. In each inner loop, we train the weights for 2000 iterations for MobileNet V1/V2 and 1000 iterations for ResNet with a batch size of 256. We use the SGD optimizer with momentum for weight training. Then we update the configuration vector for 20 iterations with the estimated gradients. In gradient estimation, the number of samples is set to 100 for each iteration, the deviation and the update rate are initialized with 1.25 and 5 respectively, and linearly decay to 0.25 and 0, respectively, with the outer loop.

Constraints The experiments are carried out under the FLOPs, GPU latency as well as the CPU latency constraints. For the latency constraints, we follow the practice in FBNet wu2018fbnet to build a latency look-up-table for a layer with different configurations and obtain the total latency of the network by summing up the latency of all layers. In our experiments, we estimate GPU latency on the GTX 1080Ti with a batch size of 256. For CPU latency, we use the look-up-table released by ChamNet dai2018chamnet for a fair comparison. As ChamNet has a very sparse look-up-table, we use the Gaussian process to predict the missing latency values as dai2018chamnet did for energy estimation.

### 4.2 Details in configuration vector settings

For MobileNet V1, we set the optimization vector() as , where are the numbers of output channels in layer , and denotes total number of layers. is the spatial size of the input image. As MobileNet V1 is a network without shortcuts, reducing the depth will result in channel mismatch. With this structure restriction, we only optimize the channel and spatial dimensions. We initiate the configuration vector as the configuration of the original MobileNet V1. After obtaining the optimal configuration, the pruned network is constructed through pruning each layer’s input channel equaling to previous layer’s output channel, specified by , and then crop the weight kernels correspondingly as shown in Figure 1(b).

Similar to MobileNet V1, the optimization vector() for MobileNet V2 is defined as . Since MobileNet V2 contains the shortcut structure, we confine the layers connected with identity shortcuts to have the same number of output channels. For pruning depth dimension, we drop the last block in the stage that contains the most number of blocks.

For ResNet, we adopt similar settings of MobileNet V2, and confine the configuration vectors to layer-wise channel numbers only, i.e. for a direct comparison to the traditional channel pruning methods.

### 4.3 Comparisons with state-of-the-arts

To verify the effectiveness of proposed JointPruning, we compare our method with the uniform baselines, traditional pruning methods as well as the AutoML-based model adaptation methods. Our experiments are conducted on MobileNet V1, MobileNet V2 howard2017mobilenets; sandler2018mobilenetv2 and ResNet he2016deep backbones.

MobileNet V1&V2. MobileNets howard2017mobilenets; sandler2018mobilenetv2 are already compact networks, many recent pruning algorithms focus on these structures for the practical significance in pruned models.

The baseline group in Table 1 shows that rescaling channel and spatial dimension (C+S) by the same ratio can achieve higher accuracy than merely rescale channel (C) or spatial (S), suggesting the importance of jointly dealing with multi-dimensions. Then, in this joint pruning space, the proposed JointPruning can automatically capture the delicate linkage between spatial pruning and channel-wise pruning ratio adjustments, which outputs optimized pruned networks with higher accuracy than state-of-the-art pruning methods focusing on channels only. When further considering the depth dimension, JointPruning obtains even better accuracy, especially under the extreme small FLOPs constraint (45M), which demonstrates the superiority to others.

Besides the FLOPs constraint, we extensively study the behavior of JointPruning under direct metrics like GPU latency and CPU latency. Given various latency constraints, JointPruning consistently improves the accuracy by a remarkable margin especially for highly paralleled GPU devices. As shown in Table 2, on MobileNet V1 JointPruning with the channel and spatial dimension (C+S) achieves more than 3.9% accuracy enhancements. On MobileNet V2, JointPruning comprehensively considers channel, spatial and depth (C+S+D) dimensions, and automatically capture and utilize the underlying hardware specialty, which further boosts the accuracy. Compared to the state-of-the-art model adaptation method ChamNet building atop the Gaussian process, JointPurning with stochastic gradient estimation enjoys high optimization efficiency. As shown in Table 5, JointPruning achieves comparable or higher accuracy compared to ChamNet, but with much lower optimization time cost.

ResNet. Despite that JointPruning is designed for multi-dimensional pruning, we show that it is also effective when targeting at channel dimension only. In comparison to the traditional channel pruning methods, JointPruning achieves better performance with less human participation. The accuracy enhancement mainly comes from JointPruning’s ability in pruning shortcuts. For traditional pruning with a layer-by-layer scheme, shortcuts will affect more than one layer which is tough to deal with. While JointPruning can effortlessly prune the shortcut by modeling the shortcut pruning as updating the numerical channel numbers.

Random search Compared to the random search which determines the configuration in three dimensions randomly, Table 5 shows that JointPurning is able to end up at an optimized minimum with high accuracy, and significantly outperforms random search scheme.

### 4.4 Optimization results visualization

In this section, we visualize two sets of pruning configurations for MobileNetV2 focusing on optimizing CPU and GPU latency, respectively. By incorporating the latency into the error function , JointPruning is able to take advantage of hardware characteristics without knowing the implementation details. The final network optimized under the CPU latency constraint is deep with smaller spatial resolution. While for the GPU, the corresponding architecture discovered by JointPruning adopts large spatial resolution, more channels with fewer layers to fully utilize the parallel computing capability of GPUs. Figure 2: This figure shows the architecture hyper-parameters (input image size, layer-wise channel numbers and depth) of MobileNet V2 network structure optimized under (a) CPU latency constraint with latency = 10ms and (b) GPU latency constraint with latency = 5.62ms.

## 5 Conclusion

In this work, we focused on the joint multi-dimension pruning which naturally has broader pruning space on spatial, depth and channel for digging out better configurations than the isolated single dimension solution. We have proposed to use stochastic gradient estimation to optimize this problem and further introduced a weight sharing strategy to avoid repeatedly training multiple models from scratch. Our results on large-scale ImageNet dataset with MobileNet V1&V2 and ResNet outperformed previous state-of-the-art pruning methods with significant margins.

In the future, we will conduct more deep analyses about how multi-dimension pruning helps to find better optimum. It will also be interesting to apply our method to other tasks like unsupervised pruning to explore the upper limit of the proposed method.

## 6 Acknowledgement

The authors would like to acknowledge National Key R&D Program of China (No. 2017YFA0700800), Beijing Academy of Artificial Intelligence (BAAI) and HKSAR RGC’s funding support under grant GRF-16203918.
{"ft_lang_label":"__label__en","ft_lang_prob":0.8448846,"math_prob":0.87184554,"size":29414,"snap":"2020-24-2020-29","text_gpt3_token_len":6452,"char_repetition_ratio":0.16572595,"word_repetition_ratio":0.029306648,"special_character_ratio":0.22700074,"punctuation_ratio":0.124975085,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9561279,"pos_list":[0,1,2],"im_url_duplicate_count":[null,1,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-06-03T00:35:54Z\",\"WARC-Record-ID\":\"<urn:uuid:8b3f2e0c-8f8d-4571-ba56-2f5489e015c2>\",\"Content-Length\":\"293176\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:574d8308-26fe-400e-8e1d-d4c344d6ba80>\",\"WARC-Concurrent-To\":\"<urn:uuid:0908e27f-4098-4b90-bdd1-63f6126ba572>\",\"WARC-IP-Address\":\"104.28.21.249\",\"WARC-Target-URI\":\"https://www.arxiv-vanity.com/papers/2005.08931/\",\"WARC-Payload-Digest\":\"sha1:EVWY2EUBTUFKRN7EN7AFQHH5AGOFIHBZ\",\"WARC-Block-Digest\":\"sha1:4OEC5YHR7AT4U6BS6YAFANBWKQI5MBBO\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-24/CC-MAIN-2020-24_segments_1590347426956.82_warc_CC-MAIN-20200602224517-20200603014517-00428.warc.gz\"}"}