Large language model merging method and device, electronic equipment and storage medium

By determining the density hyperparameter and model merging coefficient hyperparameter during the large language model merging process, generating a mask matrix and calculating the parameter vector angle, and adopting a weighted average or interpolation merging strategy, the problem of poor performance of the merged model is solved, and high-efficiency performance is achieved in downstream tasks.

CN119476418BActive Publication Date: 2026-03-27INST OF AUTOMATION CHINESE ACAD OF SCI
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-29
Publication Date
2026-03-27

AI Technical Summary

Technical Problem

Existing model merging methods result in poor performance of merged models, fail to effectively combine the advantages of different models, and may introduce parameter space conflicts.

Method used

By determining the density hyperparameter and model merging coefficient hyperparameter, a mask matrix is ​​generated, the parameter vector angle and task vector of the models to be merged are calculated, and a weighted average or interpolation merging strategy is adopted to ensure that the merged model fully leverages the advantages of each model in the downstream task.

Benefits of technology

This improves the performance of the merging model in downstream tasks, avoids parameter conflicts, and ensures the best performance of the merging model in specific application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119476418B_ABST
    Figure CN119476418B_ABST
Patent Text Reader

Abstract

The application provides a large language model merging method and device, electronic equipment and storage medium, comprising: determining a density hyperparameter and a model merging coefficient hyperparameter used for model merging based on a task target of a downstream task of a merging model; generating a mask matrix based on the density hyperparameter, and determining a task vector of each of two models to be merged based on the mask matrix, model parameters of the two models to be merged and model parameters of a base model; determining a task vector of the merging model based on a parameter vector angle of corresponding neurons between the two models to be merged, the task vectors of the two models to be merged and the model merging coefficient hyperparameter; and obtaining the merging model based on the task vector of the merging model and the model parameters of the base model. The above technical solution solves the problem of poor performance of the merging model obtained by the existing model merging method.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of model merging, in particular to a large language model merging method and device, electronic equipment and storage medium. BACKGROUND

[0002] Model merging technology is to use parameter averaging, interpolation and other methods to merge two or more models of the same structure and the same initialization weight into a model with better performance.

[0003] A large language model refers to a model with a large number of parameters, such as Llama2-13B and other models. As the training cost of a large language model is becoming higher and higher, model merging technology has become an important solution to improve model performance. Merging models can effectively combine the advantages of different models to improve the performance of the model, reduce the complexity of the model, or achieve better generalization ability.

[0004] In the traditional model merging method, the model parameters are usually directly weighted and averaged. However, the model merging method in the prior art may cause conflicts in the parameter space, and the performance of the merged model is not good. SUMMARY

[0005] The present application provides a large language model merging method, device, electronic equipment and storage medium to solve the problem of poor performance of the merged model obtained by the existing model merging method.

[0006] In a first aspect, the present application provides a large language model merging method, comprising: determining a density hyperparameter and a model merging coefficient hyperparameter used for model merging based on a task target of a merged model in a downstream task. Generating a mask matrix based on the density hyperparameter, and determining a task vector of each of two models to be merged based on the mask matrix, the model parameters of the two models to be merged, and the model parameters of a base model. Determining a task vector of the merged model based on the parameter vector angle of the corresponding neurons between the two models to be merged, the task vectors of the two models to be merged, and the model merging coefficient hyperparameter. Obtaining the merged model based on the task vector of the merged model and the model parameters of the base model.

[0007] Optionally, determining the task vector of the merged model based on the parameter vector angle of the corresponding neurons between the two models to be merged, the task vectors of the two models to be merged, and the model merging coefficient hyperparameter comprises: determining the task vector of the merged model based on the angle interval in which the parameter vector angle of the corresponding position neurons between the two models to be merged is located, and the task vectors of the two models to be merged and the model merging coefficient hyperparameter. The angle interval includes [0°, 60°], (60°, 120°], and (120°, 180°].

[0008] Optionally, the task vector of the merged model is determined based on the angle interval in which the parameter vector angle of the corresponding position neuron between the two models to be merged is located, and the task vector of the two models to be merged and the model merging coefficient hyperparameter, including: in the case that the parameter vector angle of the first position neuron between the two models to be merged is located in the interval [0°, 60°], determining the element corresponding to the first position neuron in the task vector of the merged model based on the element corresponding to the first position neuron in the task vector of the two models to be merged and the model merging coefficient hyperparameter. In the case that the parameter vector angle of the first position neuron between the two models to be merged is located in the interval (60°, 120°], determining the element corresponding to the first position neuron in the task vector of the merged model based on the element corresponding to the first position neuron in the task vector of the two models to be merged and the parameter vector angle of the first position neuron between the two models to be merged. In the case that the parameter vector angle of the first position neuron between the two models to be merged is located in the interval (120°, 180°], determining the element corresponding to the first position neuron in the task vector of the merged model as 0.

