Model pruning method, device and equipment and storage medium

By pruning and optimizing the model according to the importance of the initial model, the problem in the existing technology that the model accuracy cannot be guaranteed after pruning is solved, the best balance between model size and accuracy is achieved, and the occupation of computing resources and storage space is reduced. .

CN118690815APending Publication Date: 2024-09-24CHINA FAW CO LTD +1
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202410778695.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-17
Publication Date
2024-09-24

AI Technical Summary

Technical Problem

In the process of reducing model complexity and computational cost, existing model pruning methods cannot guarantee the accuracy of the model after pruning, and there is a problem of over-pruning.

Method used

By pruning the initial model according to the preset pruning proportion and the importance of each convolution layer in the initial model, the pruning model is obtained, and the loss function value is calculated on the test data set. If the threshold condition is not met, the pruning model is re-executed. Prune until threshold conditions are met to ensure that the model is optimized for size while improving accuracy.

Benefits of technology

It is possible to improve model accuracy and efficiency while reducing model parameters and computational complexity, ensuring that the pruned model reaches the best balance between performance and size, and reducing deployment time and cost.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118690815A
    Figure CN118690815A
Patent Text Reader

Abstract

The invention discloses a model pruning method, device and equipment and a storage medium, and relates to the technical field of model pruning. The method comprises the steps that pruning is conducted on an initial model according to a preset pruning proportion and the importance degree of each convolution layer in the initial model, a pruning model is obtained, and a first loss function value of the pruning model on a test data set meets a first threshold condition; performing model optimization on the pruning model to obtain an optimization model, and calculating a second loss function value of the optimization model on the test data set; under the condition of determining that the second loss function value does not meet the second threshold condition, returning to execute pruning on the initial model according to the preset pruning proportion and the importance degree of each convolutional layer in the initial model until the second loss function value meets the second threshold condition; and determining the previous optimization model as a target model. Through the technical scheme of the embodiment of the invention, the precision of the pruned model can be improved while the size of the model is optimized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present invention relate to the technical field of model pruning, and in particular to a model pruning method, device, equipment and storage medium. Background Art

[0002] With the rapid development of artificial intelligence technology, deep learning models are increasingly used in various fields. However, as the complexity of the model continues to increase, the computing and storage costs are also rising year by year, which has become a bottleneck restricting the further development of deep learning technology. Especially when processing large-scale data, the huge model parameters and calculation amount not only consume a lot of computing resources, but also increase the time and cost of model training, so how to optimize the model is particularly important.

[0003] Model pruning is an effective model optimization method that aims to reduce the complexity and computational cost of the model by reducing redundant parameters and structures in the model. However, existing model pruning methods all have the problem of over-pruning, which leads to the inability to guarantee the accuracy of the pruned model.

[0004] Therefore, it is urgent to propose a new method to solve the above problems. Summary of the invention

[0005] The present invention provides a model pruning method, device, equipment and storage medium, which optimize the model size and improve the accuracy of the pruned model.

[0006] In a first aspect, an embodiment of the present invention provides a model pruning method, comprising:

[0007] Pruning the initial model according to a preset pruning ratio and the importance of each convolutional layer in the initial model to obtain a pruned model, wherein a first loss function value of the pruned model on a test data set satisfies a first threshold condition;

[0008] Performing model optimization on the pruning model to obtain an optimized model, and calculating a second loss function value of the optimized model on the test data set;

[0009] If it is determined that the second loss function value does not satisfy the second threshold condition, return to execute pruning the initial model according to a preset pruning ratio and the importance of each convolutional layer in the initial model until the second loss function value satisfies the second threshold condition;

[0010] The last optimized model is determined as the target model.

[0011] The embodiment of the present invention provides a model pruning method, including: pruning the initial model according to a preset pruning ratio and the importance of each convolutional layer in the initial model to obtain a pruned model, wherein the first loss function value of the pruned model on a test data set satisfies a first threshold condition; optimizing the pruned model to obtain an optimized model, and calculating the second loss function value of the optimized model on the test data set; when it is determined that the second loss function value does not meet the second threshold condition, returning to execute pruning the initial model according to the preset pruning ratio and the importance of each convolutional layer in the initial model until the second loss function value meets the second threshold condition; determining the last optimized model as the target model. The above technical scheme first prunes the initial model according to the preset pruning ratio and the importance of each convolutional layer in the initial model to obtain a pruned model, which can reduce the number of parameters and computational complexity of the initial model, thereby optimizing the model size and improving the computational speed of the model. At the same time, it is stipulated that the first loss function value of the pruned model on the test data set satisfies the first threshold condition, thereby improving the pruning speed and thus improving the overall efficiency. After that, the pruned model is optimized to obtain an optimized model, which improves the performance of the model, that is, restores the accuracy of the model. Then, the second loss function value of the optimized model is calculated on the test data set to provide a data basis for judging whether the second loss function value meets the second threshold condition. By judging whether the second loss function value meets the second threshold condition, it is ensured that the performance of the model is guaranteed while optimizing the model size, that is, the accuracy of the pruned model can be improved while optimizing the model size. If not, the initial model is pruned again to obtain a pruned model until the second loss function value meets the second threshold condition; if satisfied, the previous optimized model is determined as the target model, achieving the optimal balance between model performance and size, which means that the model can reduce the occupation of computing resources and storage space while ensuring a sufficiently good prediction effect, thereby reducing deployment time and cost. Compared with the existing technology, excessive pruning causes the accuracy of the pruned model to be unable to be guaranteed. The present invention first prunes the initial model according to a preset pruning ratio and the importance of each convolutional layer in the initial model to obtain a pruned model, wherein the first loss function value of the pruned model on a test data set satisfies a first threshold condition; then the pruned model is optimized to obtain an optimized model, and the second loss function value of the optimized model is calculated on the test data set; then, it is determined whether the second loss function value satisfies a second threshold condition, and then the last optimized model whose second loss function value satisfies the second threshold condition is determined as the target model, which can improve the accuracy of the pruned model while optimizing the model size. Therefore, the present invention can solve the problem that the accuracy of the pruned model cannot be guaranteed due to excessive pruning according to the prior art.

[0012] In a second aspect, an embodiment of the present invention further provides a model pruning device, the device comprising:

[0013] A pruning module, used to prune the initial model according to a preset pruning ratio and the importance of each convolutional layer in the initial model to obtain a pruned model, wherein a first loss function value of the pruned model on a test data set satisfies a first threshold condition;

[0014] An optimization module, used to perform model optimization on the pruning model to obtain an optimized model, and calculate a second loss function value of the optimized model on the test data set;

[0015] A first determination module, configured to, when determining that the second loss function value does not satisfy a second threshold condition, return to execute pruning the initial model according to a preset pruning ratio and the importance of each convolutional layer in the initial model until the second loss function value satisfies the second threshold condition;

[0016] The second determination module is used to determine the last optimized model as the target model.

[0017] In a third aspect, an embodiment of the present invention further provides a computer device, the computer device comprising:

