Model fine tuning method based on pre-training model parameter fusion
Through the linear combined weight and neural network optimization method based on parameter fusion of pre-trained model, the problems of large computing resource consumption and poor model fine-tuning effects in the existing model fusion methods are solved, and more efficient model fusion and robustness are achieved.
Patent Information
- Application Number
- CN202410989398.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-23
- Publication Date
- 2024-11-22
AI Technical Summary
Existing model fusion methods are difficult to balance complexity and computational resource requirements when dealing with large-scale data.
The model fine-tuning method based on the parameter fusion of pretrained model is adopted to fuse the pretrained model through linear combination weights, and the loss barriers are eliminated through neural network optimization to ensure that the model architecture remains unchanged to achieve better fine-tuning effects.
It significantly improves the performance and robustness of the model, reduces the complexity of the model, achieves better fine-tuning effects, and reduces the consumption of computing resources.
Smart Images

Figure CN119005277A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of model fusion, and in particular relates to a model fine-tuning method based on pre-training model parameter fusion. Background Art
[0002] In the field of deep learning, the performance of a single model is often limited by the model structure and training data. To solve this problem, model fusion has become an important method to improve model performance and robustness. Traditional model fusion methods include horizontal fusion, vertical fusion, and hybrid fusion. However, these methods often have problems such as high consumption of computing resources and high model complexity in practical applications. Therefore, it is of great practical significance to propose an efficient model fusion method.
[0003] Existing model fusion methods are mainly divided into three categories: horizontal fusion, vertical fusion and hybrid fusion. The horizontal fusion method trains and predicts multiple independent models in parallel, and finally integrates the results through voting or averaging, such as bagging and boosting technology; the vertical fusion method fuses at different levels of the model, such as adding LSTM to the feature extraction layer of the convolutional neural network for sequence modeling, combining the advantages of CNN and LSTM; the hybrid fusion method is a combination of the above two methods, which fuses models at the same level and at different levels, such as integrating the output results of multiple deep learning models through an upper-level model.
[0004] However, traditional model fusion methods have some shortcomings. First, the horizontal fusion method consumes a lot of computing resources when processing large-scale data, and the complexity of the fused model is high; second, although the vertical fusion method can effectively combine the advantages of different models, it is more complicated in model structure design and hyperparameter tuning; finally, although the hybrid fusion method has higher flexibility and generalization ability, it is difficult to balance the complexity of fusion and the demand for computing resources in practical applications. Therefore, a new model fusion method is proposed, which can significantly improve the performance and robustness of the model while keeping the model complexity low, and has important research value and application prospects. Summary of the invention
[0005] The present invention aims to solve the existing problems that there are still some loss barriers after parameter fusion and the model fine-tuning effect is not good. To solve this problem, a model fine-tuning method based on pre-trained model parameter fusion is provided. This method utilizes the characteristic that the model architecture remains unchanged after parameter fusion and combines the learning ability of the neural network to eliminate the loss barrier, so that the model fine-tuning can achieve better results.
[0006] The model fine-tuning method based on the fusion of pre-trained model parameters includes the following steps:
[0007] 1. Choose whether to use the existing parameter fusion algorithm. If yes, jump to step 2. Otherwise, randomly generate linear combination weights p and jump to step 3.
[0008] First, choose whether to use the existing parameter fusion algorithm. If so, jump to step 2, otherwise randomly generate linear combination weights p. In particular, the parameters of model A and model B have the same structure to ensure that each parameter can be linearly grouped in the following steps. Since the model structure remains unchanged after parameter fusion, each fused parameter can be regarded as a linear combination of the parameters of the two models to be fused.
[0009] 2. The parameters of the pre-trained model A and the pre-trained model B are fused through the parameter fusion algorithm, and p is reversely derived according to the formula m=pa+b, where a and b represent the parameters of the two pre-trained models respectively, p is the linear combination weight, and m is the parameter of the fused model;
[0010] When using the parameter fusion algorithm proposed in the existing paper, the parameter fusion algorithm is first used to deduce the random linear combination parameter p according to the formula m=pa+b, where a and b represent the parameters of the model to be fused, p is a random variable, and m is the parameter of the fused model.
[0011] 3. Construct model P through p and optimize P;
[0012] In order to optimize the linear combination parameter p, it is necessary to construct a corresponding model P based on p. Although the division of tensors will cause a certain loss of accuracy, the loss is usually less than 10 -10 At the same time, model P is not the final result, and it will continue to be optimized through the learning ability of the neural network, so the impact of this loss of accuracy can be ignored. The optimization of model P is similar to other neural networks, but because it is necessary to ensure that the inference parameters in the forward propagation process are pa+b while optimizing model P, the forward propagation function also needs to receive two additional parameters: model A and model B. In this way, the PyTorch framework can only calculate the gradient of model P during back propagation, rather than the overall gradient of pa+b.
[0013] 4. Merge the two pre-trained models using the formula m=pa+b to obtain model M.
[0014] The two pre-trained models are merged by the formula m=pa+b to obtain the model M. The formula is applied to each parameter to ensure that the merged model M has the same architecture as the pre-trained model.
[0015] 5. Fine-tune model M
[0016] Fine-tune the model M. After training the linear combination parameters p of the two pre-trained models, M, as the merged model, has a lower loss barrier, so it can achieve better results in fine-tuning.
[0017] The advantages of the present invention are: considering that the existing parameter fusion methods still have certain loss barriers and poor model fine-tuning effects, a method of utilizing parameter fusion and training linear combination parameters is used to eliminate the loss barriers, thereby achieving better model fine-tuning effects. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 It is a flow chart of the present invention. DETAILED DESCRIPTION
[0019] The technical solution of the present invention is explained and described clearly and completely below in conjunction with the accompanying drawings.
[0020] In the following embodiments, the present method will be applied to the CIFAR-100 dataset in the field of image recognition, and an existing parameter fusion algorithm will be used. The CIFAR-100 dataset is an image classification dataset used in the field of machine vision, with 20 major categories and a total of 100 minor categories, each of which contains 600 images (500 of which are training images and 100 test images), and each image has a small label and a large label. In the following embodiments, the small label is used as the recognition target.
[0021] Example 1
[0022] Reference Figure 1 This embodiment relates to an image recognition method using the model fine-tuning method based on pre-trained model parameter fusion of the present invention, and when using an existing parameter fusion algorithm, the method includes the following steps:
[0023] 1. Choose whether to use the existing parameter fusion algorithm. If yes, jump to step 2. Otherwise, randomly generate linear combination weights p and jump to step 3.
[0024] In this embodiment, since the existing parameter fusion algorithm is adopted, the process jumps to step 2 to merge the two pre-trained models.
[0025] 2. The parameters of the pre-trained model A and the pre-trained model B are fused through the parameter fusion algorithm, and p is reversely derived according to the formula m=pa+b, where a and b represent the parameters of the two pre-trained models respectively, p is the linear combination weight, and m is the parameter of the fused model;
[0026] When adopting the parameter fusion algorithm proposed in the existing paper, the parameter fusion algorithm is first used to deduce the random linear combination parameter p according to the formula m=pa+b, where a and b represent the parameters of the model to be fused, p is a random variable, and m is the parameter of the fused model.
[0027] 3. Construct model P through p and optimize P;
[0028] In order to optimize the linear combination parameter p, it is necessary to construct a corresponding model P based on p. Although the division of tensors will cause a certain loss of accuracy, the loss is usually less than 10 -10 At the same time, model P is not the final result, and it will continue to be optimized through the learning ability of the neural network, so the impact of this loss of accuracy can be ignored. The optimization of model P is similar to other neural networks, but because it is necessary to ensure that the inference parameters in the forward propagation process are pa+b while optimizing model P, the forward propagation function also needs to receive two additional parameters: model A and model B. In this way, the PyTorch framework can only calculate the gradient of model P during back propagation, rather than the overall gradient of pa+b.
[0029] 4. Merge the two pre-trained models using the formula m=pa+b to obtain model M;
[0030] This formula is applied to each parameter to ensure that the merged model M has the same architecture as the pre-trained model.
[0031] 5. Fine-tune model M;
[0032] Fine-tune the model M. After training the linear combination parameters p of the two pre-trained models, M, as the merged model, has a lower loss barrier, so it can achieve better results in fine-tuning.
[0033] 6. Apply the fine-tuned model M in step 4 to the CIFAR-100 dataset, and the final accuracy is shown in the following table:
[0034] method Accuracy This method 53.75% Fine-tune pre-trained model A 35.85% Fine-tune pre-trained model B 34.72%
[0035] Example 2
[0036] Reference Figure 1 This embodiment relates to an image recognition method using the model fine-tuning method based on pre-trained model parameter fusion of the present invention, and when the existing parameter fusion algorithm is not used, the method includes the following steps:
[0037] 1. Choose whether to use the existing parameter fusion algorithm. If yes, jump to step 2. Otherwise, randomly generate linear combination weights p and jump to step 3.
[0038] In this embodiment, the existing parameter fusion algorithm is not adopted, so the linear combination weight p is randomly generated and jumps to step 3. The randomly generated linear combination weight p has the same structure as the parameters of model A and model B to ensure that each parameter can be linearly combined in the next step.
[0039] 2. The parameters of the pre-trained model A and the pre-trained model B are fused through the parameter fusion algorithm, and p is reversely derived according to the formula m=pa+b, where a and b represent the parameters of the two pre-trained models respectively, p is the linear combination weight, and m is the parameter of the fused model;
[0040] In this embodiment, since the existing parameter fusion algorithm is not adopted, this step is skipped.
[0041] 3. Construct model P through p and optimize P;
[0042] In order to optimize the linear combination parameter p, it is necessary to construct a corresponding model P based on p. Although the division of tensors will cause a certain loss of accuracy, the loss is usually less than 10 -10 At the same time, model P is not the final result, and it will continue to be optimized through the learning ability of the neural network, so the impact of this loss of accuracy can be ignored. The optimization of model P is similar to other neural networks, but because it is necessary to ensure that the inference parameters in the forward propagation process are pa+b while optimizing model P, the forward propagation function also needs to receive two additional parameters: model A and model B. In this way, the PyTorch framework can only calculate the gradient of model P during back propagation, rather than the overall gradient of pa+b.
[0043] 4. Merge the two pre-trained models using the formula m=pa+b to obtain model M;
[0044] The two pre-trained models are merged by the formula m=pa+b to obtain the model M. The formula is applied to each parameter to ensure that the merged model M has the same architecture as the pre-trained model.
[0045] 5. Fine-tune model M;
[0046] Fine-tune the model M. After training the linear combination parameters p of the two pre-trained models, M, as the merged model, has a lower loss barrier, so it can achieve better results in fine-tuning.
[0047] 6. Apply the fine-tuned model M in step 4 to the CIFAR-100 dataset, and the final accuracy is shown in the following table:
[0048] method Accuracy This method 41.67% Fine-tune pre-trained model A 35.85% Fine-tune pre-trained model B 34.72%
[0049] The method of the present invention overcomes the problems that the existing parameter fusion methods still have certain loss barriers and poor model fine-tuning effects. The loss barriers are eliminated by utilizing parameter fusion and training the linear combination parameters, thereby achieving better model fine-tuning effects.
[0050] The contents described in the embodiments of this specification are merely an enumeration of implementation forms of the inventive concept. The protection scope of the present invention should not be regarded as limited to the specific forms described in the embodiments. The protection scope of the present invention also extends to equivalent technical means that can be conceived by those skilled in the art based on the inventive concept.
Claims
1. The model fine-tuning method based on the fusion of pre-trained model parameters includes the following steps: Step 1. Choose whether to use the existing parameter fusion algorithm. If yes, jump to step 2. Otherwise, randomly generate linear combination weights p and jump to step 3. Step 2. The pre-trained model A and the pre-trained model B are fused by the parameter fusion algorithm, and p is reversely derived according to the formula m=pa+b, where a and b represent the parameters of the two pre-trained models, p represents the linear combination weight, and m represents the parameters of the fusion model; Step 3. Construct model P through p and optimize P; Step 4. Merge the two pre-trained models using the formula m=pa+b to obtain model M; Step 5. Fine-tune the model M.
2. The model fine-tuning method based on pre-training model parameter fusion according to claim 1, characterized in that: Step 1 includes: First, choose whether to use the existing parameter fusion algorithm. If so, jump to step 2, otherwise randomly generate linear combination weights p. In particular, the linear combination weights p, the parameters of model A and model B have the same architecture to ensure that each parameter can be linearly combined in the next step.
3. The model fine-tuning method based on pre-training model parameter fusion according to claim 1, characterized in that: Step 2 includes: When adopting the parameter fusion algorithm proposed in the existing paper, the parameter fusion algorithm is first used to deduce the random linear combination parameter p according to the formula m=pa+b, where a and b represent the parameters of the model to be fused, p represents the random variable, and m represents the parameter of the fusion model.
4. The model fine-tuning method based on pre-training model parameter fusion according to claim 1, characterized in that: Step 3 includes: In order to optimize the linear combination parameter p, we need to build a corresponding model P based on p. Although there will be some loss of precision in the division of tensors, the loss is usually less than 10 -10 At the same time, model P is not the final result, and it will continue to be optimized through the learning ability of the neural network, so the impact of this loss of accuracy can be ignored. The optimization of model P is similar to other neural networks, but because the inference parameter line pa+b must be guaranteed during the forward propagation process while optimizing model P, the forward propagation function also needs to receive two additional parameters: model A and model B. In this way, the PyTorch framework can only calculate the gradient of model P during back propagation, rather than the overall gradient of pa+b.
5. The model fine-tuning method based on pre-training model parameter fusion according to claim 1, characterized in that: Step 4 includes: The two pre-trained models are merged by the formula m=pa+b to obtain the model M. The applicable range of this formula is each parameter to ensure that the merged model M has the same architecture as the pre-trained model.
6. The model fine-tuning method based on pre-training model parameter fusion according to claim 1, characterized in that: Step 5 includes Fine-tune the model M. After training the linear combination parameters p of the two pre-trained models, the linear merging model M has a lower loss barrier, so it can achieve better results in fine-tuning.