[0009] Optionally, the element corresponding to the first position neuron in the task vector of the merged model is determined based on the element corresponding to the first position neuron in the task vector of the two models to be merged and the model merging coefficient hyperparameter, including: performing weighted average on the element corresponding to the first position neuron in the task vector of the two models to be merged based on the model merging coefficient hyperparameter to obtain the element corresponding to the first position neuron in the task vector of the merged model.

[0010] Optionally, the element corresponding to the first position neuron in the task vector of the merged model is determined based on the element corresponding to the first position neuron in the task vector of the two models to be merged and the parameter vector angle of the first position neuron between the two models to be merged, including: performing interpolation merging on the element corresponding to the first position neuron in the task vector of the two models to be merged based on the parameter vector angle of the first position neuron between the two models to be merged and an interpolation factor to obtain the element corresponding to the first position neuron in the task vector of the merged model.

[0011] Optionally, the task vectors of the two models to be merged are respectively determined based on the mask matrix, the model parameters of the two models to be merged and the model parameters of the base model, including: subtracting the model parameter matrix of the base model from the model parameter matrix of any model to be merged, and performing multiplication operation on the result and the mask matrix to obtain the task vector of the model to be merged.

[0012] In a second aspect, the present application provides a large language model merging device, comprising: a first determining module configured to determine a density hyperparameter and a model merging coefficient hyperparameter used for model merging based on a task target of a downstream task of a merging model; a second determining module configured to generate a mask matrix based on the density hyperparameter, and determine a task vector of each of two models to be merged based on the mask matrix, model parameters of the two models to be merged, and model parameters of a base model; a third determining module configured to determine a task vector of the merging model based on a parameter vector angle of corresponding neurons between the two models to be merged, the task vectors of the two models to be merged, and the model merging coefficient hyperparameter; and a processing module configured to obtain the merging model based on the task vector of the merging model and the model parameters of the base model.

[0013] In a third aspect, the present application further provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements any of the above large language model merging methods when executing the computer program.

[0014] In a fourth aspect, the present application further provides a non-transitory computer readable storage medium having a computer program stored thereon, and the computer program is executable on a processor to implement any of the above large language model merging methods.

[0015] In a fifth aspect, the present application further provides a computer program product comprising a computer program, and the computer program is executable on a processor to implement any of the above large language model merging methods.

[0016] The large language model merging method, device, electronic device, and storage medium provided by the present application determine a density hyperparameter and a model merging coefficient hyperparameter used for model merging based on a task target of a downstream task of a merging model. A mask matrix is generated based on the density hyperparameter, and a task vector of each of two models to be merged is determined based on the mask matrix, model parameters of the two models to be merged, and model parameters of a base model. The task vector of the merging model is determined based on a parameter vector angle of corresponding neurons between the two models to be merged, the task vectors of the two models to be merged, and the model merging coefficient hyperparameter, so as to ensure that the merged model can fully exert the advantages of each model in the downstream task. The merging model is obtained based on the task vector of the merging model and the model parameters of the base model. With the parameter vector angle and the task vector, it is ensured that the merged model can achieve the best performance in a specific application scenario. The problem of poor performance of the merging model obtained by using the existing model merging method is solved. BRIEF DESCRIPTION OF DRAWINGS

[0017] In order to more clearly illustrate the technical solutions of the present application or the prior art, the drawings required to be used in the embodiments or prior art description will be briefly introduced as follows. Obviously, the drawings in the following description are some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor on the basis of these drawings.

[0018] Figure 1 is a flowchart of the large language model merging method provided by the present application.

[0019] Figure 2 is a structural schematic diagram of the large language model merging device provided by the present application.

[0020] Figure 3 is a structural schematic diagram of the electronic device provided by the present application. DETAILED DESCRIPTION

[0021] In order to make the objects, technical solutions and advantages of the present application clearer, the technical solutions in the present application will be described clearly and completely in combination with the drawings in the present application. Obviously, the described embodiments are some embodiments of the present application, not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the present application.

