Multi-task model parameter fusion method, apparatus, electronic device and storage medium
By merging task vectors and mask vectors to divide shared and unique parameter offsets, the problem of high storage and deployment overhead in multi-task model fine-tuning is solved, achieving efficient model parameter fusion and stability.
Patent Information
- Application Number
- CN202611261028.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-19
- Publication Date
- 2026-11-17
AI Technical Summary
Existing technologies suffer from high overhead in storing and deploying model parameters during multi-task model fine-tuning, especially as the number of tasks increases, leading to a large amount of parameter redundancy.
By merging the task vectors, a merged task vector is obtained. The parameter offsets of the shared and unique parts are divided using the mask vector. Combined with distillation loss optimization, the shared and unique parameter offsets are output to deploy the recombined model and reduce redundant storage.
It effectively reduces the storage and deployment overhead of model parameters, improves the stability and flexibility of model merging, maintains the ability to differentiate between tasks, and avoids cross-task knowledge interference.
Smart Images

Figure CN123116133A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence technology, specifically to a method, apparatus, electronic device, and storage medium for multi-task model parameter fusion. Background Technology
[0002] With the widespread application of large-scale pre-trained models in tasks such as visual understanding and natural language processing, fine-tuning downstream tasks based on a unified pre-trained backbone model has become the mainstream approach to obtaining multi-task expert models. While this approach can fully leverage the transferability of pre-trained models, it also introduces significant storage and deployment overhead. Especially with the continuous increase in the number of tasks, storing a complete copy of the model for each task results in substantial parameter redundancy. Summary of the Invention
[0003] This invention provides a method, apparatus, electronic device, and storage medium for multi-task model parameter fusion, in order to solve the problem of high storage and deployment overhead of model parameters after adding models for multi-task fine-tuning.
[0004] In a first aspect, the present invention provides a method for fusing parameters of a multi-task model, comprising: Obtain the task vector for fine-tuning the pre-trained model for each task; Obtain the merged task vector obtained by merging the task vectors corresponding to all tasks; Output the shared parameter offsets determined based on the shared part coordinates in the merged task vector and the unique parameter offsets determined based on the unique part coordinates in each task vector, so as to deploy the reorganization model of the corresponding task according to the shared parameter offsets and the unique parameter offsets of the corresponding task.
[0005] In multi-task deployment, the above implementation method does not require repeatedly saving the entire set of complete model updates for each task. By setting the parameters to zero, only the shared parameter offsets in the merged task vector and the unique parameter offsets in each task vector are retained, thus saving the storage and deployment overhead of model parameters.
[0006] In one optional implementation, obtaining the merged task vector based on the merging of task vectors corresponding to all tasks includes: Perform a linear combination of the task vectors corresponding to all tasks to obtain the merged task vector or retrieve the merged task vector that has already been merged. Construct a mask vector with the same dimension as the task vector and the merged task vector. The mask vector defines coordinates belonging to the shared part and coordinates belonging to the unique part. The mask vector is configured to calculate the merged task vector and the task vector by element-wise multiplication, so as to deploy the initialization reorganization model based on the determined shared parameter offset and the unique parameter offset. The unlabeled sample set is input into the expert model and the initialization and recombination model are processed to determine the distillation loss between the two. The optimal merging task vector and mask vector are determined based on the backpropagation of the distillation loss. The expert model is a model obtained by fine-tuning the pre-trained model for each task.
[0007] The above implementation establishes a trainable connection between discrete coordinate selection and continuous parameter optimization through distillation joint optimization, obtains the optimal merged task vector and mask vector, extracts reusable knowledge between multiple recombined models as much as possible, and retains residual structures that preserve task differences, thereby avoiding mutual interference between cross-task shared knowledge and task-specific knowledge.
[0008] In one optional implementation, constructing a mask vector with the same dimension as the task vector and the merged task vector includes: The construction of a mask vector with the same dimension as the task vector and the merged task vector includes: Initialize the first mask vector, where each vector component of the first mask vector is a random value between 0 and 1; When the vector component in the first mask vector is greater than the first threshold, it is set to 1; when the vector component in the first mask vector is less than the first threshold, it is set to 0, so as to obtain the second mask vector. The vector components of the second mask vector are used to determine the coordinates belonging to the shared part and the coordinates belonging to the unique part. The process of determining the optimal merging task vector and mask vector based on the backpropagation of the distillation loss includes: The distillation loss is introduced into the mask sparse regularization loss corresponding to the first mask vector.
[0009] The above implementation introduces mask sparsity through the first mask vector and realizes coordinate filtering of shared coordinate information and unique coordinate information through the second mask vector, avoiding the extreme case of the mask degenerating into all 1s or all 0s, and automatically sparsely dividing the shared dimension of multiple tasks and the task-specific dimension.
[0010] In one optional implementation, the step of deploying the initial reorganization model based on the determined shared parameter offset and unique parameter offset includes: Determine the upper and lower limits of the corresponding coordinate shared parameter offset, wherein the upper and lower limits are determined based on the vector component distribution of the same coordinate in the task vectors corresponding to all tasks; When the value of the shared parameter offset is greater than the upper limit value, it is set to the upper limit value; when the value of the shared parameter offset is between the upper limit value and the lower limit value, the original value is maintained; when the value of the shared parameter offset is less than the lower limit value, it is set to the lower limit value.
[0011] The above implementation restricts the shared parameter offset values participating in the joint optimization of distillation to the parameter region commonly supported by the initialization and recombination model, preventing unconstrained extrapolation offsets from occurring during the distillation optimization process, thereby improving the stability and fidelity of model merging.
[0012] In one optional implementation, the upper and lower limits are determined based on the distribution of vector components at the same coordinate in the task vectors corresponding to all tasks, including: The upper limit value is determined based on the maximum value in the vector component distribution; The lower limit value is determined based on the minimum value in the vector component distribution.
[0013] The above implementation method uses the maximum and minimum values in the vector component distribution as the limiting range, which is simple to determine and direct to implement.
[0014] In one alternative implementation, outputting the unique parameter offset in each task vector, determined based on the unique partial coordinates, includes: Remove zeroing information except for the specific parameter offset; The specific parameter offset is quantized to compress the data volume; Save the unique parameter offsets and corresponding coordinates after quantization.
[0015] The above implementation achieves data compression by quantizing the offset of unique parameters, further reducing the marginal storage cost brought about by each new task.
[0016] In one optional implementation, the step of deploying the reorganization model of the corresponding task based on the shared parameter offset and the specific parameter offset of the corresponding task includes: Deploy the recombined model based on the pre-trained model and the shared parameter offset; The recombination model is updated by loading the specific parameter offsets of the corresponding task according to the task to be processed.
[0017] The above implementation supports dynamic loading across multiple tasks, improving the flexibility of switching between reorganization models.
[0018] Secondly, the present invention provides a multi-task model parameter fusion device, comprising: The task vector acquisition module is used to acquire the task vector for fine-tuning the pre-trained model for each task; The merged task vector acquisition module is used to obtain the merged task vector obtained by merging the task vectors corresponding to all tasks. The parameter offset output module is used to output the shared parameter offset determined based on the coordinates of the shared part in the merged task vector and the unique parameter offset determined based on the coordinates of the unique part in each task vector, so as to deploy the reorganization model of the corresponding task according to the shared parameter offset and the unique parameter offset of the corresponding task.
[0019] Thirdly, the present invention provides an electronic device, comprising: a memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the computer instructions to perform the multi-task model parameter fusion method described in the first aspect or any corresponding embodiment thereof.
[0020] Fourthly, the present invention provides a computer-readable storage medium storing computer instructions for causing a computer to execute the multi-task model parameter fusion method described in the first aspect or any of its corresponding embodiments. Attached Figure Description
[0021] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0022] Figure 1 This is a schematic diagram of the first type of multi-task model parameter fusion method according to an embodiment of the present invention.
[0023] Figure 2 This is a schematic diagram of the second process of the multi-task model parameter fusion method according to an embodiment of the present invention.
[0024] Figure 3 This is a schematic diagram of the system architecture for implementing the multi-task model parameter fusion method according to an embodiment of the present invention.
[0025] Figure 4 This is a schematic diagram of the verification results based on the RoBERTa and GPT-2 models in an embodiment of the present invention.
[0026] Figure 5 This is a schematic diagram illustrating the verification results of the ViT-B / 32 and ViT-L / 14 models in an embodiment of the present invention.
[0027] Figure 6 This is a schematic diagram of the similarity analysis results represented by CKA in an embodiment of the present invention.
[0028] Figure 7This is a schematic diagram illustrating the analysis results from the perspective of downstream task accuracy in an embodiment of the present invention.
[0029] Figure 8 This is a schematic diagram of the one-dimensional loss landscape analysis results according to an embodiment of the present invention.
[0030] Figure 9 This is a structural block diagram of the multi-task model parameter fusion device according to an embodiment of the present invention.
[0031] Figure 10 This is a schematic diagram of the hardware structure of an electronic device according to an embodiment of the present invention. Detailed Implementation
[0032] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0033] It is understood that before using the technical solutions disclosed in the various embodiments of the present invention, users should be informed of the types, scope of use, and usage scenarios of the personal information involved in the present invention and their authorization should be obtained in accordance with relevant laws and regulations through appropriate means.
[0034] The terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this invention, "a plurality of" means two or more, unless otherwise explicitly specified.
[0035] In related technologies, "pre-training-fine-tuning" involves first performing unified pre-training using large-scale general data to learn general underlying representations and obtain a shared backbone network. Then, based on this single backbone, adaptive fine-tuning is performed for different downstream tasks to achieve multi-task reuse of a set of backbone weights.
[0036] The model parameters of the pre-trained model can be , where d is the total dimension of the model parameters, indicating that the parameter vector of the pre-trained model is a d-dimensional real vector.
[0037] There are N expert models, each fine-tuned for different tasks. Each expert model can be considered as the result of superimposing the parameters of the pre-trained model and updating the corresponding task. Therefore, the task vector corresponding to the i-th task is defined as: , Among them, task vector The parameter shift of the representation model to adapt to the task is the parameter difference vector between the fine-tuned model and the pre-trained model.
[0038] In related technologies, for the purpose of model merging methods, attempts are made to directly extract data from multiple task vectors. A unified fusion update is constructed and added back to the pre-trained model to obtain a fusion model with multi-task capabilities. Its basic form can be expressed as: , in, For the parameter vector of the fusion model, The parameter vector of the pre-trained model. To merge task vectors, .
[0039] However, since the effective update regions of different tasks in the parameter space are not completely consistent, if multiple task vectors are directly fused as a whole, conflicts may easily occur at the same parameter coordinates, resulting in cross-task shared knowledge and task-specific knowledge interfering with each other.
[0040] According to an embodiment of the present invention, a method for fusing parameters of a multi-task model is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0041] This embodiment provides a method for fusing parameters in a multi-task model, which can be used in servers that run the model, etc. Figure 1 This is a flowchart of a multi-task model parameter fusion method according to an embodiment of the present invention, such as... Figure 1 As shown, the process includes the following steps: Step S101: Obtain the task vector for fine-tuning the pre-trained model for each task.
[0042] Fine-tuning the pre-trained model for each task yields an expert model adapted to that task. The task vector is the difference vector obtained by subtracting the pre-trained model's parameters from the expert model's parameters, representing the parameter shift resulting from adapting to the corresponding task. Based on this parameter shift, the expert model for the corresponding task can be deployed on top of the pre-trained model. Accordingly, the expert model fine-tuned for a specific downstream task has a corresponding task vector, while multiple tasks will result in multiple task vectors.
[0043] Step S102: Obtain the merged task vector obtained by merging the task vectors corresponding to all tasks.
[0044] The merged task vector is a new task vector formed by combining multiple task vectors according to their weights. Specifically, the merged task vector can be determined based on the average value of the multiple task vectors. , in, To merge task vectors, Let N be the task vector corresponding to the i-th expert model, and N be the total number of expert models. This method is simple to implement and suitable as a default initialization scheme. Optionally, the task vectors can be weighted according to the importance of each task, the amount of data, the validation performance, or the prior weights to obtain the merged task vector.
[0045] The merged task vector comprehensively reflects the parameter shifts generated by multiple tasks. However, if it is directly superimposed on the model parameters of the pre-trained model, it will not be stable enough when dealing with multiple tasks. Therefore, it is necessary to optimize itself and achieve fine-grained partitioning based on the merged task vector.
[0046] Step S103: Output the shared parameter offsets determined based on the shared part coordinates in the merged task vector and the unique parameter offsets determined based on the unique part coordinates in each task vector, so as to deploy the reorganization model of the corresponding task according to the shared parameter offsets and the unique parameter offsets of the corresponding task.
[0047] To mitigate the conflict issue caused by directly superimposing merged task vectors onto the model parameters of a pre-trained model—specifically, the potential incompatibility between task vectors from different tasks—the merged task vector superimposed on the pre-trained model is split into shared vectors and specific vectors. Shared vectors, which can be used simultaneously across multiple tasks, include shared parameter offsets acceptable to all tasks. Specific vectors, however, do not use vector components from the merged task vectors but are constructed using the specific parameter offsets from the task vectors of the corresponding tasks, thus avoiding incompatibility issues. The specific formula is as follows: , in, Let be the parameter vector of the reorganization model corresponding to the i-th task. The parameter vector of the pre-trained model. For shared vectors, This is the unique vector corresponding to the i-th task. Compared to merging task vectors, only the shared vector components, i.e., the shared parameter offsets, are retained, while the vector components of other coordinates are set to zero because they are not suitable for sharing. Relative to the task vector of the i-th task, only the vector components specific to that task (i.e., the specific parameter offset) are retained, while the vector components of other coordinates are set to zero. This means that a unified shared parameter offset can be directly supplemented through addition. Since the shared and specific parts of the vector are complementary, The resulting vector contains both shared parameter offsets and task-specific parameter offsets, enabling the reconfiguration of task-specific models. This approach overcomes incompatibility issues while allowing for the deployment of reconfigured models for different tasks using a unified shared parameter offset and multiple task-specific parameter offsets, thus reducing the amount of data involved, at least in the shared parameter offset portion.
[0048] Shared component coordinates are used to locate the offset of shared parameters within a vector, while unique component coordinates are used to locate the offset of unique parameters within a vector. Therefore, shared and unique component coordinates can be divided based on the characteristics of the task vectors, thus combining the advantages of task vectors and merged task vectors. Furthermore, the granularity of shared and unique component coordinates can be parametric, channel, layer, or hybrid granularity, depending on actual needs. Parametric coordinates are the finest, dividing down to each vector component, offering the finest granularity and strongest expressive power. Channel coordinates are divided by neuron channels or tensor slices, facilitating improved computational efficiency. Layer-based division of shared and unique components by layer is relatively simple and suitable for resource-constrained scenarios. Hybrid granularity combines multiple granularities, using parametric coordinates for some key layers and channel or layer-based division for other layers, balancing performance and efficiency.
[0049] Accordingly, the shared partial coordinates and the unique partial coordinates can be defined by the mask vector m. In other words, the mask vector uses the same d-dimensional vector as the parameter vector of the pre-trained model, so it can be directly superimposed. For example, positions with a 1 in the mask vector represent shared coordinates, and positions with a 0 represent unique coordinates, and vice versa. The shared parameter offset can be automatically extracted using the following formula: , in, Let m be the shared vector and m be the mask vector. To merge the task vectors, element-wise multiplication can automatically set the vector components other than the shared parts in the merged task vectors to zero, thus obtaining... The non-zero values in the vector are the shared parameter offsets.
[0050] The specific parameter offset can be automatically extracted using the following formula: , in, Let be the unique vector corresponding to the i-th task, and let 1-m be the vector of all 1s subtracted element by element to generate the inverse mask. Let be the task vector corresponding to the i-th expert model. Through element-wise multiplication, all vector components in the task vector except for those specific to the task can be automatically set to zero, thus obtaining... The non-zero values in the vector represent the unique parameter offsets. The existence of the mask vector not only improves the efficiency of determining the shared parameter offsets and unique parameter offsets, but also allows it to participate in the joint distillation optimization as a variable.
[0051] This embodiment provides a method for fusing parameters in a multi-task model, which can be used in servers that run the model, etc. Figure 2 This is a flowchart of a multi-task model parameter fusion method according to an embodiment of the present invention, such as... Figure 2 As shown, the process includes the following steps: Step S201: Obtain the task vector for fine-tuning the pre-trained model for each task. See details below. Figure 1 Step S101 of the illustrated embodiment will not be described again here.
[0052] Step S202: Obtain the merged task vector obtained by merging the task vectors corresponding to all tasks.
[0053] Specifically, step S202 includes: Step S2021: Perform a linear combination of the task vectors corresponding to all tasks to obtain the merged task vector or retrieve the merged task vector that has already been merged.
[0054] The initialized merging task vector can be obtained through real-time linear combination, such as the average or weighted calculation in step S102. Alternatively, it can be a merging task vector obtained using an existing model merging method, further decoupled and optimized through this embodiment of the invention, thereby facilitating its integration with other model merging techniques.
[0055] Step S2022: Construct a mask vector with the same dimension as the task vector and the merged task vector. The mask vector is defined with coordinates belonging to the shared part and coordinates belonging to the unique part.
[0056] In the joint optimization of distillation, the initialized merged task vector needs to be optimized. At the same time, in order to obtain the shared parameter offset and the unique parameter offset in the merged task vector, a mask vector is introduced in the early stage of the joint optimization of distillation to extract the shared parameter offset and the unique parameter offset, and the mask vector is also optimized at the same time.
[0057] In an optional implementation, step S2022 includes: Step a1: Initialize the first mask vector. Each vector component of the first mask vector is a random value between 0 and 1.
[0058] The vector components in the first mask vector can be generated using random numbers, in order to make the final first mask vector... The sigmoid function needs to be used for constraint: , in, Let z be the first mask vector after constraint processing, and z be the random number initialization vector before constraint processing. The continuous representation of the mask can participate in gradient updates. Accordingly, the first mask vector is not directly used to separate the shared and unique coordinates; instead, it is combined with the second mask vector to ensure that the selection of the shared coordinates is synchronized with the learning process of the shared parameter offsets, thus achieving end-to-end optimization.
[0059] Step a2: When the vector component in the first mask vector is greater than the first threshold, set it to 1; when the vector component in the first mask vector is less than the first threshold, set it to 0, so as to obtain the second mask vector. The vector components of the second mask vector are used to determine the coordinates belonging to the shared part and the coordinates belonging to the unique part.
[0060] To facilitate the definition of shared and unique coordinates and achieve hard selection, the second mask vector needs to be configured to... Specifically, it is derived from the first mask vector according to the following formula: , in, For the j-th vector component in the second mask vector, This is the first mask vector. The first threshold is set empirically and can be predetermined via hyperparameters. Each vector component in the first mask vector is compared with the first threshold; those exceeding the threshold are set to 1 at their corresponding sequence coordinates in the second mask vector, and those falling below the threshold are set to 0.
[0061] Step S2023: The mask vector is configured to calculate the merged task vector and the task vector by element-wise multiplication, so as to deploy the initial reorganization model based on the determined shared parameter offset and the unique parameter offset.
[0062] When the mask vector uses 1 to represent the coordinates of the shared part and 0 to represent the coordinates of the unique part, the example in step S103 can be directly referred to, so that the shared parameter offset and the unique parameter offset used for deploying the initial recombinant model can be extracted. The shared parameter offset and the unique parameter offset can be superimposed on the pre-trained model parameters to generate the initial recombinant model for different tasks.
[0063] In an optional implementation, step S2023 includes: Step b1: Determine the upper and lower limits of the corresponding coordinate shared parameter offset. The upper and lower limits are determined based on the vector component distribution of the same coordinate in the corresponding task vectors of all tasks.
[0064] The initialization of the recombinant model is for subsequent distillation joint optimization. When updating shared parameter offsets solely based on distillation of the unlabeled sample set, without limiting the parameter range, the optimization results may cause some shared parameter offsets to deviate from the reasonable range of all input expert models, leading to model instability or performance degradation. Therefore, it is necessary to numerically limit the shared parameter offsets on which the initialization model is based, specifically determining the reasonable range based on the task vector corresponding to the expert model, i.e., setting upper and lower limits.
[0065] Accordingly, for any shared parameter offset in the shared vector, the coordinates... Collect the values of the task vectors corresponding to all tasks (e.g., N tasks) at this coordinate: , Therefore, the upper and lower limits are determined based on the distribution of vector components at the same coordinate in the task vectors corresponding to all tasks. For example: , in, The lower limit value is set and determined by the minimum value in the vector component distribution. The upper limit value is determined by the maximum value in the vector component distribution. Similarly, the shared parameter offset of each coordinate will have a corresponding upper limit value and lower limit value, which are determined by the maximum and minimum values of the corresponding task vectors of all tasks at that coordinate, respectively.
[0066] Optionally, with For example, the upper and lower quantiles of these values will be counted to determine the upper and lower limits, such as the 90th quantile and the 10th quantile, instead of using the extreme values to construct the interval, so as to reduce the impact of outliers on the calibration range.
[0067] Optionally, with For example, the average and standard deviation of these values will be calculated, and the upper and lower limits will be determined based on the multiple of the standard deviation.
[0068] Alternatively, different calibration intensities or different interval construction rules can be used for different layers to accommodate the different sensitivity of different layers of the network to parameter drift.
[0069] Step b2: When the value of the shared parameter offset is greater than the upper limit value, set it to the upper limit value; when the value of the shared parameter offset is between the upper limit value and the lower limit value, keep the original value; when the value of the shared parameter offset is less than the lower limit value, set it to the lower limit value.
[0070] Once the upper and lower limits of each coordinate are found, calibration can be performed using the following formula: , in, For the final value, The set lower limit value, The set upper limit value, This is the original value of the shared parameter offset. That is, when the original value of the shared parameter offset exceeds the upper or lower limit, it will be calibrated to the upper or lower limit to ensure that it does not exceed the range. For values between the upper and lower limits, it is sufficient to maintain the original value.
[0071] Step S2024: Input the unlabeled sample set into the expert model respectively, initialize the recombination model processing to determine the distillation loss between the two, and determine the optimal merging task vector and mask vector based on the backpropagation of the distillation loss. The expert model is the model obtained by fine-tuning the pre-trained model for each task.
[0072] After determining the decoupling structure, joint optimization of the merged task vector and mask vector is required to ensure that the initial reassembly model of each task approximates the corresponding expert model as closely as possible at the output level. Specifically, for the unlabeled sample set x, the outputs of the expert model and the initial reassembly model are calculated separately, assuming the i-th... The output of the expert model is: , The corresponding initialization and recombination model output is: , Where f(x;θ) represents the input of an unlabeled sample x to a neural network model running with model parameters θ. This is the output of the expert model for the corresponding task. This is the output of the initialization and reorganization model for the corresponding task, where i is the sequence for the corresponding task.
[0073] This invention uses distillation loss to measure the behavioral difference between the initialization and recombination model and the expert model. Distillation loss can be logits mean squared error, KL divergence, or other output alignment losses, and is suitable for common tasks such as classification and generation. For example, it can be written as: , in, For distillation losses, Let be the distillation error function, i be the sequence of the corresponding task, and N be the total number of tasks.
[0074] Optionally, by aligning the intermediate hidden layer representations, the error between the calculated intermediate hidden feature vectors can be used as the object of distillation loss analysis, and distillation constraints can be applied to the intermediate hidden states, thereby improving the ability of shared vectors to preserve the internal knowledge structure.
[0075] Optionally, by aligning the Transformer attention distribution, the calculation error of the Transformer attention matrix can be used as the object of distillation loss analysis, and distillation constraints can be applied to the attention matrix or attention distribution, which is suitable for scenarios that need to maintain structural behavior.
[0076] Optionally, output layer distillation, hidden layer distillation, and attention distillation can be combined simultaneously to form a joint loss function, thereby enhancing the ability to fit the behavior of expert models.
[0077] In an optional implementation, step S2024 includes: Introduce the mask sparse regularization loss corresponding to the first mask vector into the distillation loss.
[0078] To achieve hard coordinate selection during forward propagation while maintaining differentiability during back propagation, a pass-through estimator is employed, and the mask used during optimization is defined as follows: , in, This indicates that the gradient operation is stopped. This is the first mask vector. This is the second mask vector. Under this configuration, forward propagation uses a discrete mask. The coordinates are chosen, while the gradient is obtained through continuous variables. Propagation, thereby enabling the mask to be transmitted. End-to-end optimization.
[0079] M determines which parameter coordinates are assigned to the shared parts. If too few coordinates are shared, the model may not be able to fully utilize the common knowledge between different tasks. Conversely, if too many coordinates are assigned to the shared parts, the task-specific parts may interfere with each other, thus degrading the quality of the merged representation. To balance these two effects, the desired mask density is regularized to a target sharing ratio using the following formula. : , in, For density-regularized loss scalars, the first mask vector It is a continuous relaxation form of the mask M, where d is the dimension of the first mask vector, and ρ is the mask density target. Setting ρ to 0.8 means that about 80% of the parameter coordinates are shared, and setting it to 0.5 means that only 50% of the parameter coordinates are shared, leaving more for the unique parts. The specific settings are determined in advance through hyperparameters.
[0080] To avoid the mask degenerating into all 1s or all 0s, we can introduce the mask sparsity corresponding to the density regularization loss scalar, and calculate the mask sparsity regularization loss according to the following formula.
[0081] , in, Depend on Used as a mask for sparse regularization loss. Let d be the i-th vector component of the first mask vector, d be the dimension of the first mask vector, and ρ be the mask density target. For details, please refer to the description above.
[0082] Optionally, the average activation ratio of the mask can be constrained within a preset range to ensure that the proportion of the shared portion meets deployment requirements.
[0083] Optionally, a sharing ratio can be set for different layers to accommodate differences in parameter redundancy and task sensitivity at different layers.
[0084] Accordingly, the overall optimization objective function can be expressed as: , in, For the total loss, For distillation losses, The mask sparsity regularization loss is the value corresponding to the first mask vector. The weighting coefficients are determined empirically and pre-set via hyperparameters. Essentially, a regularization loss based on the mask coefficients of the first mask vector is introduced into the distillation loss as an additional constraint on the total loss, automatically and sparsely partitioning the shared dimension and task-specific dimension of multiple tasks. By minimizing the above objective function, the merged task vector and the second mask vector can be updated simultaneously. The second mask vector is used to separate the shared and task-specific parts. Minimizing the objective is essentially the training process, continuously calculating the total loss and using backpropagation to calculate the gradient. The gradient represents the direction in which the current parameters are adjusted to reduce the total loss.
[0085] Furthermore, in the optimization of the merged task vectors, the speed at which the merged task vectors are updated during training is controlled by optimizing the learning rate through shared updates. The initialized merged task vectors are not simply processed as averaged task vectors, but are further optimized through shared updates to make them more suitable for all tasks. The merged task vectors are a shared part across all tasks. If the learning rate is too large, it may deviate from the reasonable parameter range of the original expert model to adapt to certain tasks, leading to a decrease in performance on other tasks. Optimizing the learning rate through shared updates can be done by setting the hyperparameters in advance.
[0086] Step S203: Output the shared parameter offsets determined based on the shared part coordinates in the merged task vector and the unique parameter offsets determined based on the unique part coordinates in each task vector, so as to deploy the reorganization model of the corresponding task according to the shared parameter offsets and the unique parameter offsets of the corresponding task.
[0087] The output shared parameter offsets and / or unique parameter offsets can be saved after quantization and compression to reduce storage usage. When deploying the reconstructed model, the required parameter offsets can also be restored through quantization. This enables rapid fine-tuning based on the pre-trained model.
[0088] Specifically, step S203 includes: Step c1: Delete zeroing information other than the specific parameter offset.
[0089] The unique vector containing the unique parameter offset obtained through the mask vector can be further compressed by deleting all zeroing information except for the unique part of the unique vector and saving only the unique parameter offset and the corresponding coordinate position as an index.
[0090] Step c2: Quantize the unique parameter offset to compress the data volume.
[0091] Because the unique vectors are sparser and more concentrated at specific coordinates compared to the complete task vectors, they have better quantization friendliness. Accordingly, fixed-point quantization with 8 bits, 4 bits, or lower (pre-set via hyperparameters) is used for storage to reduce the additional parameter overhead per task. Essentially, this involves offsetting the unique parameters from their original high-precision floating-point values and compressing them into a finite integer value space with fewer bits through a linear mapping transformation; during inference, the floating-point values are then approximated and used in computation through inverse mapping. Optionally, quantization can also be performed separately by tensor blocks or parameter groups to balance quantization error and storage compression ratio.
[0092] Step c3: Save the quantized parameter offsets and corresponding coordinates.
[0093] By simplifying the zeroing information in the unique vectors, only the unique parameter offsets with information content are saved to reduce redundant storage. Since the coordinates of the unique parameter offsets are saved synchronously, the original unique vector shape can also be restored through the coordinate information to realize the deployment of the recombined model.
[0094] Specifically, step S203 above also includes: Step d1: Deploy the recombined model based on the pre-trained model and shared parameter offsets; Step d2: Load the specific parameter offsets of the corresponding task to update and reconstruct the model according to the task to be processed.
[0095] The recombined model can be deployed offline, dynamically online, or with a shared backbone and task plugins. Offline recombining involves pre-adding shared parameter offsets and unique parameter offsets to the pre-trained model to deploy it as a recombined model independent of the corresponding task, suitable for scenarios with long-term single-task operation. In scenarios requiring greater flexibility, the recombined model can be deployed first based on the pre-trained model and shared parameter offsets, and unique parameter offsets can be dynamically loaded during inference based on task requests, suitable for scenarios with frequent multi-task switching. Furthermore, the shared backbone with task plugins approach can directly embed the shared parameter offsets from step d1 into the unified backbone of the pre-trained model for management, while only loading unique parameter offsets as pluggable parameter modules on demand, facilitating large-scale service deployment.
[0096] like Figure 3As shown, each task has a corresponding task vector, and different task vectors include the offset direction and magnitude of the pre-trained model parameters for different tasks. By setting a learnable mask vector, the parameter coordinates can be finely divided. For each parameter coordinate, it is no longer pre-determined that it must participate in unified fusion; instead, it adaptively determines whether the coordinate is more suitable as a shared part for multiple tasks or as a task-specific part based on the optimization objective. This results in a parameter representation method where shared parameter offsets and task-specific parameter offsets coexist. After obtaining the above parameter partitioning structure, the shared part is trained and optimized using the output distillation signal on unlabeled samples, enabling it to extract reusable knowledge from multiple expert models as much as possible. During distillation, the task-specific part maintains the differences between the corresponding tasks, while the shared part undertakes the role of cross-task capability integration. To avoid unreasonable offsets exceeding the support range of the expert models during the optimization process, a coordinate-level numerical calibration mechanism is designed. This mechanism corrects the shared part coordinate by coordinate based on the numerical range of each expert model on the same parameter coordinate, achieving constrained optimization and thus improving the stability of the optimized parameters. During the deployment phase, only one set of shared parameter offsets is retained, and corresponding lightweight task-specific parameter offsets are also retained for each task. For any given task, simply recombining the shared parameter offsets with the task-specific parameter offsets restores the task-specific model's capabilities. Since the task-specific parameter offsets only occupy a portion of the parameter coordinates, this approach offers good compactness and quantization adaptability, making it suitable for large-scale multi-task deployments. Accordingly, the model merging method of this invention is applicable to merging expert models for supervised tasks such as image classification and text classification. It can also be applied to multi-task merging of generative models such as text generation, dialogue generation, and code generation. Furthermore, it can be applied to the unified merging of multimodal expert models such as vision-language and speech-text models. Furthermore, provided that parameter alignment or structural mapping relationships are satisfied, it can be extended to related model fusion scenarios with corresponding parameter spaces.
[0097] like Figure 4 As shown, the results of RoBERTa (a robust version of BERT) and GPT-2 models on seven language tasks demonstrate that the embodiments of the present invention can significantly outperform traditional static merging methods in language model merging scenarios, and their performance is close to that of single-task expert models.
[0098] like Figure 5 As shown, the generality and scalability of the embodiments of the present invention are further verified in experiments merging 8, 14, and 20 visual tasks of the ViT-B / 32 and ViT-L / 14 models, demonstrating that it can still maintain stable and close performance to the average performance of expert models when the number of tasks increases and the heterogeneity of tasks is enhanced.
[0099] like Figure 6As shown, the role of the learnable mask is analyzed from the perspective of CKA (Centered Kernel Alignment) to represent similarity. This shows that the mask learned in the embodiments of the present invention can effectively distinguish between shared and unique parameters, so that the final merged model is both close to the corresponding task expert and reduces confusion with other tasks.
[0100] like Figure 7 As shown, the effectiveness of this parameter decomposition is further verified from the perspective of downstream task accuracy. It shows that using the shared part or the unique part alone is not as good as the model after the two are recombined, proving that the structural design of shared knowledge + task individuality is necessary.
[0101] like Figure 8 As shown, the effect of coordinate-level numerical calibration in one-dimensional loss landscape analysis reveals that uncalibrated shared updates often deviate from the optimal region, while coordinate-level numerical calibration can pull them back to a reasonable range supported by expert parameters, thereby reducing over-extrapolation and improving merging stability. Overall, these figures demonstrate from multiple perspectives—method structure, master experiment performance, representation mechanism, performance decomposition, and geometric interpretation—that the core design of this invention can indeed alleviate parameter conflicts between tasks, preserve expert knowledge, and achieve high-fidelity multi-task model merging.
[0102] In summary, this invention does not simply compress all task model updates into a single shared parameter. Instead, it uses a learnable mask vector (e.g., at the parameter coordinate level) to perform fine-grained partitioning of the fused updates. The parts that can be reused across tasks are modeled as shared updates, while task-specific parts are retained as unique parts. Furthermore, it combines distillation optimization and coordinate-level numerical calibration mechanisms to improve the stability and fidelity of the shared parts. This invention systematically solves the key problems of existing model merging techniques in terms of task conflicts, knowledge loss, numerical drift, and deployment and storage.
[0103] According to embodiments of the present invention, a multi-task model parameter fusion apparatus is also provided. This apparatus is used to implement the above embodiments and preferred embodiments, and details already described will not be repeated. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the apparatus described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0104] This embodiment provides a multi-task model parameter fusion device, such as... Figure 9 As shown, it includes: The task vector acquisition module 901 is used to acquire the task vector for fine-tuning the pre-trained model for each task. The merged task vector acquisition module 902 is used to acquire the merged task vector obtained by merging the task vectors corresponding to all tasks. The parameter offset output module 903 is used to output the shared parameter offset determined based on the coordinates of the shared part in the merged task vector and the unique parameter offset determined based on the coordinates of the unique part in each task vector, so as to deploy the reorganization model of the corresponding task according to the shared parameter offset and the unique parameter offset of the corresponding task.
[0105] The multi-task model parameter fusion apparatus provided in this embodiment of the invention can execute the multi-task model parameter fusion method provided in any embodiment of the invention, and has the corresponding functional modules and beneficial effects for executing the method. Further functional descriptions of the above modules and units are the same as those in the corresponding embodiments described above, and will not be repeated here.
[0106] Figure 10 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention.
[0107] The following is a detailed reference. Figure 10 This diagram illustrates a suitable structural schematic for implementing an electronic device according to embodiments of the present invention. The electronic device may include a processor (e.g., a central processing unit, graphics processor, etc.) 1001, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1002 or a program loaded from memory 1008 into random access memory (RAM) 1003. The RAM 1003 also stores various programs and data required for the operation of the electronic device. The processor 1001, ROM 1002, and RAM 1003 are interconnected via a bus 1004. An input / output (I / O) interface 1005 is also connected to the bus 1004.
[0108] Typically, the following devices can be connected to the I / O interface 1005: input devices 1006 including, for example, a touchscreen, touchpad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; output devices 1007 including, for example, a liquid crystal display (LCD), speaker, vibrator, etc.; memory devices 1008 including, for example, magnetic tape, hard disk, etc.; and communication devices 1009. Communication device 1009 allows electronic devices to exchange data via wireless or wired communication with other devices. Although Figure 10 Electronic devices with various devices are shown, but it should be understood that it is not required to implement or have all of the devices shown, and more or fewer devices may be implemented or have instead.
[0109] In particular, according to embodiments of the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of the present invention include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 1009, or installed from a memory 1008, or installed from a ROM 1002. When the computer program is executed by the processor 1001, it performs the functions defined in the multi-task model parameter fusion method of the embodiments of the present invention.
[0110] Figure 10 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments of the present invention.
[0111] This invention also provides a computer-readable storage medium. The methods described above according to embodiments of the invention can be implemented in hardware or firmware, or implemented as computer code that can be recorded on a storage medium, or implemented as computer code downloaded via a network and originally stored on a remote storage medium or a non-transitory machine-readable storage medium and then stored on a local storage medium. Thus, the methods described herein can be processed by software stored on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. The storage medium can be a magnetic disk, optical disk, read-only memory, random access memory, flash memory, hard disk, or solid-state drive, etc.; further, the storage medium can also include combinations of the above types of memory. It is understood that computers, processors, microprocessor controllers, or programmable hardware include storage components capable of storing or receiving software or computer code. When the software or computer code is accessed and executed by the computer, processor, or hardware, the multi-task model parameter fusion method shown in the above embodiments is implemented.
[0112] Although embodiments of the invention have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the invention, and such modifications and variations all fall within the scope defined by the appended claims.
Claims
1. A method for fusing parameters in a multi-task model, characterized in that, The method includes: Obtain the task vector for fine-tuning the pre-trained model for each task; Obtain the merged task vector obtained by merging the task vectors corresponding to all tasks; Output the shared parameter offsets determined based on the shared part coordinates in the merged task vector and the unique parameter offsets determined based on the unique part coordinates in each task vector, so as to deploy the reorganization model of the corresponding task according to the shared parameter offsets and the unique parameter offsets of the corresponding task.
2. The multi-task model parameter fusion method according to claim 1, characterized in that, The process of obtaining the merged task vector based on the merging of task vectors corresponding to all tasks includes: Perform a linear combination of the task vectors corresponding to all tasks to obtain the merged task vector or retrieve the merged task vector that has already been merged. Construct a mask vector with the same dimension as the task vector and the merged task vector. The mask vector defines coordinates belonging to the shared part and coordinates belonging to the unique part. The mask vector is configured to calculate the merged task vector and the task vector by element-wise multiplication, so as to deploy the initialization reorganization model based on the determined shared parameter offset and the unique parameter offset. The unlabeled sample set is input into the expert model and the initialization and recombination model are processed to determine the distillation loss between the two. The optimal merging task vector and mask vector are determined based on the backpropagation of the distillation loss. The expert model is a model obtained by fine-tuning the pre-trained model for each task.
3. The multi-task model parameter fusion method according to claim 2, characterized in that, The construction of a mask vector with the same dimension as the task vector and the merged task vector includes: Initialize the first mask vector, where each vector component of the first mask vector is a random value between 0 and 1; When the vector component in the first mask vector is greater than the first threshold, it is set to 1; when the vector component in the first mask vector is less than the first threshold, it is set to 0, so as to obtain the second mask vector. The vector components of the second mask vector are used to determine the coordinates belonging to the shared part and the coordinates belonging to the unique part. The process of determining the optimal merging task vector and mask vector based on the backpropagation of the distillation loss includes: The distillation loss is introduced into the mask sparse regularization loss corresponding to the first mask vector.
4. The multi-task model parameter fusion method according to claim 2, characterized in that, The deployment and initialization of the reorganization model based on the determined shared parameter offset and unique parameter offset includes: Determine the upper and lower limits of the corresponding coordinate shared parameter offset, wherein the upper and lower limits are determined based on the vector component distribution of the same coordinate in the task vectors corresponding to all tasks; When the value of the shared parameter offset is greater than the upper limit value, it is set to the upper limit value; when the value of the shared parameter offset is between the upper limit value and the lower limit value, the original value is maintained; when the value of the shared parameter offset is less than the lower limit value, it is set to the lower limit value.
5. The multi-task model parameter fusion method according to claim 4, characterized in that, The upper and lower limits are determined based on the distribution of vector components at the same coordinate in the task vectors corresponding to all tasks, including: The upper limit value is determined based on the maximum value in the vector component distribution; The lower limit value is determined based on the minimum value in the vector component distribution.
6. The multi-task model parameter fusion method according to claim 1, characterized in that, The output of the unique parameter offsets in each task vector, determined based on the unique partial coordinates, includes: Remove zeroing information except for the specific parameter offset; The specific parameter offset is quantized to compress the data volume; Save the unique parameter offsets and corresponding coordinates after quantization.
7. The multi-task model parameter fusion method according to claim 1, characterized in that, The reorganization model that deploys the corresponding task based on the shared parameter offset and the specific parameter offset of the corresponding task includes: Deploy the recombined model based on the pre-trained model and the shared parameter offset; The recombination model is updated by loading the specific parameter offsets of the corresponding task according to the task to be processed.
8. A multi-task model parameter fusion device, characterized in that, The device includes: The task vector acquisition module is used to acquire the task vector for fine-tuning the pre-trained model for each task; The merged task vector acquisition module is used to obtain the merged task vector obtained by merging the task vectors corresponding to all tasks. The parameter offset output module is used to output the shared parameter offset determined based on the coordinates of the shared part in the merged task vector and the unique parameter offset determined based on the coordinates of the unique part in each task vector, so as to deploy the reorganization model of the corresponding task according to the shared parameter offset and the unique parameter offset of the corresponding task.
9. An electronic device, characterized in that, include: A memory and a processor are interconnected, the memory stores computer instructions, and the processor executes the computer instructions to perform the multi-task model parameter fusion method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing the computer to execute the multi-task model parameter fusion method according to any one of claims 1 to 7.
