Learning Structured Sparsity in Deep Neural Networks

Wei Wen, Chunpeng Wu, Yandan Wang, Yiran Chen, Hai Li

Introduction

Inspired by the facts that (1) there is redundancy across filters and channels ; (2) shapes of filters are usually fixed as cuboid but enabling arbitrary shapes can potentially eliminate unnecessary computation imposed by this fixation; and (3) depth of the network is critical for classification but deeper layers cannot always guarantee a lower error because of the exploding gradients and degradation problem , we propose Structured Sparsity Learning (SSL) method to directly learn a compressed structure of deep CNNs by group Lasso regularization during the training. SSL is a generic regularization to adaptively adjust mutiple structures in DNN, including structures of filters, channels, and filter shapes within each layer, and structure of depth beyond the layers. SSL combines structure regularization (on DNN for classification accuracy) with locality optimization (on memory access for computation efficiency), offering not only well-regularized big models with improved accuracy but greatly accelerated computation (e.g. 5.1×\times on CPU and 3.1×\times on GPU for AlexNet).

Related works

Connection pruning and weight sparsifying. Han et al. reduced number of parameters of AlexNet by 9×\times and VGG-16 by 13×\times using connection pruning. Since most reduction is achieved on fully-connected layers, the authors obtained 3×\times to 4×\times layer-wise speedup for fully-connected layers. However, no practical speedups of convolutional layers are observed because of the issue shown in Figure 1. As convolution is the computational bottleneck and many new DNNs use fewer fully-connected layers, e.g., only 3.99% parameters of ResNet-152 in are from fully-connected layers, compression and acceleration on convolutional layers become essential. Liu et al. achieved >90% sparsity of convolutional layers in AlexNet with 2% accuracy loss, and bypassed the issue shown in Figure 1 by hardcoding the sparse weights into program, achieving layer-wise 4.59×\times speedup on a CPU. In this work, we also focus on convolutional layers. Compared to the above techniques, our SSL method can coordinate sparse weights in adjacent memory space and achieve higher speedups with the same accuracy. Note that hardware and program optimizations can further boost the system performance on top of the level of SSL but are not covered in this work.

Low rank approximation. Denil et al. predicted 95% parameters in a DNN by exploiting the redundancy across filters and channels. Inspired by it, Jaderberg et al. achieved 4.5×\times speedup on CPUs for scene text character recognition and Denton et al. achieved 2×\times speedups on both CPUs and GPUs for the first two layers. Both of the works used Low Rank Approximation (LRA) with \sim1% accuracy drop. improved and extended LRA to larger DNNs. However, the network structure compressed by LRA is fixed; reiterations of decomposing, training/fine-tuning, and cross-validating are still needed to find an optimal structure for accuracy and speed trade-off. As number of hyper-parameters in LRA method increases linearly with layer depth , the search space increases linearly or even polynomially for very deep DNNs. Comparing to LRA, our contributions are: (1) SSL can dynamically optimize the compactness of DNN structure with only one hyper-parameter and no reiterations; (2) besides the redundancy within the layers, SSL also exploits the necessity of deep layers and reduce them; (3) DNN filters regularized by SSL have lower rank approximation, so it can work together with LRA for more efficient model compression.

Model structure learning. Group Lasso is an efficient regularization to learn sparse structures. Kim et al. used group Lasso to regularize the structure of correlation tree for multi-task regression problem and reduced prediction errors. Liu et al. utilized group Lasso to constrain the scale of the structure of LRA. To adapt DNN structure to different databases, Feng et al. learned the appropriate number of filters in DNN. Different from these prior arts, we apply group Lasso to regularize multiple DNN structures (filters, channels, filter shapes, and layer depth). Our source code can be found at https://github.com/wenwei202/caffe/tree/scnn.

Structured Sparsity Learning Method for DNNs

We focus mainly on the Structured Sparsity Learning (SSL) on convolutional layers to regularize the structure of DNNs. We first propose a generic method to regularize structures of DNN in Section 3.1, and then specify the method to structures of filters, channels, filter shapes and depth in section 3.2. Variants of formulations are also discussed from computational efficiency viewpoint in Section 3.3.

2 Structured sparsity learning for structures of filters, channels, filter shapes and depth