[0022] Figure 1 is a flowchart of the large language model merging method provided by the present application. As shown in Figure 1 , the method comprises the following steps S101-S104.

[0023] Step S101, based on the task target of the downstream task of the merging model, determine the density hyperparameters and model merging coefficient hyperparameters used for model merging.

[0024] As an optional embodiment, model merging requires at least two models to be merged. In order to facilitate the description of the following embodiments, two models to be merged are taken as an example. The number of specific models to be merged is not further limited by the present application.

[0025] As an optional embodiment, to complete model merging, it is required that the models to be merged meet the condition that the model structure and the initialized weight are the same. For example, GAIR / Abel-7B-001 (mathematics field model) and AdaptLLM / finance-chat (finance field model) are selected, both of which are based on the Llama2 architecture, are the fine-tuned versions of the Llama2-7B pre-training model, and have a size of 7B. The task objective of the downstream task can be to improve the performance of the AdaptLLM / finance-chat model in mathematical reasoning through model merging, so as to improve the indicators on the test set.

[0026] As an optional embodiment, the task objective of the downstream task of the merged model is the actual performance requirement of the merged model in the final application scenario. For example, if the objective of the downstream task is image classification, then when merging the model, it is necessary to ensure that the final model can better recognize and classify images. If the objective is sentiment analysis in natural language processing, then when merging the model, it is necessary to focus on preserving and strengthening the characteristics of sentiment understanding in the two models. Therefore, the density hyperparameter and the model merging coefficient hyperparameter are set by means of the task objective during the merging process, so that the merged model can perform well in specific tasks.

[0027] As an optional embodiment, the density hyperparameter determines the proportion of parameters selected from the two models to be merged when merging the model. The merging coefficient hyperparameter controls the fusion proportion of the task vectors of the two models to be merged when merging.

[0028] As an optional embodiment, when determining the density hyperparameter and the model merging coefficient hyperparameter used for model merging, it is necessary to determine the objective function according to the task objective of the merged model in the downstream task. The expression of the objective function is

[0029]

[0030] In the above formula, is the accuracy of the merged model on the evaluation data set, D is the evaluation data set of the merged model, is the model input, is the output of the merged model, is the density hyperparameter, denotes the model merging coefficient hyperparameter. denotes the merged model.

[0031] As an optional embodiment, when determining the density hyperparameter and the model merging coefficient hyperparameter used for model merging, the hyperparameters can be set by relying on artificial experience, or can be determined by means of the Bayesian-particle swarm algorithm.

[0032] As an optional embodiment, when the Bayesian-particle swarm algorithm is used to determine the density hyperparameter and the model merging coefficient hyperparameter, the following steps are mainly included.

[0033] Step 1, determining a target function based on the task target of the merging model in the downstream task. The expression of the target function has been described in the above embodiment, and will not be repeated here.

[0034] Step 2, setting a hyperparameter search space and initializing the hyperparameters (including the density hyperparameter and the model merging coefficient hyperparameter).

[0035] Step 3, modeling the target function by using the Bayesian algorithm, updating the posterior mean and variance and calculating the acquisition function, and obtaining the initialization hyperparameters with better performance through multiple iterations.

[0036] Step 4, using the initialization hyperparameters (including the density hyperparameter and the model merging coefficient hyperparameter) obtained in step 3 as the initialization particle swarm of the particle swarm algorithm, updating the particle velocity and position.

[0037] Step 5, when the iteration reaches the maximum number of times, stopping the iteration and outputting the density hyperparameter and the model merging coefficient hyperparameter at this time.

[0038] As an optional embodiment, the present application does not further limit the way of obtaining the density hyperparameter and the model merging coefficient hyperparameter used for model merging.

[0039] Step S102, generating a mask matrix based on the density hyperparameter, and determining the task vectors of the two models to be merged based on the mask matrix, the model parameters of the two models to be merged respectively, and the model parameters of the base model.

[0040] As an optional embodiment, the elements in the mask matrix are composed of 0 and 1, an element matrix with the same dimension as the parameter vector and all elements being 1 is initialized first, and the elements with a proportion of the density hyperparameter are randomly set to 0, and finally a binary matrix containing only 0 and 1 is obtained, which is the mask matrix.

[0041] As an optional embodiment, the model parameters of the two models to be merged and the model parameters of the base model are all parameter matrices, each neuron in the model to be merged corresponds to a parameter matrix, and the parameter matrices of all neurons constitute the model parameters of the model to be merged. Since the architectures and sizes of the two models to be merged are the same as those of the base model.