[0018] at least one processor; and a memory communicatively coupled to the at least one processor;

[0019] The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can implement any model pruning method described in the first aspect.

[0020] In a fourth aspect, an embodiment of the present invention further provides a storage medium including computer executable instructions,

[0021] The computer executable instructions, when executed by a computer processor, implement any model pruning method described in the first aspect.

[0022] It should be noted that the above computer instructions may be stored in whole or in part on a computer-readable storage medium, wherein the computer-readable storage medium may be packaged together with the processor of the model pruning device, or may be packaged separately from the processor of the model pruning device, and the present invention does not limit this.

[0023] The description of the second, third and fourth aspects of the present invention can refer to the detailed description of the first aspect; and the beneficial effects of the description of the second, third and fourth aspects can refer to the beneficial effect analysis of the first aspect, which will not be repeated here.

[0024] In the present invention, the name of the model pruning device does not limit the device or functional module itself. In actual implementation, these devices or functional modules may appear with other names. As long as the functions of each device or functional module are similar to those of the present invention, they belong to the scope of the claims of the present invention and their equivalent technologies.

[0025] These and other aspects of the present invention will become more apparent from the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0027] Figure 1 A flow chart of a model pruning method provided by an embodiment of the present invention;

[0028] Figure 2 A flowchart of another model pruning method provided by an embodiment of the present invention;

[0029] Figure 3 A schematic diagram of the structure of a model pruning device provided in an embodiment of the present invention;

[0030] Figure 4 A schematic diagram of the structure of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0031] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.

[0032] The term "and / or" in this article is merely a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone.

[0033] The terms “first” and “second” and the like in the specification and drawings of the present invention are used to distinguish different objects, or to distinguish different processing of the same object, rather than to describe a specific order of the objects.

[0034] In addition, the terms "including" and "having" and any variations thereof mentioned in the description of the present invention are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but may optionally include other steps or units that are not listed, or may optionally include other steps or units that are inherent to these processes, methods, products or devices.

[0035] It should be mentioned before discussing exemplary embodiments in more detail that some exemplary embodiments are described as processes or methods depicted as flow charts. Although the flow charts describe various operations (or steps) as sequential processes, many operations therein can be implemented in parallel, concurrently or simultaneously. In addition, the order of various operations can be rearranged. The process can be terminated when its operation is completed, but can also have additional steps not included in the accompanying drawings. The process can correspond to methods, functions, procedures, subroutines, subprograms, etc. In addition, the embodiments in the present invention and the features in the embodiments can be combined with each other without conflict.

[0036] It should be noted that, in the embodiments of the present invention, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present invention should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.

[0037] In the description of the present invention, unless otherwise specified, "plurality" means two or more.

[0038] Figure 1 This is a flow chart of a model pruning method provided by an embodiment of the present invention. This embodiment is applicable to situations where it is necessary to improve the model accuracy while pruning the model. The method can be executed by a model pruning device, which can be implemented in software and / or hardware. For example, the device can be a server. Specifically, the following steps are included:

[0039] Step 110: Prune the initial model according to a preset pruning ratio and the importance of each convolutional layer in the initial model to obtain a pruned model.

[0040] The pre-set pruning ratio refers to the total ratio of model connections or parameters that need to be removed from each convolutional layer during the model pruning process, which is pre-set according to actual conditions or needs. The initial model refers to the original model before the pruning operation, which can be obtained through training of the deep learning framework and contains a large number of parameters and connections. The convolution layer is a key component of the convolutional neural network, which extracts features from the input through convolution operations. The importance of the convolution layer refers to an indicator that measures the contribution of the convolution layer to the overall performance of the model, helping to decide which convolution layers should be retained and which convolution layers should be pruned during the pruning process. The pruned model refers to the model obtained after pruning the initial model.

[0041] The first loss function value of the pruned model on the test data set meets the first threshold condition. The test data set is an independent data set used to evaluate the performance of the model. In the actual application of model pruning, it is usually started from a small pruning ratio, for example: 0.01%, and the initial model is pruned preliminarily. Due to the small pruning ratio, the decline in model performance is usually not particularly significant. At this time, there is no need to optimize the pruned model. At this time, you can continue to use a larger pruning ratio to preliminarily prune the initial model, and calculate the performance index of the pruned model on the test data set, that is, the loss function value, to preliminarily evaluate the performance of the pruned model. After that, as the pruning ratio increases, for example: gradually increasing to 1%, 5% or even 10%, the size of the model will be significantly reduced, but at the same time the performance of the model will also be greatly affected. When the pruning ratio increases to a certain extent, for example: 10%, if the performance of the pruned model on the test data set is significantly reduced at this time, that is, the loss function value exceeds the preset performance threshold, that is, the first threshold condition is met, then it is necessary to optimize the pruned model to restore the performance of the pruned model. In this way, by gradually increasing the pruning ratio, evaluating the performance of the pruning model, and combining the judgment of the first threshold condition to determine whether to optimize the pruning model, the time for determining the target model can be saved, thereby improving the overall efficiency. Therefore, in this embodiment, it can be determined whether to optimize the pruning model by judging whether the first loss function value of the pruning model on the test data set meets the first threshold condition. The first loss function value refers to the loss function value calculated after the pruning model predicts the test data set, which is used to evaluate the performance of the pruning model. The first threshold condition refers to the condition set according to the actual situation or demand for whether the pruning model needs to be optimized. Exemplarily, the first threshold condition can be that the first loss function value is greater than 1.1 times the loss function value obtained by the initial model on the same test data set, and the loss function used by the initial model and the pruning model is consistent. That is, when the first loss function value is less than or equal to 1.1 times the loss function value obtained by the initial model on the test data set, the first threshold condition is not met. At this time, the pruning ratio can be continued to increase and the initial model can be pruned again according to the importance of each convolutional layer in the initial model to obtain a pruned model. When the first loss function value is greater than 1.1 times the loss function value obtained by the initial model on the test data set, the first threshold condition is met. At this time, the pruned model is optimized to obtain an optimized model.

[0042] Specifically, before the initial model is pruned according to the preset pruning ratio and the importance of each convolution layer in the initial model, it is necessary to first determine the importance of each convolution layer. Specifically, a suitable importance evaluation method can be selected according to the actual situation and application requirements to determine the importance of each convolution layer in the initial model. For example, the importance evaluation method can be a weight-based evaluation method, an output feature map-based evaluation method, or a gradient information-based evaluation method. Then, the selected importance evaluation method is applied to determine the importance of each convolution layer in the initial model. When the selected importance evaluation method is a weight-based evaluation method, the weight of each convolution layer can be extracted based on the attributes and methods corresponding to each convolution layer, and then the weight norm of each convolution layer can be calculated, such as the L1 norm, and then the weight norms of all convolution layers are sorted. The importance of each convolution layer is determined according to the sorting result, and then the convolution layer that needs to be pruned can be determined according to the importance of each convolution layer. For example, an importance threshold can be set, and the convolution layer with a weight norm less than the importance threshold is determined as the convolution layer that needs to be pruned. Then, the convolutional layers that need to be pruned are pruned according to the preset pruning ratio to obtain a pruned model. For example, the convolutional layers that need to be pruned are convolutional layer A and convolutional layer B, and the preset pruning ratio is 10%. Then, convolutional layer A and convolutional layer B jointly subtract 10% of the parameters or connections. The pruning ratios of convolutional layer A and convolutional layer B can be determined according to the ratio of the number of parameters of convolutional layer A to the number of parameters of convolutional layer B. When the ratio of the number of parameters of convolutional layer A to the number of parameters of convolutional layer B is 3 to 2, the pruning ratio of convolutional layer A is 6%, and the pruning ratio of convolutional layer B is 4%. Then, convolutional layer A and convolutional layer B are pruned according to the aforementioned pruning ratios to obtain a pruned model.

