{'fraction_non_alphanumeric': 0.037497210029015696, 'fraction_numerical': 0.013205862659028346, 'mean_word_length': 4.669126950653733, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 0, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Global Sparse Momentum SGD for Pruning Very Deep Neural Networks

Deep Neural Network (DNN) is powerful but computationally expensive and memory intensive, thus impeding its practical usage on resource-constrained front-end devices. DNN pruning is an approach for deep model compression, which aims at eliminating some parameters with tolerable performance degradation. In this paper, we propose a novel momentum-SGD-based optimization method to reduce the network complexity by on-the-fly pruning. Concretely, given a global compression ratio, we categorize all the parameters into two parts at each training iteration which are updated using different rules. In this way, we gradually zero out the redundant parameters, as we update them using only the ordinary weight decay but no gradients derived from the objective function. As a departure from prior methods that require heavy human works to tune the layer-wise sparsity ratios, prune by solving complicated non-differentiable problems or finetune the model after pruning, our method is characterized by 1) global compression that automatically finds the appropriate per-layer sparsity ratios; 2) end-to-end training; 3) no need for a time-consuming re-training process after pruning; and 4) superior capability to find better winning tickets which win the initialization lottery.

Though the existing methods have achieved great success in pruning, there are some typical drawbacks. Specifically, when we seek to prune a model in advance and finetune it, we confront two problems: • The layer-wise sparsity ratios are inherently tricky to set as hyper-parameters. Many previous works [21,24,26,32] have shown that some layers in a DNN are sensitive to pruning, but some can be pruned significantly without degrading the model in accuracy. As a consequence, it requires prior knowledge to tune the layer-wise hyper-parameters in order to maximize the global compression ratio without unacceptable accuracy drop. • The pruned models are difficult to train, and we cannot predict the final accuracy after finetuning. E.g., the filter-level-pruned models can be easily trapped into a bad local minima, and sometimes cannot even reach a similar level of accuracy with a counterpart trained from scratch [10,38]. And in the context of connection pruning, the sparser the network, the slower the learning and the lower the eventual test accuracy [15].
On the other hand, pruning by learning is not easier due to: • In some cases we introduce a hyper-parameter to control the trade-off, which does not directly reflect the resulting compression ratio. For instance, MorphNet [17] uses group Lasso [44] to zero out some filters for structured pruning, where a key hyper-parameter is the Lasso coefficient. However, given a specific value of the coefficient, we cannot predict the final compression ratio before the training ends. Therefore, when we target at a specific eventual compression ratio, we have to try multiple coefficient values in advance and choose the one that yields the result closest to our expectation. • Some methods prune by solving an optimization problem which directly concerns the sparsity. As the problem is non-differentiable, it cannot be solved using SGD-based methods in an end-to-end manner. A more detailed discussion will be provided in Sect. 3.2.
In this paper, we seek to overcome the drawbacks discussed above by directly altering the gradient flow based on momentum SGD, which explicitly concerns the eventual compression ratio and can be implemented via end-to-end training. Concretely, we use first-order Taylor series to measure the importance of a parameter by estimating how much the objective function value will be changed by removing it [41,49]. Based on that, given a global compression ratio, we categorize all the parameters into two parts that will be updated using different rules, which is referred to as activation selection. For the unimportant parameters, we perform passive update with no gradients derived from the objective function but only the ordinary weight decay (i.e., -2 regularization) to penalize their values. On the other hand, via active update, the critical parameters are updated using both the objective-function-related gradients and the weight decay to maintain the model accuracy. Such a selection is conducted at each training iteration, so that a deactivated connection gets a chance to be reactivated in the next iteration. Through continuous momentum-accelerated passive updates we can make most of the parameters infinitely close to zero, such that pruning them causes no damage to the model's accuracy. Owing to this, there is no need for a finetuning process. In contrast, some previously proposed regularization terms can only reduce the parameters to some extent, thus pruning still degrades the model. Our contributions are summarized as follows.
• For lossless pruning and end-to-end training, we propose to directly alter the gradient flow, which is clearly distinguished with existing methods that either add a regularization term or turn the model pruning to solving some non-differentiable optimization problems. • We propose Global Sparse Momentum SGD (GSM), a novel SGD optimization method, which splits the update rule of momentum SGD into two parts. GSM-based DNN pruning requires a sole global eventual compression ratio as hyper-parameter and can automatically discover the appropriate per-layer sparsity ratios to achieve it. • Seen from the experiments, we have validated the capability of GSM to achieve high compression ratios on MNIST, CIFAR-10 [29] and ImageNet [9] as well as find better winning tickets [15]. The codes are available at https://github.com/DingXiaoH/GSM-SGD.
2 Related work