[0042] As an optional embodiment, the two models to be merged are GAIR / Abel-7B-001 (model 1) and AdaptLLM / finance-chat (model 2), both of which are Llama2 architecture and are fine-tuned versions of Llama2-7B pre-training model, and the base model is Llama2-7B.

[0043] As an optional embodiment, the density hyperparameter is used to determine the proportion of parameters selected from the two models to be merged when merging the models. Through the density hyperparameter, a mask matrix can be generated, which indicates which model's parameters are preferred during the merging process. For example, if the density hyperparameter is 0.7, the matrix mask will select 70% of the parameters from GAIR / Abel-7B-001, and the remaining 30% of the parameters will come from AdaptLLM / finance-chat.

[0044] As an optional embodiment, the mask matrix determines which parameters are preferred during the merging of model parameters. Using the mask matrix, the parts to be retained are extracted from the respective model parameters of the two models to be merged, and the model parameters of the base model are combined to generate the task vectors of the two models to be merged, which represent the characteristics of the model in a specific task.

[0045] In an exemplary embodiment, based on the mask matrix, the respective model parameters of the two models to be merged, and the model parameters of the base model, the task vectors of the two models to be merged are determined respectively, including:

[0046] Subtracting the model parameter matrix of any one of the models to be merged from the model parameter matrix of the base model, and performing a multiplication operation on the result with the mask matrix, the task vector of the model to be merged is obtained.

[0047] As an optional embodiment, the task vectors of the two models to be merged can be represented as

[0048]

[0049]

[0050] wherein, and are the model parameter matrices of the two models to be merged, is the task vector, i.e., the model parameter matrix of the model to be merged minus the model parameter matrix and the dot product of the mask matrix , and is the density hyperparameter. corresponds to the task vector of the first model to be merged, a task vector representing a second model to be merged. As an optional embodiment, which can be understood as the task vector of GAIR / Abel-7B-001, which can be understood as the task vector of AdaptLLM / finance-chat. that is, the model parameters of Llama2-7B.

[0051] In the above embodiment, the task vectors are extracted from the two models to be merged using the mask matrix. Through this selective parameter reservation and fusion, the new model obtained by merging can effectively combine the advantages of the two models to be merged and improve the performance of the merged model on downstream tasks.

[0052] In step S103, the task vector of the merged model is determined based on the parameter vector angle between the corresponding neurons of the two models to be merged, the task vectors of the two models to be merged, and the model merging coefficient hyperparameter.

[0053] As an optional embodiment, since the sizes and architectures of the two models to be merged are exactly the same, the neurons between the two models to be merged are one-to-one corresponding, so the parameter vector angle can be determined by the respective parameter matrices of the corresponding neurons between the two models to be merged and the cosine operation formula. The task vector of the merged model is determined based on the parameter vector angle, the task vector, and the model merging coefficient hyperparameter.

[0054] As an optional embodiment, the parameter vector angle between the corresponding neurons of the two models to be merged can be calculated by the following formula.

[0055]

[0056]

[0057] wherein, represents the neuron corresponding parameter matrix of the first position in the model parameters of model 1, represents the neuron corresponding parameter matrix of the corresponding position in the model parameters of model 2.

[0058] As an optional embodiment, before calculating the parameter vector angle, the following normalization needs to be performed on and The angle cosine value between the parameter vectors is calculated by dot product, and then the parameter vector angle is derived.

[0059] As an optional embodiment, since there are multiple neurons in the model 1 and the model 2, and there are multiple parameter matrices of the multiple neurons, multiple parameter vector angles can be obtained, different merging strategies need to be adopted according to the angles of the parameter vector angles to determine the task vector corresponding to each parameter vector angle, and the task vector of the final merged model is determined based on each task vector.

[0060] In step S104, the merged model is obtained based on the task vector of the merged model and the model parameter of the base model.

[0061] As an optional embodiment, since the merged model is obtained by merging the two to-be-merged models which have the same size and architecture as the base model, only the weight parameters of the model merging are changed in the merging process, and the structure of the model is not changed, therefore, the architecture of the merged model is still the same as that of the base model, therefore, the model parameter of the base model is a parameter matrix, and the corresponding obtained task vector is also a vector matrix which is one-to-one corresponding to the model parameter of the base model, therefore, the task vector of the merged model can be obtained by adding the task vector of the merged model to the model parameter of the base model through the operation between the matrices.