[0043] After obtaining the pruned model, the first loss function value of the pruned model is calculated on the test data set to ensure that the first loss function value meets the first threshold condition. Specifically, first determine the loss function used for the pruned model, for example: the loss function can be mean square error or cross entropy loss, etc. Then use the determined loss function to calculate the loss value of the pruned model on the test data set, that is, the first loss function value, and then determine whether the calculated first loss function value meets the first threshold condition. If it does, it is considered that the performance of the pruned model does not meet the requirements and needs to be optimized; otherwise, increase the pruning ratio and continue to prune the initial model.

[0044] In this embodiment, the initial model is pruned according to a preset pruning ratio and the importance of each convolutional layer in the initial model to obtain a pruned model, which can reduce the number of parameters and computational complexity of the initial model, thereby optimizing the model size and improving the computational speed of the model. In addition, setting the first loss function value of the pruned model on the test data set to meet the first threshold condition can increase the pruning speed, thereby improving the overall efficiency.

[0045] Step 120: Optimize the pruned model to obtain an optimized model, and calculate a second loss function value of the optimized model on a test data set.

[0046] The second loss function value refers to the loss function value calculated after the optimization model predicts the test data set, which is used to evaluate the performance of the optimization model.

[0047] Specifically, after determining that the first loss function value satisfies the first threshold condition, the pruned model that satisfies the first threshold condition can be optimized. Specifically, a suitable model optimization method can be selected according to the actual situation or needs. For example, the model optimization method can be a parameter adjustment method, a gradient descent method, a momentum method, or an adjustment model architecture. Then, the selected model optimization method is applied to optimize the pruned model. When the selected model optimization method is a parameter adjustment method, the pruned model can be optimized by adjusting the learning rate of the pruned model. For example, the pruned model can be trained using the same training data set as the initial model. When training the pruned model, the initial learning rate is first set, and then the learning rate is gradually reduced as the number of training rounds increases. For example, after each round of training is completed, the learning rate is multiplied by a decay factor less than 1, such as 0.9. After each round of training, the performance of the model is evaluated by calculating the loss function value on the validation data set, and the model with the best performance on the validation data set is recorded. After the training is completed, the model with the best performance on the validation data set is determined as the optimized model. The termination condition of the training can be set to reach a preset number of iterations, the performance on the validation data set no longer improves, or the learning rate drops to a preset threshold. After obtaining the optimized model, the second loss function value of the optimized model is calculated on the test data set. For example, when the loss function is the mean square error, the mean square error is used to calculate the loss value of the optimized model on the test data set, that is, the second loss function value.

[0048] In this embodiment, the pruned model is optimized to obtain an optimized model, thereby improving the performance of the model, that is, restoring the accuracy of the model. Then, the second loss function value of the optimized model is calculated on the test data set to provide a data basis for determining whether the second loss function value meets the second threshold condition.

[0049] Step 130: Determine whether the second loss function value satisfies a second threshold condition.

[0050] If so, execute step 140 ; ​​if not, return to execute step 110 .

[0051] Among them, in the actual application of model pruning and optimization, an iterative process is usually experienced to balance the performance and size of the model. Specifically, when the pruned model does not meet the performance requirements, it will be optimized to improve the performance. However, the performance of the optimized model may be in two situations: one is that the performance meets the actual requirements, and the other is that the performance still does not meet the actual requirements. If the performance of the optimized model obtained by optimizing the pruned model meets the actual requirements, in order to ensure that the accuracy of the pruned model is improved while optimizing the model size, the initial model can continue to be pruned. If the performance of the optimized model obtained by optimizing the pruned model does not meet the actual requirements, it means that the optimization model of the previous round has been pruned to the minimum, which also means that a model that achieves a balance between performance and size is found, that is, the optimization model of the previous round. At this time, the optimization model of the previous round can be determined as the target model. Therefore, in this embodiment, in order to more accurately control the process of model optimization and pruning, on the basis of setting the first threshold condition, a second threshold condition can be set to determine whether to continue pruning when the performance meets the requirements, so as to ensure that the obtained model achieves the best balance between performance and size, that is, while reducing the model size, the accuracy of the pruned model is improved. Therefore, the target model can be determined by setting a second threshold condition, and the second threshold condition refers to a requirement that the performance of the target model set according to actual conditions or needs must meet.

[0052] Specifically, after obtaining the second loss function value, it is determined whether the second loss function value satisfies the second threshold condition. If so, the previous optimization model is determined as the target model. If not, the initial model is pruned again to obtain a pruned model until the second loss function value satisfies the second threshold condition. Specifically, the initial model can be pruned again by adjusting the pruning strategy, that is, adjusting the pruning ratio determined above, so that the second loss function value obtained later satisfies the second threshold condition.

[0053] Exemplarily, the second threshold condition may be that the second loss function value is greater than 1.2 times the loss function value obtained by the initial model on the same test data set, and the loss function used by the initial model and the optimization model is consistent. That is, when the second loss function value is less than or equal to 1.2 times the loss function value obtained by the initial model on the test data set, the second threshold condition is not met. At this time, the pruning ratio is increased and the initial model is pruned again according to the importance of each convolutional layer in the initial model to obtain a pruned model. When the second loss function value is greater than 1.2 times the loss function value obtained by the initial model on the test data set, the second threshold condition is met, and the previous optimization model is determined as the target model.

[0054] In this embodiment, by determining whether the second loss function value satisfies the second threshold condition, it is ensured that the performance of the model is guaranteed while optimizing the model size, that is, the accuracy of the pruned model can be improved while optimizing the model size.

[0055] Step 140: determine the last optimized model as the target model.

[0056] The target model refers to the model that achieves the best balance between performance and size.

[0057] Specifically, after determining that the second loss function value satisfies the second threshold condition, the previous optimization model can be determined as the target model.

[0058] In this embodiment, the previous optimization model is determined as the target model, which ensures that the model achieves the optimal balance between performance and size. This means that the model can reduce the usage of computing resources and storage space while ensuring sufficiently good prediction results, thereby reducing deployment time and cost.