Momentum SGD
Stochastic gradient descent only takes the first order derivatives of the objective function into account and not the higher ones [28]. Momentum is a popular technique used along with SGD, which accumulates the gradients of the past steps to determine the direction to go, instead of using only the gradient of the current step. I.e., momentum gives SGD a short-term memory [16]. Formally, let L be the objective function, w be a single parameter, α be the learning rate, β be the momentum coefficient which controls the percentage of the gradient retained every iteration, η be the ordinary weight decay coefficient (e.g., 1 × 10 −4 for ResNets [23]), the update rule is There is a popular story about momentum [16,42,45,48]: gradient descent is a man walking down a hill. He follows the steepest path downwards; his progress is slow, but steady. Momentum is a heavy ball rolling down the same hill. The added inertia acts both as a smoother and an accelerator, dampening oscillations and causing us to barrel through narrow valleys, small humps and local minima. In this paper, we use momentum as an accelerator to boost the passive updates.

DNN pruning and other techniques for compression and acceleration
DNN pruning seeks to remove some parameters without significant accuracy drop, which can be categorized into unstructured and structured techniques based on the pruning granularity. Unstructured pruning (a.k.a. connection pruning) [7,21,22,31] targets at significantly reducing the number of non-zero parameters, resulting in a sparse model, which can be stored using much less space, but cannot effectively reduce the computational burdens on off-the-shelf hardware and software platforms. On the other hand, structured pruning removes structures (e.g., neurons, kernels or whole filters) from DNN to obtain practical speedup. E.g., channel pruning [10,11,32,35,37,38] cannot achieve an extremely high compression ratio of the model size, but can convert a wide CNN into a narrower (but still dense) one to reduce the memory and computational costs. In real-world applications, unstructured and structured pruning are often used together to achieve the desired trade-off. This paper is focused on connection pruning (but the proposed method can be easily generalized to structured pruning), which has attracted much attention since Han et al. [21] pruned DNN connections based on the magnitude of parameters and restored the accuracy via ordinary SGD. Some inspiring works have improved the paradigm of pruning-and-finetuning by splicing connections as they become important again [18], directly targeting at the energy consumption [55], utilizing per-layer second derivatives [13], etc. The other learning-based pruning methods will be discussed in Sect. 3.2 Apart from pruning, we can also compress and accelerate DNN in other ways. Some works [2,46,57] decompose or approximate parameter tensors; quantization and binarization techniques [8,19,20,36] approximate a model using fewer bits per parameter; knowledge distillation [3,25,43] transfers knowledge from a big network to a smaller one; some researchers seek to speed up convolution with the help of perforation [14], FFT [40,50] or DCT [53]; Wang et al. [52] compact feature maps by extracting information via a Circulant matrix.

Formulation
We first clarify the notations in this paper. For a fully-connected layer with p-dimensional input and q-dimensional output, we use W ∈ R p×q to denote the kernel matrix. For a convolutional layer with kernel tensor K ∈ R h×w×r×s , where h and w are the height and width of convolution kernel, r and s are the numbers of input and output channels, respectively, we unfold the tensor K into W ∈ R hwr×s . Let N be the number of all such layers, we use Θ = [W i ] (∀1 ≤ i ≤ N ) to denote the collection of all such kernel matrices, and the global compression ratio C is given by where |Θ| is the size of Θ and ||Θ|| 0 is the -0 norm, i.e., the number of non-zero entries. Let L, X, Y be the accuracy-related loss function (e.g., cross entropy for classification tasks), test examples and labels, respectively, we seek to obtain a good trade-off between accuracy and model size by achieving a high compression ratio C without unacceptable increase in the loss L(X, Y, Θ).

Rethinking learning-based pruning
The optimization target or direction of ordinary DNN training is to minimize the objective function only, but when we seek to produce a sparse model via a customized learning procedure, the key is to deviate the original training direction by taking into account the sparsity of the parameters. Through training, the sparsity emerges progressively, and we eventually reach the expected trade-off between accuracy and model size, which is usually controlled by one or a series of hyper-parameters.

