Neural network channel pruning method based on improved metapruning

By constructing a meta-network and evolutionary algorithm to optimize the pruning network, the problem of imbalance between accuracy and FLOPs in the MetaPruning method is solved, and efficient neural network pruning is achieved in a resource-constrained environment. The generated pruning network can be used under different constraints. Balance accuracy with computational effort.

WO2024174310A1PCT designated stage expired Publication Date: 2024-08-29SHANDONG INSPUR SCI RES INST CO LTD

Patent Information

Application Number
PCT/CN2023/082119
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-02-23
Filing Date
2023-03-17
Publication Date
2024-08-29

AI Technical Summary

Technical Problem

Existing MetaPruning methods cannot effectively balance the relationship between accuracy and FLOPs in pruned networks, resulting in no appropriate balance between sacrificing accuracy and reducing computational complexity.

Method used

By constructing a meta-network, a pruned network that satisfies different constraints is generated, and an evolutionary algorithm is used to search for the optimal network. Combined with mutation and crossover operations, the accuracy and FLOPs parameters of the pruned network are optimized, and FLOPs are replaced with a balance between accuracy and computational effort. Parameters to realize the generation of multiple pruning networks of the model under different constraints.

Benefits of technology

It achieves a significant reduction in model FLOPs while maintaining model accuracy, solving the problem of imbalance in accuracy and FLOPs in the original MetaPruning method. The generated pruning network can better adapt to resource-constrained systems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2023082119_29082024_PF_FP_ABST
    Figure CN2023082119_29082024_PF_FP_ABST
Patent Text Reader

Abstract

The present invention belongs to the technical fields of artificial intelligence and model compression. Provided is a neural network channel pruning method based on improved MetaPruning. The method comprises: (1) selecting a neural network model and accordingly training a meta-network, randomly selecting the number of channels as an input, taking an output result as a post-pruning weight of an original network, also constructing a pruning network, and making the width of an output channel in each layer equal to an element in a network coding vector, thereby obtaining a pruning network; (2) inputting a batch of data, calculating the loss of the generated pruning network, and updating a parameter of the meta-network; (3) repeatedly iterating steps 1 and 2 to obtain several pruning networks; (4) selecting pruning networks that meet a constraint condition, calculating the precision thereof, and selecting the top k networks; (5) coding the selected networks, and calculating a balance parameter between the precision thereof and FLOPs; and (6) using an evolutionary algorithm to perform an optimal network search. The problem of the precision and FLOPs being unbalanced can be solved.
Need to check novelty before this filing date? Find Prior Art

Description

A neural network channel pruning method based on improved MetaPruning Technical Field

[0001] The present invention relates to the field of artificial intelligence and model compression technology, and in particular to a neural network channel pruning method based on improved MetaPruning. Background Art

[0002] With the continuous advancement of neural networks, modern deep learning is pushing the boundaries of artificial intelligence with increasingly complex models. However, the costs of these models are skyrocketing in terms of data, energy, memory, computing power, and training time. Consequently, these deep learning neural network models are typically deployed on cloud servers. However, with the development of edge computing, an increasing number of inference tasks are being moved to the edge of the network. Despite the tremendous success of large deep models, they remain difficult to implement in resource-constrained systems, such as edge devices and embedded systems. To address this imbalance, model pruning technology has emerged.

[0003] Model pruning involves removing redundant weights from a model. Based on the granularity of pruning, model pruning can be categorized as either structured or unstructured. Unstructured pruning removes unimportant neurons. Consequently, the connections between the pruned neurons and other neurons are ignored during computation. While unstructured pruning can significantly reduce the number of model parameters and theoretical computational complexity, it cannot be accelerated by existing hardware architectures, resulting in no actual improvement in running speed. Acceleration requires specialized hardware design. In contrast to unstructured pruning, structured pruning typically operates on a filter or channel basis. When a filter is pruned, both the previous and next feature maps undergo corresponding changes, but the model's structure remains intact, allowing it to be accelerated using GPUs or other hardware. This approach is therefore referred to as structured pruning.