In SSL, the learned “structure” is decided by the way of splitting groups of w(g)\bm{w}^{(g)}. We investigate and formulate the filer-wise, channel-wise, shape-wise, and depth-wise structured sparsity in Figure 2. For simplicity, the R()R(\cdot) term of Eq. (1) is omitted in the following formulation expressions.

Penalizing unimportant filers and channels. Suppose Wnl,:,:,:(l)\bm{W}_{n_{l},:,:,:}^{(l)} is the nln_{l}-th filter and W:,cl,:,:(l)\bm{W}_{:,c_{l},:,:}^{(l)} is the clc_{l}-th channel of all filters in the ll-th layer. The optimization target of learning the filter-wise and channel-wise structured sparsity can be defined as

As indicated in Eq. (2), our approach tends to remove less important filters and channels. Note that zeroing out a filter in the ll-th layer results in a dummy zero output feature map, which in turn makes a corresponding channel in the (l+1)(l+1)-th layer useless. Hence, we combine the filter-wise and channel-wise structured sparsity in the learning simultaneously.

Learning arbitrary shapes of filers. As illustrated in Figure 2, W:,cl,ml,kl(l)\bm{W}_{:,c_{l},m_{l},k_{l}}^{(l)} denotes the vector of all corresponding weights located at spatial position of (ml,kl)(m_{l},k_{l}) in the 2D filters across the clc_{l}-th channel. Thus, we define W:,cl,ml,kl(l)\bm{W}_{:,c_{l},m_{l},k_{l}}^{(l)} as the shape fiber related to learning arbitrary filter shape because a homogeneous non-cubic filter shape can be learned by zeroing out some shape fibers. The optimization target of learning shapes of filers becomes:

Regularizing layer depth. We also explore the depth-wise sparsity to regularize the depth of DNNs in order to improve accuracy and reduce computation cost. The corresponding optimization target is E(W) = ED(W)+λdl=1LW(l)gE(\bm{W})~{}=~{}E_{D}(\bm{W})+\lambda_{d}\cdot\sum_{l=1}^{L}||\bm{W}^{(l)}||_{g}. Different from other discussed sparsification techniques, zeroing out all the filters in a layer will cut off the message propagation in the DNN so that the output neurons cannot perform any classification. Inspired by the structure of highway networks and deep residual networks , we propose to leverage the shortcuts across layers to solve this issue. As illustrated in Figure 2, even when SSL removes an entire unimportant layers, feature maps will still be forwarded through the shortcut.

3 Structured sparsity learning for computationally efficient structures

All proposed schemes in section 3.2 can learn a compact DNN for computation cost reduction. Moreover, some variants of the formulations of these schemes can directly learn structures that can be efficiently computed.

2D-filter-wise sparsity for convolution. 3D convolution in DNNs essentially is a composition of 2D convolutions. To perform efficient convolution, we explored a fine-grain variant of filter-wise sparsity, namely, 2D-filter-wise sparsity, to spatially enforce group Lasso on each 2D filter of Wnl,cl,:,:(l)\bm{W}^{(l)}_{n_{l},c_{l},:,:}. The saved convolution is proportional to the percentage of the removed 2D filters. The fine-grain version of filter-wise sparsity can more efficiently reduce the computation associated with convolution: Because the group sizes are much smaller and thus the weight updating gradients are shaper, it helps group Lasso to quickly obtain a high ratio of zero groups for a large-scale DNN.

Combination of filter-wise and shape-wise sparsity for GEMM. Convolutional computation in DNNs is commonly converted to modality of GEneral Matrix Multiplication (GEMM) by lowering weight tensors and feature tensors to matrices . For example, in Caffe , a 3D filter Wnl,:,:,:(l)\bm{W}^{(l)}_{n_{l},:,:,:} is reshaped to a row in the weight matrix where each column is the collection of weights W:,cl,ml,kl(l)\bm{W}^{(l)}_{:,c_{l},m_{l},k_{l}} related to shape-wise sparsity. Combining filter-wise and shape-wise sparsity can directly reduce the dimension of weight matrix in GEMM by removing zero rows and columns. In this context, we use row-wise and column-wise sparsity as the interchangeable terminology of filter-wise and shape-wise sparsity, respectively.

Experiments

We evaluated the effectiveness of our SSL using published models on three databases – MNIST, CIFAR-10, and ImageNet. Without explicit explanation, SSL starts with the network whose weights are initialized by the baseline, and speedups are measured in matrix-matrix multiplication by Caffe in a single-thread Intel Xeon E5-2630 CPU .

