Model pruning method and device, and electronic device
By determining the target network layer and sensitivity indicators of parameters in the model, and removing redundant parameters based on a preset pruning rate, the problem of long model pruning time in the prior art is solved, the pruning efficiency is improved and hardware resources are saved.
Patent Information
- Application Number
- CN202111603095.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-24
- Publication Date
- 2026-02-06
- Estimated Expiration
- 2041-12-24
AI Technical Summary
Existing model pruning methods require reasoning through the entire model and retraining, resulting in long pruning times and low efficiency.
By determining the sensitivity indices of the target network layers and their specified parameters in the model to be pruned, and determining the pruning threshold based on the preset pruning rate, parameters with sensitivity indices below the threshold are removed, resulting in the pruned model.
It reduces model pruning time, improves pruning efficiency, saves hardware resources, and enables batch model pruning.
Smart Images

Figure CN115115045B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of model compression, in particular to a model pruning method and device and electronic equipment. BACKGROUND
[0002] At present, with the continuous development of artificial intelligence technology, various models are more and more applied to various fields, for example, image recognition, voice interaction, intelligent security, etc.
[0003] Among them, there may be a large number of redundant parameters in each network layer in the model, so that there may be a large number of neurons with activation values close to 0 in each network layer. Since these neurons have little contribution to the model performance of the model, after removing these neurons, the model has the same model expression ability as the model before removing these neurons. The above situation is called over-parameterization, and the technology of removing the above neurons is called model pruning.
[0004] In order to save the hardware resources occupied by the model, speed up the inference process of the model, and reduce the calculation amount of the model, so as to facilitate the deployment of the model on the embedded end, mobile end, etc., usually, the model pruning can be used to remove the redundant parameters with less contribution to the model performance of the model.
[0005] In related technologies, the method of model pruning is: for a trained model, removing different substructures of the model, and performing structure fine-tuning on the model after removing the substructures, and then selecting the model with the best performance after fine-tuning to retrain to obtain the final pruned model.
[0006] However, in the above related technology, when selecting the model with the best performance after fine-tuning, the entire model needs to be inferred, and the selected model needs to be retrained to obtain the final pruned model, thereby increasing the time of model pruning and reducing the efficiency of model pruning. SUMMARY
[0007] The purpose of the embodiments of the present application is to provide a model pruning method, device and electronic equipment to reduce the time of model pruning and improve the efficiency of model pruning. The specific technical solutions are as follows:
[0008] In a first aspect, the embodiments of the present application provide a model pruning method, which comprises:
[0009] determining each target network layer in a to-be-pruned model;
[0010] determining a sensitivity index corresponding to each specified parameter in each target network layer;
[0011] determine a pruning threshold among the determined sensitivity indicators based on the preset pruning rate of the to-be-pruned model;
[0012] remove each specified parameter in each target network layer corresponding to a sensitivity indicator less than the pruning threshold, to obtain a pruned to-be-pruned model.
[0013] Optionally, in a specific implementation, the method further includes:
[0014] calculate a pruning rate of each target network layer based on a number of specified parameters in each target network layer corresponding to a sensitivity indicator less than the pruning threshold.
[0015] Optionally, in a specific implementation, the preset pruning rate includes:
[0016] a ratio of a number of specified parameters corresponding to a sensitivity indicator less than the pruning threshold to a total number of all specified parameters included in each target network layer.
[0017] Optionally, in a specific implementation, the step of determining a sensitivity indicator corresponding to each specified parameter in each target network layer includes:
[0018] for each target network layer, determining a sensitivity indicator corresponding to each specified parameter in the target network layer based on a reconstruction error of a subsequent network layer of the target network layer when the specified parameter is removed.
[0019] Optionally, in a specific implementation, the step of determining a sensitivity indicator corresponding to each specified parameter in each target network layer based on a reconstruction error of a subsequent network layer of the target network layer when the specified parameter is removed includes:
[0020] for each specified parameter in the target network layer, determining an output result of the subsequent network layer when the specified parameter is removed as an output result corresponding to the specified parameter;
[0021] determining an expected output result of the subsequent network layer, and determining a reconstruction error of the subsequent network layer when each specified parameter is removed based on the expected output result and an output result corresponding to the specified parameter;
[0022] determining a sensitivity indicator corresponding to each specified parameter based on a reconstruction error of the subsequent network layer when the specified parameter is removed.
[0023] Optionally, in a specific implementation, the step of determining an expected output result of the subsequent network layer includes:
[0024] determine a second output result of the post-network layer based on the first output result of the target network layer, and determine an expected output result of the post-network layer based on the second output result;
[0025] alternatively,
[0026] construct the expected output result of the post-network layer based on a task performed by the model to be pruned.
[0027] Optionally, in a specific implementation, the determining of the expected output result of the post-network layer based on the second output result comprises:
[0028] determining the second output result as the expected output result of the post-network layer;
[0029] alternatively,
[0030] correcting the second output result by using a preset algorithm, and determining the corrected second output result as the expected output result of the post-network layer.
[0031] Optionally, in a specific implementation, the determining of the reconstruction error of the post-network layer when the specified parameter is removed based on the expected output result and the output result corresponding to each specified parameter comprises:
[0032] calculating a difference between the expected output result and the output result corresponding to each specified parameter as the reconstruction error of the post-network layer when the specified parameter is removed;
[0033] alternatively,
[0034] calculating a similarity between the expected output result and the output result corresponding to each specified parameter as the reconstruction error of the post-network layer when the specified parameter is removed.
[0035] Optionally, in a specific implementation, before the determining of the sensitivity index corresponding to each specified parameter based on the reconstruction error of the post-network layer when the specified parameter is removed, the method further comprises:
[0036] weighting and correcting the reconstruction error of the post-network layer when each specified parameter is removed based on a task performed by the model to be pruned, to obtain a corrected reconstruction error of the post-network layer when each specified parameter is removed;
[0037] the determining of the sensitivity index corresponding to each specified parameter based on the reconstruction error of the post-network layer when the specified parameter is removed comprises:
[0038] determining the sensitivity index corresponding to each specified parameter based on the corrected reconstruction error of the post-network layer when the specified parameter is removed.
[0039] Optionally, in some embodiments, the to-be-pruned model is a convolutional neural network model, and each target network layer is a convolutional layer and / or a fully connected layer in the to-be-pruned network layer.
[0040] The post-network layer of each target network layer is a next network layer of the target network layer.
[0041] In a second aspect, some embodiments of the present application provide a model pruning device, which comprises:
[0042] A network layer determination module is configured to determine each target network layer in a to-be-pruned model.
[0043] An index determination module is configured to determine a sensitivity index corresponding to each specified parameter in each target network layer.
[0044] A threshold determination module is configured to determine a pruning threshold in the determined sensitivity indexes based on a preset pruning rate of the to-be-pruned model, wherein a ratio of a number of specified parameters with a sensitivity index less than the pruning threshold to a total number of all specified parameters included in each target network layer is the preset pruning rate.
[0045] A model pruning module is configured to remove each specified parameter in each target network layer with a sensitivity index less than the pruning threshold, to obtain a pruned to-be-pruned model.
[0046] Optionally, in some embodiments, the device further comprises:
[0047] A pruning rate calculation module is configured to calculate a pruning rate of each target network layer based on a number of specified parameters in each target network layer with a sensitivity index less than the pruning threshold.
[0048] Optionally, in some embodiments, the preset pruning rate comprises:
[0049] A ratio of a number of specified parameters with a sensitivity index less than the pruning threshold to a total number of all specified parameters included in each target network layer.
[0050] Optionally, in some embodiments, the index determination module comprises an index determination sub-module configured to determine, for each target network layer, a sensitivity index corresponding to each specified parameter in the target network layer based on a reconstruction error of a post-network layer of the target network layer when each specified parameter in the target network layer is removed.
[0051] Optionally, in some embodiments, the index determining submodule comprises: a structure determining unit configured to determine, for each specified parameter in each target network layer, an output result of a post-network layer of the target network layer after removing the specified parameter as the output result corresponding to the specified parameter; an error determining unit configured to determine, for each target network layer, an expected output result of the post-network layer, and determine a reconstruction error of the post-network layer after removing each specified parameter based on the expected output result and the output result corresponding to the specified parameter; and an index determining unit configured to determine, for each target network layer, a sensitivity index corresponding to each specified parameter based on the reconstruction error of the post-network layer after removing the specified parameter.
[0052] Optionally, in some embodiments, the error determining unit comprises: a first determining subunit configured to determine, for each target network layer, a second output result of the post-network layer based on a first output result of the target network layer, and determine an expected output result of the post-network layer based on the second output result; or a second determining subunit configured to construct, for each target network layer, an expected output result of the post-network layer based on a task performed by the to-be-pruned model.
[0053] Optionally, in some embodiments, the first determining subunit is specifically configured to: determine, for each target network layer, the second output result as the expected output result of the post-network layer; or utilize a preset algorithm to correct the second output result, and determine the corrected second output result as the expected output result of the post-network layer for each target network layer.
[0054] Optionally, in some embodiments, the error determining unit is specifically configured to: calculate, for each target network layer, a difference between the expected output result and the output result corresponding to each specified parameter as the reconstruction error of the post-network layer after removing the specified parameter; or calculate, for each target network layer, a similarity between the expected output result and the output result corresponding to each specified parameter as the reconstruction error of the post-network layer after removing the specified parameter.
[0055] Optionally, in an implementation form, the apparatus further comprises an error correction module configured to, for each target network layer, before determining the sensitivity index corresponding to each specified parameter based on the reconstruction error of the subsequent network layer when each specified parameter is removed, perform weighted correction on the reconstruction error of the subsequent network layer when each specified parameter is removed based on the task performed by the to-be-pruned model, to obtain a corrected reconstruction error of the subsequent network layer when each specified parameter is removed; and the index determination unit is specifically configured to: for each target network layer, determine the sensitivity index corresponding to each specified parameter based on the corrected reconstruction error of the subsequent network layer when each specified parameter is removed.
[0056] Optionally, in an implementation form, the to-be-pruned model is a convolutional neural network model, and the target network layers are each convolutional layer and / or each fully connected layer in the to-be-pruned network layers; and the subsequent network layer of each target network layer is a next network layer of the target network layer.
[0057] In a third aspect, an electronic device is provided, which comprises a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory complete communication with each other through the communication bus.
[0058] The memory is configured to store a computer program.
[0059] The processor is configured to execute the program stored on the memory, to implement the steps of any model pruning method provided in the first aspect.
[0060] In a fourth aspect, a computer readable storage medium is provided, which stores a computer program, and the computer program is executed by a processor to implement the steps of any model pruning method provided in the first aspect.
[0061] In a fifth aspect, a computer program product containing instructions is provided, which, when executed on a computer, causes the computer to perform the steps of any model pruning method provided in the first aspect.
[0062] The embodiments of the present application have the following beneficial effects:
[0063] It can be seen from the above that, when pruning the to-be-pruned model, the scheme provided by the embodiments of the present application first determines each target network layer in the to-be-pruned model, and then, for each target network layer, the sensitivity index corresponding to each specified parameter in the target network layer can be determined; thus, based on the preset pruning rate of the to-be-pruned model, the pruning threshold can be determined among the determined sensitivity indexes. In this way, for each target network layer, each specified parameter corresponding to the sensitivity index smaller than the pruning threshold can be removed in the network layer, and the pruned to-be-pruned model is obtained.
[0064] Based on this, when pruning each target network layer in the to-be-pruned model, the scheme provided by the embodiments of the present application can represent the influence of each specified parameter in the target network layer on the subsequent network layer of the target network layer through the sensitivity index corresponding to the specified parameter, so as to evaluate the redundancy degree of the specified parameter according to the influence of the specified parameter on the subsequent network layer of the target network layer, and then determine the specified parameter with higher redundancy degree and smaller contribution to the model performance in the target network layer by using the size relationship between the sensitivity index corresponding to each specified parameter and the pruning threshold determined based on the preset pruning rate. After removing the specified parameters determined above, the pruned model can still have high model performance without the need for training. In this way, the time for model pruning can be reduced, and the efficiency of model pruning can be improved.
[0065] In addition, since the entire model does not need to be inferred, when pruning the to-be-pruned model, the occupation of hardware resources such as CPU (Central Processing Unit) and GPU (Graphics Processing Unit) can be reduced, and hardware resources can be saved. Moreover, since the time for model pruning is reduced, batch model pruning can be more easily realized.
[0066] Of course, implementing any product or method of the present application does not necessarily require all the advantages described above. BRIEF DESCRIPTION OF DRAWINGS
[0067] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed to be used in the embodiments or prior art description will be briefly introduced as follows. Obviously, the drawings in the following description only constitute some embodiments of the present application, and other embodiments can also be obtained by those skilled in the art based on these drawings.
[0068] Figure 1 A flowchart of a model pruning method provided by an embodiment of the present application;
[0069] Figure 2 Another flowchart of a model pruning method provided by an embodiment of the present application is shown in FIG. 6;
[0070] Figure 3 Another flowchart of a model pruning method provided by an embodiment of the present application is shown in FIG. 6;
[0071] Figure 4 A flowchart of a process performed in S102A of FIG. 1 for each target network layer is shown in FIG. 7; Figure 2 A flowchart of a process performed in S102A of FIG. 1 for each target network layer is shown in FIG. 7;
[0072] Figure 5 A flowchart of another process performed in S102A of FIG. 1 for each target network layer is shown in FIG. 8; Figure 2 A flowchart of another process performed in S102A of FIG. 1 for each target network layer is shown in FIG. 8;
[0073] Figure 6 A diagram of the change of reconstruction error of feature points obtained by using a sigmoid algorithm is shown in FIG. 9;
[0074] Figure 7 A structural diagram of a model pruning device provided by an embodiment of the present application is shown in FIG. 10;
[0075] Figure 8 A structural diagram of an electronic device provided by an embodiment of the present application is shown in FIG. 11. DETAILED DESCRIPTION
[0076] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art based on the present application belong to the scope of protection of the present application.
[0077] In the related art, the method of model pruning is as follows: for a trained model, different substructures of the model are removed, and the model after the substructure removal is fine-tuned, then the model with the best performance after fine-tuning is selected for retraining to obtain the final pruned model. However, in the above related art, when the model with the best performance after fine-tuning is selected, the entire model needs to be inferred, and the selected model needs to be retrained to obtain the final pruned model, thereby increasing the time of model pruning and reducing the efficiency of model pruning.
[0078] To solve the above technical problems, an embodiment of the present application provides a model pruning method.
[0079] The method can be applied to any application scenario requiring pruning of a trained model, for example, deploying an image recognition model on a mobile phone, deploying a speech recognition model on an embedded device, etc. The method can be applied to various electronic devices such as notebook computers, desktop computers, servers, etc., hereinafter referred to as electronic devices. The electronic device used to execute the method can be a standalone electronic device or at least one electronic device in a system or device cluster. Therefore, the embodiments of the present application do not specifically limit the application scenario and the execution subject of the method.
[0080] The model pruning method provided by the embodiments of the present application can include the following steps:
[0081] Determine each target network layer in the to-be-pruned model;
[0082] Determine the sensitivity index corresponding to each specified parameter in each target network layer;
[0083] Based on the preset pruning rate of the to-be-pruned model, determine a pruning threshold among the determined sensitivity indexes;
[0084] Remove each specified parameter in each target network layer whose corresponding sensitivity index is less than the pruning threshold, to obtain a pruned to-be-pruned model.
[0085] As can be seen from the above, when pruning the to-be-pruned model, the embodiments of the present application first determine each target network layer in the to-be-pruned model, and then for each target network layer, the sensitivity index corresponding to each specified parameter in the target network layer is determined. Thus, based on the preset pruning rate of the to-be-pruned model, a pruning threshold can be determined among the determined sensitivity indexes. In this way, for each target network layer, each specified parameter in the network layer whose corresponding sensitivity index is less than the pruning threshold can be removed, and a pruned to-be-pruned model is obtained.
[0086] Based on this, when pruning each target network layer in the to-be-pruned model, the influence of each specified parameter in the target network layer on the subsequent network layer of the target network layer can be represented by the sensitivity index corresponding to the specified parameter, so as to evaluate the redundancy degree of the specified parameter according to the influence of the specified parameter on the subsequent network layer of the target network layer, and then determine the specified parameter with a higher redundancy degree and a smaller contribution to the model performance in the target network layer by using the size relationship between the sensitivity index corresponding to each specified parameter and the pruning threshold value determined based on the preset pruning rate. After removing the specified parameter determined above, the pruned model can still have a higher model performance without the need for training. In this way, the time for model pruning can be reduced, and the efficiency of model pruning can be improved.
[0087] In addition, since the entire model does not need to be inferred, when pruning the to-be-pruned model, the occupation of hardware resources such as a CPU (Central Processing Unit) and a GPU (Graphics Processing Unit) can be reduced, and the hardware resources can be saved. Moreover, since the time for model pruning is reduced, batch model pruning can be more easily implemented.
[0088] Next, a model pruning method provided by an embodiment of the present application will be described in detail with reference to the accompanying drawings.
[0089] Figure 1 A flowchart of the model pruning method provided by an embodiment of the present application is shown in FIG. 1, which can include the following steps. Figure 1
[0090] S101: Determine each target network layer in a to-be-pruned model.
[0091] When pruning the to-be-pruned model, each target network layer in the to-be-pruned model that needs to be pruned can be determined first, so that the pruning of the to-be-pruned model is realized by pruning each target network layer.
[0092] Optionally, the to-be-pruned model can be a convolutional neural network model.
[0093] Optionally, each target network layer in the to-be-pruned model can be each convolutional layer and / or each fully connected layer in the to-be-pruned model.
[0094] S102: Determine a sensitivity index corresponding to each specified parameter in each target network layer.
[0095] For each network layer of the model, according to different granularities, the parameter of the network layer can be divided from different angles, so as to obtain each parameter matched with the granularity.
[0096] For example, the above granularity can be any of a plurality of granularities such as model parameters, convolution kernels, channels, and convolution layers. In this way, for the model, the model can be divided into parameters from multiple different angles according to a plurality of granularities such as model parameters, convolution kernels, channels, and convolution layers, to obtain each model parameter, each convolution kernel, each channel, or each convolution layer.
[0097] Based on this, for each target network layer in the model to be pruned, the parameter of the target network layer can be divided according to the specified granularity, so as to obtain each specified parameter matched with the specified granularity.
[0098] In this way, for each target network layer in the model to be pruned, after obtaining each specified parameter in the target network layer, the sensitivity index corresponding to each specified parameter in the target network layer can be determined.
[0099] The sensitivity refers to the stability of the model output for a given sample, which can be understood as the robustness of the model in obtaining sample features for known samples. The higher the sensitivity of the model, the lower the stability of the model output, and vice versa, the higher the stability of the model output.
[0100] Correspondingly, for each specified parameter, the higher the sensitivity, the greater the contribution to the model performance of the model, and the smaller the redundancy, so that when the specified parameter is removed, the model performance of the model to be pruned decreases more; on the contrary, the lower the sensitivity, the smaller the contribution to the model performance of the model, and the greater the redundancy, so that when the specified parameter is removed, the model performance of the model to be pruned decreases less. In this way, when pruning each target network layer in the model to be pruned, the specified parameter with lower sensitivity is preferred to be removed.
[0101] The sensitivity of each specified parameter can be indicated by the sensitivity index corresponding to the specified parameter. For each specified parameter, the higher the sensitivity index corresponding to the specified parameter, the higher the sensitivity of the specified parameter; on the contrary, the lower the sensitivity index corresponding to the specified parameter, the lower the sensitivity of the specified parameter.
[0102] Optionally, in a specific implementation, as shown in Figure 2 The step S102 can include the following step S102A:
[0103] S102A: For each target network layer, determine a sensitivity index corresponding to each specified parameter in the target network layer based on reconstruction errors of post-network layers of the target network layer when each specified parameter in the target network layer is removed.
[0104] For the model, the output result of each network layer in the model except the last network layer is the input data of the next network layer of the network layer, so that the output result of the next network layer of the network layer can be determined according to the output result of the network layer.
[0105] In this way, for each network layer in the model except the last network layer, the output result of each network layer located after the network layer can be determined using the output result of the network layer. The network layer located after the network layer can be referred to as a post-network layer of the network layer.
[0106] That is, for each target network layer in the model to be pruned, the output result of the post-network layer of the target network layer can be determined using the output result of the target network layer. And since the reconstruction error of the post-network layer of each target network layer needs to be used when pruning the model to be pruned, each target network layer in the model to be detected is not the last network layer of the model to be detected.
[0107] For each target network layer, when the target network layer obtains input data, the target network layer can output a direct output result about the input data, and the direct output result is determined based on all specified parameters in the target network layer.
[0108] Correspondingly, for each target network layer, when a specified parameter in the target network layer is removed, if the target network layer still obtains the input data, the target network layer can output a non-direct output result about the input data, and the non-direct output result is determined based on each remaining specified parameter in the target network layer.
[0109] For example, the target network layer is a convolution layer with N (N > 1) convolution kernels, and the specified parameter is the convolution kernel. When the picture data is input to the target network layer, N feature maps learned by the target network layer about the picture data can be obtained, and a direct output result determined by the N feature maps output by the target network layer can be obtained. The direct output result is the input data of the next network layer of the target network layer.
[0110] Correspondingly, when one of the convolution kernels in the target network layer is removed and the picture data is input to the target network layer after the removal of the convolution kernel, N-1 feature maps learned by the target network layer about the picture data can be obtained, and a non-direct output result determined by the N-1 feature maps output by the target network layer after the removal of the convolution kernel can be obtained. The non-direct output result can still be used as input data of a next network layer of the target network layer.
[0111] Further, for each target network layer, considering the size of the contribution of each specified parameter in the target network layer to the model performance of the model, when different specified parameters in the target network layer are removed, the error between the actual output result and the expected output result of the post-network layer of the target network layer can be different, and the difference in the error can reflect the difference in the contribution of the different specified parameters in the target network layer to the model performance of the model, that is, the sensitivity of the different specified parameters in the target network layer.
[0112] Based on this, for each target network layer, the reconstruction error of the post-network layer of the target network layer when each specified parameter in the target network layer is removed can be determined first, and then for each specified parameter in the target network layer, the sensitivity index corresponding to the specified parameter is determined based on the reconstruction error of the post-network layer of the target network layer when the specified parameter is removed.
[0113] Optionally, the post-network layer of each target network layer can be a next network layer of the target network layer.
[0114] In the specific implementation, when each target network layer in the model to be pruned is pruned, the degree of redundancy of each specified parameter in the target network layer can be evaluated according to the influence of the specified parameter on the post-network layer of the target network layer, and when the sensitivity index corresponding to each specified parameter in the target network layer is determined, only the post-network layer of each target network layer needs to be inferred, and the entire model cannot be inferred. In this way, the time for model pruning can be further reduced, and the efficiency of model pruning can be improved.
[0115] S103: determining a pruning threshold in the determined sensitivity indexes based on a preset pruning rate of the model to be pruned;
[0116] After the sensitivity index corresponding to each parameter index in each target network layer is determined, the pruning threshold can be determined in the determined sensitivity indexes based on a preset pruning rate of the model to be pruned.
[0117] The pruning of the model aims to reduce the size of the model and the amount of calculation in model inference as much as possible while ensuring the model performance of the model. For example, the size of the model is reduced as much as possible while ensuring that the detection rate and / or the accuracy of the model meet the detection requirement and / or the accuracy requirement.
[0118] In this way, when pruning the to-be-pruned model, the user can determine the preset pruning rate of the to-be-pruned model according to the requirements of the actual application.
[0119] Optionally, in a specific implementation, the preset pruning rate includes a ratio of a number of specified parameters corresponding to the sensitivity index less than the pruning threshold to a total number of all specified parameters included in each target network layer.
[0120] In this specific implementation, it is considered that when pruning each target network layer in the to-be-pruned model, the specified parameters with lower sensitivity are inclined to be removed. Moreover, for each specified parameter, the higher the corresponding sensitivity index, the higher the sensitivity of the specified parameter; otherwise, the lower the corresponding sensitivity index, the lower the sensitivity of the specified parameter.
[0121] Then, from the overall perspective of the to-be-pruned model, when pruning the to-be-pruned model, in order to ensure that the to-be-pruned model after pruning has high model performance, the specified parameters with lower sensitivity among all specified parameters included in each target network layer are inclined to be removed, that is, the specified parameters corresponding to the lower sensitivity index among all specified parameters included in each target network layer are inclined to be removed.
[0122] Based on this, the above-mentioned preset pruning rate can represent the proportion of the specified parameters to be removed among all specified parameters included in each target network layer. Therefore, the above-mentioned preset pruning rate can include a ratio of a number of specified parameters corresponding to the sensitivity index less than the pruning threshold to a total number of all specified parameters included in each target network layer.
[0123] In this way, after determining the sensitivity index corresponding to each specified parameter among all specified parameters included in each target network layer, the product of the above-mentioned preset pruning rate and the total number of the above-mentioned all specified parameters is calculated, and each specified parameter in the above-mentioned all specified parameters is sorted in the order of the corresponding sensitivity index from small to large. In this way, the specified parameter with the sum of the above-mentioned product plus 1 in the above-mentioned sorting can be found.
[0124] Obviously, the ratio of the number of the specified parameters arranged before the searched specified parameter to the total number of the specified parameters is the preset pruning rate, that is, the specified parameters arranged before the searched specified parameter are the specified parameters to be removed, and the sensitivity indicators corresponding to the specified parameters arranged before the searched specified parameter are all less than the sensitivity indicator corresponding to the searched specified parameter. In this way, the sensitivity indicator corresponding to the searched specified parameter can be determined as the pruning threshold.
[0125] That is, the ratio of the number of the specified parameters corresponding to the sensitivity indicators less than the pruning threshold to the total number of the specified parameters is the preset pruning rate.
[0126] The specified parameters arranged before the searched specified parameter can belong to different target network layers or belong to the same target network layer, which is reasonable.
[0127] For example, the total number of the specified parameters is 100, the preset pruning rate is 20%, and 100*20% = 20. After the 100 specified parameters are sorted according to the sensitivity indicators from small to large, the sensitivity indicator corresponding to the specified parameter arranged in the 21st order can be determined as the pruning threshold.
[0128] S104: Remove the specified parameters corresponding to the sensitivity indicators less than the pruning threshold in each target network layer to obtain a pruned-to-be-pruned model.
[0129] After the pruning threshold is determined, for each target network layer, the specified parameters corresponding to the sensitivity indicators less than the pruning threshold in the target network layer can be removed, so that the pruning of the target network layer is completed.
[0130] In this way, after the pruning of all target network layers is completed, the specified parameters corresponding to the sensitivity indicators less than the pruning threshold are all removed, and the ratio of the number of the removed specified parameters to the total number of the specified parameters is the preset pruning rate. Therefore, after the pruning of all target network layers is completed, the obtained model is a pruned-to-be-pruned model after the pruning of the to-be-pruned model.
[0131] For each target network layer, the pruning rate of the target network layer can be further determined according to the number of the removed specified parameters in the target network layer.
[0132] Based on this, in an optional specific implementation manner, as shown in Figure 3 The model pruning method provided by the embodiment of the application can further include the following step S105:
[0133] S105: calculating a pruning rate of each target network layer based on a number of specified parameters in the corresponding target network layer whose corresponding sensitivity indicators are less than the pruning threshold.
[0134] In the specific implementation, for each target network layer, a number of specified parameters in the target network layer whose corresponding sensitivity indicators are less than the pruning threshold can be determined, and then a ratio of the number to a total number of all specified parameters included in the target network layer can be calculated, and the ratio is the pruning rate of the target network layer.
[0135] In the specific implementation, the execution order of steps S104 and S105 is not limited.
[0136] Optionally, when the pruning threshold is determined, the target network layer to which each parameter before the target specified parameter is arranged belongs can be determined, and then a number of specified parameters arranged before the target specified parameter and included in each target network layer can be determined, and then a ratio of the number to a total number of all specified parameters included in the target network layer can be calculated to obtain the pruning rate of the target network layer. The target specified parameter is a specified parameter whose corresponding sensitivity indicator is the determined pruning threshold.
[0137] Optionally, for each target network layer, a number of specified parameters in the target network layer whose corresponding sensitivity indicators are less than the pruning threshold can be counted, and then a ratio of the number to a total number of all specified parameters included in the target network layer can be calculated to obtain the pruning rate of the target network layer.
[0138] As can be seen above, when pruning each target network layer in the model to be pruned, the influence of each specified parameter in the target network layer on the subsequent network layer of the target network layer can be represented by the sensitivity indicator corresponding to the specified parameter, so that the redundancy degree of the specified parameter is evaluated according to the influence of the specified parameter on the subsequent network layer of the target network layer, and then the specified parameter with a higher redundancy degree and a smaller contribution to the model performance in the target network layer is determined by using the size relationship between the sensitivity indicator corresponding to each specified parameter and the pruning threshold determined based on the preset pruning rate. After removing the specified parameter determined above, the pruned model can still have a higher model performance without training the pruned model. In this way, the time for model pruning can be reduced, and the efficiency of model pruning can be improved.
[0139] In addition, since the entire model does not need to be inferred, when pruning the to-be-pruned model, the occupation of hardware resources such as a central processing unit (CPU) and a graphics processing unit (GPU) can be reduced, and the hardware resources can be saved. In addition, since the time for model pruning is reduced, batch model pruning can be more easily implemented.
[0140] Optionally, a specific implementation manner is as shown in the following table: Figure 4 As shown in the above step S102A, for each target network layer, based on the reconstruction error of the post-network layer of the target network layer when each specified parameter in the target network layer is removed, the sensitivity index corresponding to the specified parameter is determined. For each target network layer, the following steps S1021-S1023 can be performed:
[0141] S1021: For each specified parameter in the target network layer, the output result of the post-network layer of the target network layer when the specified parameter is removed is determined as the output result corresponding to the specified parameter.
[0142] For each specified parameter in each target network layer, the output result of the target network layer after the specified parameter is removed can be determined, and the output result of the post-network layer of the target network layer is further determined based on the determined output result as the output result corresponding to the specified parameter.
[0143] S1022: The expected output result of the post-network layer is determined, and the reconstruction error of the post-network layer when the specified parameter is removed is determined based on the expected output result and the output result corresponding to each specified parameter.
[0144] For each model, for each network layer in the model, according to the task performed by the model and the expected task execution effect, each network layer can have a result that a user expects the network layer to output. When the result output by the network layer is the result that the user expects to output, the model can achieve a task execution effect that meets the user's expectation.
[0145] For example, when the task performed by the model is a target detection task, the expected output result of the box region in the output result is 1, and the expected output result of the region outside the box is 0. When the task performed by the model is a segmentation task, the expected output result of the mask region containing a target object in the output result is 1, and the expected output result of the remaining region is 0.
[0146] Based on this, for each target network layer, the expected output result of the post-network layer of the target network layer can be determined.
[0147] Further, since the so-called reconstruction error is the difference between the expected output result of the model and the actual output result, for each target network layer, the difference between the output result corresponding to each specified parameter determined above and the expected output result of the post-network layer of the target network layer is the reconstruction error of the post-network layer of the target network layer when the specified parameter is removed.
[0148] In this way, the reconstruction error of the post-network layer when each specified parameter is removed can be determined based on the determined expected output result and the output result corresponding to each specified parameter. Moreover, the magnitude of the reconstruction error of the post-network layer when each specified parameter is removed depends on the magnitude of the influence of the removed specified parameter on the output result of the target network layer.
[0149] When the influence of the specified parameter on the output result of the target network layer is greater, the reconstruction error of the post-network layer when each specified parameter is removed is greater; and when the influence of the specified parameter on the output result of the target network layer is smaller, the reconstruction error of the post-network layer when each specified parameter is removed is smaller.
[0150] S1023: Determine the sensitivity index corresponding to each specified parameter based on the reconstruction error of the post-network layer when each specified parameter is removed.
[0151] For each target network layer, after determining the reconstruction error of the post-network layer of the target network layer when each specified parameter in the target network layer is removed, the sensitivity index corresponding to each specified parameter in the target network layer can be determined based on the reconstruction error of the post-network layer of the target network layer when each specified parameter in the target network layer is removed.
[0152] The sensitivity index can be an L1 norm, an L2 norm, a mean squared error (MSE), etc., which is not limited in the embodiments of the present application.
[0153] For the to-be-pruned model, when the user expects different task execution effects, different reconstruction errors of the post-network layer of the target network layer can be set when different specified parameters are removed for the same target network layer. Thus, the determined reconstruction error of the post-network layer of the target network layer when each specified parameter is removed can be adjusted by weighted calculation.
[0154] Based on this, an optional specific implementation manner is as follows: Figure 5As shown, in the step S102A, for each target network layer, the following step S1024 can also be performed:
[0155] S1024: based on the task performed by the to-be-pruned model, weighting correction is performed on the reconstruction error of the post-network layer when each specified parameter is removed, to obtain the corrected error of the post-network layer when each specified parameter is removed.
[0156] Correspondingly, in the specific implementation manner, the step S1023 can include the following step S1023A:
[0157] S1023A: based on the corrected error of the post-network layer when each specified parameter is removed, the sensitivity index corresponding to the specified parameter is determined.
[0158] In the specific implementation manner, for each target network layer, after determining the reconstruction error of the post-network layer when each specified parameter is removed, the task performed by the to-be-pruned model can be further determined, so that the reconstruction error of the post-network layer when each specified parameter is removed is weighted and corrected according to the expected task execution effect, to obtain the corrected error of the post-network layer when each specified parameter is removed, and then the sensitivity index corresponding to the specified parameter is determined based on the corrected error of the post-network layer when each specified parameter is removed.
[0159] For example, when the task performed by the to-be-pruned model is a target detection task, if more attention is paid to the detection rate and the to-be-pruned model is expected to obtain a higher detection rate, the reconstruction error of the box region in the output result can be weighted and emphasized, and if more attention is paid to the false alarm of the background and the to-be-pruned model is expected to obtain a higher accuracy, the reconstruction error of the non-box region in the output result can be weighted and emphasized.
[0160] Optionally, in a specific implementation manner, the step S1022 of determining the expected output result of the post-network layer can include the following step 11:
[0161] Step 11: based on the first output result of the target network layer, the second output result of the post-network layer is determined, and the expected output result of the post-network layer is determined based on the second output result.
[0162] In the specific implementation manner, for each target network layer, the first output result of the target network layer can be obtained first, so that the first output result is the input data of the next network layer of the target network layer, and thus the first output result can be used to determine the output result of the next network layer of the target network layer. Furthermore, the output result of the next network layer of the target network layer is the input data of the next network layer of the next network layer, which is used to determine the output result of the next network layer of the next network layer.
[0163] By analogy, the second output of the subsequent network layer can be determined based on the first output of the target network layer. Furthermore, the desired output of the subsequent network layer can be determined using this second output.
[0164] Optionally, for each target network layer, the second output result of the subsequent network layer of the target network layer can be directly determined as the expected output result of the subsequent network layer of the target network layer.
[0165] Optionally, for each target network layer, a preset algorithm can be used to correct the second output result of the subsequent network layer of the target network layer, so as to obtain the corrected output result of the subsequent network layer of the target network layer, and the corrected output result is determined as the expected output result of the subsequent network layer of the target network layer.
[0166] The aforementioned preset algorithms can be sigmoid, softmax, tanh, or other algorithms that can be used to balance the reconstruction error of each feature point in the output of the model's network layers. In other words, when the actual value of a feature point differs significantly from the expected value of that point, the aforementioned preset algorithms can be used to increase the reconstruction error of the feature point; conversely, when the difference between the actual value of a feature point and the expected value of that point is small, the aforementioned preset algorithms can be used to reduce the reconstruction error of the feature point.
[0167] For example, such as Figure 6 The diagram illustrates the variation in feature point reconstruction error when the preset algorithm is the sigmoid algorithm. Near the origin of the coordinate axis, the difference between the actual value of the feature point and the expected value of a specific point is amplified, while on both sides of the horizontal axis, the difference is reduced.
[0168] Optionally, in another specific implementation, determining the expected output result of the post-network layer in step S1022 above may include the following step 12:
[0169] Step 12: Based on the task performed by the model to be pruned, construct the expected output of the post-network layer.
[0170] In this specific implementation, for each target network layer, when determining the expected output of the subsequent network layer of the target network layer, the expected output of the subsequent network layer of the target network layer can be constructed based on the task performed by the model to be pruned.
[0171] For each model, for each network layer in the model, according to the task performed by the model and the expected task execution effect to be achieved, there can be a result that a user expects the network layer to output.
[0172] For example, when the task performed by the model is a target detection task, the expected output result of the box (target frame) region in the output result is 1, and the expected output result outside the box region is 0; when the task performed by the model is a segmentation task, the expected output result of the mask region containing the target in the output result is 1, and the expected output result of the remaining region is 0.
[0173] Based on this, for each target network layer, the expected task execution effect to be achieved can be determined based on the task performed by the pruned model, and the expected output result of the post-network layer of the target network layer can be constructed according to the expected task execution effect.
[0174] Optionally, in a specific implementation, based on the expected output result and the output result corresponding to each specified parameter, the step S1022 of determining the reconstruction error of the post-network layer when the specified parameter is removed can include the following step 21:
[0175] Step 21: calculating the difference between the expected output result and the output result corresponding to each specified parameter as the reconstruction error of the post-network layer when the specified parameter is removed.
[0176] In this specific implementation, for each target network layer, after determining the output result corresponding to each specified parameter in the target network layer and the expected output result of the post-network layer of the target network layer, the difference between the expected output result and the output result corresponding to each specified parameter can be calculated, so that the obtained difference is the reconstruction error of the post-network layer when the specified parameter is removed.
[0177] Optionally, in another specific implementation, based on the expected output result and the output result corresponding to each specified parameter, the step S1022 of determining the reconstruction error of the post-network layer when the specified parameter is removed can include the following step 22:
[0178] Step 22: calculating the similarity between the expected output result and the output result corresponding to each specified parameter as the reconstruction error of the post-network layer when the specified parameter is removed.
[0179] In the specific implementation, for each target network layer, after determining the output result corresponding to each specified parameter in the target network layer and the expected output result of the subsequent network layer of the target network layer, the similarity between the expected output result and the output result corresponding to each specified parameter can be calculated, so that the obtained similarity is the reconstruction error of the subsequent network layer after removing the specified parameter.
[0180] Corresponding to the model pruning method provided in the above embodiment of the application, the embodiment of the application further provides a model pruning device.
[0181] Figure 7 A structural schematic diagram of a model pruning device provided in the embodiment of the application is shown in FIG. 7, which can include the following modules: Figure 7
[0182] The network layer determination module 710 is configured to determine each target network layer in the model to be pruned.
[0183] The index determination module 720 is configured to determine the sensitivity index corresponding to each specified parameter in each target network layer.
[0184] The threshold determination module 730 is configured to determine a pruning threshold in the determined sensitivity indexes based on a preset pruning rate of the model to be pruned.
[0185] The model pruning module 740 is configured to remove each specified parameter in each target network layer, which has a sensitivity index less than the pruning threshold, to obtain a pruned model to be pruned.
[0186] As can be seen from the above, when pruning each target network layer in the model to be pruned, the influence of each specified parameter in the target network layer on the subsequent network layer of the target network layer can be represented by the sensitivity index corresponding to the specified parameter, so that the redundancy degree of the specified parameter is evaluated according to the influence of the specified parameter on the subsequent network layer of the target network layer, and then the specified parameter with a higher redundancy degree and a smaller contribution to the model performance in the target network layer is determined by using the size relationship between the sensitivity index corresponding to each specified parameter and the pruning threshold determined based on the preset pruning rate. After removing the specified parameter determined above, the pruned model can still have a higher model performance without the need for training. In this way, the time for model pruning can be reduced and the efficiency of model pruning can be improved.
[0187] In addition, since the entire model does not need to be inferred, when pruning the to-be-pruned model, the occupation of hardware resources such as a central processing unit (CPU) and a graphics processing unit (GPU) can be reduced, and the hardware resources can be saved. In addition, since the time for model pruning is reduced, batch model pruning can be more easily implemented.
[0188] Optionally, in an implementation, the apparatus further includes:
[0189] The pruning rate calculation module is configured to calculate a pruning rate of each target network layer based on a number of specified parameters in each target network layer for which the corresponding sensitivity index is less than the pruning threshold.
[0190] Optionally, in an implementation, the preset pruning rate includes a ratio of a number of specified parameters for which the corresponding sensitivity index is less than the pruning threshold to a total number of all specified parameters included in each target network layer.
[0191] Optionally, in an implementation, the index determination module 720 includes:
[0192] The index determination submodule is configured to, for each target network layer, determine, based on a reconstruction error of a subsequent network layer of the target network layer when each specified parameter in the target network layer is removed, a sensitivity index corresponding to the specified parameter.
[0193] Optionally, in an implementation, the index determination submodule includes:
[0194] The structure determination unit is configured to, for each specified parameter in each target network layer, determine, as an output result corresponding to the specified parameter, an output result of a subsequent network layer of the target network layer when the specified parameter is removed.
[0195] The error determination unit is configured to, for each target network layer, determine an expected output result of the subsequent network layer, and determine, based on the expected output result and the output result corresponding to each specified parameter, a reconstruction error of the subsequent network layer when the specified parameter is removed.
[0196] The index determination unit is configured to, for each target network layer, determine, based on the reconstruction error of the subsequent network layer when each specified parameter is removed, a sensitivity index corresponding to the specified parameter.
[0197] Optionally, in an implementation, the error determination unit includes:
[0198] The first determining sub-unit is configured to determine, for each target network layer, a second output result of the post-network layer based on a first output result of the target network layer, and determine an expected output result of the post-network layer based on the second output result.
[0199] Alternatively,
[0200] The second determining sub-unit is configured to construct, for each target network layer, an expected output result of the post-network layer based on a task performed by the to-be-pruned model.
[0201] Optionally, in a specific implementation, the first determining sub-unit is specifically configured to:
[0202] For each target network layer, the second output result is determined as the expected output result of the post-network layer.
[0203] Alternatively,
[0204] For each target network layer, the second output result is corrected by using a preset algorithm, and the corrected second output result is determined as the expected output result of the post-network layer.
[0205] Optionally, in a specific implementation, the error determining unit is specifically configured to:
[0206] For each target network layer, a difference between the expected output result and an output result corresponding to each specified parameter is calculated as a reconstruction error of the post-network layer when the specified parameter is removed.
[0207] Alternatively,
[0208] For each target network layer, a similarity between the expected output result and an output result corresponding to each specified parameter is calculated as a reconstruction error of the post-network layer when the specified parameter is removed.
[0209] Optionally, in a specific implementation, the apparatus further includes:
[0210] The error correction module is configured to, for each target network layer, before determining, for each specified parameter, a sensitivity index corresponding to the specified parameter based on the reconstruction error of the post-network layer when the specified parameter is removed, perform weighted correction on the reconstruction error of the post-network layer when each specified parameter is removed based on a task performed by the to-be-pruned model, to obtain a corrected reconstruction error of the post-network layer when each specified parameter is removed.
[0211] The index determining unit is specifically configured to, for each target network layer, determine, based on the corrected reconstruction error of the post-network layer when each specified parameter is removed, a sensitivity index corresponding to the specified parameter.
[0212] Optionally, in an implementation form, the to-be-pruned model is a convolutional neural network model, and the target network layers are each convolutional layer and / or each fully connected layer in the to-be-pruned network layers.
[0213] The post-network layer of each target network layer is a next network layer of the target network layer.
[0214] The embodiments of the present application also provide an electronic device, such as Figure 8 As shown in the figure, the electronic device includes a processor 801, a communication interface 802, a memory 803 and a communication bus 804, wherein the processor 801, the communication interface 802 and the memory 803 complete mutual communication through the communication bus 804,
[0215] The memory 803 is configured to store a computer program.
[0216] The processor 801 is configured to execute the program stored in the memory 803, and implement the steps of any model pruning method provided by the embodiments of the present application.
[0217] The communication bus mentioned above can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For the convenience of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or only one type of bus.
[0218] The communication interface is configured to perform communication between the electronic device and other devices.
[0219] The memory can include a Random Access Memory (RAM) and can also include a Non-Volatile Memory (NVM), for example, at least one disk memory. Optionally, the memory can also be at least one storage device located away from the aforementioned processor.
[0220] The processor described above can be a general processor, including a central processing unit (CPU), a network processor (NP), etc.; can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component.
[0221] In a further embodiment provided by the present application, a computer readable storage medium is also provided, and the computer readable storage medium stores a computer program. The computer program is executed by a processor to implement the steps of any model pruning method provided by the embodiments of the present application.
[0222] In a further embodiment provided by the present application, a computer program product containing instructions is also provided, and when the computer program product is executed on a computer, the computer is caused to perform the steps of any model pruning method provided by the embodiments of the present application.
[0223] In the above embodiments, all or part of the embodiments can be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments can be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable device. The computer instructions can be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another computer readable storage medium, for example, the computer instructions can be transmitted from one website, computer, server or data center to another website, computer, server or data center through wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.) mode. The computer readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. integrated with one or more available media. The available media can be a magnetic medium (for example, a floppy disk, a hard disk, a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid state disk (SSD)) and the like.
[0224] It is to be noted that, in the present text, the relative terms such as first and second and the like are used merely to differentiate one entity or operation from another entity or operation, without necessarily requiring or implying any such actual relationship or order between such entities or operations. Moreover, the terms "comprising", "including", or any other variant thereof are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but can also include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element preceded by "comprises a" does not, without more constraints, preclude the existence of additional identical elements in the process, method, article, or apparatus that comprises the element.
[0225] Each of the embodiments in the present specification is described in a relevant manner, and the same or similar parts between the embodiments can be referred to each other. Each of the embodiments focuses on the difference from other embodiments. In particular, for the device embodiments, the electronic device embodiments, the computer-readable storage medium embodiments, and the computer program product embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the part of the method embodiments.
[0226] The above only describes the preferred embodiments of the present application and is not intended to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A model pruning method, characterized in that, The method is applied to an image recognition or voice recognition scenario, and comprises: determining each target network layer in a to-be-pruned model; determining a sensitivity index corresponding to each specified parameter in each target network layer, wherein the specified parameter is a parameter matched with a preset granularity obtained by performing parameter division on the network layer according to the preset granularity, and the preset granularity is any of a model parameter, a convolution kernel, a channel, and a convolution layer; based on a preset pruning rate of the to-be-pruned model, determining a pruning threshold in the determined sensitivity indexes; removing each specified parameter in each target network layer corresponding to a sensitivity index less than the pruning threshold to obtain a pruned to-be-pruned model. The step of determining the sensitivity index corresponding to each specified parameter in each target network layer comprises: for each target network layer, performing the following operations: for each specified parameter in the target network layer, determining an output result of a subsequent network layer of the target network layer when the specified parameter is removed as an output result corresponding to the specified parameter, determining an expected output result of the subsequent network layer, and determining a reconstruction error of the subsequent network layer when the specified parameter is removed based on the expected output result and the output result corresponding to each specified parameter, wherein the expected output result is an output result expected to be output by the subsequent network layer to enable the to-be-pruned model to achieve an expected task execution effect; and determining the sensitivity index corresponding to the specified parameter based on the reconstruction error of the subsequent network layer when the specified parameter is removed. The method further comprises, after determining the reconstruction error of the subsequent network layer when each specified parameter is removed, weighting and correcting the reconstruction error based on a task executed by the to-be-pruned model to obtain a corrected error of the subsequent network layer when each specified parameter is removed; and the step of determining the sensitivity index corresponding to each specified parameter based on the reconstruction error of the subsequent network layer when the specified parameter is removed comprises determining the sensitivity index corresponding to each specified parameter based on the corrected error of the subsequent network layer when the specified parameter is removed. The step of determining the expected output result of the subsequent network layer comprises determining a second output result of the subsequent network layer based on a first output result of the target network layer, correcting the second output result by using a preset algorithm, and determining the corrected second output result as the expected output result of the subsequent network layer, wherein the preset algorithm is any one of a sigmoid algorithm, a softmax algorithm, or a tanh algorithm. In the step of determining the output result of the subsequent network layer of the target network layer when the specified parameter is removed, the subsequent network layer is a next network layer of the target network layer, and the step of determining the output result of the subsequent network layer is only inferred to the subsequent network layer, but not to the entire to-be-pruned model.
2. The method of claim 1, wherein, The method further comprises: calculating a pruning rate of each target network layer based on a number of specified parameters in each target network layer corresponding to a sensitivity index less than the pruning threshold.
3. The method of claim 1, wherein, The preset pruning rate comprises: A ratio of a number of the specified parameters corresponding to the sensitivity indicators less than the pruning threshold to a total number of all the specified parameters included in each target network layer.
4. The method of claim 1, wherein, The step of determining the reconstruction error of the post-network layer when the specified parameter is removed based on the expected output result and the output result corresponding to each specified parameter comprises: calculating a difference between the expected output result and the output result corresponding to each specified parameter as the reconstruction error of the post-network layer when the specified parameter is removed; or calculating a similarity between the expected output result and the output result corresponding to each specified parameter as the reconstruction error of the post-network layer when the specified parameter is removed. The to-be-pruned model is a convolutional neural network model, and the target network layers are each convolutional layer and / or each fully connected layer in the to-be-pruned network layer.
5. The method according to any one of claims 1 to 4, characterized in that, The device is applied to an image recognition or speech recognition scenario, and the device comprises:
6. A model pruning apparatus characterized by comprising: a network layer determination module configured to determine each target network layer in a to-be-pruned model; an indicator determination module configured to determine a sensitivity indicator corresponding to each specified parameter in each target network layer, wherein the specified parameter is a parameter matched with a preset granularity obtained by performing parameter division on a network layer according to the preset granularity, and the preset granularity is any granularity of a model parameter, a convolution kernel, a channel, or a convolutional layer; a threshold determination module configured to determine a pruning threshold in the determined sensitivity indicators based on a preset pruning rate of the to-be-pruned model, wherein a ratio of a number of the specified parameters corresponding to the sensitivity indicators less than the pruning threshold to a total number of all the specified parameters included in each target network layer is the preset pruning rate; a model pruning module configured to remove each specified parameter corresponding to the sensitivity indicators less than the pruning threshold in each target network layer to obtain a pruned to-be-pruned model; The indicator determination module comprises: a structure determination unit configured to determine, for each specified parameter in each target network layer, an output result of a post-network layer of the target network layer when the specified parameter is removed as the output result corresponding to the specified parameter; an error determination unit configured to determine, for each target network layer, an expected output result of the post-network layer, and determine a reconstruction error of the post-network layer when the specified parameter is removed based on the expected output result and the output result corresponding to each specified parameter, wherein the expected output result is an output result expected to be output by the post-network layer so that the to-be-pruned model can achieve an expected task execution effect; and an indicator determination unit configured to determine, for each target network layer, a sensitivity indicator corresponding to each specified parameter based on the reconstruction error of the post-network layer when the specified parameter is removed. The device further comprises an error correction module configured to, for each target network layer, before determining the sensitivity index corresponding to each specified parameter based on the reconstruction error of the subsequent network layer when each specified parameter is removed, correct the reconstruction error of the subsequent network layer when each specified parameter is removed based on the task performed by the to-be-pruned model, to obtain the corrected error of the subsequent network layer when each specified parameter is removed. The error determination unit is specifically configured to determine the second output result of the subsequent network layer based on the first output result of the target network layer, and correct the second output result by using a preset algorithm, determine the corrected second output result as the expected output result of the subsequent network layer, and the preset algorithm is any one of a sigmoid algorithm, a softmax algorithm or a tanh algorithm. In the step of determining the output result of the subsequent network layer of the target network layer when the specified parameter is removed, the subsequent network layer is the next network layer of the target network layer, and the step of determining the output result of the subsequent network layer is only inferred to the subsequent network layer, but not to the entire to-be-pruned model.
7. The apparatus of claim 6, wherein, The device further comprises: a pruning rate calculation module configured to calculate the pruning rate of each target network layer based on the number of specified parameters corresponding to the sensitivity index less than the pruning threshold in each target network layer; and / or, The preset pruning rate comprises: a ratio of the number of specified parameters corresponding to the sensitivity index less than the pruning threshold to the total number of all specified parameters included in each target network layer; and / or, The error determination unit is specifically configured to, for each target network layer, calculate a difference between the expected output result and the output result corresponding to each specified parameter as the reconstruction error of the subsequent network layer when the specified parameter is removed, or calculate a similarity between the expected output result and the output result corresponding to each specified parameter as the reconstruction error of the subsequent network layer when the specified parameter is removed. and / or, The to-be-pruned model is a convolutional neural network model, and the target network layers are each convolutional layer and / or each fully connected layer in the to-be-pruned network layer.
8. An electronic device, comprising: The device comprises a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; The memory is configured to store a computer program; The processor is configured to execute the program stored on the memory to implement the method steps of any one of claims 1-5.
9. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, and the computer program is executed by the processor to implement the method steps of any one of claims 1-5.
Citation Information
Patent Citations
Deep learning model compression method and device
CN111598238A