[0004] Channel pruning, as a neural network pruning method, has been widely recognized for its effectiveness and is widely used in industry. A classic pruning method consists of three steps: 1) training a large network with too many parameters; 2) pruning unimportant weights or channels; and 3) fine-tuning or retraining the pruned network. The second stage is critical and typically relies on iterative layer-by-layer pruning, fast fine-tuning, or weight reconstruction to maintain accuracy. MetaPruning is a meta-learning method for channel pruning. Its core idea is to learn a meta-network to generate weights for different pruned structures, thereby obtaining multiple pruned networks under different constraints. Compared to traditional pruning methods, MetaPruning eliminates the cumbersome manual tuning of hyperparameters and directly optimizes the desired metric. However, MetaPruning only finds the highest-accuracy pruned network within a predetermined FLOPs range, rather than attempting to find the appropriate balance between sacrificing accuracy and reducing FLOPs.

[0005] Summary of the Invention

[0006] In order to solve the above technical problems, the present invention provides a neural network channel pruning method based on improved MetaPruning.

[0007] The technical solution of the present invention is:

[0008] A neural network channel pruning method based on improved MetaPruning, the steps are as follows:

[0009] (1) A neural network model is selected and a meta-network is trained based on it. The number of channels is randomly selected as input, and the output result is used as the weight of the original network after pruning. At the same time, a pruned network is constructed, and the output channel width in each layer is made equal to the elements in the network encoding vector, thus obtaining a pruned network.

[0010] (2) Input a batch of data, calculate the loss of the generated pruned network and update the parameters of the meta-network;

[0011] (3) Repeat iterations 1 and 2 to obtain several pruned networks;

[0012] (4) Select the pruned network calculator accuracy that meets the constraints and select the top k networks;

[0013] (5) Encode the selected network and calculate the balance parameter between its accuracy and FLOPs;

[0014] (6) Use evolutionary algorithms to search for optimal networks.

[0015] Further,

[0016] In step S1, the MetaPruning algorithm is used to automatically prune channels in the deep neural network, and the pruned network can meet different constraints.

[0017] In step S1, the meta-network is a two-layer fully connected layer network (FC layer). In the forward propagation, its input is the network's encoding vector, that is, the output channel width of each layer; during training, the number of channels is randomly selected for input, and then the output result of the fully connected layer is used as the weight of the original network after pruning; at the same time, a pruned network is constructed, and the output channel width in each layer is equal to the elements in the network encoding vector, that is, the generated weight matrix is ​​pruned to match the number of input and output channels in the pruned network, thus obtaining a pruned network.

[0018] In step S2, the gradient of the weights in the meta-network is calculated by the chain rule. In each iteration, the network encoding vector is randomized, and the meta-network generates weights by taking the vector as input. The parameter values ​​of the meta-network are adjusted in each iteration. The meta-network can learn to generate different weights for various pruned networks.

[0019] In step S4, the corresponding weights of the generated pruned networks are evaluated on the validation set to obtain the accuracy of each possible pruned network; each pruned network is encoded into a vector containing the number of channels in each layer, called the "gene of the pruned network"; first, several genes are randomly selected and the accuracy of the corresponding pruned network is obtained through evaluation.

[0020] In step S5, the k genes with the highest accuracy are selected to generate new genes using mutation and crossover. Mutation is achieved by randomly changing the ratio of elements in a gene, and crossover is achieved by randomly recombining genes from two parental genes to produce offspring. After multiple iterations of this process, genes that meet the constraints and achieve the highest accuracy are obtained.

[0021] MetaPruning uses evolutionary search while respecting any soft or hard constraints.

[0022] MetaPruning evolution, that is, the last element of the candidate gene in the original MetaPruning algorithm is replaced by FLOPs to the parameter R(G i ) to balance its accuracy and FLOPs;

[0023] Among them, G i Represents the index in the candidate gene; this parameter replaces the last element FLOPs of the candidate gene in the original MetaPruning algorithm, stores the first 50 pruned networks of each iteration, and then mutates and crosses the best 10 of them to obtain the candidate gene for the next iteration.

[0024] The beneficial effects of the present invention are

[0025] Weights can be generated for different pruned structures, thereby obtaining a variety of pruned networks under different constraints. Compared with the pruning method without improved MetaPruning, this can solve the problem of imbalanced accuracy and FLOPs in the resulting pruned networks. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] Figure 1 is a schematic diagram of a pruning network generated by MetaPruning;

[0027] Figure 2 is a flow chart of the evolutionary algorithm;

