Model automatic pruning method and device, equipment, storage medium and program product
Through the automatic pruning method of model combination of agent and Wanda algorithm, the problem of low pruning efficiency in the existing technology is solved, and the efficient pruning and performance improvement of the model is achieved, which is suitable for resource-constrained environments.
Patent Information
- Application Number
- CN202411275944.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-12
- Publication Date
- 2024-12-27
AI Technical Summary
The prior art is difficult to effectively prune the model, which makes it difficult to reduce the size of the model, limiting its application in resource-constrained environments.
The actor network in the agent is used to predict the compression ratio, combine the Wanda algorithm to evaluate the importance of weights, and through pruning model optimization and knowledge distillation technology, pruning strategies are automatically designed to achieve efficient pruning of the model.
It realizes efficient and accurate pruning of the model, reduces the difficulty of manual design, reduces the computing and storage requirements, and improves the compression rate and performance of the model.
Smart Images

Figure CN119204138A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a model automatic pruning method, device, equipment, storage medium and program product. Background Art
[0002] Large Language Models (LLMs) often have extremely large parameters and training data, and are able to learn challenging tasks in the real world. However, this excessively high model size requires a lot of computing and memory to deploy, which limits their applicability in many resource-constrained environments. Model compression is a strategy to reduce the size of neural networks while maintaining their capabilities. In order to build lighter, faster, and more interpretable models, there are many model compression algorithms available, including model pruning, quantization, knowledge distillation, etc. Among them, pruning is currently a very popular model compression technology that reduces the size of the model and reduces the complexity of the model by removing unnecessary or redundant components.
[0003] Therefore, how to effectively perform model pruning has become a problem that needs to be solved urgently in the industry. Summary of the invention
[0004] The present invention provides a model automatic pruning method, device, equipment, storage medium and program product, which are used to solve the problem of how to effectively prune the model in the prior art.
[0005] The present invention provides a model automatic pruning method, comprising: Inputting the state information of any group to be pruned in the model into the actor network in the agent to obtain the predicted compression ratio of the group to be pruned; Pruning the to-be-pruned group based on the predicted compression ratio of the to-be-pruned group to obtain a first pruned group, and pruning the to-be-pruned group based on a preset compression ratio to obtain a second pruned group; All the to-be-pruned groups are traversed, and based on the loss disturbance between the first pruned group and the second pruned group, and the long-term reward, the agent is optimized to obtain a pruning model.
[0006] According to a model automatic pruning method provided by the present invention, after the step of obtaining the pruning model, the method further includes: Pruning the target language model to be pruned by using the pruning model to obtain a pruned language model; Decomposing the learnable weight matrix in the pruned language model into a low-rank matrix by using a low-rank approximation technique; The target language model before pruning is used as a teacher model, and the low-rank matrix is used as a student model. The pruned language model is optimized through knowledge distillation technology to obtain a final pruned target language model.
[0007] According to a model automatic pruning method provided by the present invention, the group to be pruned is pruned based on the predicted compression ratio of the group to be pruned to obtain a first pruned group, and the group to be pruned is pruned based on a preset compression ratio to obtain a second pruned group, including: Using the Wanda algorithm, the weight importance of the to-be-pruned group is evaluated based on the weight value and the activation value to obtain the weight importance of the to-be-pruned group; The to-be-pruned group is pruned based on the weight importance and the predicted compression ratio to obtain a first pruned group, and the to-be-pruned group is pruned based on the weight importance and a preset compression ratio to obtain a second pruned group.
[0008] According to a model automatic pruning method provided by the present invention, all the to-be-pruned groups are traversed, and based on the loss disturbance between the first pruning group and the second pruning group, and the long-term reward, the agent is optimized to obtain a pruning model, including: Determining a short-term reward value of the agent according to a loss perturbation between the first pruning group and the second pruning group; Traverse all the groups to be pruned, and obtain the long-term reward value based on the short-term reward of each group to be pruned, the loss perturbation of the language model before and after pruning, and the difference between the compression rate of the language model after pruning and the preset compression rate; The agent is optimized by the long-term reward value and the short-term reward value, and any input target language model is pruned by the optimized agent to obtain a pruned language model.
[0009] According to a model automatic pruning method provided by the present invention, a long-term reward value is obtained according to the short-term rewards of each to-be-pruned group, including: Obtain the loss perturbation of the pruned language model and the original language model before and after automatic pruning, and the difference between the compression rate of the pruned language model and the preset compression rate; A long-term reward value is obtained based on the loss disturbance of the language model before and after the automatic pruning, the compression rate difference, and the sum of each of the short-term rewards.
[0010] According to a model automatic pruning method provided by the present invention, the long-term reward value is specifically:
[0011] in, is the loss perturbation of the language model before and after automatic pruning, is the compression ratio of the language model after the automatic pruning process is completed, is a preset fixed compression ratio, It is the weighted sum of the short-term rewards of each group to be pruned.
[0012] The present invention also provides a model automatic pruning device, comprising: An input module, used to input the state information of any group to be pruned in the model into the actor network in the agent to obtain the predicted compression ratio of the group to be pruned; A pruning module, configured to prune the group to be pruned based on the predicted compression ratio of the group to be pruned to obtain a first pruned group, and prune the group to be pruned based on a preset compression ratio to obtain a second pruned group; An optimization module is used to optimize the intelligent agent based on the loss disturbance between the first pruning group and the second pruning group to obtain a pruning model.
[0013] According to a model automatic pruning device provided by the present invention, the device is also used for: Decomposing the learnable weight matrix in the pruned language model into a low-rank matrix by using a low-rank approximation technique; The target language model before pruning is used as a teacher model, and the low-rank matrix is used as a student model. The pruned language model is optimized through knowledge distillation technology to obtain a final pruned language model.
[0014] According to a model automatic pruning device provided by the present invention, the device is also used for: Using the Wanda algorithm, the weight importance of the to-be-pruned group is evaluated based on the weight value and the activation value to obtain the weight importance of the to-be-pruned group; The to-be-pruned group is pruned based on the weight importance and the predicted compression ratio to obtain a first pruned group, and the to-be-pruned group is pruned based on the weight importance and a preset compression ratio to obtain a second pruned group.
[0015] According to a model automatic pruning device provided by the present invention, the device is also used for: Determining a short-term reward value of the agent according to a loss perturbation between the first pruning group and the second pruning group; Traverse all the groups to be pruned, and get the long-term reward value based on the short-term rewards of each group to be pruned; The agent is optimized by the long-term reward value and the short-term reward value, and any input target language model is pruned by the optimized agent to obtain a pruned language model.
[0016] According to a model automatic pruning device provided by the present invention, the device is also used for: Obtain the loss perturbation of the pruned language model and the original language model before and after automatic pruning, and the difference between the compression rate of the pruned language model and the preset compression rate; A long-term reward value is obtained based on the loss disturbance of the language model before and after the automatic pruning, the compression rate difference, and the sum of each of the short-term rewards.
[0017] According to a model automatic pruning device provided by the present invention, the long-term reward value is specifically:
[0018] in, is the loss perturbation of the language model before and after automatic pruning, is the compression ratio of the language model after the automatic pruning process is completed, is a preset fixed compression ratio, It is the weighted sum of the short-term rewards of each group to be pruned.
[0019] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the automatic model pruning method described above is implemented.
[0020] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the above-described automatic model pruning methods.
[0021] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements any of the above-mentioned automatic model pruning methods.
[0022] The model automatic pruning method, device, equipment, storage medium and program product provided by the present invention can automatically design different pruning strategies for different parameter groups of LLM through reinforcement learning technology, reducing the difficulty of manual design. A contrast pruning network is introduced, and long-term and short-term rewards are added to each round of pruning and the pruning process of each group in between, so that the actor network can learn more accurate decisions. Thereby achieving efficient and accurate model pruning processing. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0024] Figure 1A schematic diagram of the process flow of the automatic model pruning method provided in the embodiment of the present application; Figure 2 A schematic diagram of Wanda importance estimation provided in an embodiment of the present application; Figure 3 A schematic diagram of the structure of a model automatic pruning device provided in an embodiment of the present application; Figure 4 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0025] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0026] Figure 1 A schematic diagram of the process flow of the automatic model pruning method provided in the embodiment of the present application is as follows: Figure 1 As shown, including: Step 110, inputting the state information of any group to be pruned in the model into the actor network in the agent to obtain the predicted compression ratio of the group to be pruned; In an embodiment of the present application, the models that need to be compressed are grouped, and an actor network and a critic network are trained based on the training data, so that the actor network can predict the corresponding compression ratio according to the status of different groups and prune the model.
[0027] In the embodiment of the present application, it is first necessary to determine and prepare the state information of the group to be pruned. The state information should be able to fully describe the characteristics of the current group, which may include weight statistics, activation values, gradient information, pruning ratio of the previous layer, etc.
[0028] The prepared state information is input into the agent's Actor network. The Actor network is a decision-making network in reinforcement learning, responsible for generating actions, that is, generating compression ratios in this scenario.
[0029] More specifically, in the embodiment of the present application, the state includes the following features: (Group Index): Indicates the position of the current group in the model, helping the agent to identify different groups.
[0030] (Activation value of the current group): Indicates the input of the current group in the model, reflecting the function and role of the group.
[0031] (Weight of current group): Represents the parameter of the current group, which is the target of pruning operation.
[0032] (Compression ratio of the previous set of parameters): Indicates the compression ratio of the previous set of parameters, providing a reference for pruning the current set.
[0033] (Compression ratio indicator of the entire model before pruning): Indicates the compression target of the entire model and guides the direction and degree of pruning.
[0034] (Weight of the previous set of parameters): Represents the weight of the previous set of parameters, helping the agent understand the structure of the model and the relationship between the parameters.
[0035] These features are crucial for the agent to make decisions because they can help the agent: identify different groups, , the agent can distinguish different groups and perform targeted pruning.
[0036] You can understand the function and role of the group by activating the value , the agent can understand the input of the current group in the model and thus judge the importance of the group.
[0037] You can choose a suitable pruning strategy by weighting and compression ratio index , the agent can determine the pruning ratio of the current group and perform effective pruning operations.
[0038] You can refer to the previous pruning experience and use the compression rate of the previous set of parameters and weight , the agent can refer to previous pruning experience and make more reasonable pruning decisions.
[0039] In the embodiment of the present application, by representing the network state of each set of parameters as the above features, the reinforcement learning agent can better understand the structure and function of the model and select a more appropriate pruning strategy, thereby achieving efficient model compression.
[0040] Step 120, pruning the group to be pruned based on the predicted compression ratio of the group to be pruned to obtain a first pruned group, and pruning the group to be pruned based on a preset compression ratio to obtain a second pruned group; In the embodiment of the present application, the predicted compression ratio refers to the compression ratio predicted by the agent (Actor) network according to the state of the current group. The first pruned group is a group obtained after pruning based on the predicted compression ratio, and its compression ratio is consistent with the prediction of the agent.
[0041] The preset compression ratio refers to a preset compression ratio, which is used as a reference and comparison. The second pruning group refers to a group obtained after pruning based on the preset compression ratio, and its compression ratio is consistent with the preset ratio.
[0042] In the embodiment of the present application, by comparing the performance of the first pruning group and the second pruning group, it is possible to evaluate whether the compression ratio predicted by the agent is reasonable, and guide the agent to learn and adjust. By comparing the model performance under different compression ratios, the best compression strategy can be determined to achieve a balance between model compression and performance.
[0043] Step 130, traverse all the to-be-pruned groups, optimize the agent based on the loss disturbance between the first pruned group and the second pruned group, and the long-term reward, and obtain a pruning model.
[0044] In the embodiment of the present application, the loss perturbation refers to the performance difference between the first pruning group and the second pruning group on the validation set, reflecting the impact of different compression ratios on model performance. The difference between the loss values of the first pruning group and the second pruning group is usually used as the loss perturbation.
[0045] This improves the performance of the pruned model by enabling the agent to learn more accurate predictions of the compression ratio, which can be done by updating the agent network using a deep deterministic policy gradient algorithm, allowing it to learn based on loss perturbations.
[0046] In the embodiment of the present application, the optimized agent is applied to all the to-be-pruned groups of the target language model to obtain the best compression ratio for each group. Each group is pruned according to the best compression ratio to obtain a pruned language model.
[0047] By optimizing the agent, the pruning strategy is made more effective, thereby improving the performance of the pruned model.
[0048] In the embodiment of the present application, different pruning strategies can be automatically designed for different parameter groups of LLM through reinforcement learning technology, reducing the difficulty of manual design. A contrast pruning network is introduced, and long-term and short-term rewards are added to each round of pruning and each group of pruning in between, so that the actor network can learn more accurate decisions. Thus, efficient and accurate model pruning processing is achieved.
[0049] Optionally, after the step of obtaining the pruning model, the method further includes: Pruning the target language model using the pruning model to obtain a pruned language model; Decomposing the learnable weight matrix in the pruned language model into a low-rank matrix by using a low-rank approximation technique; The target language model before pruning is used as a teacher model, and the low-rank matrix is used as a student model. The pruned language model is optimized through knowledge distillation technology to obtain a final pruned target language model.
[0050] The update value △W of each learnable weight matrix W in the model can be decomposed into the product of two low-rank matrices P and Q, that is, △W=PQ. The ranks of P and Q are much smaller than the rank of △W, so the number of parameters is greatly reduced. Only P and Q need to be trained to complete the model training, reducing the training complexity and data requirements.
[0051] The forward calculation can be expressed as: ; in is the bias in the dense layer. Only train and Reduces the overall training complexity, thereby reducing the need for large-scale training data. Additional parameters and can be re-parameterized as It does not result in extra parameters in the final compression model.
[0052] In the embodiment of the present application, by minimizing the difference in the output distribution of the model before and after pruning, the pruned model can learn the "knowledge" of the original model. In addition, a variety of knowledge distillation methods can be used, such as soft target distillation, feature distillation, etc. The generality of the model is retained so that the pruned model can adapt to a variety of tasks. The model performance is improved so that the performance of the pruned model is closer to the original model.
[0053] Optionally, pruning the to-be-pruned group based on the predicted compression ratio of the to-be-pruned group to obtain a first pruned group, and pruning the to-be-pruned group based on a preset compression ratio to obtain a second pruned group includes: Using the Wanda algorithm, the weight importance of the to-be-pruned group is evaluated based on the weight value and the activation value to obtain the weight importance of the to-be-pruned group; The to-be-pruned group is pruned based on the weight importance and the predicted compression ratio to obtain a first pruned group, and the to-be-pruned group is pruned based on the weight importance and a preset compression ratio to obtain a second pruned group.
[0054] In the embodiment of the present application, the Wanda algorithm is applied to evaluate the importance of each weight. The Wanda algorithm does not rely on the first-order or second-order derivatives of the weight, but directly evaluates the importance of the weight based on the weight value and the activation value. The predicted compression ratio is obtained from the Actor network of reinforcement learning, or a preset compression ratio is used.
[0055] The weights are pruned based on the weight importance scores and compression ratios obtained by the Wanda algorithm. The pruning operation usually involves the following steps: a. Sorting: Sort the weights according to the importance scores obtained by the Wanda algorithm.
[0056] b. Selection: Select the weights to keep based on the predicted compression ratio or the preset compression ratio. Usually, weights with lower importance scores are pruned (i.e. set to zero).
[0057] After the weights are pruned using the predicted compression ratio, the resulting weight set is called the first pruned group. After the weights are pruned using the preset compression ratio, the resulting weight set is called the second pruned group.
[0058] Compare the performance of the first and second pruning groups to evaluate the impact of different compression ratios on model accuracy. Calculate rewards based on the performance of the pruned model. If the performance of the pruned model meets the predetermined criteria, a positive reward is given, otherwise a negative reward is given.
[0059] The reward information is fed back into the reinforcement learning framework to train the Actor network to improve future compression ratio predictions.
[0060] Through multiple iterations, the agent learns how to better predict the compression ratio to achieve effective model compression while maintaining model performance.
[0061] Specifically, the Wanda importance estimation method does not require solving the first-order and second-order derivatives of the weights. Instead, the importance of parameters is evaluated based on weights and activation values, which greatly improves the speed of pruning. Figure 2 A schematic diagram of Wanda importance estimation provided in the embodiment of the present application is shown in FIG. Figure 2 As shown, for the weight , and its importance calculation formula is:
[0062] By processing different groups, we can avoid being affected by the magnitude of the values in each group.
[0063] Optionally, traversing all the to-be-pruned groups, optimizing the agent based on the loss disturbance between the first pruned group and the second pruned group, and the long-term reward, to obtain a pruning model, including: Determining a short-term reward value of the agent according to a loss perturbation between the first pruning group and the second pruning group; Traverse all the groups to be pruned, and get the long-term reward value based on the short-term rewards of each group to be pruned; The agent is optimized by the long-term reward value and the short-term reward value, and any input target language model is pruned by the optimized agent to obtain a pruned language model.
[0064] In the embodiment of the present application, the above pruning and evaluation process is repeated for all weight groups to be pruned, and a short-term reward value is calculated for each group. According to the short-term reward values of each group to be pruned, they are accumulated or combined in some way to obtain a long-term reward value. The long-term reward value reflects the overall performance of the entire pruning process.
[0065] The pruned language model is validated using the long-term reward value. This may include evaluating the model's performance on an independent test set. If the pruned language model passes the validation, i.e., the performance meets the predetermined criteria, then the model is accepted as a pruned model.
[0066] The pruning results and verification feedback are used for further training of the agent to improve the pruning strategy. This process is iterative, and the agent gradually learns how to prune better through multiple trainings.
[0067] After multiple iterations and fine-tuning, the model with the best performance is selected as the final pruned model.
[0068] Optionally, a long-term reward value is obtained according to the short-term rewards of each to-be-pruned group, including: Obtain the loss perturbation of the pruned language model and the original language model before and after automatic pruning, and the difference between the compression rate of the pruned language model and the preset compression rate; A long-term reward value is obtained based on the loss disturbance of the model before and after the automatic pruning, the compression rate difference, and the sum of each of the short-term rewards.
[0069] The compression ratio is continuously controlled using Deep Deterministic Policy Gradient (DDPG). For the exploration of noise process, the truncated normal distribution is used in the embodiment of the present application:
[0070] During the exploration process, noise It is initialized to 0.5 and decays exponentially with each episode.
[0071] When calculating the loss function, a variant of Bellman's Equation is used in the embodiment of the present application. Each conversion in each episode is , where R is the reward received during network compression. During the update process, the baseline reward is subtracted To reduce the variance of the gradient estimate, this is an exponential moving average of the previous rewards.
[0072]
[0073] Here the discount factor Set to 1 to avoid over-prioritizing short-term rewards.
[0074] Among them, the reward R is the cumulative value of the reward after each group is processed. In the embodiment of this application, the reward is calculated separately. The pruned model and the fixed compression rate The loss perturbation of the pruned model is recorded as and , the overall reward is:
[0075] The first half of the formula is the reward of the final compressed model, which is represented by the final loss perturbation of the pruned model compared with the original model. The second half is the reward of the model after each set of parameter compression, which is The weight of each group of rewards, in the embodiment of the present application, gives higher weights to the rewards of later actions.
[0076] However, the above rewards cannot perceive the size of the model after pruning. In the embodiment of this application, it is hoped that the model can be compressed with maximum efficiency. Therefore, in the embodiment of this application, the final compression rate of the model is As a reward, the model in the embodiment of the present application is dynamically transformed, and the compression rate of each group of the model cannot be required to be higher than the effect of fixed compression rate pruning in the embodiment of the present application. Therefore, in the embodiment of the present application, only the compression rate-related reward is added to the final compressed model:
[0077] In the present embodiment, the final compression rate of the model is expected to be Not less than the expected compression ratio .
[0078] In the embodiment of the present application, different compression rates are designed for different weight groups to perform network pruning, and a comparative pruning algorithm is introduced to calculate short-term rewards for each group of pruning to improve the pruning effect. The Wanda algorithm is used to calculate the importance of parameters and reduce the computational complexity.
[0079] In some cases, after the agent has pruned the target language model, it may also need to fine-tune the pruned language model to recover the performance that may have been lost due to pruning.
[0080] Figure 3 A schematic diagram of the structure of the model automatic pruning device provided in the embodiment of the present application is shown in FIG. Figure 3 As shown, including: The input module 310 is used to input the state information of any group to be pruned in the model into the actor network in the agent to obtain the predicted compression ratio of the group to be pruned; The pruning module 320 is used to prune the to-be-pruned group based on the predicted compression ratio of the to-be-pruned group to obtain a first pruning group, and prune the to-be-pruned group based on a preset compression ratio to obtain a second pruning group; The optimization module 330 is used to optimize the agent based on the loss disturbance between the first pruning group and the second pruning group to obtain a pruning model.
[0081] According to a model automatic pruning device provided by the present invention, the device is also used for: Decomposing the learnable weight matrix in the pruned language model into a low-rank matrix by using a low-rank approximation technique; The target language model before pruning is used as a teacher model, and the low-rank matrix is used as a student model. The pruned language model is optimized through knowledge distillation technology to obtain a target language model.
[0082] According to a model automatic pruning device provided by the present invention, the device is also used for: Using the Wanda algorithm, the weight importance of the to-be-pruned group is evaluated based on the weight value and the activation value to obtain the weight importance of the to-be-pruned group; The to-be-pruned group is pruned based on the weight importance and the predicted compression ratio to obtain a first pruned group, and the to-be-pruned group is pruned based on the weight importance and a preset compression ratio to obtain a second pruned group.
[0083] According to a model automatic pruning device provided by the present invention, the device is also used for: Determining a short-term reward value of the agent according to a loss perturbation between the first pruning group and the second pruning group; Traverse all the groups to be pruned, and get the long-term reward value based on the short-term rewards of each group to be pruned; The pruning model optimizes the agent through the long-term reward value and the short-term reward value, and prunes any input target language model through the optimized agent to obtain a pruned language model.
[0084] According to a model automatic pruning device provided by the present invention, the device is also used for: Obtain the loss perturbation of the pruned language model and the original language model before and after automatic pruning, and the difference between the compression rate of the pruned language model and the preset compression rate; A long-term reward value is obtained based on the loss disturbance of the language model before and after the automatic pruning, the compression rate difference, and the sum of each of the short-term rewards.
[0085] According to a model automatic pruning device provided by the present invention, the long-term reward value is specifically:
[0086] in, is the loss perturbation of the language model before and after automatic pruning, is the compression ratio of the language model after the automatic pruning process is completed, is a preset fixed compression ratio, It is the weighted sum of the short-term rewards of each group to be pruned.
[0087] In the embodiment of the present application, different pruning strategies can be automatically designed for different parameter groups of LLM through reinforcement learning technology, reducing the difficulty of manual design. A contrast pruning network is introduced, and long-term and short-term rewards are added to each round of pruning and each group of pruning in between, so that the actor network can learn more accurate decisions. Thus, efficient and accurate model pruning processing is achieved.
[0088] Figure 4 is a schematic diagram of the structure of the electronic device provided by the present invention, such as Figure 4 As shown, the electronic device may include: a processor 410, a communication interface 420, a memory 430 and a communication bus 440, wherein the processor 410, the communication interface 420 and the memory 430 communicate with each other through the communication bus 440. The processor 410 may call the logic instructions in the memory 430 to execute the model automatic pruning method, which includes: inputting the state information of any group of to-be-pruned groups in the model into the actor network in the intelligent agent, and obtaining the predicted compression ratio of the to-be-pruned group; Pruning the to-be-pruned group based on the predicted compression ratio of the to-be-pruned group to obtain a first pruned group, and pruning the to-be-pruned group based on a preset compression ratio to obtain a second pruned group; All the to-be-pruned groups are traversed, and based on the loss disturbance between the first pruned group and the second pruned group, and the long-term reward, the agent is optimized to obtain a pruning model.
[0089] In addition, the logic instructions in the above-mentioned memory 430 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0090] On the other hand, the present invention further provides a computer program product, the computer program product includes a computer program, the computer program can be stored on a non-transitory computer-readable storage medium, when the computer program is executed by a processor, the computer can execute the model automatic pruning method provided by the above methods, the method comprising: inputting the state information of any group of to-be-pruned groups in the model into the actor network in the intelligent agent, and obtaining the predicted compression ratio of the to-be-pruned group; Pruning the to-be-pruned group based on the predicted compression ratio of the to-be-pruned group to obtain a first pruned group, and pruning the to-be-pruned group based on a preset compression ratio to obtain a second pruned group; All the to-be-pruned groups are traversed, and based on the loss disturbance between the first pruned group and the second pruned group, and the long-term reward, the agent is optimized to obtain a pruning model.
[0091] In another aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which is implemented when the computer program is executed by a processor to execute the model automatic pruning method provided by the above methods, the method comprising: inputting the state information of any group of to-be-pruned groups in the model into the actor network in the agent, and obtaining the predicted compression ratio of the to-be-pruned group; Pruning the to-be-pruned group based on the predicted compression ratio of the to-be-pruned group to obtain a first pruned group, and pruning the to-be-pruned group based on a preset compression ratio to obtain a second pruned group; All the to-be-pruned groups are traversed, and based on the loss disturbance between the first pruned group and the second pruned group, and the long-term reward, the agent is optimized to obtain a pruning model.
[0092] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0093] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0094] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A model automatic pruning method, characterized in that: include: Inputting the state information of any group to be pruned in the model into the actor network in the agent to obtain the predicted compression ratio of the group to be pruned; Pruning the to-be-pruned group based on the predicted compression ratio of the to-be-pruned group to obtain a first pruned group, and pruning the to-be-pruned group based on a preset compression ratio to obtain a second pruned group; All the to-be-pruned groups are traversed, and based on the loss disturbance between the first pruned group and the second pruned group, and the long-term reward, the agent is optimized to obtain a pruning model.
2. The automatic model pruning method according to claim 1, characterized in that: After the step of obtaining the pruning model, the method further includes: Pruning the target language model to be pruned by using the pruning model to obtain a pruned language model; Decomposing the learnable weight matrix in the pruned language model into a low-rank matrix by using a low-rank approximation technique; The target language model before pruning is used as a teacher model, and the low-rank matrix is used as a student model. The pruned language model is optimized through knowledge distillation technology to obtain a final pruned target language model.
3. The automatic model pruning method according to claim 1, characterized in that: Pruning the to-be-pruned group based on the predicted compression ratio of the to-be-pruned group to obtain a first pruned group, and pruning the to-be-pruned group based on a preset compression ratio to obtain a second pruned group, including: Using the Wanda algorithm, the weight importance of the to-be-pruned group is evaluated based on the weight value and the activation value to obtain the weight importance of the to-be-pruned group; The to-be-pruned group is pruned based on the weight importance and the predicted compression ratio to obtain a first pruned group, and the to-be-pruned group is pruned based on the weight importance and a preset compression ratio to obtain a second pruned group.
4. The automatic model pruning method according to claim 1, characterized in that: Traversing all the to-be-pruned groups, optimizing the agent based on the loss perturbation between the first pruning group and the second pruning group, and the long-term reward, to obtain a pruning model, including: Determining a short-term reward value of the agent according to a loss perturbation between the first pruning group and the second pruning group; Traverse all the groups to be pruned, and obtain the long-term reward value based on the short-term reward of each group to be pruned, the loss perturbation of the language model before and after pruning, and the difference between the compression rate of the language model after pruning and the preset compression rate; The agent is optimized by using the long-term reward value and the short-term reward value to obtain a pruning model.
5. The automatic model pruning method according to claim 4, characterized in that: According to the short-term rewards of each group to be pruned, the long-term reward value is obtained, including: Obtain the loss perturbation of the pruned language model and the original language model before and after automatic pruning, and the difference between the compression rate of the pruned language model and the preset compression rate; A long-term reward value is obtained based on the loss disturbance of the language model before and after the automatic pruning, the compression rate difference, and the sum of each of the short-term rewards.
6. The automatic model pruning method according to claim 5, characterized in that: The long-term reward value is specifically: in, is the loss perturbation of the language model before and after automatic pruning, is the compression ratio of the language model after the automatic pruning process is completed, The preset fixed compression rate It is the weighted sum of the short-term rewards of each group to be pruned.
7. A model automatic pruning device, characterized in that: include: An input module, used to input the state information of any group to be pruned in the model into the actor network in the agent to obtain the predicted compression ratio of the group to be pruned; A pruning module, configured to prune the group to be pruned based on the predicted compression ratio of the group to be pruned to obtain a first pruned group, and prune the group to be pruned based on a preset compression ratio to obtain a second pruned group; An optimization module is used to optimize the agent based on the loss disturbance between the first pruning group and the second pruning group, and a long-term reward to obtain a pruning model.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the automatic model pruning method as described in any one of claims 1 to 6 is implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the automatic model pruning method according to any one of claims 1 to 6 is implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the automatic model pruning method according to any one of claims 1 to 6 is implemented.