[0059] The model pruning method provided by the embodiment of the present invention includes: pruning the initial model according to a preset pruning ratio and the importance of each convolutional layer in the initial model to obtain a pruned model, wherein the first loss function value of the pruned model on the test data set meets the first threshold condition; optimizing the pruned model to obtain an optimized model, and calculating the second loss function value of the optimized model on the test data set; when it is determined that the second loss function value does not meet the second threshold condition, returning to execute pruning the initial model according to the preset pruning ratio and the importance of each convolutional layer in the initial model until the second loss function value meets the second threshold condition; determining the previous optimized model as the target model. The above technical scheme first prunes the initial model according to the preset pruning ratio and the importance of each convolutional layer in the initial model to obtain a pruned model, which can reduce the number of parameters and the computational complexity of the initial model, thereby optimizing the model size and improving the computational speed of the model. At the same time, it is stipulated that the first loss function value of the pruned model on the test data set meets the first threshold condition, which improves the pruning speed and thus improves the overall efficiency. After that, the pruned model is optimized to obtain an optimized model, which improves the performance of the model, that is, restores the accuracy of the model. Then, the second loss function value of the optimized model is calculated on the test data set to provide a data basis for judging whether the second loss function value meets the second threshold condition. By judging whether the second loss function value meets the second threshold condition, it is ensured that the performance of the model is guaranteed while optimizing the model size, that is, the accuracy of the pruned model can be improved while optimizing the model size. If not, the initial model is pruned again to obtain a pruned model until the second loss function value meets the second threshold condition; if satisfied, the previous optimized model is determined as the target model, achieving the optimal balance between model performance and size, which means that the model can reduce the occupation of computing resources and storage space while ensuring a sufficiently good prediction effect, thereby reducing deployment time and cost. Compared with the existing technology, excessive pruning causes the accuracy of the pruned model to be unable to be guaranteed. The present invention first prunes the initial model according to a preset pruning ratio and the importance of each convolutional layer in the initial model to obtain a pruned model, wherein the first loss function value of the pruned model on a test data set satisfies a first threshold condition; then the pruned model is optimized to obtain an optimized model, and the second loss function value of the optimized model is calculated on the test data set; then, it is determined whether the second loss function value satisfies a second threshold condition, and then the last optimized model whose second loss function value satisfies the second threshold condition is determined as the target model, which can improve the accuracy of the pruned model while optimizing the model size. Therefore, the present invention can solve the problem that the accuracy of the pruned model cannot be guaranteed due to excessive pruning according to the prior art.

[0060] Figure 2A flowchart of another model pruning method provided by an embodiment of the present invention, which is specific based on the above embodiment. In this embodiment, the method may also include:

[0061] Step 210: Perform trial pruning on the initial model according to a preset trial pruning ratio to obtain multiple trial pruning models.

[0062] In order to determine the importance of each convolutional layer in the initial model, each convolutional layer in the initial model can be pruned with the same pruning ratio to obtain the corresponding pruning model of each convolutional layer. Then, the performance of each pruning model is evaluated on the test data set, and each pruning model is sorted in order of performance from high to low. Finally, the importance of each convolutional layer in the initial model is determined according to the performance sorting result of the pruning model. That is, the higher the ranking of the pruning model, the lower the importance of the convolutional layer corresponding to the pruning model. Because the higher the performance of the model means that the impact on the model performance after pruning the convolutional layer is small, therefore, the importance of the convolutional layer is low, so the convolutional layer can be selected for pruning in the subsequent pruning, so as to minimize the model size and the amount of calculation, while ensuring the model performance. Therefore, in this embodiment, the pre-set trial pruning ratio refers to the ratio of model connections or parameters that need to be removed in the pruned convolutional layer during the trial pruning process determined according to the actual situation or demand. Exemplarily, the pre-set trial pruning ratio can be 20%, 25%.

[0063] Specifically, first, the trial pruning ratio and pruning strategy are determined according to the actual situation or needs, for example: the trial pruning ratio can be 20%, and the pruning strategy can be a weight-based pruning strategy or a channel-based pruning strategy. Then, the selected trial pruning ratio and pruning strategy are applied to prune each convolution layer in the model to obtain multiple trial pruning models. Exemplarily, if the currently pruned convolution layer is convolution layer A, the selected trial pruning ratio is 20%, and the pruning strategy is a weight-based pruning strategy, then the weights of the convolution kernels in convolution layer A can be sorted from high to low, and the number of convolution kernels that need to be pruned for each convolution layer is calculated according to the set trial pruning ratio, and then pruned according to the sorting result and the calculated number. For example, if a convolution layer has 100 convolution kernels, the number of convolution kernels that need to be pruned is 20, and then the convolution kernel with the lowest weight is pruned according to the sorting result until the number of pruned convolution kernels is equal to 20.

[0064] In this embodiment, the initial model is trial pruned according to a preset trial pruning ratio to obtain multiple trial pruning models, which provide a data basis for subsequently determining the importance of each convolutional layer in the initial model.

[0065] Step 211, determine the importance of each convolutional layer in the initial model based on the first loss value list of each functional module in the initial model on the test data set and the second loss value list of each functional module in each trial pruning model on the test data set.

[0066] The first loss value list refers to the list of loss values ​​output by each functional module when the initial model is run on the test data set. The second loss value list refers to the list of loss values ​​output by each functional module when the trial pruned model is run on the test data set. Each trial pruned model has a corresponding second loss value list.

[0067] Specifically, after obtaining the first loss value list and the second loss value list of each trial pruning model, the difference between the first loss value list and the second loss value list of each trial pruning model can be calculated respectively to obtain a difference loss value list, and then the variance of each difference loss value list is calculated to obtain the variance result, and then each difference loss value list is sorted from high to low according to the variance result, and finally, according to the sorting result of the variance, the importance of each convolutional layer in the initial model is determined, that is, the higher the ranking of the trial pruning model, the higher its importance, because the larger the variance, the greater the change in the corresponding difference loss value list, that is, the more serious the performance of the corresponding trial pruning model is damaged, that is, the higher the importance of the convolutional layer corresponding to the trial pruning model.

[0068] Furthermore, step 211 may specifically include: determining a difficulty value list of each functional module in the initial model according to the first loss value list; determining an intermediate loss value list corresponding to each trial pruning model according to the first loss value list and the second loss value list corresponding to each trial pruning model; determining the importance of each convolutional layer in the initial model according to the initial execution time corresponding to the initial model, the trial pruning execution time corresponding to each trial pruning model, the difficulty value list, and each intermediate loss value list.

[0069] Among them, the difficulty value list refers to the list composed of the loss percentage values ​​of each functional module in the initial model. The intermediate loss value list refers to the list obtained by subtracting the second loss value list from the first loss value list. The initial execution time corresponding to the initial model refers to the sum of the time it takes for the initial model to run each functional module. The trial pruning execution time corresponding to the trial pruning model refers to the sum of the time it takes for the trial pruning model to run each functional module.

