A post-training pruning method for neural networks
By using the evolutionary search algorithm that reduces regrowth and the attenuation-based loss to optimize the sparse structure in the neural network, the problem of performance loss of the post-training sparse method under high sparsity rates is solved, and high accuracy and stability after pruning are achieved. , superior to existing technology.
Patent Information
- Application Number
- CN202410661740.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-27
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2044-05-27
AI Technical Summary
Existing post-training sparse methods show performance loss at high sparsity rates. Especially at 90% sparsity, the accuracy of sparse networks even collapses to random levels, and it is difficult to effectively restore performance in constrained scenarios with limited data.
An evolutionary search algorithm that reduces regrowth is used to determine the optimal sparsity rate of the neural network, and the sparse structure is optimized through attenuation-based loss and dynamic sparse training, combined with weight amplitude as an importance assessment, and the sparse mask is gradually adjusted to achieve post-pruning Performance recovery.
It significantly improves the accuracy of the neural network after pruning, especially under high sparsity rates, it can maintain high performance stability and accuracy, is better than traditional methods, and performs superior in multiple benchmark tests.
Smart Images

Figure CN118246510B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of neural network, and in particular to a post-training pruning method of a neural network. Background Art
[0002] In recent years, deep neural networks have achieved great success in various application fields such as image recognition, object detection, and semantic segmentation. As deep neural networks flourish in various machine learning applications, the scale of neural networks is getting larger and larger, requiring a lot of computing resources and storage space. For example, networks such as ResNet50 have more than 25 million parameters, and VGG16 has more than 138 million weights. The excellent performance of deep neural networks is largely driven by the increased number of parameters and computations. This also leads to a large amount of computational overhead in the operation of neural networks, which limits their application in resource-constrained scenarios such as mobile devices and embedded devices. Therefore, neural network compression has emerged. Researchers have invested a lot of effort in developing neural network compression algorithms, including model quantization, network sparsity, and knowledge distillation. Although these methods perform well in reducing the number of parameters of deep neural networks, they usually require retraining the model through a large training set to restore the performance of the compressed model. However, this requirement will be very demanding in the context of constraints with less available data. To avoid this problem, researchers have developed post-training compression methods that can efficiently fine-tune compressed deep neural networks using a calibration set, which is a much smaller data set than the training set. To date, the most significant progress in post-training compression methods has been around post-training quantization, which has achieved performance comparable to 32-bit full-precision models in 8-bit settings.
[0003] Compared with post-training quantization, post-training sparsity has received relatively less attention, but it is as important as quantization in compressing deep neural networks.
[0004] For a specific layer in a pre-trained deep neural network, the output Y is calculated using the layer weights W and the input X:
[0005]
[0006] Network sparseness can be regarded as multiplying a binary mask M on W, where the 0 element indicates the pruning of the weight at the corresponding position, and vice versa, the weight at the corresponding position is retained. Therefore, the output of this layer after pruning can be expressed as:
[0007]
[0008] Unfortunately, the network usually suffers from significant performance degradation after pruning. Therefore, it is a common practice to fine-tune the sparse network by training set. However, this not only requires a large amount of training data, but also incurs significant training cost.
[0009] A recently proposed post-training sparsification method, POT, provides a baseline method for post-training sparsification. POT achieves performance recovery in post-training scenarios by minimizing the mean squared error loss of the output activation values of the sparse model and the dense model layer by layer. Although the performance of the sparse network can be maintained at a moderate pruning rate, such as 50%, POT suffers from severe performance loss at high sparsity rates, especially at 90% sparsity, and the accuracy of the sparse network even collapses to a random level, while traditional sparse methods on the full dataset can still maintain the same performance as the original model in this case. Therefore, how to better utilize a small amount of data in post-training sparsification to maintain the performance of sparse networks remains an unsolved problem to date. Summary of the invention
[0010] In view of the problems existing in the prior art, the object of the present invention is to provide a post-training pruning method for a neural network, which can effectively improve the accuracy of the neural network after pruning.
[0011] To achieve the above object, the technical solution adopted by the present invention is:
[0012] A post-training pruning method for a neural network comprises the following steps:
[0013] Step 1: Determine the optimal sparsity rate of the neural network using a reduced regrowth evolutionary search algorithm; Step 1 is specifically as follows:
[0014] Introducing a new initial sparsity rate for each layer of a dense neural network and , is the global sparsity rate; at this time, the search target is from the sparse neural network The weights are transformed into the overly sparse The weights are restored; then an evolutionary algorithm is used to search for the ratio of each layer that needs to be restored, specifically, defined as the recovery rate of each layer , in each iteration, all individuals are evaluated, and the first k individuals are selected as parents according to fitness; in order to generate the next generation population, the crossover operation is used to randomly exchange the recovery rates of some layers between the two parents, and the mutation operation randomly changes the recovery rates of some layers; by repeating the above process, the optimal recovery rate distribution is obtained; and then by Subtract the recovery rate of each layer , we can get the optimal sparseness rate of this layer .
[0015] Step 2: Using the weight amplitude as the importance evaluation, and according to the optimal sparsity rate determined in step 1, determine the sparse neural network; then input the training sample into the sparse neural network to obtain the sparse output result;
[0016] Step 3: Input the training samples into the dense neural network to obtain dense output results;
[0017] Step 4: Calculate the attenuation-based loss based on the sparse output results and the dense output results;
[0018] Step 5: Update the weights of the sparse network in reverse according to the attenuation-based loss, then determine the pruning mask based on the sparse rate of the neural network and the updated weights, and prune the sparse network based on the mask to obtain a new sparse network;
[0019] Step 6: Input the training samples into the new sparse neural network to obtain sparse output results, and repeat steps 4-6 until the preset training number or stop condition is reached, completing the post-training pruning of the neural network.
[0020] In step 4, the attenuation-based loss is as follows:
[0021]
[0022] in, Respectively represent The probability distribution of samples obtained by dense neural network and sparse neural network, represents the natural logarithm, represents the hyperparameter that controls the degree of attenuation, t represents the number of training iterations, and C represents the batch size.
[0023] In step 5, based on the attenuation-based loss, the weight gradient is obtained using the gradient pass-through estimator, and then the gradient is updated to obtain the first Layer weights ;
[0024] The weight gradient is as follows:
[0025]
[0026] in, represents the output of the sparse neural network at layer l, is the pruning mask, is the loss based on attenuation.
[0027] In step 5, the pruned mask The calculation formula is:
[0028]
[0029] in, Indicates the sparsity of the weight matrix (i, j) of the lth layer, 1 means retention, 0 means sparse; It means to calculate the largest number in a. represents the number of parameters of this layer, Represents the value of the weight matrix of the lth layer of the neural network at the (i, j) position.
[0030] After adopting the above scheme, the present invention adopts an evolutionary search algorithm that reduces regrowth to determine the optimal sparsity rate of the neural network; then uses a sparse target that promotes the sparse network to learn effective knowledge from the dense network to learn the sparse neural network; finally, based on the above two factors, combined with dynamic sparse training to comprehensively optimize the sparse structure, ensure the stability of training, and at the same time improve the accuracy of the pruned sparse network. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 is a flow chart of the method of the present invention;
[0032] Figure 2 It is a principle block diagram of the present invention;
[0033] Figure 3 Schematic diagram of image classification performance of sparse network on ImageNet-1K;
[0034] Figure 4 Schematic diagram of the performance of the sparse network on the target detection task at 90% sparsity rate. DETAILED DESCRIPTION
[0035] like Figure 1 and Figure 2 As shown, the present invention discloses a post-training pruning method for a neural network, which comprises the following steps:
[0036] Step 1: Determine the optimal sparsity rate of the neural network using the reduced-regrowth evolutionary search algorithm.
[0037] assumed Represented as the weight parameter of an L-layer dense neural network, represents the sparse distribution that should be followed when the weight of the dense neural network is sparse, where Indicates The sparse rate of the layer. Evolutionary algorithms usually randomly initialize a set of sparse distributions, each of which has an indicator for measuring the performance of the sparse network corresponding to its sparse distribution, called the fitness score. The core of the evolutionary algorithm is to continuously evolve from these initial sparse distributions through a series of crossover and mutation operations, and finally select the sparse rate distribution with the best performance.
[0038] Although these methods have been successful in traditional sparsity, they will encounter problems when directly applied to post-training sparsity: since the sparsity rate of each layer is an arbitrary real number between [0,1], the search space of sparse distribution is quite large. How to ensure that each candidate sparse distribution can meet the expected global sparsity rate? This is a challenge. To solve this problem, the present invention adopts an over-pruning and re-growing strategy to ensure that each candidate sparse distribution meets the global sparse rate requirement. Specifically, the present invention introduces a new initial sparse rate for each layer. and , at this time the search target is from the sparse neural network The weights are transformed into the overly sparse The weights are restored (that is, converted into weights in the sparse neural network). Then, the evolutionary algorithm can be used to search for the ratio of each layer to be restored. It is easy to know that the global recovery rate is .
[0039] Specifically, the individuals in the evolutionary algorithm are defined as the recovery rate of each layer , the fitness of an individual means the task performance of the dense neural network under the corresponding recovery rate distribution. In each iteration, all individuals are evaluated, and the first k individuals are selected as parents according to the fitness. In order to generate the next generation of population, the crossover operation is used to randomly exchange the recovery rates of some layers between the two parents, while the mutation operation randomly changes the recovery rates of some layers. By repeating the above process, the optimal recovery rate distribution can be obtained. Then by Subtract the recovery rate of each layer , the final sparseness rate of this layer can be obtained .
[0040] Step 2: Use the weight amplitude as the importance assessment, and determine the sparse neural network based on the optimal sparsity rate determined in step 1; then input the training sample into the sparse neural network to obtain a sparse output result.
[0041] Step 3: Input the training samples into the dense neural network to obtain dense output results.
[0042] Step 4: Calculate the attenuation-based loss based on the sparse output results and the dense output results.
[0043] This step 4 is to calibrate the density of knowledge transferred from the dense network to the sparse network to avoid a sudden performance drop at high sparsity rates.
[0044] The supervision strength of KL divergence is related to the base of the log operation. For the case of high sparsity, it is considered that: in the early stages of training, there is a huge gap between dense output and sparse output, which drives the instability of training; as training progresses, the goal of learning from a dense network causes the KL loss to drop rapidly, however, this brings very small gradients, which in turn leads to insufficient training, and it becomes challenging to recover from the optimized sparsified weights. That is, at high sparsity rates, it is very difficult to require element-by-element alignment, and this deviation will be further exacerbated as the number of layers increases. Therefore, the present invention proposes to attenuate the base of the log operation throughout the training process to adjust the loss scale, and the attenuation-based loss is obtained as follows:
[0045]
[0046] in Respectively represent The probability distribution (i.e. output result) of samples obtained by dense neural network and sparse neural network is represents the natural logarithm, represents the hyperparameter that controls the degree of attenuation, t represents the number of training iterations, and C represents the batch size.
[0047] Step 5: Update the weights of the sparse network in reverse based on the attenuation-based loss, then determine the pruning mask based on the sparsity rate of the neural network and the updated weights, and prune the sparse network based on the mask to obtain a new sparse network.
[0048] Based on the attenuation-based loss, the gradient pass-through estimator is used to obtain the weight gradient, and then the gradient is updated to obtain the first Layer weights .
[0049] The weight gradient is as follows:
[0050]
[0051] in, Represents the output of the sparse neural network at layer l.
[0052] The dynamic sparse training method is used to complete the sparseness and regrowth of network weights after a certain training interval to explore the sparse structure. However, under the limitation of the limited amount of post-training sparse data, the gradient is not reliable in measuring the importance of weights. Therefore, the present invention directly uses the weight size as the metric for sparseness and regrowth. According to the Layer weights and the corresponding sparsity rate , during training the mask The calculation formula is:
[0053]
[0054] in, Indicates the sparsity of the weight matrix (i, j) of the lth layer, 1 means retention, 0 means sparse; It means to calculate the largest number in a. represents the number of parameters of this layer, Represents the value of the weight matrix of the lth layer of the neural network at position (i, j).
[0055] Step 6: Input the training samples into the new sparse neural network to obtain sparse output results, and repeat steps 4-6 until the preset training number or stop condition is reached, completing the post-training pruning of the neural network.
[0056] In summary, the present invention adopts an evolutionary search algorithm with reduced regrowth to determine the optimal sparsity rate of the neural network; then the sparse neural network is learned using a sparse objective that promotes the sparse network to learn effective knowledge from a dense network; finally, based on the above two factors, dynamic sparse training is combined to comprehensively optimize the sparse structure, ensure the stability of the training, and improve the accuracy of the pruned sparse network.
[0057] For the convenience of comparison, the experimental settings of the present invention follow the POT experimental settings, which include image classification using CNN on ImageNet-1K and object detection using Faster-RCNN and SSD on PASCAL VOC. For the image classification task, the present invention uses 10240 images randomly selected from the ImageNet-1K training set to form a calibration set to train sparse ResNet-18 / 50 and MobileNet-V2. For ResNet-18 / 50, the initial learning rate is 0.01 and the weight decay is 1×10−4. For MobileNet-V2, the initial learning rate is 0.05 and the weight decay is 4×10−5.
[0058] For object detection, the present invention uses VGGNet-16 as the backbone network of Faster-RCNN and MobileNet-V1 as the backbone network of SSD. 10240 images are randomly selected from the VOC2007 training set and the VOC2012 training set to form the calibration set. The sparse network is trained with a 16000 learning rate scheduling strategy using a stochastic gradient descent optimizer, and the batch size is set to 64 iterations. In all experiments, the cosine learning rate is used.
[0059] The present invention can be applied to neural network pruning compression to achieve compression and acceleration of neural networks. First, the present invention shows the quantitative results of various methods of pruning networks in image classification tasks. Figure 3As described in, in contrast, the present invention (UniPTS) consistently outperforms POT in all settings, and the accuracy gap widens as the sparsity rate increases. For example, the present invention (UniPTS) is able to improve the accuracy of POT from only 3.9% to 68.60%, and the accuracy of MobileNet-V2 from 0.2% to 42.46% at a sparsity rate of 90%. In addition, UniPTS is compared with traditional sparse methods in a post-training scenario. UniPTS consistently outperforms traditional methods at all sparsity rates. The low performance of STR emphasizes that traditional differentiable training for sparse distributions is impractical in post-training sparse scenarios with limited data, thereby supporting the design of the present invention of over-sparse-regrowth sparse distributions. In addition, results from RigL show the importance of dynamic sparse training for post-training sparsity at high sparsity rates, further supporting the sparse training design.
[0060] The present invention also tests the generalization ability of UniPTS in the target detection task. Figure 4 As shown, Figure 4 The performance of UniPTS and POT on sparse Faster-RCNN and SSD on PASCAL VOC is compared with 90% sparsity. It is worth noting that UniPTS achieves a robust performance improvement of 3.3 and 3.4 mAP when pruning Faster-RCNN and SSD, respectively. Given these good results, the robustness and effectiveness of UniPTS in visual tasks are demonstrated.
[0061] As mentioned above, the method proposed in the present invention is verified to be much superior to the existing PTS method in a wide range of benchmark tests. As an example, when the sparsity rate of ResNet50 is pruned to 90% on ImageNet, the performance of the POT method is improved from 3.9% to 68.6%.
[0062] The above description is merely an embodiment of the present invention and does not limit the technical scope of the present invention. Therefore, any minor modifications, equivalent changes and modifications made to the above embodiments based on the technical essence of the present invention are still within the scope of the technical solution of the present invention.
Claims
1. A post-training pruning method for a neural network, characterized in that: The following steps are involved: Step 1: Determine the optimal sparsity rate of the neural network using a reduced regrowth evolutionary search algorithm; Step 1 is specifically as follows: Introducing a new initial sparsity rate for each layer of a dense neural network and , is the global sparsity rate; at this time, the search target is from the sparse neural network The weights are transformed into weights in the restored sparse neural network; then an evolutionary algorithm is used to search for the ratio of each layer that needs to be restored, specifically, defined as the recovery rate of each layer , where L represents the number of layers in the neural network, and l represents the lth layer of the neural network; in each iteration, all individuals are evaluated, and the first k individuals are selected as parents according to fitness; in order to generate the next generation of population, the crossover operation is used to randomly exchange the recovery rates of some layers between the two parents, and the mutation operation randomly changes the recovery rates of some layers; by repeating the above process, the optimal recovery rate distribution is obtained; and then by Subtract the recovery rate of each layer , we can get the optimal sparseness rate of this layer ; Step 2, using the weight amplitude as an importance assessment, and determining a sparse neural network according to the optimal sparsity rate determined in step 1; then inputting the training sample into the sparse neural network to obtain a sparse output result; the training sample is an image training sample; Step 3: Input the training samples into the dense neural network to obtain dense output results; Step 4: Calculate the attenuation-based loss based on the sparse output results and the dense output results; Step 5: Update the weights of the sparse neural network in reverse according to the attenuation-based loss, then determine the pruning mask based on the sparsity rate of the neural network and the updated weights, and prune the sparse neural network based on the mask to obtain a new sparse neural network; Step 6: Input the training samples into the new sparse neural network to obtain sparse output results, and repeat steps 4-6 until the preset training number or stop condition is reached, completing the post-training pruning of the neural network.
2. A post-training pruning method for a neural network according to claim 1, characterized in that: In step 4, the attenuation-based loss is as follows: in, Respectively represent The probability distribution of samples obtained by dense neural network and sparse neural network, represents the natural logarithm, represents the hyperparameter that controls the degree of attenuation, t represents the number of training iterations, and C represents the batch size.
3. A post-training pruning method for a neural network according to claim 2, characterized in that: In step 5, based on the attenuated loss, the weight gradient is obtained using the gradient pass-through estimator, and then the gradient is updated to obtain the first Layer weights ; The weight gradient is as follows: in, represents the output of the sparse neural network at layer l, is the pruning mask, is the loss based on attenuation.
4. A post-training pruning method for a neural network according to claim 3, characterized in that: In step 5, the pruned mask The calculation formula is: in, Indicates the sparsity of the weight matrix (i, j) of the lth layer, 1 means retention, 0 means sparse; It means to calculate the largest number in a. represents the number of parameters of this layer, Represents the value of the weight matrix of the lth layer of the neural network at the (i, j) position.