In the experiment of MNIST, we examined the effectiveness of SSL in two types of networks: LeNet implemented by Caffe and a multilayer perceptron (MLP) network. Both networks were trained without data augmentation.

LeNet: When applying SSL to LeNet, we constrain the network with filter-wise and channel-wise sparsity in convolutional layers to penalize unimportant filters and channels. Table 1 summarizes the remained filters and channels, floating-point operations (FLOP), and practical speedups. In the table, LeNet 1 is the baseline and the others are the results after applying SSL in different strengths of structured sparsity regularization. The results show that our method achieves the similar error (±0.1%\pm 0.1\%) with much fewer filters and channels, and saves significant FLOP and computation time.

To demonstrate the impact of SSL on the structures of filters, we present all learned conv1 filters in Figure 3. It can be seen that most filters in LeNet 2 are entirely zeroed out except for five most important detectors of stroke patterns that are sufficient for feature extraction. The accuracy of LeNet 3 (that further removes the weakest and redundant stroke detector) drops only 0.2% from that of LeNet 2. Compared to the random and blurry filter patterns in LeNet 1 that resulted from the high freedom of parameter space, the filters in LeNet 2 & 3 are regularized and converge to smoother and more natural patterns. This explains why our proposed SSL obtains the same-level accuracy but has much less filters. The smoothness of the filters are also observed in the deeper layers.

The effectiveness of the shape-wise sparsity on LeNet is summarized in Table 2. The baseline LeNet 1 has conv1 filters with a regular 5×55\times 5 square (size = 25) while LeNet 5 reduces the dimension that can be constrained by a 2×42\times 4 rectangle (size = 7). The 3D shape of conv2 filters in the baseline is also regularized to the 2D shape in LeNet 5 within only one channel, indicating that only one filter in conv1 is needed. This fact significantly saves FLOP and computation time.

MLP: Besides convolutional layers, our proposed SSL can be extended to learn the structure (i.e. the number of neurons) of fully-connected layers. We enforce the group Lasso regularization on all the input (or output) connections of each neuron. A neuron whose input connections are all zeroed out can degenerate to a bias neuron in the next layer; similarly, a neuron can degenerate to a removable dummy neuron if all of its output connections are zeroed out.

Figure 4 summarizes the learned structure and FLOP of different MLP networks. The results show that SSL can not only remove hidden neurons but also discover the sparsity of images. For example, Figure 4 depicts the number of connections of each input neuron in MLP 2, where 40.18% of input neurons have zero connections and they concentrate at the boundary of the image. Such a distribution is consistent with our intuition: handwriting digits are usually written in the center and pixels close to the boundary contain little discriminative classification information.

2 ConvNet and ResNet on CIFAR-10

We implemented the ConvNet of and deep residual networks (ResNet) on CIFAR-10. When regularizing filters, channels, and filter shapes, the results and observations of both networks are similar to that of the MNIST experiment. Moreover, we simultaneously learn the filter-wise and shape-wise sparsity to reduce the dimension of weight matrix in GEMM of ConvNet. We also learn the depth-wise sparsity of ResNet to regularize the depth of the DNNs.

ConvNet: We use the network from Alex Krizhevsky et al. as the baseline and implement it using Caffe. All the configurations remain the same as the original implementation except that we added a dropout layer with a ratio of 0.5 in the fully-connected layer to avoid over-fitting. ConvNet is trained without data augmentation. Table 3 summarizes the results of three ConvNet networks. Here, the row/column sparsity of a weight matrix is defined as the percentage of all-zero rows/columns. Figure 5 shows their learned conv1 filters. In Table 3, SSL can reduce the size of weight matrix in ConvNet 2 by 50%, 70.7% and 36.1% for each convolutional layer and achieve good speedups without accuracy drop. Surprisingly, without SSL, four conv1 filters of the baseline are actually all-zeros as shown in Figure 5, demonstrating the great potential of filter sparsity. When SSL is applied, half of conv1 filters in ConvNet 2 can be zeroed out without accuracy drop.

On the other hand, in ConvNet 3, SSL achieves 1.0% (±\pm0.16%) lower error with a model even smaller than the baseline. In this scenario, SSL performs as a structure regularization to dynamically learn a better network structure (including the number of filters and filer shapes) to reduce the error.