[0028] FIG3 is a parameter replacement flow chart;

[0029] FIG4 is a schematic diagram of the workflow of the present invention. DETAILED DESCRIPTION

[0030] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0031] The present invention provides a deep learning neural network pruning method based on meta-pruning to solve the problems encountered in the above background technology. While taking into account the accuracy of the model, it can also reduce the FLOPs of the model. As shown in Figure 1, it includes the following steps:

[0032] S1. Train a meta-network to predict pruned networks of different structures.

[0033] S2, back propagation calculates the loss and updates the weight value in the meta-network;

[0034] S3, repeat S1 and S2 to obtain several pruned networks;

[0035] S4. Select candidate networks based on constraints and evaluate their accuracy;

[0036] S5. Perform optimal network search based on evolutionary algorithm.

[0037] In step S1, MetaPruning can automatically prune the channels in the deep neural network, and the pruned network can meet different constraints. This channel pruning problem can be expressed as the following formula:

[0038] Where L represents Loss, A represents the network with different number of channels, c i Represents the number of channels in layer i. Constraints can be model size, computational complexity, etc. The constraint used in this patent is FLOPs, which means that the number of channels in the network is minimized as much as possible while keeping the computational complexity below a certain level.

[0039] In step S1, the meta-network consists of two fully connected layers (FC layers). During forward propagation, its input is the network's encoding vector, i.e., the output channel width of each layer, corresponding to the "network encoding vector" in Figure 1 below. During training, the number of channels is randomly selected for input (for example, for a 3-layer CNN network: the input is [3, 5, 12] or [32, 24, 14], etc.). The output of the fully connected layer is then used as the pruned weights of the original network. Simultaneously, a pruned network is constructed, with the output channel width of each layer equal to the elements in the network encoding vector. In other words, the generated weight matrix is ​​pruned to match the number of input and output channels in the pruned network, resulting in a pruned network.

[0040] In step S2, given a batch of input images, the loss of the pruned network with generated weights is calculated. During backpropagation, instead of updating the weights of the pruned network, the gradient of the meta-network weights is calculated. Since the reshape and convolution operations between the output of the meta-network's fully connected layer and the output of the previous convolutional layer of the pruned network are also differentiable, the gradient of the meta-network weights can be calculated using the chain rule, as shown in Figure 1. In each iteration, the network encoding vector is randomized. The meta-network generates weights by taking the vector as input. By adjusting the meta-network parameter values ​​in each iteration, the meta-network learns to generate different weights for various pruned networks.

[0041] In step S4, the corresponding weights of the generated pruned networks are evaluated on the validation set to obtain the accuracy of each possible pruned network. Each pruned network is encoded as a vector containing the number of channels per layer, called the "gene of the pruned network." Under strict constraints, multiple genes are first randomly selected and evaluated to obtain the accuracy of the corresponding pruned network.

[0042] In step S5, the top k genes by accuracy are selected to generate new genes using mutation and crossover. Mutation is achieved by randomly changing the ratio of elements within a gene, and crossover is achieved by randomly recombining genes from two parental genes to produce offspring. After multiple iterations of this process, genes that satisfy the constraints while achieving the highest accuracy are obtained. Due to the large number of network encoding vectors, MetaPruning uses evolutionary search to find a pruned network with high accuracy under the constraints, while taking into account any soft or hard constraints. Figure 2 shows the flowchart of the MetaPruning evolutionary algorithm.

[0043] In the original MetaPruning algorithm, the constraint is the FLOPs of the pruned network. If the model's FLOPs is between the maximum and minimum FLOPs, the gene encoded by it is considered valid. The FLOPs of each gene are stored as the last element to reduce the overall computation time.

[0044] However, this method cannot balance the pros and cons between the model's FLOPs and accuracy. Therefore, this patent proposes an improved method that can enable the model to have lower FLOPs while taking into account the model's accuracy.

[0045] In step S3, this patent replaces the last element of the candidate gene in the original MetaPruning algorithm from FLOPs to the parameter R(G i ) to balance its accuracy and FLOPs. The calculation formula of this parameter is as follows, ɑ is the accuracy coefficient, and Ψ is the computational FLOPs coefficient. i )=α(G i ,b a )×ψ(G i ,b f ) (Formula 2)

