A model pruning rate determination method and device, and an electronic device
By obtaining the pruning sensitivity characteristics and target performance of each part of the model to be pruned, the pruning rate is determined, which solves the problem of difficulty in estimating model performance caused by randomly generated pruning rates and realizes efficient model pruning without retraining.
Patent Information
- Application Number
- CN202111601699.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-24
- Publication Date
- 2025-12-09
- Estimated Expiration
- 2041-12-24
AI Technical Summary
In existing technologies, the random generation of model pruning rates makes it difficult to estimate the performance of the pruned model, requiring retraining and reducing the efficiency of model pruning.
By acquiring the pruning sensitivity characteristics of each part of the model to be pruned, the preset target model performance is determined, and the corresponding pruning intensity is found from the pruning sensitivity characteristics. Based on these intensity, the pruning rate of each part of the model is determined, taking into account the relationship and mutual influence between the parts of the model, and avoiding retraining.
Accurately predict the performance of the model after pruning, reduce the pruning time, and improve pruning efficiency.
Smart Images

Figure CN114298303B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of model compression, in particular to a model pruning rate determination 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, such as image recognition, voice interaction, intelligent security, etc.
[0003] In the use process of various models, for the trained model, the user hopes to reduce the size of the model as much as possible on the basis of ensuring the detection accuracy of the model, and reduce the calculation amount of the model inference.
[0004] Generally, there are a large number of various parameters in the model, and many parameters have little effect on the inference process of the model, such as some weight parameters being zero. These parameters that have little effect on the inference result of the model are called redundant parameters. In this way, the redundant parameters in the model can be removed through model pruning to reduce the size of the model, reduce the calculation amount of the model inference, and reduce the inference time of the model.
[0005] In related technologies, the method of model pruning is: for a to-be-pruned model, a plurality of sets of pruning rates are randomly generated, then each set of pruning rates is used to prune the to-be-pruned model, and the model with the best performance is selected from the plurality of pruned models, then the selected model is retrained to obtain the final pruned model. The so-called pruning rate refers to the ratio of the removed parameter module to all parameter modules with the same granularity as itself.
[0006] However, in the above related technology, since the pruning rate is randomly generated, the relationship and mutual influence between each part of the to-be-pruned model are not considered when using the pruning rate, which makes it difficult to estimate the performance of the pruned model. After selecting the pruned model, retraining is needed, 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 rate determination method, device and electronic equipment to reduce the time of model pruning and improve the efficiency of model pruning without retraining the pruned model after pruning the model using the determined model pruning rate. The specific technical solutions are as follows:
[0008] In a first aspect, the embodiments of the present application provide a model pruning rate determination method, which comprises:
[0009] obtaining pruning sensitivity characteristics of each part of the model to be pruned, wherein the pruning sensitivity characteristics of each part are a corresponding relationship between pruning strength and model performance of the part at a specified pruning granularity;
[0010] determining a target model performance of the model to be pruned after pruning;
[0011] For each part, searching for each pruning strength corresponding to a model performance not less than the target model performance from the pruning sensitivity characteristics;
[0012] determining a model pruning rate of each part of the model to be pruned based on the searched each pruning strength.
[0013] Optionally, in a specific implementation, before the step of obtaining the pruning sensitivity characteristics of each part of the model to be pruned, the method further comprises:
[0014] dividing the model to be pruned into multiple parts according to the structure of the model to be pruned.
[0015] Optionally, in a specific implementation, the step of obtaining the pruning sensitivity characteristics of each part of the model to be pruned comprises:
[0016] determining the specified pruning granularity and each pruning strength;
[0017] For each part, pruning the part according to each pruning strength at the specified pruning granularity, and determining the model performance of the model to be pruned after each pruning;
[0018] For each part, establishing a corresponding relationship between the pruning strength used in each pruning and the obtained model performance, to obtain the pruning sensitivity characteristics of the part.
[0019] Optionally, in a specific implementation, before the step of pruning the part according to each pruning strength at the specified pruning granularity, the method further comprises:
[0020] determining the importance of each parameter module corresponding to the specified pruning granularity in the part to the model performance of the model to be pruned, and sorting each parameter module in order of importance from small to large to obtain a parameter module order;
[0021] The step of pruning the part according to each pruning strength at the specified pruning granularity comprises:
[0022] For each pruning strength, determine the target number of parameter modules corresponding to the pruning granularity that meets the pruning strength, and from the first parameter module in the parameter module ranking, sequentially remove the target number of parameter modules.
[0023] Optionally, in an implementation manner, the model to be pruned is a classification model.
[0024] The step of determining the target model performance of the pruned model includes:
[0025] Determine the target model performance of the pruned model corresponding to each classification label.
[0026] The step of searching for, for each part, from the pruning sensitive characteristics, each pruning strength whose corresponding model performance is not less than the target model performance includes:
[0027] For each part, search for, from the pruning sensitive characteristics, a maximum pruning strength whose corresponding model performance is not less than the target model performance corresponding to each classification label.
[0028] The step of determining the model pruning rate of each part of the model to be pruned based on the searched each pruning strength includes:
[0029] The step of determining the model pruning rate of each part of the model to be pruned based on the searched each maximum pruning strength.
[0030] Optionally, in an implementation manner, the step of determining the model pruning rate of each part of the model to be pruned based on the searched each maximum pruning strength includes:
[0031] For each part, determine the minimum pruning strength in the searched each maximum pruning strength as the model pruning rate of the part in the model to be pruned.
[0032] Optionally, in an implementation manner, the step of determining the model pruning rate of each part of the model to be pruned based on the searched each maximum pruning strength includes:
[0033] According to the proportional relationship of the total number of parameter modules corresponding to the specified pruning granularity included in each part, determine a weighting coefficient corresponding to each part.
[0034] For each part, determine the minimum pruning strength in the searched each maximum pruning strength, and based on the determined minimum pruning strength, calculate the product of the determined minimum pruning strength and the corresponding weighting coefficient as the model pruning rate of the part.
[0035] Optionally, in an implementation form, the method further comprises:
[0036] pruning each part of the to-be-pruned model according to the determined model pruning rate of each part, to obtain a pruned to-be-pruned model;
[0037] determining a model index of the pruned to-be-pruned model, and determining whether the model index meets a preset index threshold; wherein the model index comprises at least one of model performance, calculation amount, F1, and AP value;
[0038] If not, adjusting the target model performance to obtain a new target model performance, and returning to the step of searching, for each part, each pruning intensity from the pruning sensitive characteristics, which has a corresponding model performance not less than the target model performance.
[0039] In a second aspect, an embodiment of the present application provides a model pruning rate determination apparatus, the apparatus comprising:
[0040] a pruning sensitive characteristics acquisition module configured to acquire pruning sensitive characteristics of each part of a to-be-pruned model; wherein the pruning sensitive characteristics of each part is a corresponding relationship between pruning intensity and model performance of the part at a specified pruning granularity;
[0041] a target model performance determination module configured to determine a preset target model performance of the to-be-pruned model after pruning;
[0042] a pruning intensity searching module configured to search, for each part, each pruning intensity from the pruning sensitive characteristics, which has a corresponding model performance not less than the target model performance;
[0043] a model pruning rate determination module configured to determine, based on the searched each pruning intensity, a model pruning rate of each part of the to-be-pruned model.
[0044] Optionally, in an implementation form, the apparatus further comprises:
[0045] a model division module configured to divide the to-be-pruned model into multiple parts according to a structure of the to-be-pruned model before acquiring the pruning sensitive characteristics of each part of the to-be-pruned model.
[0046] Optionally, in an implementation form, the pruning sensitive characteristics acquisition module comprises:
[0047] a data determination sub-module configured to determine the specified pruning granularity and each preset pruning intensity;
[0048] The model pruning submodule is configured to prune each part according to a preset pruning intensity at the specified pruning granularity, and determine the model performance of the to-be-pruned model after each pruning.
[0049] The pruning sensitivity characteristic acquisition submodule is configured to, for each part, establish a corresponding relationship between the pruning intensity used in each pruning and the obtained model performance, and obtain the pruning sensitivity characteristic of the part.
[0050] Optionally, in an implementation manner, the apparatus further includes:
[0051] The parameter module sorting module is configured to, before pruning each part according to a preset pruning intensity at the specified pruning granularity, determine the importance of each parameter module corresponding to the specified pruning granularity in the part to the model performance of the to-be-pruned model, sort the parameter modules in an order from small to large according to the determined importance, and obtain a parameter module sorting.
[0052] The model pruning submodule is specifically configured to, for each preset pruning intensity, determine a target number of parameter modules corresponding to the pruning granularity that meets the pruning intensity, and remove the target number of parameter modules in sequence from the first parameter module in the parameter module sorting.
[0053] Optionally, in an implementation manner, the to-be-pruned model is a classification model.
[0054] The target model performance determination module includes a target model performance determination submodule, which is configured to determine the target model performance of the to-be-pruned model after pruning for each classification label.
[0055] The pruning intensity searching module includes a pruning intensity searching submodule, which is configured to, for each part, search, from the pruning sensitivity characteristic, a maximum pruning intensity corresponding to each classification label, respectively, the maximum pruning intensity being greater than or equal to the target model performance corresponding to each classification label.
[0056] The model pruning rate determination module includes a model pruning rate determination submodule, which is configured to determine the model pruning rate of each part of the to-be-pruned model based on the searched maximum pruning intensity.
[0057] Optionally, in an implementation manner, the model pruning rate determination submodule is specifically configured to:
[0058] For each part, the minimum pruning intensity in the searched maximum pruning intensity is used to determine the model pruning rate of the part in the to-be-pruned model.
[0059] Optionally, in an implementation form, the model pruning rate determination sub-module is specifically configured to:
[0060] determine a weighting coefficient corresponding to each part according to a proportional relationship of a total number of parameter modules corresponding to the specified pruning granularity included in each part;
[0061] for each part, determine a minimum pruning intensity from the found maximum pruning intensities, and calculate a product of the determined minimum pruning intensity and the corresponding weighting coefficient as a model pruning rate of the part based on the determined minimum pruning intensity.
[0062] Optionally, in an implementation form, the apparatus further comprises:
[0063] a model pruning module configured to prune each part of the to-be-pruned model according to the determined model pruning rates, to obtain a pruned to-be-pruned model;
[0064] an index determination module configured to determine a model index of the pruned to-be-pruned model, and determine whether the model index meets a preset index threshold; if not, trigger the performance adjustment module; wherein the model index comprises at least one of a model performance, a calculation amount, an F1, and an AP value;
[0065] the performance adjustment module is configured to adjust the target model performance to obtain a new target model performance, and trigger the pruning intensity finding module.
[0066] 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 mutual communication through the communication bus;
[0067] the memory is configured to store a computer program;
[0068] the processor is configured to execute the program stored on the memory, to implement the steps of any model pruning rate determination method provided in the first aspect.
[0069] 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 rate determination method provided in the first aspect.
[0070] 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 rate determination method provided in the first aspect.
[0071] The embodiment of the present application has the following beneficial effects:
[0072] As can be seen above, when determining the model pruning rate, the embodiment of the present application can first determine each part of the to-be-pruned model, and specify the pruning granularity and each pruning strength. In this way, the correspondence between the pruning strength of each part and the model performance under the specified pruning granularity can be specified, so that the pruning sensitivity characteristics of each part of the to-be-pruned model are obtained. Further, the target model performance of the to-be-pruned model after pruning can be determined. In this way, for each part of the model, each pruning strength corresponding to a model performance not less than the target model performance can be found from the above pruning sensitivity characteristics. After each pruning strength is found, the model pruning rate of each part of the to-be-pruned model can be determined based on the found each pruning strength.
[0073] Based on this, the embodiment of the present application provides a scheme. Since there is a mutual relationship and mutual influence between each part of the model, the pruning sensitivity of each part of the model is also affected by the above content. Therefore, after determining each part of the to-be-pruned model, for each part, the other parts can be fixed, and the pruning sensitivity characteristics of the part alone are considered. Since each individual model pruning characteristic can not only represent the pruning sensitivity characteristics of the part, but also represent the influence degree of the pruning sensitivity characteristics of the part on other parts, the relationship between each part of the to-be-pruned model and the mutual influence are considered when the pruning sensitivity characteristics of each part of the to-be-pruned model are considered. Therefore, when the model pruning rate of each part of the to-be-pruned model is determined by using the pruning sensitivity characteristics of each part of the to-be-pruned model, the model performance after pruning can be accurately estimated when the to-be-pruned model is pruned according to the determined each model pruning rate without retraining the model after pruning, so that the time of model pruning can be reduced and the efficiency of model pruning can be improved. BRIEF DESCRIPTION OF DRAWINGS
[0074] In order to more clearly illustrate the technical solutions of the embodiments of the present application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or prior art description. Obviously, the drawings in the following description are only some embodiments of the present application, and other embodiments can also be obtained by those skilled in the art based on these drawings.
[0075] Figure 1 A flowchart of a model pruning rate determination method provided by the embodiment of the present application;
[0076] FIG. 2(a) is a schematic diagram of the pruning sensitivity characteristics of each part of a to-be-pruned model;
[0077] Fig. 2(b) is a schematic diagram of a specific implementation of the method for searching, for each part, the maximum pruning intensity of the corresponding model performance not less than the target model performance corresponding to each classification label from the pruning sensitive characteristics, based on Fig. 2(a);
[0078] Figure 3 Fig. 2(b) is a schematic diagram of a specific implementation of the method for searching, for each part, the maximum pruning intensity of the corresponding model performance not less than the target model performance corresponding to each classification label from the pruning sensitive characteristics, based on Fig. 2(a);
[0079] Figure 4 Fig. 2(b) is a schematic diagram of a specific implementation of the method for searching, for each part, the maximum pruning intensity of the corresponding model performance not less than the target model performance corresponding to each classification label from the pruning sensitive characteristics, based on Fig. 2(a); Figure 1 Fig. 2(b) is a schematic diagram of a specific implementation of the method for searching, for each part, the maximum pruning intensity of the corresponding model performance not less than the target model performance corresponding to each classification label from the pruning sensitive characteristics, based on Fig. 2(a);
[0080] Figure 5 Fig. 2(b) is a schematic diagram of a specific implementation of the method for searching, for each part, the maximum pruning intensity of the corresponding model performance not less than the target model performance corresponding to each classification label from the pruning sensitive characteristics, based on Fig. 2(a); Figure 1 Fig. 2(b) is a schematic diagram of a specific implementation of the method for searching, for each part, the maximum pruning intensity of the corresponding model performance not less than the target model performance corresponding to each classification label from the pruning sensitive characteristics, based on Fig. 2(a);
[0081] Figure 6 Fig. 2(b) is a schematic diagram of a specific implementation of the method for searching, for each part, the maximum pruning intensity of the corresponding model performance not less than the target model performance corresponding to each classification label from the pruning sensitive characteristics, based on Fig. 2(a);
[0082] Figure 7 Fig. 2(b) is a schematic diagram of a specific implementation of the method for searching, for each part, the maximum pruning intensity of the corresponding model performance not less than the target model performance corresponding to each classification label from the pruning sensitive characteristics, based on Fig. 2(a);
[0083] Figure 8 Fig. 2(b) is a schematic diagram of a specific implementation of the method for searching, for each part, the maximum pruning intensity of the corresponding model performance not less than the target model performance corresponding to each classification label from the pruning sensitive characteristics, based on Fig. 2(a); Figure 6 Fig. 2(b) is a schematic diagram of a specific implementation of the method for searching, for each part, the maximum pruning intensity of the corresponding model performance not less than the target model performance corresponding to each classification label from the pruning sensitive characteristics, based on Fig. 2(a);
[0084] Figure 9 Fig. 2(b) is a schematic diagram of a specific implementation of the method for searching, for each part, the maximum pruning intensity of the corresponding model performance not less than the target model performance corresponding to each classification label from the pruning sensitive characteristics, based on Fig. 2(a);
[0085] Figure 10 Fig. 2(b) is a schematic diagram of a specific implementation of the method for searching, for each part, the maximum pruning intensity of the corresponding model performance not less than the target model performance corresponding to each classification label from the pruning sensitive characteristics, based on Fig. 2(a);
[0086] Figure 11 Fig. 2(b) is a schematic diagram of a specific implementation of the method for searching, for each part, the maximum pruning intensity of the corresponding model performance not less than the target model performance corresponding to each classification label from the pruning sensitive characteristics, based on Fig. 2(a); DETAILED DESCRIPTION
[0087] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than 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.
[0088] In the related art, the method of model pruning is as follows: for a to-be-pruned model, a plurality of sets of pruning rates are randomly generated, then the to-be-pruned model is pruned by using each set of pruning rates, and the model with the best performance is selected from the plurality of pruned models, then the selected model is retrained to obtain the final pruned model. The so-called pruning rate refers to the ratio of the removed parameter module to all parameter modules with the same granularity as itself.
[0089] However, in the above related art, since the pruning rate is randomly generated, the relationship and mutual influence between each part of the to-be-pruned model are not considered when the pruning rate is used, which makes it difficult to estimate the model performance of the pruned model. After selecting the pruned model, retraining is needed, thereby increasing the time of model pruning and reducing the efficiency of model pruning.
[0090] To solve the above technical problems, an embodiment of the present application provides a model pruning rate determination method.
[0091] The method can be applied to any application scenario that requires pruning of a trained model, such as image recognition, voice interaction, intelligent security, 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.
[0092] The model pruning rate determination method provided by the embodiment of the present application can include the following steps:
[0093] Obtain the pruning sensitivity characteristics of each part of the to-be-pruned model; the pruning sensitivity characteristics of each part is the corresponding relationship between the pruning strength and the model performance of the part under a specified pruning granularity;
[0094] Determine the target model performance of the to-be-pruned model after pruning;
[0095] For each part, find the pruning strength corresponding to the model performance not less than the target model performance from the pruning sensitivity characteristics;
[0096] Determine the model pruning rate of each part of the to-be-pruned model based on the found maximum pruning strength.
[0097] It can be seen from the above that, in the scheme provided by the embodiments of the present application, when determining the model pruning rate, each part of the to-be-pruned model can be determined first, and the pruning granularity and the pruning strength of each part are specified. In this way, the correspondence between the pruning strength of each part and the model performance under the specified pruning granularity can be specified, so that the pruning sensitivity characteristics of each part of the to-be-pruned model are obtained. Further, the target model performance of the to-be-pruned model after pruning can be determined. In this way, for each part of the model, the pruning strength corresponding to the model performance not less than the target model performance can be found from the above pruning sensitivity characteristics. After each pruning strength is found, the model pruning rate of each part of the to-be-pruned model can be determined based on the found pruning strength.
[0098] Based on this, in the scheme provided by the embodiments of the present application, because there is a mutual relationship and mutual influence between the parts of the model, the pruning sensitivity of each part of the model is also affected by the above content. Therefore, after the parts of the to-be-pruned model are determined, for each part, the other parts can be fixed, and the pruning sensitivity characteristics of the part alone are considered. Since each individual model pruning characteristic can not only represent the pruning sensitivity characteristics of the part, but also represent the influence degree of the pruning sensitivity characteristics of the part on other parts, the relationship between the parts of the to-be-pruned model and the mutual influence are considered when the pruning sensitivity characteristics of the parts of the to-be-pruned model are considered. Therefore, when the model pruning rate of each part of the to-be-pruned model is determined by using the pruning sensitivity characteristics of the parts of the to-be-pruned model, the model performance after pruning can be accurately estimated when the to-be-pruned model is pruned according to the determined model pruning rate without retraining the model after pruning, so that the time of model pruning can be reduced and the efficiency of model pruning can be improved.
[0099] Next, a model pruning rate determination method provided by the embodiments of the present application will be described in detail with reference to the accompanying drawings.
[0100] Figure 1 The flowchart of the model pruning rate determination method provided by the embodiments of the present application is shown in FIG. 1, which can include the following steps: Figure 1
[0101] S101: Obtain the pruning sensitivity characteristics of each part of the to-be-pruned model;
[0102] The pruning sensitivity characteristics of each part are the correspondence between the pruning strength of the part and the model performance under the specified pruning granularity.
[0103] For the to-be-pruned model, when determining the model pruning rate of the to-be-pruned model, each part of the to-be-pruned model can be determined first, and then for each part, the correspondence between the pruning strength and the model performance under a specified pruning granularity can be determined, to obtain the pruning sensitivity characteristics of each part of the to-be-pruned model.
[0104] For the to-be-pruned model, the parameter module division can be performed on the to-be-pruned model according to different granularity sizes, to obtain each parameter module of the to-be-pruned model; wherein when the granularity sizes are different, the sizes of the obtained each parameter module are different, and the number of the obtained each parameter module is also different.
[0105] For example, for the same to-be-pruned model, when the granularity is the smallest neuron unit of the model, each parameter module obtained by division is a neuron; and when the granularity is a filter larger than the neuron, each parameter module obtained by division is a filter.
[0106] Therefore, the pruning granularity is the size of each parameter module removed when pruning the to-be-pruned model.
[0107] For example, the pruning granularity can be a neuron, and each parameter module removed when pruning the to-be-pruned model is a neuron; for example, the pruning granularity can be a filter, and each parameter module removed when pruning the to-be-pruned model is a filter; for example, the pruning strength can be a convolution layer, and each parameter module removed when pruning the to-be-pruned model is a convolution layer.
[0108] In this way, when determining the model pruning rate of each part of the to-be-pruned model, a pruning granularity can be specified first, that is, a specified pruning granularity is obtained. Thus, based on the specified pruning granularity, each pruning strength can be understood as the proportion of the parameter module removed in all parameter modules included in each part in the specified pruning granularity; wherein all parameter modules included in the part are all parameter modules obtained by performing parameter module division on the part according to the specified pruning granularity; each parameter module in the all parameter modules can be referred to as the parameter module corresponding to each specified pruning granularity in the part.
[0109] For example, a part includes 10 filters, the pruning granularity is a filter, and the pruning strength includes 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, and 0.9; when pruning the part according to each pruning granularity, that is, removing 1, 2, 3, 4, 5, 6, 7, 8, and 9 filters from the 10 filters, respectively, under the above pruning granularity. Wherein, the 10 filters are not completely removed in order to maintain the structural integrity of the part in the model.
[0110] Based on this, for each part of the to-be-pruned model, the part can be pruned according to each pruning strength at the pruning granularity, and the model performance after each pruning is determined, so that the corresponding relationship between the pruning strength used at each pruning and the determined model performance is obtained, so that the pruning sensitivity characteristics of the part are obtained. Moreover, for each part, the pruning sensitivity characteristics of the part are determined while the other parts remain unchanged.
[0111] Among them, for each part, the greater the pruning strength, the smaller the model performance after pruning. Moreover, different parts have different sensitivities. Some parts are very sensitive, and the model performance will change greatly when the pruning strength is small, and then sharply decrease. Some parts have poor sensitivity, and the model performance will not change greatly when the pruning strength is large.
[0112] Among them, the pruning sensitivity characteristics of each part of the to-be-pruned model can be represented in various forms such as tables and line graphs, and the embodiments of the present application do not make specific limitations. For example, as shown in FIG. 2(a), it is a schematic diagram of the pruning sensitivity characteristics of each part of a to-be-pruned model. Each line is the pruning sensitivity characteristics of a part of the to-be-pruned model, the horizontal coordinate of the coordinate axis is the pruning strength, and the vertical coordinate of the coordinate axis is the detection rate.
[0113] In addition, the above-mentioned parts of the to-be-pruned model, and the pruning granularity and each pruning strength used can be determined according to the structure and / or size of the to-be-pruned model. The embodiments of the present application do not make specific actions.
[0114] Based on this, in an optional specific implementation manner, as shown in FIG. 2(b), the embodiments of the present application provide a flowchart of a model pruning rate determination method, which can further include the following step S100: Figure 3
[0115] S100: According to the structure of the to-be-pruned model, the to-be-pruned model is divided into multiple parts.
[0116] In this specific implementation manner, after the to-be-pruned model is determined, the structure of the to-be-pruned model can be determined first, so that the to-be-pruned model is divided into multiple parts according to the structure of the to-be-pruned model.
[0117] Optionally, when the structure of the to-be-pruned model is large, the to-be-pruned model can be divided into a larger number of parts; and when the structure of the to-be-pruned model is small, the to-be-pruned model can be divided into a smaller number of parts, or even the to-be-pruned model can be determined as a whole.
[0118] For example, each network layer of the to-be-pruned model can be divided into a part of the to-be-pruned model, that is, each network layer of the to-be-pruned model is a part of the to-be-pruned model.
[0119] For another example, each specified number of network layers in the to-be-pruned model can be divided into a part of the to-be-pruned model, the specified number being greater than 1, that is, each specified number of network layers of the to-be-pruned model is a part of the to-be-pruned model.
[0120] For another example, the to-be-pruned model can not be divided, and the entire to-be-pruned model is taken as a part of the to-be-pruned model, that is, the to-be-pruned model has only one part, which is the to-be-pruned model itself.
[0121] Optionally, the model performance can include at least one of the recall rate, the accuracy rate, the F1 score, and the average precision.
[0122] S102: Determine the target model performance of the to-be-pruned model after pruning.
[0123] The purpose of model pruning is to reduce the size of the model as much as possible and reduce the calculation amount of the model during inference on the basis of ensuring the detection accuracy of the model, and therefore, the user expects the pruned model to have a model performance that meets the actual demand. For example, the recall rate of the pruned model is not lower than the preset recall rate, the accuracy rate of the pruned model is not lower than the preset accuracy rate, and the calculation amount of the pruned model is not higher than the preset calculation amount.
[0124] Based on this, the target model performance that the user expects the pruned model to achieve after the to-be-pruned model is pruned can be preset. That is, the target model performance of the to-be-pruned model after pruning can be determined. The target model performance is the same model performance as the model performance in the pruning sensitivity characteristics of each part of the to-be-pruned model.
[0125] When the target model performance is the target recall rate, it means that the user expects the recall rate of the pruned model to be not lower than the target recall rate; when the target model performance is the target accuracy rate, it means that the user expects the accuracy rate of the pruned model to be not lower than the target accuracy rate.
[0126] S103: For each part, find each pruning intensity corresponding to the model performance that is not less than the target model performance from the pruning sensitivity characteristics.
[0127] S104: Determine the model pruning rate of each part of the to-be-pruned model based on the found pruning intensities.
[0128] After obtaining the pruning-sensitive characteristics of each part of the to-be-pruned model and the target model performance, for each part, each pruning granularity corresponding to a model performance not less than the target model performance can be found from the pruning-sensitive characteristics of the part. Obviously, when pruning the part according to the determined pruning intensities, the model performance after pruning can meet the target model performance. In this way, the model pruning rate of the part can be determined based on the found pruning intensities. Thus, the model pruning rate of each part of the to-be-pruned model is obtained.
[0129] Optionally, when the part of the to-be-pruned model is only one, that is, the to-be-pruned model itself is a part, the maximum pruning intensity among the found pruning intensities can be determined as the model pruning rate of the part to reduce the calculation amount of the model after pruning as much as possible; or a pruning intensity can be randomly selected from the found pruning intensities as the model pruning rate of the part; or the average of the found pruning intensities can be determined as the model pruning rate of the part to balance the model performance and the calculation amount after pruning.
[0130] Of course, for each part, the model pruning rate of the part can also be determined based on the found pruning intensities in other manners.
[0131] As can be seen above, since there is a mutual relationship and mutual influence between the parts of the model, the pruning sensitivity of each part of the model is also affected by the mutual relationship and mutual influence. Thus, after determining each part of the to-be-pruned model, for each part, the other parts can be fixed, and the pruning-sensitive characteristics of the part alone are considered. Since each individual model pruning characteristic can not only represent the pruning-sensitive characteristics of the part, but also represent the influence degree of the part on the pruning-sensitive characteristics of other parts, the relationship and mutual influence between the parts of the to-be-pruned model are considered when the pruning-sensitive characteristics of the parts of the to-be-pruned model are considered. Thus, when the model pruning rate of each part of the to-be-pruned model is determined based on the pruning-sensitive characteristics of the parts of the to-be-pruned model, the model performance after pruning can be accurately estimated without retraining the model after pruning when the to-be-pruned model is pruned according to the determined model pruning rates, thereby reducing the time of model pruning and improving the efficiency of model pruning.
[0132] Optionally, in a specific implementation manner, as Figure 4As shown, the step S101 of acquiring the pruning sensitivity characteristics of each part of the model to be pruned can include the following steps:
[0133] S1011: specify the pruning granularity and the preset pruning intensities;
[0134] S1012: for each part, prune the part according to the preset pruning intensities respectively at the specified pruning granularity, and determine the model performance of the model to be pruned after each pruning;
[0135] S1013: for each part, establish a corresponding relationship between the pruning intensity used in each pruning and the acquired model performance, to obtain the pruning sensitivity characteristics of the part.
[0136] In the specific implementation, after determining each part of the model to be pruned, the specified pruning granularity and the preset pruning intensities can be further determined.
[0137] Further, for each part, the part is pruned according to the preset pruning intensities respectively at the specified pruning granularity, and the model performance of the model to be pruned after each pruning is determined, and then a corresponding relationship between the pruning intensity used in each pruning and the acquired model performance can be established, to obtain the pruning sensitivity characteristics of the part.
[0138] For each part, the total number of parameter modules corresponding to the specified pruning granularity included in the part is first determined;
[0139] Then, the preset pruning intensities can be traversed, and when each pruning intensity is traversed, the number of parameter modules to be removed corresponding to the pruning intensity can be calculated, for example, the product of the total number and the pruning intensity is calculated, and the product is the number of parameter modules to be removed. Then, the calculated number of parameter modules corresponding to the specified pruning granularity can be removed to obtain the pruned model to be pruned, and the model performance of the obtained pruned model to be pruned is further determined. Then, a corresponding relationship between the pruning intensity and the determined model performance can be established. In this way, after traversing all the preset pruning intensities, the pruning sensitivity characteristics of the part can be obtained.
[0140] In each part, the importance of each parameter module corresponding to the specified pruning granularity in contributing to the model performance of the model to be pruned can be different.
[0141] For example, when the specified pruning granularity is a filter and each part of the model to be pruned is a convolutional layer of the model to be pruned, the importance of each filter included in each convolutional layer in contributing to the model performance of the model to be pruned can be different.
[0142] In each part, the more important the parameter module that contributes to the model performance of the model to be pruned is, the greater the impact on the model performance is, so if the parameter module is removed when the model pruning is performed, the model performance of the pruned model to be pruned decreases more.
[0143] Therefore, in order to realize the purpose of model pruning, that is, to reduce the size of the model as much as possible and reduce the calculation amount of the model inference on the basis of ensuring the model detection accuracy, when the model pruning is performed, the parameter module that contributes less to the model performance of the model to be pruned is more inclined to be removed.
[0144] Based on this, in an optional specific implementation manner, as shown in Figure 5 The step S101 of obtaining the pruning sensitive characteristics of each part of the model to be pruned can further include the following steps:
[0145] S1014: Determine the importance of each parameter module corresponding to the specified pruning granularity in the part to the model performance of the model to be pruned, and sort the parameter modules in the order of the determined importance from small to large to obtain a parameter module sorting.
[0146] Correspondingly, in the specific implementation manner, the step S1012 of pruning the part according to each pruning intensity under the specified pruning granularity can include the following step S1012A:
[0147] S1012A: For each pruning intensity, determine the target number of parameter modules corresponding to the pruning granularity that meets the pruning intensity, and remove the target number of parameter modules from the first parameter module in the parameter module sorting.
[0148] In the specific implementation manner, after the specified pruning granularity and the preset pruning intensity are determined, for each part of the model to be pruned, the parameter modules corresponding to the specified pruning granularity in the part can be determined first, and the importance of each parameter module to the model performance of the model to be pruned is determined. Then, the parameter modules can be sorted in the order of the determined importance from small to large to obtain a parameter module sorting.
[0149] That is, in the obtained parameter module sequence, the first parameter module has the least importance on the model performance of the model to be pruned, and the last parameter module has the greatest importance on the model performance of the model to be pruned, and the importance of each parameter module on the model performance of the model to be pruned increases in order from the first parameter module to the last parameter module.
[0150] The importance of each parameter module on the model performance of the model to be pruned can be determined in various ways, and the embodiments of the present application do not make specific actions.
[0151] For example, when the specified pruning granularity is a filter, the sum of the absolute values of the model parameters included in each filter can be calculated, and the sum is taken as the importance of the filter on the model performance of the model to be pruned.
[0152] In this way, for each part of the model, when pruning the part according to each pruning strength, the target number of parameter modules corresponding to the pruning granularity that meets the pruning strength can be determined first, that is, the number of parameter modules corresponding to the pruning granularity that needs to be removed under the pruning strength is determined first.
[0153] Further, the target number of parameter modules determined can be removed from the first parameter module in the parameter module sequence.
[0154] For a classification model, it has multiple classification labels, and usually, the required detection rate, accuracy and other model performances of each classification label can be different. Therefore, when pruning the classification model, the model performance after pruning needs to meet the required model performance of each classification label.
[0155] Based on this, in an optional specific implementation, the model to be pruned is a classification model, as shown in Figure 6 The model pruning rate determination method provided by the embodiments of the present application can include the following steps:
[0156] S601: Obtain the pruning sensitive characteristics of each part of the model to be pruned;
[0157] The specific content of S601 is the same as that of S101, and will not be repeated here.
[0158] S602: Determine the target model performance of the model to be pruned after pruning corresponding to each classification label;
[0159] Since the required detection rate, accuracy and other model performances of each classification label can be different for a classification model, when the to-be-pruned model is a classification model, the user can hope that the target model performances of each classification label of the pruned model can not be exactly the same.
[0160] In this way, after obtaining the pruning-sensitive characteristics of each part of the to-be-pruned model, the target model performance of each classification label after pruning of the to-be-pruned model can be determined.
[0161] S603: For each part, find the maximum pruning intensity in the pruning-sensitive characteristics, which is not less than the target model performance corresponding to each classification label;
[0162] S604: Determine the model pruning rate of each part of the to-be-pruned model based on the found maximum pruning intensities.
[0163] After obtaining the target model performance corresponding to each classification label, for each part, the maximum pruning intensity corresponding to each classification label can be found according to the target model performance corresponding to different classification labels, so that the found maximum pruning intensities are used as the found pruning intensities.
[0164] That is, for each part, each classification label can be traversed, when each classification label is traversed, each pruning intensity corresponding to the classification label can be found in the pruning-sensitive characteristics of the part, which is not less than the target model performance corresponding to the classification label, and the maximum pruning intensity in the found pruning intensities can be determined. In this way, after traversing each classification label, the determined maximum pruning intensities can be obtained, and then the model pruning rate of the part can be determined based on the determined maximum pruning intensities.
[0165] For example, as shown in FIG. 2(b), when the pruning-sensitive characteristics of each part of a to-be-pruned model are as shown in FIG. 2(a), for each classification label, a horizontal line parallel to the abscissa and the ordinate of the target model performance corresponding to the classification label can be drawn in FIG. 2(a), as shown in FIG. 2(b), and the abscissa of the intersection of the horizontal line and each broken line is the maximum pruning intensity corresponding to the model performance not less than the target model performance corresponding to the classification label in the pruning intensities of the part represented by the broken line. Similarly, for the next classification label, the maximum pruning intensity corresponding to the model performance not less than the target model performance corresponding to the next classification label in the pruning intensities of each part can be determined. In this specific embodiment, this method can be referred to as a geometric method.
[0166] Thus, for each part, the maximum pruning strength corresponding to the model performance not less than the target model performance of each classification label can be obtained among the pruning strengths of the part, so that the model pruning rate of the part can be determined based on the maximum pruning strengths found.
[0167] It should be emphasized that, in addition to the classification model described above, the above Figure 6 The specific implementation shown can use any model capable of detecting targets of each class, such as a target detection model. In this regard, the embodiments of the present application are not limited, and the above is merely an example using a classification model, not a limitation.
[0168] Optionally, in one specific implementation, as Figure 7 shown, the step S604 of determining the model pruning rate of each part of the model to be pruned based on the maximum pruning strengths found can be as follows:
[0169] S6041: For each part, the minimum pruning strength among the maximum pruning strengths found is determined as the model pruning rate of the part in the model to be pruned.
[0170] In this specific implementation, for each part, the maximum pruning strength corresponding to the model performance not less than the target model performance of each classification label can be obtained among the pruning strengths of the part. That is, for each part, since there are multiple classification labels, multiple maximum pruning strengths can be determined, that is, one maximum pruning strength of the part is determined for each classification label.
[0171] For each part, when the multiple maximum pruning strengths determined are not all the same, for each part, the greater the pruning strength, the smaller the model performance after pruning. Then, if pruning is performed on the part according to any target pruning strength other than the minimum pruning strength among the multiple maximum pruning strengths, the performance of the target classification label of the pruned model is less than the target model performance corresponding to the target classification label, where the target classification label is the classification label corresponding to each pruning strength less than the target pruning strength among the multiple maximum pruning strengths. In this way, the model performance required by each classification label in the pruned model cannot be met.
[0172] Based on this, in order to ensure that the model performance after pruning each part meets the target model performance corresponding to each classification label, for each part of the model, the minimum pruning strength among the pruning strengths found can be determined as the model pruning rate of the part in the model to be pruned.
[0173] Optionally, for each part of the model, when the determined multiple maximum pruning intensities are all the same, the maximum pruning intensity can be directly determined as the model pruning rate of the part.
[0174] Optionally, in one specific implementation manner, as shown in the following table, the step S604 of determining the model pruning rate of each part of the model to be pruned based on the found multiple maximum pruning intensities can be implemented as the following steps S604A-S604B: Figure 8
[0175] S604A: determining a weighting coefficient corresponding to each part according to the proportional relationship of the total number of parameter modules corresponding to the specified pruning granularity included in each part;
[0176] S604B: for each part, determining the minimum pruning intensity among the found multiple maximum pruning intensities, and calculating the product of the determined minimum pruning intensity and the corresponding weighting coefficient as the model pruning rate of the part.
[0177] In the specific implementation manner, the total number of parameter modules corresponding to the specified pruning intensity included in each part can be different. When the model pruning is performed according to the model pruning rate of each part, the number of parameter modules removed by different parts is also different, and even greatly different.
[0178] In this way, the proportional relationship of the total number of parameter modules corresponding to the pruning granularity included in each part can be determined first, and then the weighting coefficient corresponding to each part is determined according to the proportional relationship.
[0179] Further, for each part, after the minimum pruning intensity among the found multiple maximum pruning intensities is determined, the product of the determined minimum pruning intensity and the corresponding weighting coefficient can be calculated as the model pruning rate of the part based on the determined minimum pruning intensity.
[0180] Optionally, for the part including the total number of parameter modules corresponding to the specified pruning intensity that is less than the first threshold, the weighting coefficient corresponding to the part can be less than 1; and for the part including the total number of parameter modules corresponding to the specified pruning intensity that is greater than the second threshold, the weighting coefficient corresponding to the part can be greater than 1; wherein the first threshold is not greater than the second threshold.
[0181] That is, for the part including more parameter modules, the model pruning rate can be appropriately increased, and for the part including fewer parameter modules, the model pruning rate can be appropriately reduced.
[0182] The model pruning rate of each part is determined to meet the preset target model performance, and after the overall pruning of the model to be pruned is performed according to the determined model pruning rates, the model performance after pruning can meet the preset target model performance. However, in some cases, the pruning intensity of the model to be pruned can be limited, or even there can be almost no pruning. Therefore, the preset target model performance needs to be continuously reduced to increase the pruning intensity of the model to be pruned, and with the increase of the pruning intensity, the model performance after pruning can continuously decrease, and therefore, the model index after pruning needs to be continuously monitored to meet the preset index threshold.
[0183] Based on this, optionally, a specific implementation is provided as shown in the figure, Figure 9 The model pruning rate determination method provided by the embodiment of the application can further include the following steps S105-S107:
[0184] S105: pruning each part of the model to be pruned according to the determined model pruning rate to obtain a pruned model to be pruned;
[0185] S106: determining a model index of the pruned model to be pruned, and judging whether the model index meets a preset index threshold; if not, performing S107;
[0186] The model index includes at least one of model performance, calculation amount, F1, and AP value.
[0187] S107: adjusting the target model performance to obtain a new target model performance, and returning to S103.
[0188] In the specific implementation, after the model pruning rate of each part of the model to be pruned is determined, the pruning of the part can be performed according to the model pruning rate of the part, so as to obtain a pruned model to be pruned. Further, the model index of the pruned model to be pruned can be determined, and whether the model index meets a preset index threshold can be judged.
[0189] When the above judgment result is met, the determination of the model pruning rate can be stopped, and the model pruning rate of each part of the model to be pruned determined above is obtained.
[0190] When the above judgment result is not met, it means that the model obtained after pruning the model according to the model pruning rate of each part of the model to be pruned determined above is not the model expected by the user, and therefore, the target model performance needs to be adjusted to obtain a new target model performance, and the step S103 is returned to be performed, that is, for each part of the model, the pruning intensity corresponding to the model performance not less than the target model performance is searched from the pruning sensitive characteristics.
[0191] wherein, when returning to execute the step S103, the target model performance utilized is the adjusted new target model performance.
[0192] In this way, the target-oriented automatic pruning scheme can be introduced in the process of determining the model pruning rate, and the model to be pruned is pruned by continuously adjusting the target model performance, so that the pruned model continuously approaches the model desired by the user until the model pruning index reaches the preset index threshold.
[0193] Corresponding to the model pruning rate determination method provided by the above-mentioned embodiments of the present application, the embodiments of the present application also provide a model pruning rate determination device.
[0194] Figure 10 A structural diagram of a model pruning rate determination device provided by the embodiments of the present application is shown in FIG. 1. Figure 10 As shown in the figure, the device can include the following modules:
[0195] The pruning sensitivity characteristic acquisition module 1001 is configured to acquire the pruning sensitivity characteristics of each part of the model to be pruned, wherein the pruning sensitivity characteristic of each part is the corresponding relationship between the pruning intensity of the part and the model performance under a specified pruning granularity.
[0196] The target model performance determination module 1002 is configured to determine the target model performance of the model to be pruned after pruning.
[0197] The pruning intensity searching module 1003 is configured to search for, for each part, the pruning intensities corresponding to the model performance not less than the target model performance from the pruning sensitivity characteristics.
[0198] The model pruning rate determination module 1004 is configured to determine the model pruning rate of each part of the model to be pruned based on the searched pruning intensities.
[0199] As can be seen, the scheme provided by the embodiments of the present application is sensitive to pruning of each part of the model due to the mutual relationship and mutual influence between the parts of the model. Thus, after determining the parts of the model to be pruned, for each part, the other parts can be fixed, and the individual pruning sensitivity of the part is considered. Since each individual model pruning feature can not only represent the pruning sensitivity of the part, but also represent the influence degree of the pruning sensitivity of the part on other parts, the relationship and mutual influence between the parts of the model to be pruned are considered when the pruning sensitivity of the parts of the model to be pruned is considered. Thus, when the pruning sensitivity of the parts of the model to be pruned is used to determine the model pruning rate of each part of the model to be pruned, the model performance after pruning can be accurately estimated without retraining the model after pruning when the model to be pruned is pruned according to the determined model pruning rate, thereby reducing the time of model pruning and improving the efficiency of model pruning.
[0200] Optionally, in an implementation manner, the apparatus further includes:
[0201] The model division module is configured to divide the model to be pruned into a plurality of parts according to the structure of the model to be pruned before the pruning sensitivity of each part of the model to be pruned is obtained.
[0202] Optionally, in an implementation manner, the pruning sensitivity obtaining module 1001 includes:
[0203] The data determining sub-module is configured to determine the specified pruning granularity and the preset pruning intensities.
[0204] The model pruning sub-module is configured to, for each part, prune the part according to the preset pruning intensities at the specified pruning granularity, and determine the model performance of the model to be pruned after each pruning.
[0205] The pruning sensitivity obtaining sub-module is configured to, for each part, establish a corresponding relationship between the pruning intensity used in each pruning and the obtained model performance, and obtain the pruning sensitivity of the part.
[0206] Optionally, in an implementation manner, the apparatus further includes:
[0207] The parameter module sorting module is configured to determine, before the part is pruned according to the preset respective pruning intensities at the specified pruning granularity, the importance of each parameter module corresponding to the specified pruning granularity in the part in contributing to the model performance of the model to be pruned, and sort the respective parameter modules in an order from small to large according to the determined importance, to obtain a parameter module sorting.
[0208] The model pruning submodule is specifically configured to, for each preset pruning intensity, determine a target number of parameter modules corresponding to the pruning granularity satisfying the pruning intensity, and remove the target number of parameter modules in sequence from the first parameter module in the parameter module sorting.
[0209] Optionally, in a specific implementation manner, the model to be pruned is a classification model.
[0210] The target model performance determination module 1002 includes a target model performance determination submodule, which is configured to determine the target model performance of the model to be pruned after pruning corresponding to each classification label.
[0211] The pruning intensity searching module 1003 includes a pruning intensity searching submodule, which is configured to, for each part, search, from the pruning sensitive characteristics, a maximum pruning intensity corresponding to each classification label, whose model performance is not less than the target model performance corresponding to each classification label.
[0212] The model pruning rate determination module 1004 includes a model pruning rate determination submodule, which is configured to determine the model pruning rate of each part of the model to be pruned based on the searched respective maximum pruning intensities.
[0213] Optionally, in a specific implementation manner, the model pruning rate determination submodule is specifically configured to:
[0214] For each part, the minimum pruning intensity in the searched respective maximum pruning intensities is used to determine the model pruning rate of the part in the model to be pruned.
[0215] Optionally, in a specific implementation manner, the model pruning rate determination submodule is specifically configured to:
[0216] According to a proportional relationship of the total number of parameter modules corresponding to the specified pruning granularity included in each part, a weighting coefficient corresponding to each part is determined.
[0217] For each part, the minimum pruning strength among the found maximum pruning strengths is determined, and a product of the determined minimum pruning strength and a corresponding weighting coefficient is calculated as a model pruning rate of the part based on the determined minimum pruning strength.
[0218] Optionally, in an implementation form, the apparatus further comprises:
[0219] a model pruning module configured to prune each part of the to-be-pruned model according to the determined model pruning rate, to obtain the pruned to-be-pruned model;
[0220] an index judging module configured to determine a model index of the pruned to-be-pruned model, and judge whether the model index meets a preset index threshold; if not, triggering the performance adjusting module; wherein the model index comprises at least one of model performance, calculation amount, F1, and AP value;
[0221] the performance adjusting module is configured to adjust the target model performance to obtain a new target model performance, and trigger the pruning strength finding module.
[0222] Corresponding to the model pruning rate determination method provided in the above embodiments of the present application, the embodiments of the present application further provide an electronic device, such as Figure 11 As shown in the figure, the electronic device comprises a processor 1101, a communication interface 1102, a memory 1103 and a communication bus 1104, wherein the processor 1101, the communication interface 1102 and the memory 1103 complete communication with each other through the communication bus 1104,
[0223] The memory 1103 is configured to store a computer program.
[0224] The processor 1101 is configured to execute the program stored in the memory 1103, to implement the steps of any model pruning rate determination method provided in the above embodiments of the present application.
[0225] The communication bus mentioned in the above electronic device 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 shown in the figure, but it does not mean that there is only one bus or only one type of bus.
[0226] The communication interface is configured to communicate between the above electronic device and other devices.
[0227] The memory can include a random access memory (RAM) and can also include a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory can also be at least one storage device located away from the aforementioned processor.
[0228] 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.
[0229] In yet another 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 rate determination method provided by the embodiments of the present application.
[0230] In yet another embodiment provided by the present application, a computer program product containing instructions is also provided, and when the computer program product is run on a computer, the computer is caused to perform the steps of any model pruning rate determination method provided by the embodiments of the present application.
[0231] In the embodiments described above, all or some of the steps can be implemented by software, hardware or firmware, or any combination thereof. When implemented by software, all or some of the steps can be implemented in the form of one or more computer programs. The computer program can be stored in any computer readable medium, and loaded into the computer for execution. The computer readable medium includes computer storage media and communication media. The computer storage media includes any tangible or physical medium for storing or transmitting the program. The computer storage media can be a volatile (such as RAM) or non-volatile (such as ROM, disk, or CD) storage medium. The communication media typically include computer readable instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transport mechanism, and includes any information delivery media. The computer readable medium can be a computer program product.
[0232] It should be noted that, in this document, the terms such as first and second are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Also, the terms "comprises", "comprising", or any other variations thereof are intended to cover a non-exclusive inclusion, so that a process, method, article, or apparatus that comprises a list of elements does not only include those elements, but also includes other elements not expressly listed, or other elements inherent in such process, method, article, or apparatus. Without more limitations, an element defined by the statement "comprising a" does not exclude the existence of additional identical elements in the process, method, article, or apparatus that includes the element.
[0233] Each of the embodiments in the specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other. Each embodiment focuses on the difference from other embodiments. In particular, for the device embodiment, the electronic device embodiment, the computer readable storage medium embodiment, and the computer program product embodiment, since they are basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the part of the method embodiment.
[0234] The above merely describes the preferred embodiments of the present application, but is not used 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 method for determining the pruning rate of a model, characterized in that, The method is applied to image recognition, voice interaction or intelligent security scenarios, and comprises the following steps: Obtaining pruning sensitivity characteristics of each part of a to-be-pruned model; wherein, the pruning sensitivity characteristics of each part are the corresponding relationship between the pruning strength and the model performance of the part under a specified pruning granularity, the pruning sensitivity characteristics of each part are used to represent the pruning sensitivity characteristics of the part and the influence degree of the part on the pruning sensitivity characteristics of other parts, the to-be-pruned model is a classification model, the specified pruning granularity is the size of each parameter module removed when pruning the to-be-pruned model, and the pruning strength is the proportion of the removed parameter module in all parameter modules included in the part. Determining the target model performance of the to-be-pruned model after pruning corresponding to each classification label. For each part, finding the maximum pruning strength corresponding to the model performance not less than the target model performance corresponding to each classification label from the pruning sensitivity characteristics. Based on the found maximum pruning strength, determining the model pruning rate of each part of the to-be-pruned model. The step of obtaining the pruning sensitivity characteristics of each part of the to-be-pruned model comprises the following steps: Determining the specified pruning granularity and the preset pruning strength. For each part, determining the total number of parameter modules corresponding to the specified pruning granularity included in the part; traversing the preset pruning strength, calculating the product of the total number and each pruning strength as the number of parameter modules to be removed when traversing each pruning strength, removing the calculated number of parameter modules corresponding to the specified pruning granularity to obtain the pruned to-be-pruned model, and determining the model performance of the obtained pruned to-be-pruned model. For each part, establishing the corresponding relationship between the pruning strength used in each pruning and the obtained model performance to obtain the pruning sensitivity characteristics of the part.
2. The method of claim 1, wherein, Before the step of obtaining the pruning sensitivity characteristics of each part of the to-be-pruned model, the method further comprises the following step: According to the structure of the to-be-pruned model, dividing the to-be-pruned model into multiple parts.
3. The method of claim 1, wherein, Before the step of pruning the part under the specified pruning granularity according to the preset pruning strength, the method further comprises the following step: Determining the importance of each parameter module corresponding to the specified pruning granularity in the part to the model performance of the to-be-pruned model; and sorting the parameter modules in the order from small to large according to the determined importance to obtain a parameter module sorting. The step of pruning the part under the specified pruning granularity according to the preset pruning strength comprises the following steps: For each preset pruning strength, determining the target number of parameter modules corresponding to the pruning granularity satisfying the pruning strength, and removing the target number of parameter modules from the first parameter module in the parameter module sorting in sequence.
4. The method of claim 1, wherein, The step of determining the model pruning rate of each part of the model to be pruned based on the found maximum pruning strength of each part comprises: For each part, the minimum pruning strength of the found maximum pruning strength of each part is determined, and the model pruning rate of the part is calculated based on the determined minimum pruning strength and the product of the determined minimum pruning strength and the corresponding weighting coefficient.
5. The method of claim 1, wherein, The step of determining the model pruning rate of each part of the model to be pruned based on the found maximum pruning strength of each part comprises: According to the proportional relationship of the total number of parameter modules corresponding to the specified pruning granularity included in each part, a weighting coefficient corresponding to each part is determined; For each part, the minimum pruning strength of the found maximum pruning strength of each part is determined, and the model pruning rate of the part is calculated based on the determined minimum pruning strength and the product of the determined minimum pruning strength and the corresponding weighting coefficient.
6. The method of claim 1, wherein, The method further comprises: Pruning each part of the model to be pruned according to the determined model pruning rate to obtain the pruned model to be pruned; Determine the model index of the pruned model to be pruned, and determine whether the model index meets the preset index threshold; wherein the model index comprises at least one of model performance, computational complexity, F1, and AP value; If not, adjust the target model performance to obtain a new target model performance, and return to the step of finding, for each part, the pruning strength corresponding to the model performance not less than the target model performance from the pruning sensitive characteristics.
7. A model pruning rate determination apparatus characterized by comprising: Applied to image recognition, voice interaction or intelligent security scene, the device comprises: A pruning sensitive characteristic acquisition module is configured to acquire pruning sensitive characteristics of each part of a model to be pruned; wherein the pruning sensitive characteristics of each part are the corresponding relationship between the pruning strength of the part under a specified pruning granularity and the model performance, and the pruning sensitive characteristics of each part are used to represent the pruning sensitive characteristics of the part and the influence degree of the part on the pruning sensitive characteristics of other parts; the model to be pruned is a classification model; the specified pruning granularity is the size of each parameter module removed when pruning the model to be pruned; and the pruning strength is the proportion of the removed parameter module in all parameter modules included in the part for each part, wherein all parameter modules included in the part are all parameter modules obtained by dividing the parameter modules of the part according to the specified pruning granularity. A target model performance determination module is configured to determine a preset target model performance of the model to be pruned after pruning. A pruning strength finding module is configured to find, for each part, the pruning strength corresponding to the model performance not less than the target model performance from the pruning sensitive characteristics. A model pruning rate determination module is configured to determine the model pruning rate of each part of the model to be pruned based on the found pruning strength of each part. The target model performance determination module comprises a target model performance determination submodule, which is configured to determine the target model performance of the to-be-pruned model after pruning corresponding to each classification label. The pruning sensitivity characteristic acquisition module comprises a data determination submodule, a model pruning submodule, and a pruning sensitivity characteristic acquisition submodule.
8. The apparatus of claim 7, wherein, The device further comprises: The model division module is configured to divide the to-be-pruned model into a plurality of parts according to the structure of the to-be-pruned model before the pruning sensitivity characteristic of each part of the to-be-pruned model is acquired. The parameter module sorting module is configured to determine the importance of each parameter module corresponding to each specified pruning granularity in the part to the model performance of the to-be-pruned model before the part is pruned according to the preset pruning intensities at the specified pruning granularity, and sort the parameter modules in the part according to the determined importance from small to large to obtain a parameter module sorting. The model pruning rate determination submodule is configured to determine the model pruning rate of each part of the to-be-pruned model based on the found maximum pruning intensities. The model pruning rate determination submodule is configured to determine the model pruning rate of the part in the to-be-pruned model by taking the smallest pruning intensity among the found maximum pruning intensities. The model pruning rate determination submodule is configured to determine the model pruning rate of the part in the to-be-pruned model by taking the smallest pruning intensity among the found maximum pruning intensities. The model pruning rate determination submodule is configured to determine the model pruning rate of the part in the to-be-pruned model by taking the smallest pruning intensity among the found maximum pruning intensities. The model pruning rate determination submodule is specifically configured to: determine a weighting coefficient corresponding to each part according to a proportional relationship of a total number of parameter modules corresponding to the specified pruning granularity included in each part; for each part, determine a minimum pruning intensity from the found maximum pruning intensities, and calculate a product of the determined minimum pruning intensity and the corresponding weighting coefficient as the model pruning rate of the part based on the determined minimum pruning intensity; And / or, The device further includes: a model pruning module configured to prune each part of the to-be-pruned model according to the determined model pruning rates to obtain the pruned to-be-pruned model; an index determination module configured to determine a model index of the pruned to-be-pruned model and determine whether the model index meets a preset index threshold; if not, triggering a performance adjustment module; wherein the model index includes at least one of a model performance, a calculation amount, an F1, and an AP value; the performance adjustment module is configured to adjust the target model performance to obtain a new target model performance, and trigger the pruning intensity finding module.
9. An electronic device, comprising: The device includes 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 used to store a computer program. The processor is used to execute the program stored on the memory to implement the method of any one of claims 1-6.
10. A computer-readable storage medium, characterized in that, The computer program stored in the computer readable storage medium is executed by the processor to implement the method of any one of claims 1-6. The computer program stored in the computer readable storage medium is executed by the processor to implement the method of any one of claims 1-6.
Citation Information
Patent Citations
Hierarchical pruning method based on layer recovery sensitivity
CN111461324A
Model pruning method, device and equipment and storage medium
CN113240085A