[0070] Specifically, after obtaining the first loss value list, the difficulty value list of each functional module in the initial model can be determined according to the first loss value list, wherein the calculation formula of the difficulty value of each functional module is shown in formula (1).

[0071]

[0072] Among them, difficulty represents the difficulty value, N represents the Nth functional module, and loss N represents the loss value of the Nth functional module, sum_losslist represents the sum of the loss values ​​of each functional module, α represents the reduction or expansion ratio, which is used to reduce the calculation complexity, and e represents the sensitivity factor, which is used to prevent some functional modules from having too small loss values, resulting in the calculated difficulty value approaching zero. The calculation formula of e is shown in formula (2).

[0073]

[0074] Where num represents the number of functional modules in the initial model.

[0075] Then, the difficulty value of each functional module can be combined in order to obtain a difficulty value list. Furthermore, the difference between the second loss value list and the first loss value list corresponding to each trial pruning model can be calculated respectively to obtain the intermediate loss value list corresponding to each trial pruning model, wherein, in order to facilitate subsequent calculations, the values ​​less than zero in the intermediate loss value list can be set to zero. Finally, the importance of each convolutional layer in the initial model can be determined based on the initial execution time corresponding to the initial model, the trial pruning execution time corresponding to each trial pruning model, the difficulty value list, and each intermediate loss value list. The specific process is as follows: the importance value of each functional module can be calculated based on the initial execution time corresponding to the initial model, the trial pruning execution time corresponding to each trial pruning model, the difficulty value list, and each intermediate loss value list, wherein the calculation formula for the importance value of each functional module is shown in formula (3).

[0076] Importane N = midlist N ×difficulty N / (TT N ) (3)

[0077] Among them, importane represents the importance value, midlist represents the intermediate loss value list, T represents the initial execution time corresponding to the initial model, and T N Indicates the trial pruning execution time corresponding to the trial pruning model corresponding to the Nth functional module. The initial execution time corresponding to each model can be obtained by recording the time consumed by the model from the start of operation to the completion of operation through the model operation software.

[0078] Then sort the importance values ​​of each functional module to determine the importance of each convolutional layer.

[0079] In this embodiment, the importance of each convolutional layer in the initial model is determined based on the first loss value list of each functional module in the initial model on the test data set and the second loss value list of each functional module in each trial pruning model on the test data set, thereby improving the accuracy and efficiency of determining the importance of each convolutional layer.

[0080] Step 212: Determine the pruned convolutional layer according to the importance of each convolutional layer in the initial model and the preset screening ratio.

[0081] In practical applications, in order to avoid affecting the performance of the model by pruning the convolutional layers with higher importance, these convolutional layers are usually not pruned directly. The importance of each convolutional layer will be determined first and sorted. Then, according to the preset screening ratio, a part of the convolutional layers with relatively low importance is selected for pruning. Therefore, in this embodiment, the preset screening ratio refers to the proportion of convolutional layers that can be selected for pruning among all convolutional layers, which can be set according to actual conditions or needs. For example, the preset screening ratio can be 20%, that is, when the number of convolutional layers is 100, the last 20 convolutional layers in the order of importance from high to low can be pruned. Pruned convolutional layers refer to convolutional layers that can be pruned.

[0082] Specifically, after determining the importance of each convolutional layer in the initial model, the convolutional layers that can be pruned can be screened out from the convolutional layers according to the importance of each convolutional layer and the preset screening ratio, that is, the pruned convolutional layers. Exemplarily, assuming that the preset screening ratio can be 50%, the number of convolutional layers is 10, and the convolutional layers are A, B, C, D, E, F, G, H, I, and J, respectively. The importance ranking results of each convolutional layer are: A>B>E>D>C>J>G>I>H>F, then the five convolutional layers J, G, I, H, and F can be determined as pruned convolutional layers.

[0083] In this embodiment, the pruned convolutional layers are determined according to the importance of each convolutional layer in the initial model and a preset screening ratio, which can avoid the problem of greatly reducing the model performance due to pruning the convolutional layers with higher importance, thereby ensuring the accuracy of the model.

[0084] Step 213: Prune the pruned convolutional layer according to a preset pruning ratio to obtain a pruned model.

[0085] Among them, the first loss function value of the pruning model on the test data set meets the first threshold condition.

[0086] Exemplarily, assuming that the pruned convolutional layers are convolutional layer C and convolutional layer D, and the preset pruning ratio is 24%, the convolutional layer C and the convolutional layer D jointly subtract 24% of the parameters or connections, and the pruning ratios of the convolutional layer C and the convolutional layer D can be determined according to the importance ratio of the parameters of the convolutional layer C and the convolutional layer D. If the importance ratio of the parameters of the convolutional layer C and the convolutional layer D is 5 to 3, the pruning ratio of the convolutional layer C is 9%, and the pruning ratio of the convolutional layer D is 15%. After that, the convolutional layer C and the convolutional layer D are pruned according to the pruning ratios determined above, thereby obtaining a pruned model.

[0087] Step 214: Train the pruning model on the training data set to obtain a training model.

[0088] Specifically, before training the pruned model, the training data set used by the pruned model is first determined. For example, the training data set can be the same initial training data set as the initial model; or it can be a scaled-down initial training data set, such as reducing the initial training data set by 200:1 according to the ratio of each category in the initial training data set. Then, appropriate hyperparameters are set according to actual needs and the determined characteristics of the training data set. For example, hyperparameters can be learning rate, batch size, or number of iterations. Then, retrain on the training data set to obtain a training model.

[0089] In addition, during each round of training, the validation dataset can be used to monitor the performance of the model and adjust the hyperparameters of the next round of training based on the evaluation indicators such as accuracy and loss calculated on the validation dataset.

[0090] In this embodiment, the pruning model is trained on the training data set to obtain a training model, which provides a data basis for obtaining the optimization model later.

[0091] Step 215: Optimize the training model based on knowledge distillation to obtain an optimized model.

[0092] Specifically, a suitable distillation method can be selected according to the actual situation and application requirements to optimize the training model. For example, the distillation method can be responsive distillation, feature distillation or relational distillation. Then, the selected distillation method is applied to optimize the training model to obtain an optimized model. When the selected distillation method is responsive distillation, the initial model can be determined as the teacher model, and the training model can be determined as the student model. Then, the teacher model is used to forward propagate the training data to obtain the output of the teacher model on each sample. In the training process of the student model, the output of the teacher model is used as supervision information, and a loss function is defined to measure the difference between the output of the student model and the output of the teacher model. For example, the loss function can be cross entropy loss or KL divergence. The student model is then trained using the training data set and the defined loss function. In each iteration, the output of the student model is compared with the output of the teacher model, and the loss value is calculated. Then, the parameters of the student model are updated by the backpropagation algorithm to minimize the loss value. At the same time, during each round of training, the validation data set is used to monitor the performance of the student model, and the hyperparameters of the next round of training are adjusted according to the evaluation indicators such as accuracy and loss calculated on the validation data set until the preset stopping conditions are met. For example, the stopping condition can be reaching the maximum number of iterations, the performance of the validation set is no longer improved, etc. Finally, the model with the best evaluation indicators calculated on the validation data set is used as the optimized model.