[0046] Among them, G i represents the index of the candidate gene, A and F are the accuracy and FLOPs of the model for creating the gene, respectively, b a and b f The accuracy and FLOPs of the base model (i.e., the model without pruning). This parameter replaces the last element FLOPs in the candidate gene list in the original MetaPruning algorithm. The first 50 pruned networks of each iteration are stored, and the top 10 are then mutated and crossovered to obtain candidate genes for the next iteration. The flowchart is shown in Figure 3.

[0047] The above description is only a preferred embodiment of the present invention and is only used to illustrate the technical solution of the present invention, and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention are included in the scope of protection of the present invention.

Claims

1. A neural network channel pruning method based on improved MetaPruning, characterized in that: Here are the steps: 1) Select a neural network model and train a meta-network based on it, randomly select the number of channels as input, and use the output result as the weight of the original network after pruning; at the same time, construct a pruned network and make the output channel width in each layer equal to the element in the network coding vector, thus obtaining a pruned network; 2) Input a batch of data, calculate the loss of the generated pruned network and update the parameters of the meta-network; 3) Repeat iterative steps 1) and 2) to obtain several pruned networks; 4) Select the pruning network calculator accuracy that meets the constraints and select the top k networks; 5) Encode the selected network and calculate the balance parameter between its accuracy and FLOPs; 6) Use evolutionary algorithms to search for optimal networks.

2. The method according to claim 1, characterized in that In step S1, the MetaPruning algorithm is used to automatically prune channels in the deep neural network, and the pruned network can meet different constraints.

3. The method according to claim 2, characterized in that In step S1, the meta-network is a two-layer fully connected layer network (FC layer). In the forward propagation, its input is the encoding vector of the network, that is, the output channel width of each layer; During training, the number of channels is randomly selected for input, and then the output of the fully connected layer is used as the weight of the original network after pruning; at the same time, a pruned network is constructed, and the output channel width in each layer is equal to the elements in the network encoding vector, that is, the generated weight matrix is ​​pruned to match the number of input and output channels in the pruned network, thus obtaining a pruned network.

4. The method according to claim 3, characterized in that In step S2, the gradient of the weights in the meta-network is calculated by the chain rule. In each iteration, the network encoding vector is randomized, and the meta-network generates weights by taking the vector as input. By storing the parameter values ​​of the meta-network, the meta-network can learn to generate different weights for various pruned networks.

5. The method according to claim 4, characterized in that In step S4, the corresponding weights of the generated pruned networks are evaluated on the validation set to obtain the accuracy of each possible pruned network; each pruned network is encoded into a vector containing the number of channels in each layer, called the gene of the pruned network; first, several genes are randomly selected and the accuracy of the corresponding pruned network is obtained through evaluation.

6. The method according to claim 5, characterized in that In step S5, the top k genes with the highest accuracy are selected to generate new genes with mutation and crossover. Mutation is achieved by randomly changing the ratio of elements in the gene, and crossover is achieved by randomly recombining the genes in the two parental genes to produce offspring; after several iterations of the above process, genes that meet the constraints can be obtained while achieving the highest accuracy.

7. The method according to claim 6, characterized in that MetaPruning uses evolutionary search while respecting any soft or hard constraints.

8. The method according to claim 7, characterized in that MetaPruning evolution, that is, the last element of the candidate gene in the original MetaPruning algorithm is replaced by the parameter R(G i ) to balance its accuracy and FLOPs; Among them, G i Represents the index in the candidate gene; this parameter replaces the last element FLOPs of the candidate gene in the original MetaPruning algorithm, stores the first 50 pruned networks of each iteration, and then mutates and crosses the best 10 of them to obtain the candidate gene for the next iteration.

Citation Information

Patent Citations

  • Automatic pruning method and platform for convolutional neural network general compression architecture

    CN112396181A

  • Neural network pruning method, medium and electronic equipment

    CN114239826A

  • Apparatus and a method for neural network compression

    WO2020148482A1

Cited By

  • Motion recognition model lightweight method based on hierarchical dynamic fusion network pruning

    CN120471118A

  • Model pruning method for heterogeneous cloud edge-end cooperative system

    CN120806024A

  • Neural network automatic pruning method based on GRPO reinforcement learning

    CN121052319A