ResNet: To investigate the necessary depth of DNNs required by SSL, we use a 20-layer deep residual networks (ResNet-20) proposed in as the baseline. The network has 19 convolutional layers and 1 fully-connected layer. Identity shortcuts are utilized to connect the feature maps with the same dimension while 1×\times1 convolutional layers are chosen as shortcuts between the feature maps with different dimensions. Batch normalization is adopted after convolution and before activation. We use the same data augmentation and training hyper-parameters as that in . The final error of baseline is 8.82%. In SSL, the depth of ResNet-20 is regularized by depth-wise sparsity. Group Lasso regularization is only enforced on the convolutional layers between each pair of shortcut endpoints, excluding the first convolutional layer and all convolutional shortcuts. After SSL converges, layers with all zero weights are removed and the net is finally fine-tuned with a base learning rate of 0.01, which is lower than that (i.e., 0.1) in the baseline.

Figure 6 plots the trend of the error vs. the number of layers under different strengths of depth regularizations. Compared with original ResNet in , SSL learns a ResNet with 14 layers (SSL-ResNet-14) that reaching a lower error than the one of the baseline with 20 layers (ResNet-20); SSL-ResNet-18 and ResNet-32 achieve an error of 7.40% and 7.51%, respectively. This result implies that SSL can work as a depth regularization to improve classification accuracy. Note that SSL can efficiently learn shallower DNNs without accuracy loss to reduce computation cost; however, it does not mean the depth of the network is not important. The trend in Figure 6 shows that the test error generally declines as more layers are preserved. A slight error rise of SSL-ResNet-20 from SSL-ResNet-18 shows the suboptimal selection of the depth in the group of “32×\times32”.

3 AlexNet on ImageNet

To show the generalization of our method to large scale DNNs, we evaluate SSL using AlexNet with ILSVRC 2012. CaffeNet – the replication of AlexNet with mirror changes, is used in our experiment. All training images are rescaled to the size of 256×\times256. A 227×\times227 image is randomly cropped from each scaled image and mirrored for data augmentation and only the center crop is used for validation. The final top-1 validation error is 42.63%. In SSL, AlexNet is first trained with structure regularization; when it converges, zero groups are removed to obtain a DNN with the new structure; finally, the network is fine-tuned without SSL to regain the accuracy.

We first studied 2D-filter-wise and shape-wise sparsity by exploring the trade-offs between computation complexity and classification accuracy. Figure 7 shows the 2D-filter sparsity (the ratio between the removed 2D filters and total 2D filters) and the saved FLOP of 2D convolutions vs. the validation error. In Figure 7, deeper layers generally have higher sparsity as the group size shrinks and the number of 2D filters grows. 2D-filter sparsity regularization can reduce the total FLOP by 30%–40% without accuracy loss or reduce the error of AlexNet by \sim1% down to 41.69% by retaining the original number of parameters. Shape-wise sparsity also obtains similar results – In Table 4, for example, AlexNet 5 achieves on average 1.4×\times layer-wise speedup on both CPU and GPU without accuracy loss after shape regularization; The top-1 error can also be reduced down to 41.83% if the parameters are retained. In Figure 7, the obtained DNN with the lowest error has a very low sparsity, indicating that the number of parameters in a DNN is still important to maintain learning capacity. In this case, SSL works as a regularization to add restriction of smoothness to the model in order to avoid over-fitting. Figure 7 compares the results of dimensionality reduction of weight tensors in the baseline and our SSL-regularized AlexNet. The results show that the smoothness restriction enforces parameter searching in lower-dimensional space and enables lower rank approximation of the DNNs. Therefore, SSL can work together with low rank approximation to achieve even higher model compression.

Conclusion

In this work, we have proposed a Structured Sparsity Learning (SSL) method to regularize filter, channel, filter shape, and depth structures in deep neural networks (DNN). Our method can enforce the DNN to dynamically learn more compact structures without accuracy loss. The structured compactness of the DNN achieves significant speedups for the DNN evaluation both on CPU and GPU with off-the-shelf libraries. Moreover, a variant of SSL can be performed as structure regularization to improve classification accuracy of state-of-the-art DNNs.

This work was supported in part by NSF XPS-1337198 and NSF CCF-1615475. The authors thank Drs. Sheng Li and Jongsoo Park for valuable feedback on this work.

References