[0062] In the above steps S101-S104, the density hyperparameter and the model merging coefficient hyperparameter used for model merging are determined based on the task target of the downstream task of the merged model. The mask matrix is generated based on the density hyperparameter, and the task vectors of the two to-be-merged models are respectively determined by using the mask matrix, the model parameters of the two to-be-merged models and the model parameter of the base model. The task vector of the merged model is determined by calculating the parameter vector angle of the corresponding neurons between the two to-be-merged models, combining the task vectors of the two to-be-merged models and the model merging coefficient hyperparameter, so as to ensure that the merged model can fully exert the advantages of each model in the downstream task. The merged model is obtained based on the task vector of the merged model and the model parameter of the base model. By means of the parameter vector angle and the task vector, it is ensured that the merged model can achieve the best performance in a specific application scenario. The problem that the performance of the merged model obtained by using the existing model merging method is poor is solved.

[0063] In an exemplary embodiment, the above step S103 can be implemented by the following step S11.

[0064] In step S11, the task vector of the merged model is determined based on the angle interval of the parameter vector angle of the corresponding position neurons between the two to-be-merged models, and the task vector and the model merging coefficient hyperparameter of the two to-be-merged models.

[0065] The angle interval includes [0°, 60°], (60°, 120°] and (120°, 180°].

[0066] As an optional embodiment, in the traditional model merging method, directly weighting or averaging the parameters may introduce conflicts, especially when the characteristics of the two models to be merged are quite different. The present application analyzes the angle of the parameter vector angle. If the angle between the two parameter vectors is small ([0°, 60°]), it indicates that the characteristics of the two neurons at the corresponding position are similar or synergistic. If the parameter vector angle is between (60°, 120°], it indicates that the two parameter vectors have similarity and certain difference. If the angle is between (120°, 180°], it indicates that the parameter characteristics of the two neurons have large difference. According to the angle of the different parameter vector angles, the task vector of the final merged model is determined, which avoids invalid parameter superposition. While retaining beneficial characteristics, the stability of the merged model is enhanced.

[0067] As an optional embodiment, by determining the angle of each parameter vector angle and the elements corresponding to each parameter vector angle based on the task vector and the model merging coefficient hyperparameter, the task vector of the merged model is obtained by adding the elements of each parameter vector angle.

[0068] In the above embodiments, different merging strategies are adopted according to the angle of the task vector, and then the task vector of the final merged model is obtained. It can be ensured that when merging the model, a more accurate fusion decision can be made according to the similarity of characteristics. Avoiding the conflicts brought by simple parameter averaging, finally ensuring that the merged model has stronger adaptability and performance in downstream tasks.

[0069] In an exemplary embodiment, based on the angle interval of the parameter vector angle of the neurons at the corresponding position between the two models to be merged, and the task vector and the model merging coefficient hyperparameter of the two models to be merged, the task vector of the merged model is determined, comprising:

[0070] In the case that the parameter vector angle of the first position neuron between the two models to be merged is in the interval [0°, 60°], based on the elements corresponding to the first position neuron in the task vectors of the two models to be merged and the model merging coefficient hyperparameter, the elements corresponding to the first position neuron in the task vector of the merged model are determined.

[0071] In an exemplary embodiment, based on the elements corresponding to the first position neuron in the task vectors of the two models to be merged and the model merging coefficient hyperparameter, the elements corresponding to the first position neuron in the task vector of the merged model are determined, comprising:

[0072] Based on the model merging coefficient hyperparameter, the elements corresponding to the first position neuron in the task vectors of the two models to be merged are weighted and averaged to obtain the elements corresponding to the first position neuron in the task vector of the merged model.

[0073] As an optional embodiment, when the angle is between 0 and 60 degrees, the elements of the parameter vector angle are directly weighted and averaged in the same direction to obtain the element corresponding to the first position neuron in the task vector of the merged model.

[0074] In the case that the parameter vector angle of the first position neuron between the two models to be merged is in the interval (60°, 120°], the element corresponding to the first position neuron in the task vector of the merged model is determined based on the elements corresponding to the first position neuron in the task vectors of the two models to be merged and the parameter vector angle of the first position neuron between the two models to be merged.

[0075] In an exemplary embodiment, determining the element corresponding to the first position neuron in the task vector of the merged model based on the elements corresponding to the first position neuron in the task vectors of the two models to be merged and the parameter vector angle of the first position neuron between the two models to be merged includes:

[0076] Interpolating and merging the elements corresponding to the first position neuron in the task vectors of the two models to be merged based on the parameter vector angle of the first position neuron between the two models to be merged and the interpolation factor to obtain the element corresponding to the first position neuron in the task vector of the merged model.

[0077] As an optional embodiment, when the angle is between 60 and 120 degrees, interpolation and merging are performed.

[0078] In the case that the parameter vector angle of the first position neuron between the two models to be merged is in the interval (120°, 180°], the element corresponding to the first position neuron in the task vector of the merged model is determined to be 0.

[0079] As an optional embodiment, the above embodiments can be expressed in a formula.

[0080]

[0081] In the above formula, denotes the model merging coefficient hyperparameter, denotes the task vector, denotes the parameter vector angle, is the interpolation factor, The value of is usually a constant. denotes the task vector obtained at different angle ranges.

[0082] In the above embodiments, different elements are determined for different parameter vector angles, which can effectively preserve useful characteristics, eliminate conflicts, and finely control characteristic fusion during model merging.

[0083] In an exemplary embodiment, since the sizes and architectures of the to-be-merged models and the base model are consistent, the task vector of the merged model can be obtained by adding the model parameters of the base model.

[0084]

[0085] wherein, is the merged model, is the task vector of the merged model, which is composed of the task vectors calculated from the above three angle ranges, and is a matrix with the same size as , represents the model parameters of the base model.

[0086] The large language model merging device provided by the present application is described below. The large language model merging device described below can be correspondingly referred to the large language model merging method described above.

[0087] Figure 2 is a structural schematic diagram of the large language model merging device provided by the present application. As shown in Figure 2 , the device comprises.

[0088] The first determining module 210 is configured to determine the density hyperparameter and the model merging coefficient hyperparameter used for model merging based on the task target of the merged model in the downstream task.

[0089] The second determining module 220 is configured to generate a mask matrix based on the density hyperparameter, and determine the task vectors of the two to-be-merged models based on the mask matrix, the model parameters of the two to-be-merged models, and the model parameters of the base model.

[0090] The third determining module 230 is configured to determine the task vector of the merged model based on the parameter vector angle of the corresponding neurons between the two to-be-merged models, the task vectors of the two to-be-merged models, and the model merging coefficient hyperparameter.

[0091] The processing module 240 is configured to obtain the merged model based on the task vector of the merged model and the model parameters of the base model.

[0092] The device determines the density hyperparameter and the model merging coefficient hyperparameter used for model merging by merging the task targets of the downstream tasks of the model. A mask matrix is generated based on the density hyperparameter, and the task vectors of the two models to be merged are determined by using the mask matrix, the model parameters of the two models to be merged, and the model parameters of the base model. The task vector of the merged model is determined by calculating the parameter vector angle of the corresponding neurons between the two models to be merged, combining the task vectors of the two models to be merged and the model merging coefficient hyperparameter, so that the merged model can fully exert the advantages of each model in the downstream tasks. The merged model is obtained based on the task vector of the merged model and the model parameters of the base model. With the parameter vector angle and the task vector, the performance of the merged model in a specific application scenario can be ensured. The problem of poor performance of the merged model obtained by using the existing model merging method is solved.

[0093] In some embodiments, the third determination module 230 is further configured to determine the task vector of the merged model based on the angle interval in which the parameter vector angle of the corresponding position neurons between the two models to be merged is located, and the task vectors of the two models to be merged and the model merging coefficient hyperparameter. The angle interval includes [0°, 60°], (60°, 120°], and (120°, 180°].

[0094] In some embodiments, the third determination module 230 is further configured to, in a case where the parameter vector angle of the first position neuron between the two models to be merged is in the [0°, 60°] interval, determine the element corresponding to the first position neuron in the task vector of the merged model based on the element corresponding to the first position neuron in the task vectors of the two models to be merged and the model merging coefficient hyperparameter. In a case where the parameter vector angle of the first position neuron between the two models to be merged is in the (60°, 120°] interval, the element corresponding to the first position neuron in the task vector of the merged model is determined based on the element corresponding to the first position neuron in the task vectors of the two models to be merged and the parameter vector angle of the first position neuron between the two models to be merged. In a case where the parameter vector angle of the first position neuron between the two models to be merged is in the (120°, 180°] interval, the element corresponding to the first position neuron in the task vector of the merged model is determined to be 0.