[0093] In this embodiment, the training model is optimized based on knowledge distillation to obtain an optimized model, which can improve the accuracy of the pruned model while improving the stability of the model.

[0094] Step 216: Calculate the second loss function value of the optimization model on the test data set.

[0095] Step 217: Determine whether the second loss function value satisfies the second threshold condition.

[0096] If satisfied, execute step 218; if not satisfied, after executing step 219, return to execute step 210.

[0097] Step 218: determine the last optimized model as the target model.

[0098] Furthermore, when it is determined that the second loss function value satisfies the second threshold condition, it also includes: training the optimization model to obtain an intermediate model, and calculating the third loss function value of the intermediate model on a test data set; when it is determined that the third loss function value does not satisfy the second threshold condition, returning to execute pruning the initial model according to the importance of each convolutional layer in the initial model until the third loss function value satisfies the second threshold condition; and determining the previous intermediate model or the previous optimization model as the target model.

[0099] The intermediate model refers to the model obtained after training the optimization model. The third loss function value refers to the loss function value calculated after the intermediate model predicts the test data set, which is used to evaluate the performance of the intermediate model.

[0100] Specifically, in order to improve computational efficiency, when optimizing the pruned model, the training data set used can be a scaled-down initial training data set, because a smaller data set can speed up training. However, this approach will result in the performance of the obtained model being lower than that of the model trained directly using the complete initial training data set. After the pruned model is optimized on the reduced data set, if the second loss function value of the optimized model calculated on the test data set meets the second threshold condition, the optimized model is trained again using the complete initial training data set to obtain an intermediate model, and the third loss function value of the intermediate model is calculated on the test data set to evaluate the performance of the intermediate model. If the third loss function value does not meet the second threshold condition, it means that the performance of the intermediate model meets the actual needs. At this time, in order to ensure that the accuracy of the pruned model is improved while optimizing the model size, the initial model can continue to be pruned until the third loss function value meets the second threshold condition. If the third loss function value meets the second threshold condition, it means that the performance of the intermediate model still cannot meet the actual needs, that is, the model of the previous round has been pruned to the minimum, which also means that a model that strikes a balance between performance and size has been found. At this time, the previous intermediate model or the previous optimized model can be determined as the target model. For example, if the current round of pruning is the first time to train the optimized model and the third loss function value meets the second threshold condition, the previous optimized model is determined as the target model. If the current round of pruning is not the first time to train the optimized model and the third loss function value meets the second threshold condition, the previous intermediate model is determined as the target model.

[0101] In this embodiment, through the above steps, the model performance can be improved, ensuring that the accuracy of the pruned model is improved while reducing the model size.

[0102] Step 219: update the first threshold condition according to the threshold update method to obtain an updated first threshold condition; and update the pruning ratio according to the ratio update method to obtain an updated pruning ratio.

[0103] Among them, the threshold update method refers to a method for dynamically adjusting or updating the first threshold condition according to the pruning degree of the model. In this embodiment, as the pruning ratio of the model increases, although the pruning model can be optimized and its performance can be improved, the overall performance is gradually reduced, that is, the recovery ability of the model gradually deteriorates. Therefore, in order to ensure the balance of each round of pruning, the first threshold can be reduced at a fixed ratio, that is, the threshold update method is updated threshold = fixed ratio × threshold, for example: the fixed ratio can be 90%. The proportion update method refers to a method for dynamically adjusting or updating the pruning ratio determined according to actual conditions or needs, for example: the proportion update method can be updated ratio = pruning ratio + 0.1%, that is, each pruning ratio is 0.1% more than the pruning ratio of the previous round.

[0104] Specifically, after determining that the second loss function value does not meet the first threshold condition, the first threshold condition is updated according to the threshold update method to obtain the updated first threshold condition, and the pruning ratio is updated according to the ratio update method to obtain the updated pruning ratio, and then the updated pruning ratio is used to prune the initial model, and when determining the pruned model, the updated first threshold condition is used. Specifically, after determining that the second loss function value does not meet the currently set second threshold condition, the first threshold condition is adjusted according to the preset threshold update method, and the pruning ratio is adjusted according to the ratio update method. Then, the initial model is pruned using the updated pruning ratio to obtain a pruned model, wherein the first loss function value of the pruned model on the test data set meets the updated first threshold condition. In subsequent processing, the second loss function value will be recalculated, and it will be determined whether the second threshold condition is met. If not, the first threshold and pruning ratio will continue to be updated until the conditions are met.

[0105] After executing step 219, the first threshold condition may be replaced based on the updated first threshold condition, the pruning ratio may be replaced based on the updated pruning ratio, and the process returns to execute step 210. In this embodiment, by updating the first threshold condition and the pruning ratio, the degree of pruning may be more accurately controlled to avoid over-pruning and under-pruning, while improving the flexibility and efficiency of the pruning process, and helping to reduce the scale of the model while ensuring the accuracy of the model.

[0106] The model pruning method provided by the embodiment of the present invention includes: trial pruning the initial model according to a preset trial pruning ratio to obtain multiple trial pruning models; determining the importance of each convolution layer in the initial model according to a first loss value list of each functional module in the initial model on a test data set and a second loss value list of each functional module in each trial pruning model on a test data set; determining the pruned convolution layer according to the importance of each convolution layer in the initial model and a preset screening ratio; pruning the pruned convolution layer according to a preset pruning ratio to obtain a pruned model; training the pruned model on a training data set to obtain a training model; optimizing the training model based on knowledge distillation to obtain an optimized model; calculating a second loss function value of the optimized model on a test data set; judging whether the second loss function value meets a second threshold condition; if so, determining the previous optimized model as the target model; if not, returning to execute pruning the initial model according to a preset pruning ratio and the importance of each convolution layer in the initial model until the second loss function value meets the second threshold condition. The above technical solution first performs trial pruning on the initial model according to a preset trial pruning ratio to obtain multiple trial pruning models, and determines the importance of each convolution layer in the initial model according to the first loss value list of each functional module in the initial model on the test data set and the second loss value list of each functional module in each trial pruning model on the test data set, thereby improving the accuracy and efficiency of determining the importance of each convolution layer. Then, the pruned convolution layer is determined according to the importance of each convolution layer in the initial model and the preset screening ratio, thereby avoiding the problem of greatly reducing the performance of the model due to pruning the convolution layer with higher importance, thereby ensuring the accuracy of the model. The pruned convolution layer is pruned according to the preset pruning ratio to obtain a pruned model, which can reduce the number of parameters and computational complexity of the initial model, thereby optimizing the model size and improving the computational speed of the model. Afterwards, the pruned model is trained on the training data set to obtain a training model, and the training model is optimized based on knowledge distillation to obtain an optimized model, which can improve the accuracy of the pruned model while improving the stability of the model. Then, the second loss function value of the optimized model is calculated on the test data set, and then it is determined whether the second loss function value meets the second threshold condition to ensure that the model accuracy is guaranteed while optimizing the model size, that is, the accuracy of the pruned model can be improved while optimizing the model size. If not, the initial model is pruned again to obtain a pruned model until the second loss function value meets the second threshold condition; if it is satisfied, the previous optimized model is determined as the target model, achieving the optimal balance between the performance and size of the model, which means that the model can reduce the use of computing resources and storage space while ensuring a sufficiently good prediction effect, thereby reducing deployment time and cost.