Explicit trade-off as constrained optimization
The trade-off can be explicitly modeled as a constrained optimization problem [56], e.g., where g i is an indicator function, and l i is the required number of non-zero parameters at layer i. Since the second term of the objective function is non-differentiable, the problem cannot be settled analytically or by stochastic gradient descent, but can be tackled by alternately applying SGD and solving the non-differentiable problem, e.g., using ADMM [6]. In this way, the training direction is deviated, and the trade-off is obtained.

Implicit trade-off using regularizations
It is a common practice to apply some extra differentiable regularizations during training to reduce the magnitude of some parameters, such that removing them causes less damage [1,21,54]. Let R(Θ) be the magnitude-related regularization term, λ be a trade-off hyper-parameter, the problem is However, the weaknesses are two-fold. 1) Some common regularizations, e.g., -1, -2 and Lasso [44], cannot literally zero out the entries in Θ, but can only reduce the magnitude to some extent, such that removing them still degrades the performance. We refer to this phenomenon as the magnitude plateau. The cause behind is simple: for a specific trainable parameter w, when its magnitude |w| is large at the beginning, the gradient derived from R, i.e., λ ∂R ∂w , overwhelms ∂L ∂w , thus |w| is gradually reduced. However, as |w| shrinks, ∂R ∂w diminishes, too, such that the reducing tendency of |w| plateaus when ∂R ∂w approaches ∂L ∂w , and w maintains a relatively small magnitude.
2) The hyper-parameter λ does not directly reflect the resulting compression ratio, thus we may need to make several attempts to gain some empirical knowledge before we obtain the model with our expected compression ratio.

Global sparse gradient flow via momentum SGD
To overcome the drawbacks of the two paradigms discussed above, we intend to explicitly control the eventual compression ratio via end-to-end training by directly altering the gradient flow of momentum SGD to deviate the training direction in order to achieve a high compression ratio as well as maintain the accuracy. Intuitively, we seek to use the gradients to guide the few active parameters in order to minimize the objective function, and penalize most of the parameters to push them infinitely close to zero. Therefore, the first thing is to find a proper metric to distinguish the active part. Given a global compression ratio C, we use Q = |Θ| C to denote the number of non-zero entries in Θ. At each training iteration, we feed a mini-batch of data into the model, compute the gradients using the ordinary chain rule, calculate the metric values for every parameter, perform active update on Q parameters with the largest metric values and passive update on the others. In order to make GSM feasible on very deep models, the metrics should be calculated using only the original intermediate computational results, i.e., the parameters and gradients, but no second-order derivatives. Inspired by two preceding methods which utilized first-order Taylor series for greedy channel pruning [41,49], we define the metric in a similar manner. Formally, at each training iteration with a mini-batch of examples x and labels y, let T (x, y, w) be the metric value of a specific parameter w, we have The theory is that for the current mini-batch, we expect to reduce those parameters which can be removed with less impact on L(x, y, Θ). Using the Taylor series, if we set a specific parameter w to 0, the loss value becomes Ignoring the higher-order term, we have which is an approximation of the change in the loss value if w is zeroed out.
We rewrite the update rule of momentum SGD (Formula 1). At the k-th training iteration with a mini-batch of examples x and labels y on a specific layer with kernel W , the update rule is where • is the element-wise multiplication (a.k.a. Hadamard-product), and B (k) is the mask matrix, We refer to the computation of B for each kernel as activation selection. Obviously, there are exactly Q ones in all the mask matrices, and GSM degrades to ordinary momentum SGD when Q = |Θ|.
Of note is that GSM is model-agnostic because it makes no assumptions on the model structure or the form of loss function. I.e., the calculation of gradients via back propagation is model-related, of course, but it is model-agnostic to use them for GSM pruning.