[0095] In some embodiments, the third determination module 230 is further configured to perform weighted averaging on the elements corresponding to the first position neurons in the task vectors of the two models to be merged based on the model merging coefficient hyperparameter, to obtain the element corresponding to the first position neuron in the task vector of the merged model.

[0096] In some embodiments, the third determining module 230 is further configured to perform interpolation merging on elements corresponding to the first position neuron in the task vectors of the two models to be merged based on the parameter vector angle of the first position neuron between the two models to be merged and the interpolation factor, to obtain elements corresponding to the first position neuron in the task vector of the merged model.

[0097] In some embodiments, the second determining module 220 is further configured to subtract the model parameter matrix of the base model from the model parameter matrix of any model to be merged, and perform multiplication operation on the obtained result and the mask matrix to obtain the task vector of the model to be merged.

[0098] Figure 3 An example of an entity structure diagram of an electronic device is shown in Figure 3 As shown, the electronic device can include a processor 310, a communications interface 320, a memory 330, and a communications bus 340, wherein the processor 310, the communications interface 320, and the memory 330 can communicate with each other through the communications bus 340. The processor 310 can invoke the logical instructions in the memory 330 to execute a large language model merging method, which includes.

[0099] Based on the task target of the merged model in the downstream task, determine the density hyperparameter and the model merging coefficient hyperparameter used in the model merging.

[0100] Based on the density hyperparameter, generate a mask matrix, and based on the mask matrix, the model parameters of the two models to be merged, and the model parameters of the base model, respectively determine the task vectors of the two models to be merged.

[0101] Based on the parameter vector angle of the corresponding neurons between the two models to be merged, the task vectors of the two models to be merged, and the model merging coefficient hyperparameter, determine the task vector of the merged model.

[0102] Based on the task vector of the merged model and the model parameters of the base model, obtain the merged model.

[0103] Moreover, the logic instructions in the memory 330 described above can be implemented in the form of a software function unit and sold or used as an independent product, which can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application essentially or the parts that make contributions to the prior art or parts of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the embodiments of the method of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various media that can store program codes.

[0104] In another aspect, the present application also provides a computer program product, which comprises a computer program, the computer program can be stored on a non-transitory computer readable storage medium, and the computer program is executed by a processor, so that the computer can execute the large language model merging method provided by the above-mentioned methods, and the method comprises.

[0105] Based on the task target of the merging model in the downstream task, the density hyperparameter and the model merging coefficient hyperparameter used for model merging are determined.

[0106] Based on the density hyperparameter, a mask matrix is generated, and based on the mask matrix, the model parameters of the two models to be merged and the model parameters of the base model, the task vectors of the two models to be merged are respectively determined.

[0107] Based on the parameter vector angle of the corresponding neurons between the two models to be merged, the task vectors of the two models to be merged and the model merging coefficient hyperparameter, the task vector of the merging model is determined.

[0108] Based on the task vector of the merging model and the model parameters of the base model, the merging model is obtained.

[0109] In another aspect, the present application also provides a non-transitory computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the large language model merging method provided by the above-mentioned methods, and the method comprises.

[0110] Based on the task target of the merging model in the downstream task, the density hyperparameter and the model merging coefficient hyperparameter used for model merging are determined.

[0111] Based on the density hyperparameter, a mask matrix is generated, and based on the mask matrix, the model parameters of the two models to be merged and the model parameters of the base model, the task vectors of the two models to be merged are respectively determined.

[0112] The task vector of the merged model is determined based on the parameter vector angle of corresponding neurons between two models to be merged, the task vectors of the two models to be merged, and a model merging coefficient hyperparameter.

[0113] The merged model is obtained based on the task vector of the merged model and the model parameters of the base model.

[0114] The apparatus embodiments described above are merely illustrative, wherein the units shown as separate components can or can not be physically separated, and the components shown as units can or can not be physical units, i.e., can be located in one place, or can be distributed to multiple network units. Part or all of the modules can be selected to achieve the purpose of the embodiments according to actual needs. Those skilled in the art can understand and implement it without creative labor.

[0115] From the above description of the embodiments, those skilled in the art can clearly understand that the embodiments can be implemented by means of software plus necessary universal hardware platforms, and of course, can also be implemented by hardware. Based on such understanding, the above technical solutions, essentially or in other words, the part that contributes to the prior art, can be embodied in the form of a software product, which can be stored in a computer readable storage medium, such as a ROM / RAM, a magnetic disk, an optical disk, etc., and includes a number of instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute the methods of the various embodiments or some parts of the embodiments.