[0107] Compared with the prior art, the accuracy of the pruned model cannot be guaranteed due to excessive pruning. The present invention first prunes the initial model according to the pre-set pruning ratio and the importance of each convolutional layer in the initial model to obtain a pruned model, wherein the first loss function value of the pruned model on the test data set satisfies the first threshold condition; then the pruned model is optimized to obtain an optimized model, and the second loss function value of the optimized model is calculated on the test data set; then, it is determined whether the second loss function value satisfies the second threshold condition, and then the previous optimized model whose second loss function value satisfies the second threshold condition is determined as the target model, which can improve the accuracy of the pruned model while optimizing the model size. Therefore, the present invention can solve the problem that the accuracy of the pruned model cannot be guaranteed due to excessive pruning according to the prior art.

[0108] In addition, the importance of each convolutional layer in the initial model is determined based on the initial execution time corresponding to the initial model, the trial pruning execution time corresponding to each trial pruning model, the difficulty value list, and the intermediate loss value list, thereby improving the accuracy of the determined importance of each convolutional layer.

[0109] Moreover, by updating the first threshold condition and the pruning ratio, the degree of pruning can be controlled more accurately to avoid over-pruning and under-pruning, while improving the flexibility and efficiency of the pruning process, helping to reduce the scale of the model while ensuring the accuracy of the model.

[0110] Of course, in order to improve computational efficiency, a scaled-down initial training dataset is used when optimizing the pruned model. However, this approach will result in a model with lower performance than the model trained directly using the full initial training dataset. To solve this problem, after the pruned model is optimized on the scaled-down dataset, the optimized model can be retrained using the full initial training dataset to improve model performance and ensure that the accuracy of the pruned model is improved while reducing the model size.

[0111] Figure 3 A schematic diagram of the structure of a model pruning device provided in an embodiment of the present invention. The device and the model pruning methods of the above-mentioned embodiments belong to the same inventive concept. For details not fully described in the embodiments of the model pruning device, reference can be made to the embodiments of the above-mentioned model pruning methods.

[0112] like Figure 3 As shown, the device comprises:

[0113] A pruning module 310 is used to prune the initial model according to a preset pruning ratio and the importance of each convolutional layer in the initial model to obtain a pruned model, wherein a first loss function value of the pruned model on a test data set satisfies a first threshold condition;

[0114] An optimization module 320 is used to perform model optimization on the pruning model to obtain an optimized model, and calculate a second loss function value of the optimized model on the test data set;

[0115] A first determination module 330 is used for returning to execute pruning the initial model according to a preset pruning ratio and the importance of each convolutional layer in the initial model, until the second loss function value satisfies the second threshold condition when it is determined that the second loss function value does not satisfy the second threshold condition;

[0116] The second determination module 340 is used to determine the last optimized model as the target model.

[0117] Based on the above embodiment, the device further includes:

[0118] A trial pruning module is used to perform trial pruning on the initial model according to a preset trial pruning ratio before pruning the initial model according to the importance of each convolutional layer in the initial model to obtain multiple trial pruning models; the importance of each convolutional layer in the initial model is determined according to a first loss value list of each functional module in the initial model on the test data set and a second loss value list of each functional module in each trial pruning model on the test data set.

[0119] On the basis of the above embodiment, determining the importance of each convolutional layer in the initial model according to the first loss value list of each functional module in the initial model on the test data set and the second loss value list of each functional module in each trial pruning model on the test data set includes:

[0120] Determine a difficulty value list of each of the functional modules in the initial model according to the first loss value list;

[0121] Determine an intermediate loss value list corresponding to each of the trial pruning models according to the first loss value list and the second loss value list corresponding to each of the trial pruning models;

[0122] The importance of each convolutional layer in the initial model is determined according to the initial execution time corresponding to the initial model, the trial pruning execution time corresponding to each trial pruning model, the difficulty value list, and the intermediate loss value list.

[0123] Based on the above embodiment, the pruning module 310 is specifically configured to:

[0124] Determine the pruned convolution layer according to the importance of each convolution layer in the initial model and a preset screening ratio;

[0125] The pruned convolutional layer is pruned according to the pruning ratio to obtain the pruned model.

[0126] Based on the above embodiment, the pruning model is optimized to obtain an optimized model, including:

[0127] Training the pruning model on a training data set to obtain a training model;

[0128] The training model is optimized based on knowledge distillation to obtain the optimized model.

[0129] Based on the above embodiment, the device further includes:

[0130] An updating module is used to update the first threshold condition according to a threshold updating method after determining that the second loss function value does not meet the second threshold condition to obtain an updated first threshold condition; and update the pruning ratio according to a ratio updating method to obtain an updated pruning ratio.

[0131] Based on the above embodiment, the device further includes:

[0132] A training module is used to train the optimization model when it is determined that the second loss function value satisfies the second threshold condition to obtain an intermediate model, and calculate the third loss function value of the intermediate model on the test data set; when it is determined that the third loss function value does not satisfy the second threshold condition, return to execute pruning the initial model according to the importance of each convolutional layer in the initial model until the third loss function value satisfies the second threshold condition; and determine the previous intermediate model or the previous optimization model as the target model.

[0133] The model pruning device provided in the embodiment of the present invention can execute the model pruning method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0134] It is worth noting that in the embodiment of the above-mentioned model pruning device, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be realized; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.

[0135] Figure 4 A schematic diagram of the structure of a computer device provided in an embodiment of the present invention. Figure 4 A block diagram of an exemplary computer device 4 suitable for use in implementing embodiments of the present invention is shown. Figure 4 The computer device 4 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0136] like Figure 4As shown, the computer device 4 is in the form of a general-purpose computing electronic device. The components of the computer device 4 may include, but are not limited to: one or more processors or processing units 16, a system memory 28, and a bus 18 connecting different system components (including the system memory 28 and the processing unit 16).

[0137] Bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. By way of example, these architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MAC) bus, an Enhanced ISA bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus.

[0138] The computer device 4 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the computer device 4, including volatile and non-volatile media, removable and non-removable media.

[0139] The system memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. The computer device 4 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 34 may be used to read and write non-removable, non-volatile magnetic media ( Figure 4 not shown, usually called a "hard drive"). Although Figure 4 Not shown in the figure, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to the bus 18 via one or more data medium interfaces. The system memory 28 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present invention.

[0140] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in system memory 28, such program modules 42 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. Program modules 42 generally perform the functions and / or methods of the embodiments described herein.