GSM enables implicit reactivation and fast continuous reduction
As GSM conducts activation selection at each training iteration, it allows the penalized connections to be reactivated, if they are found to be critical to the model again. Compared to two previous works which explicitly insert a splicing [18] or restoring [55] stage into the entire pipeline to rewire the mistakenly pruned connections, GSM features simpler implementation and end-to-end training.
However, as will be shown in Sect. 4.4, re-activation only happens on a minority of the parameters, but most of them undergo a series of passive updates, thus keep moving towards zero. As we would like to know how many training iterations are needed to make the parameters small enough to realize lossless pruning, we need to predict the eventual value of a parameter w after k passive updates, given α, η and β. We can use Formula 1 to predict w (k) , which is practical but cumbersome. In our common use cases where z (0) = 0 (from the very beginning of training), k is large (at least tens of thousands), and αη is small (e.g., α = 5 × 10 −3 , η = 5 × 10 −4 ), we have observed an empirical formula precise enough to approximate the resulting value (Fig. 1), In practice, we fix η (e.g., 1 × 10 −4 for ResNets [23] and DenseNets [27]) and adjust α just as we do for ordinary DNN training, and use β = 0.98 for 50× faster zeroing-out. When the training is completed, we prune the model by only preserving Q parameters with the largest magnitude. We decide the number of training iterations k using Eq. 11 based on an empirical observation that with (1 − αη 1−β ) k < 1 × 10 −4 , such a pruning step causes no accuracy drop on very deep models like ResNet-56 and DenseNet-40.
Momentum is critical for GSM-based pruning to be completed with acceptable time cost. As most of the parameters continuously grow in the same direction determined by the weight decay (i.e., towards zero), such a tendency accumulates in the momentum, thus the zeroing-out process is significantly accelerated. On the other hand, if a parameter does not always vary in the same direction, raising β less affect its training dynamics. In contrast, if we increase the learning rate α for faster zeroing-out, the critical parameters which are hovering around the global minima will significantly deviate from their current values reached with a much lower learning rate before.

Pruning results and comparisons
We evaluate GSM by pruning several common benchmark models on MNIST, CIFAR-10 [29] and ImageNet [9], and comparing with the reported results from several recent competitors. For each trial, we start from a well-trained base model and apply GSM training on all the layers simultaneously.
ImageNet. We prune ResNet-50 to verify GSM on large-scale image recognition applications. We use a batch size of 64 and train the model with α = 1 × 10 −3 , 1 × 10 −4 , 1 × 10 −5 for 40, 10 and 10 epochs, respectively. We compare the results with L-OBS [13], which is the only previous method that reported experimental results on ResNet-50, to the best of our knowledge. Obviously, GSM outperforms L-OBS by a clear margin (Table. 3). We assume that the effectiveness of GSM on such a very deep network is due to its capability to discover the appropriate layer-wise sparsity ratios, given a desired global compression ratio. In contrast, L-OBS performs pruning layer by layer using the same compression ratio. This assumption is further verified in Sect. 4.2.

GSM for automatic layer-wise sparsity ratio decision
Modern DNNs usually contain tens or even hundreds of layers. As the architectures deepen, it becomes increasingly impractical to set the layer-wise sparsity ratios manually to reach a desired global compression ratio. Therefore, the research community is soliciting techniques which can automatically discover the appropriate sparsity ratios on very deep models. In practice, we noticed that if directly pruning a single layer of the original model by a fixed ratio results in a significant accuracy reduction, GSM automatically chooses to prune it less, and vice versa.
In this subsection, we present a quantitative analysis of the sensitivity to pruning, which is an underlying property of a layer defined via a natural proxy: the accuracy reduction caused by pruning a certain ratio of parameters from it. We first evaluate such sensitivity via single-layer pruning attempts with different pruning ratios (Fig. 2). E.g., for the curve labeled as "prune 90%" of LeNet-5, we first experiment on the first layer by setting 90% of the parameters with smaller magnitude to zero, and testing the model to obtain the validation accuracy. Then we restore the first layer, prune the second layer and test. The same procedure is applied to the third and fourth layers. After that, we use different pruning ratios of 99%, 99.5%, 99.7%, and obtain three curves in the same way. From such experiments we learn that the first layer is far more sensitive than the third, as pruning 99% of the parameters from the first layer reduces the Top1 accuracy by around 85% (i.e., reduced to hardly above 10%), but doing so on the third layer only slightly degrades the accuracy by 3%.
Then we show the resulting layer-wise non-zero ratio of the GSM-pruned models (125× pruned LeNet-5 and 6.6× pruned DenseNet-40, as presented in Table. 1, 2) as another proxy for sensitivity, of which the curves are labeled as "GSM discovered" in Fig. 2. As the two curves vary in the same    tendency across layers as others, we find out that the sensitivities measured in the two proxies are closely related, which suggests that GSM automatically decides to prune the sensitive layers less (e.g., the 14th, 27th and 40th layer in DenseNet-40, which perform the inter-stage transitions [27]) and the insensitive layers more in order to reach the desired global compression ratio, eliminating the need for heavy human works to tune the sparsity ratios as hyper-parameters.