[0116] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit it. Although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacements to some technical features. These modifications or replacements do not make the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A large language model merging method, characterized in that, The method comprises the following steps: determining a density hyperparameter and a model merging coefficient hyperparameter used in model merging based on a task target of a downstream task of a merging model; the task target is image classification; generating a mask matrix based on the density hyperparameter, and determining a task vector of each of the two models to be merged based on the mask matrix, model parameters of the two models to be merged, and model parameters of a base model; determining a task vector of the merging model based on an angle between parameter vectors of corresponding neurons between the two models to be merged, the task vectors of the two models to be merged, and the model merging coefficient hyperparameter; obtaining the merging model based on the task vector of the merging model and the model parameters of the base model.

2. The large language model merging method of claim 1, wherein, The method comprises the following steps: determining a task vector of the merging model based on an angle between parameter vectors of corresponding neurons between the two models to be merged, the task vectors of the two models to be merged, and the model merging coefficient hyperparameter; determining a task vector of the merging model based on an angle between parameter vectors of corresponding neurons between the two models to be merged, the task vectors of the two models to be merged, and the model merging coefficient hyperparameter; 3. The large language model merging method of claim 2, wherein, The angle interval includes [0°, 60°], (60°, 120°], and (120°, 180°]. The method comprises the following steps: in a case where the angle between parameter vectors of a first position neuron between the two models to be merged is in the interval [0°, 60°], determining an element corresponding to the first position neuron in the task vector of the merging model based on an element corresponding to the first position neuron in the task vectors of the two models to be merged and the model merging coefficient hyperparameter; in a case where the angle between parameter vectors of a first position neuron between the two models to be merged is in the interval (60°, 120°], determining an element corresponding to the first position neuron in the task vector of the merging model based on an element corresponding to the first position neuron in the task vectors of the two models to be merged and the angle between parameter vectors of the first position neuron between the two models to be merged; 4. The large language model merging method of claim 3, wherein, in a case where the angle between parameter vectors of a first position neuron between the two models to be merged is in the interval (120°, 180°], determining that the element corresponding to the first position neuron in the task vector of the merging model is 0. The method comprises the following steps: determining an element corresponding to the first position neuron in the task vector of the merging model based on the model merging coefficient hyperparameter and an element corresponding to the first position neuron in the task vectors of the two models to be merged.

5. The large language model merging method of claim 3, wherein, The element corresponding to the first position neuron in the task vector of the two models to be merged is determined based on the element corresponding to the first position neuron in the task vector of the two models to be merged and the parameter vector angle of the first position neuron between the two models to be merged. The element corresponding to the first position neuron in the task vector of the two models to be merged is determined based on the element corresponding to the first position neuron in the task vector of the two models to be merged and the parameter vector angle of the first position neuron between the two models to be merged.

6. The large language model merging method according to any one of claims 1 to 5, characterized in that, The task vector of each of the two models to be merged is determined based on the mask matrix, the model parameters of each of the two models to be merged, and the model parameters of the base model. The model parameter matrix of any model to be merged is subtracted from the model parameter matrix of the base model, and the result is multiplied by the mask matrix to obtain the task vector of the model to be merged.

7. A large language model merging apparatus, characterized by comprising: It comprises: The first determination module is configured to determine the density hyperparameter used for model merging and the model merging coefficient hyperparameter based on the task target of the downstream task of the merged model. The task target is image classification. The second determination module is configured to generate a mask matrix based on the density hyperparameter, and determine the task vector of each of the two models to be merged based on the mask matrix, the model parameters of each of the two models to be merged, and the model parameters of the base model. The third determination module is configured to determine the task vector of the merged model based on the parameter vector angle of the corresponding neurons between the two models to be merged, the task vectors of the two models to be merged, and the model merging coefficient hyperparameter. The processing module is configured to obtain the merged model based on the task vector of the merged model and the model parameters of the base model.

8. An electronic device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, The processor executes the computer program to realize the large language model merging method according to any one of claims 1-6. 9.A non-transitory computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to realize the large language model merging method according to any one of claims 1-6.

10. A computer program product comprising a computer program, characterized in that, The computer program is executed by the processor to realize the large language model merging method according to any one of claims 1-6.

Citation Information

Patent Citations

  • Model merging method, device and system and computer readable storage medium

    CN114818037A

  • Task processing model merging method, task processing method and device

    CN118349813A