[0141] The computer device 4 may also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), one or more devices that enable a user to interact with the computer device 4, and / or any device that enables the computer device 4 to communicate with one or more other computing devices (e.g., network card, modem, etc.). Such communication may be performed through an input / output (I / O) interface 22. Furthermore, the computer device 4 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through a network adapter 20. Figure 4 As shown, the network adapter 20 communicates with other modules of the computer device 4 via the bus 18. It should be understood that although Figure 4 Not shown, other hardware and / or software modules may be used in conjunction with computer device 4, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0142] The processing unit 16 executes various functional applications and page displays by running the program stored in the system memory 28, for example, implementing the model pruning method provided in the embodiment of the present invention, which includes:

[0143] Pruning the initial model according to a preset pruning ratio and the importance of each convolutional layer in the initial model to obtain a pruned model, wherein a first loss function value of the pruned model on a test data set satisfies a first threshold condition;

[0144] Performing model optimization on the pruning model to obtain an optimized model, and calculating a second loss function value of the optimized model on the test data set;

[0145] If it is determined that the second loss function value does not satisfy the second threshold condition, return to execute pruning the initial model according to a preset pruning ratio and the importance of each convolutional layer in the initial model until the second loss function value satisfies the second threshold condition;

[0146] The last optimized model is determined as the target model.

[0147] Of course, those skilled in the art can understand that the processor can also implement the technical solution of the model pruning method provided by any embodiment of the present invention.

[0148] An embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon. When the program is executed by a processor, the model pruning method provided by an embodiment of the present invention is implemented, for example, and the method includes:

[0149] Pruning the initial model according to a preset pruning ratio and the importance of each convolutional layer in the initial model to obtain a pruned model, wherein a first loss function value of the pruned model on a test data set satisfies a first threshold condition;

[0150] Performing model optimization on the pruning model to obtain an optimized model, and calculating a second loss function value of the optimized model on the test data set;

[0151] If it is determined that the second loss function value does not satisfy the second threshold condition, return to execute pruning the initial model according to a preset pruning ratio and the importance of each convolutional layer in the initial model until the second loss function value satisfies the second threshold condition;

[0152] The last optimized model is determined as the target model.

[0153] The computer storage medium of the embodiment of the present invention can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to: an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.

[0154] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0155] The program code embodied on the computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

[0156] Computer program code for performing the operations of the present invention may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0157] It should be understood by those skilled in the art that the modules or steps of the present invention described above can be implemented by a general-purpose computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, optionally, they can be implemented by a program code executable by a computer device, so that they can be stored in a storage device and executed by the computing device, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present invention is not limited to any specific combination of hardware and software.

[0158] In addition, the acquisition, storage, use, and processing of data in the technical solution of the present invention are in compliance with the relevant provisions of national laws and regulations.

[0159] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims

1. A model pruning method, It is characterized in that The method comprises the following steps: Pruning the initial model according to a preset pruning ratio and the importance of each convolutional layer in the initial model to obtain a pruned model, wherein a first loss function value of the pruned model on a test data set satisfies a first threshold condition; Performing model optimization on the pruning model to obtain an optimized model, and calculating a second loss function value of the optimized model on the test data set; If it is determined that the second loss function value does not satisfy the second threshold condition, return to execute pruning the initial model according to a preset pruning ratio and the importance of each convolutional layer in the initial model until the second loss function value satisfies the second threshold condition; The last optimized model is determined as the target model.

2. The model pruning method according to claim 1, It is characterized in that Before pruning the initial model according to the importance of each convolutional layer in the initial model, the method further includes: Performing trial pruning on the initial model according to a preset trial pruning ratio to obtain multiple trial pruning models; The importance of each convolutional layer in the initial model is determined according to a first loss value list of each functional module in the initial model on the test data set and a second loss value list of each functional module in each trial pruning model on the test data set.

3. The model pruning method according to claim 2, It is characterized in that Determining the importance of each of the convolutional layers in the initial model according to a first loss value list of each functional module in the initial model on the test data set and a second loss value list of each functional module in each trial pruning model on the test data set includes: Determine a difficulty value list of each functional module in the initial model according to the first loss value list; Determine an intermediate loss value list corresponding to each of the trial pruning models according to the first loss value list and the second loss value list corresponding to each of the trial pruning models; The importance of each convolutional layer in the initial model is determined according to the initial execution time corresponding to the initial model, the trial pruning execution time corresponding to each trial pruning model, the difficulty value list, and the intermediate loss value list.

4. The model pruning method according to claim 1, It is characterized in that The initial model is pruned according to a preset pruning ratio and the importance of each convolutional layer in the initial model to obtain a pruned model, including: Determine the pruned convolution layer according to the importance of each convolution layer in the initial model and a preset screening ratio; The pruned convolutional layer is pruned according to the pruning ratio to obtain the pruned model.

5. The model pruning method according to claim 1, It is characterized in that The pruning model is optimized to obtain an optimized model, including: Training the pruning model on a training data set to obtain a training model; The training model is optimized based on knowledge distillation to obtain the optimized model.

6. The model pruning method according to claim 1, It is characterized in that After determining that the second loss function value does not satisfy the second threshold condition, the method further includes: Update the first threshold condition according to the threshold update method to obtain an updated first threshold condition; The pruning ratio is updated according to the ratio updating method to obtain an updated pruning ratio.

7. The model pruning method according to claim 1, It is characterized in that In the case where it is determined that the second loss function value satisfies the second threshold condition, the method further includes: Training the optimization model to obtain an intermediate model, and calculating a third loss function value of the intermediate model on the test data set; In the case of determining that the third loss function value does not satisfy the second threshold condition, returning to execute pruning the initial model according to the importance of each convolutional layer in the initial model until the third loss function value satisfies the second threshold condition; The last intermediate model or the last optimized model is determined as the target model.

8. A model pruning device, It is characterized in that include: A pruning module, used to prune the initial model according to a preset pruning ratio and the importance of each convolutional layer in the initial model to obtain a pruned model, wherein a first loss function value of the pruned model on a test data set satisfies a first threshold condition; An optimization module, used to perform model optimization on the pruning model to obtain an optimized model, and calculate a second loss function value of the optimized model on the test data set; A first determination module, configured to, when determining that the second loss function value does not satisfy a second threshold condition, return to execute pruning the initial model according to a preset pruning ratio and the importance of each convolutional layer in the initial model until the second loss function value satisfies the second threshold condition; The second determination module is used to determine the last optimized model as the target model.

9. A computer device, It is characterized in that The computer device comprises: at least one processor; and a memory communicatively coupled to the at least one processor; The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the model pruning method described in any one of claims 1 to 7.

10. A storage medium containing computer executable instructions, It is characterized in that The computer executable instructions, when executed by a computer processor, implement the model pruning method described in any one of claims 1-7.

Citation Information

Cited By

  • Model pruning method and device and computer readable storage medium

    CN119962609A

  • Model pruning method and device and medium

    CN120181171A

  • A model pruning method, device and medium

    CN120181171B