Momentum for accelerating parameter zeroing-out
We investigate the role momentum plays in GSM by only varying the momentum coefficient β and keeping all the other training configurations the same as the 8× pruned DenseNet-40 in Sect. 4.1. During training, we evaluate the model both before and after pruning every 8000 iterations (i.e., 10.24 epochs). We also present in Fig. 3 the global ratio of parameters with magnitude under 1 × 10 −3 and 1 × 10 −4 , respectively. As can be observed, a large momentum coefficient can drastically increase the ratio of small-magnitude parameters. E.g., with a target compression ratio of 8× and β = 0.98, GSM can make 87.5% of the parameters close to zero (under 1 × 10 −4 ) in around 150 epochs, thus pruning the model causes no damage. And with β = 0.90, 400 epochs are not enough to effectively zero the parameters out, thus pruning degrades the accuracy to around 65%. On the other hand, as a larger β value brings more rapid structural change in the model, the original accuracy decreases at the beginning but increases when such change becomes stable and the training converges.

GSM for implicit connection reactivation
GSM implicitly implements connection rewiring by performing activation selection at each iteration to restore the parameters which have been wrongly penalized (i.e., gone through at least one passive update). We investigate the significance of doing so by pruning DenseNet-40 by 8× again using β = 0.98 and the same training configurations as before but without re-selection. Concretely, we use the mask matrices computed at the first iteration to guide the updates until the end of training. The training loss and accuracy evaluated both before and after 8× pruning every 8000 iterations are shown in Fig. 4. It is observed that if re-selection is canceled, the training loss becomes higher, and the accuracy is degraded. This is because the first selection decides to eliminate some connections which are not critical for the first iteration but may be important for the subsequent input examples. Without re-selection, GSM insists on zeroing out such parameters, leading to lower accuracy. And by depicting the reactivation ratio of GSM training process (i.e., the ratio of the number of connections  which switch from passive to active to the total number of connections) at the re-selection of each training iteration, we learn that reactivation happens on a minority of the connections, and the ratio decreases gradually, such that the training converges and the desired sparsity ratio is obtained.

GSM for better winning lottery tickets
A recent work [15] reported that the parameters which are found to be important after training are actually important at the very beginning (after random initialization but before training), which are referred to as the winning tickets, because they have won the initialization lottery. We found out that GSM can be used as a more powerful method to find the winning tickets.
Frankle and Carbin [15] discovered that if we 1) randomly initialize a network parameterized by Θ 0 , 2) train and obtain Θ, 3) prune some parameters based on the properties of Θ resulting in a subnetwork parameterized by Θ , 4) find the winning ticket parametersΘ in the initialized model Θ 0 which reside in the positions corresponding to Θ , 5) trainΘ only, and remove the other parameters, we may attain a comparable level of accuracy with the trained-then-pruned model Θ . In that work, the third step is accomplished by simply preserving the parameters with the largest magnitude. In our experiments, we found out that GSM can find a better set of winner tickets than the original simple magnitude-based method. Concretely, we only replace step 3 by a pruning process via GSM, and use the resulting non-zero parameters as Θ , and all the other experimental settings are kept the same for comparability. On LeNet-300-100 with a compression ratio of 60×, finding winning tickets by the original magnitude criterion and GSM delivers a final accuracy of 96.85% v.s. 97.36% after step 5. On LeNet-5 with a compression ratio of 300×, the accuracies of the two methods are 97.94% v.s. 99.04%. More experimental details can be found in the codes.
Two possible explanations to this phenomenon are that 1) GSM distinguishes the unimportant parameters by activation selection much earlier (at each iteration) than the magnitude-based criterion (after training), and 2) GSM decides the final winning tickets in a way that is robust to mistakes (i.e., via activation re-selection). The intuition is that since we expect to find the parameters that have "won the initialization lottery", the timing when we make the decision should be closer to when the initialization takes place, and we wish to correct the mistakes immediately when we are aware of the wrong decisions. Frankle and Carbin also noted that it might bring benefits to prune as early as possible [15], which is precisely what GSM does, as GSM keeps pushing the unimportant parameters continuously to zero from the very beginning.

Conclusion
Aiming at a desired global compression ratio, we seek to prune a DNN via a learning process. We proposed Global Sparse Momentum SGD (GSM) to directly alter the gradient flow for DNN pruning, where the key is to split the ordinary momentum-SGD-based update into two parts: active update uses the gradients derived from the objective function to maintain the model's accuracy, and passive update only performs momentum-accelerated weight decay to push the redundant parameters infinitely close to zero. GSM is characterized by end-to-end training, easy implementation, lossless pruning, implicit connection rewiring, the ability to automatically discover the appropriate per-layer sparsity ratios in modern very deep neural networks and the capability to find powerful winning tickets.