Multi-task model fine-tuning method and device, electronic equipment and storage medium
By semantically encoding and feature modulation of the pre-trained language model, dynamically selecting routing expert modules and combining them with shared expert modules, the parameter conflict and forgetting problems in multi-task learning are solved, achieving efficient model updates and improved stability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- IFLYTEK CO LTD
- Filing Date
- 2026-01-21
- Publication Date
- 2026-05-29
AI Technical Summary
Existing technologies suffer from parameter conflicts and catastrophic forgetting problems in multi-task learning, making it difficult to efficiently deploy and update pre-trained language models in low-resource scenarios.
By semantically encoding the sample data of each task, modulation coefficients are generated to modulate the hidden layer features. Routing weights are calculated based on the modulation features, routing expert modules are dynamically selected, and feature aggregation and parameter fine-tuning are performed in combination with shared expert modules. A low-rank matrix factorization structure is adopted to achieve efficient parameter updates.
It effectively solves the problems of gradient interference and catastrophic forgetting in multi-task learning, improves the generalization performance and stability of the model, and reduces the consumption of computing resources.
Smart Images

Figure CN122114070A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of multi-task learning technology, and in particular to a method, apparatus, electronic device, and storage medium for fine-tuning a multi-task model. Background Technology
[0002] With the widespread application of pre-trained language models in the field of natural language processing, how to efficiently fine-tune them to adapt to various downstream tasks has become a research hotspot. However, directly fine-tuning all parameters of the model has the problems of high computational resource consumption, high training cost, and difficulty in deployment in low-resource scenarios.
[0003] Currently, low-rank adaptation (LoRA) is commonly used, which achieves efficient parameter updates by introducing a low-rank matrix into the pre-trained weights. However, in multi-task learning (MTL) scenarios, traditional LoRA methods are prone to parameter update conflicts and interference due to inconsistent gradient directions across different tasks. Furthermore, the model is susceptible to catastrophic forgetting when continuously learning new tasks. Summary of the Invention
[0004] This invention provides a method, apparatus, electronic device, and storage medium for fine-tuning a multi-task model, in order to overcome the deficiencies existing in the prior art.
[0005] This invention provides a method for fine-tuning a multi-task model, comprising the following steps: Semantic encoding is performed on the sample data for each task to obtain the corresponding encoded features; The sample data of each task is input into the feature extraction module of the multi-task model to obtain the hidden layer features of each task. The modulation coefficients of each task are generated using the coding features of each task, and the corresponding hidden layer features are modulated using the modulation coefficients of each task to obtain the modulation features of each task. The routing weight of each task is calculated based on the modulation characteristics of each task, and the corresponding target expert module is determined from the multiple routing expert modules of the multi-task model according to the routing weight of each task. The output of the shared expert module in the multi-task model is aggregated with the output of the target expert module of each task to obtain the prediction results of each task. Based on the prediction results of each task, the parameters of the multi-task model are fine-tuned. The shared expert module is an expert network that participates in the calculation of all tasks.
[0006] According to a multi-task model fine-tuning method provided by the present invention, the step of generating modulation coefficients for each task using the coding features of each task, and modulating the corresponding hidden layer features using the modulation coefficients of each task to obtain the modulation features of each task includes: The coding features of each task are projected and transformed to obtain the first modulation coefficient and the second modulation coefficient of each task. The corresponding hidden layer features are scaled using the first modulation coefficient of each task, and the scaled hidden layer features are translated using the second modulation coefficient of each task to obtain the modulation features of each task.
[0007] According to a multi-task model fine-tuning method provided by the present invention, the step of performing projection transformation on the coding features of each task to obtain the first modulation coefficient and the second modulation coefficient of each task includes: The encoded features of each task are mapped to low-dimensional feature vectors using the first projection matrix, wherein the dimension of the low-dimensional feature vectors is lower than the dimension of the hidden layer features. The low-dimensional feature vector is mapped to a combined coefficient vector using a second projection matrix, and the combined coefficient vector is split into a first modulation coefficient and a second modulation coefficient. The dimension of the combined coefficient vector is twice the dimension of the hidden layer features.
[0008] According to a multi-task model fine-tuning method provided by the present invention, the step of calculating the routing weight of each task based on the modulation characteristics of each task, and determining the corresponding target expert module from the plurality of routing expert modules according to the routing weight of each task, includes: The modulation characteristics of each task are linearly mapped to obtain the initial routing score for each task. The initial routing scores of each task are normalized to obtain the routing weights of each routing expert module under the corresponding task. The routing expert modules are sorted in descending order of routing weight, and a preset number of routing expert modules at the top of the list are selected as the target expert modules for the corresponding tasks.
[0009] According to a multi-task model fine-tuning method provided by the present invention, the step of aggregating the output of the shared expert module in the multi-task model with the output of the target expert module of each task to obtain the prediction result of each task includes: The output of the shared expert module is multiplied by the preset shared weights to obtain the shared features of each task; By using the routing weights under each task as weighting coefficients, the outputs of the corresponding target expert modules are summed in a weighted manner to obtain the routing aggregation features of each task. The shared features of each task are added to the routing aggregation features of each task to obtain the aggregate features of each task. Based on the aggregation characteristics of each task, the prediction results for each task are obtained.
[0010] According to a multi-task model fine-tuning method provided by the present invention, the parameter fine-tuning of the multi-task model based on the prediction results of each task includes: Calculate the gradient of each parameter in the shared expert module, and calculate the gradient momentum of the corresponding parameter based on the gradient of each parameter in the shared expert module; The parameters of the shared expert module are sorted by importance based on the gradient momentum of each parameter, and the parameters that meet the preset conditions are selected for updating, while the remaining parameters of the shared expert module remain unchanged. Calculate the gradient of each parameter in the target expert module, and update all parameters of the target expert module using the gradient of each parameter in the target expert module.
[0011] According to a multi-task model fine-tuning method provided by the present invention, the step of calculating the gradient momentum of the corresponding parameter based on the gradient of each parameter in the shared expert module includes: Obtain the gradient momentum of each parameter in the shared expert module at the previous training step; Using a preset smoothing coefficient, the gradient momentum of the previous training step and the gradient of the current training step are weighted and summed to obtain the gradient momentum of each parameter in the current training step.
[0012] According to the multi-task model fine-tuning method provided by the present invention, the gradients of each parameter are determined based on the following steps: Construct a joint loss function, which includes at least one of the following: task loss for measuring prediction accuracy, load balancing loss for measuring the load balancing degree of expert modules, and orthogonal constraint loss for measuring parameter independence. Backpropagation is performed based on the joint loss function to obtain the gradients of each parameter in the shared expert module and the gradients of each parameter in the target expert module.
[0013] According to a multi-task model fine-tuning method provided by the present invention, the load balancing loss is determined based on the following steps: The average routing probability of each routing expert module and the average utilization rate of the actual sample data processed by each routing expert module are statistically analyzed. Calculate the product of the average routing probability and average utilization of each routing expert module, and sum the products of all routing expert modules as the load balancing loss.
[0014] According to a multi-task model fine-tuning method provided by the present invention, the orthogonal constraint loss is determined based on the following steps: Calculate the correlation metric between the parameter matrix of the shared expert module and the parameter matrices of each routing expert module; The absolute values of the correlation metrics are summed, and the summation result is used as the orthogonal constraint loss.
[0015] According to a multi-task model fine-tuning method provided by the present invention, the step of semantically encoding the sample data of each task to obtain corresponding encoded features includes: For each task, a predetermined number of sample data are randomly sampled; Semantic encoding is performed on the sample data for each task to obtain the semantic features of each sample data under the corresponding task; Calculate the average of the semantic features of all sample data under each task, and use the average as the encoding feature of the corresponding task.
[0016] According to a multi-task model fine-tuning method provided by the present invention, both the shared expert module and the routing expert module adopt a low-rank matrix factorization structure.
[0017] The present invention also provides a multi-task model fine-tuning device, comprising the following modules: The encoding module is used to perform semantic encoding on the sample data of each task to obtain the corresponding encoded features; The extraction module is used to input the sample data of each task into the feature extraction module of the multi-task model to obtain the hidden layer features of each task. The modulation module is used to generate modulation coefficients for each task using the coding features of each task, and to modulate the corresponding hidden layer features using the modulation coefficients of each task to obtain the modulation features of each task. The determination module is used to calculate the routing weight of each task based on the modulation characteristics of each task, and determine the corresponding target expert module from multiple routing expert modules of the multi-task model according to the routing weight of each task. The fine-tuning module is used to aggregate the output of the shared expert module in the multi-task model with the output of the target expert module of each task to obtain the prediction results of each task, and to fine-tune the parameters of the multi-task model based on the prediction results of each task. The shared expert module is an expert network that participates in the calculation of all tasks.
[0018] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the multi-task model fine-tuning method as described above.
[0019] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the multi-task model fine-tuning method as described above.
[0020] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the multi-task model fine-tuning method as described above.
[0021] The multi-task model fine-tuning method, apparatus, electronic device, and storage medium provided by this invention obtain task semantic vectors by semantically encoding task samples, and use these vectors to generate modulation coefficients to linearly modulate the hidden layer features with task awareness. Then, based on the modulated features, the dynamic selection and aggregation of routing experts in a hybrid expert structure are guided. By introducing explicit task semantic guidance and feature modulation mechanisms, the problem of expert allocation errors caused by the lack of macro-level task awareness in routers in traditional methods is effectively solved. Simultaneously, by combining the division of labor and cooperation between shared experts and routing experts, efficient parameter updates are ensured while feature decoupling and adaptive adaptation between multiple tasks are achieved. This effectively avoids gradient interference and catastrophic forgetting phenomena in multi-task learning, improving the generalization performance and stability of the model. Attached Figure Description
[0022] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0023] Figure 1 This is a flowchart illustrating the multi-task model fine-tuning method provided by the present invention.
[0024] Figure 2 This is a schematic diagram of the framework of the multi-task model provided by the present invention.
[0025] Figure 3 This is a schematic diagram of the structure of the multi-task model fine-tuning device provided by the present invention.
[0026] Figure 4 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation
[0027] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0028] With the widespread application of large-scale pre-trained language models in natural language processing, they have demonstrated excellent generalization capabilities across various tasks. However, directly fine-tuning all parameters of a pre-trained model incurs significant computational and storage overhead, resulting in high training costs and difficulty in efficient deployment in multi-task or low-resource scenarios. To address this, researchers have proposed several efficient parameter fine-tuning methods, such as Adapter, Prefix-Tuning, and LoRA. Among them, LoRA introduces a low-rank decomposition structure into the weight matrix, requiring only a small number of parameter updates to achieve task transfer and model adaptation, thereby effectively reducing fine-tuning costs.
[0029] However, traditional LoRA methods are mostly used in single-task scenarios and struggle to maintain both performance and stability in multi-task environments. While multi-task learning can improve the overall performance of the model by sharing features, inconsistencies in gradient directions between tasks often lead to parameter conflicts and interference. Furthermore, during long-term training or continuous task expansion, the model is prone to forgetting knowledge from previously learned tasks, resulting in catastrophic forgetting.
[0030] To alleviate these problems, Mixture of Experts (MoE) models were introduced to achieve parameter sharing and sparse computation, dynamically allocating computational resources among different experts through task-related routing mechanisms. Although MoE improves multi-task modeling capabilities to some extent, its expert selection still relies on fixed strategies and lacks adaptability to task semantics; the high coupling between experts' parameters leads to knowledge redundancy; and the model still faces the risk of forgetting during long-term training, making it difficult to balance multi-task generalization and continuous learning performance.
[0031] Therefore, existing technologies have not yet been able to maintain efficient parameter updates while simultaneously taking into account multi-task adaptation and anti-forgetting characteristics. There is an urgent need for a novel multi-task fine-tuning method that combines low-rank hybrid expert structures, task-aware modulation mechanisms, and sparse optimization strategies to improve the learning efficiency and stability of the model.
[0032] In response to this, the present invention provides a multi-task model fine-tuning method, aiming to obtain corresponding encoded features by semantically encoding the sample data of each task, generate modulation coefficients using these encoded features to linearly modulate the hidden layer features in the pre-trained model, and based on the modulated features, guide the dynamic routing selection and aggregation of the shared expert module and multiple routing expert modules, so as to achieve adaptive feature adaptation and efficient parameter update based on task semantic perception, thereby effectively alleviating the parameter conflict and catastrophic forgetting problems in the multi-task scenario and improving the generalization ability and stability of the model. Among them, this method can be applied to the field of natural language processing, such as scenarios that need to simultaneously process multiple different tasks such as text summarization, machine translation, and sentiment analysis. This method aims to solve the problems existing in the multi-task fine-tuning process of existing large-scale pre-trained language models, such as parameter conflict, catastrophic forgetting, and excessive consumption of computing resources.
[0033] Among them, Figure 1 is a schematic flowchart of the multi-task model fine-tuning method provided by the present invention. As Figure 1 shown, this method includes steps 110, step 120, step 130, step 140 and step 150.
[0034] Step 110: Semantically encode the sample data of each task to obtain corresponding encoded features.
[0035] Specifically, multi-task model fine-tuning usually involves a multi-task data set containing multiple different tasks. Sample data refers to the specific data instances selected from this multi-task data set for training or fine-tuning. Each task can be understood as a processing type with different semantic goals, such as English-to-Chinese translation tasks, news classification tasks, etc. For an English-to-Chinese translation task, its corresponding sample data can be a text pair containing the source language English sentence and the target language Chinese translation, such as "Helloworld" and "你好世界"; for a news classification task, its corresponding sample data can be text data containing the news title, the main text content and its corresponding classification label, such as "某球队赢得冠军" and the label "体育".
[0036] In the multi-task learning scenario, if the model only processes based on the input original sample data, it is often difficult to quickly distinguish the task type to which the current sample data belongs in the deep network, which is likely to cause feature confusion between different tasks. Therefore, it is necessary to semantically encode the sample data of each task to explicitly extract the semantic fingerprint that can represent the identity of this task, so as to provide the model with macroscopic task context information.
[0037] Semantic encoding refers to the process of converting unstructured text data into a low-dimensional dense vector that can be processed by a computer using an algorithm model. Encoding features can be understood as numerical vectors that characterize the core semantic attributes of a specific task, i.e., task embedding vectors, which contain rich semantic information and can reflect the semantic similarity or differences between different tasks.
[0038] As an alternative implementation, semantic encoding of sample data can be achieved by invoking a pre-trained language model encoder. For example, the encoder of a T5-based model can be used as a semantic feature extractor. Specifically, for each task, several sample data points (e.g., 20 samples) can be randomly selected and input into the semantic feature extractor to obtain their respective feature representations. Then, average pooling is performed on these feature representations to obtain a unified encoded feature for the task. By extracting encoded features in this way, the powerful language understanding capabilities of the pre-trained model can be utilized to capture deep semantic information in the task description or sample data, providing accurate guidance signals for subsequent task-aware routing.
[0039] Step 120: Input the sample data of each task into the feature extraction module of the multi-task model to obtain the hidden layer features of each task.
[0040] Specifically, a multi-task model refers to the target model to be fine-tuned, which can be a language model pre-trained on a large-scale corpus, such as a Transformer architecture model. The feature extraction module can be understood as the structure in the multi-task model responsible for transforming the raw input into a high-dimensional feature representation, such as the attention layer or the first half of a feedforward neural network layer in a Transformer. Hidden layer features refer to the intermediate layer representation vectors generated during the flow of sample data within the model.
[0041] As an optional embodiment, the multi-task model in this step has been pre-built or inserted with a hybrid expert structure. This hybrid expert structure includes a shared expert module and multiple routing expert modules. The shared expert module is an expert network that is always active and participates in the computation of all tasks, responsible for learning the common knowledge shared by all tasks. The routing expert modules are expert networks that are dynamically and selectively activated according to routing strategies, responsible for capturing the specific knowledge of specific tasks. In other words, the multi-task model includes not only a conventional feature extraction module but also a shared expert module and multiple routing expert modules for subsequent processing. During the forward propagation of the model, sample data is input into the feature extraction module, and after computation, the corresponding hidden layer features are output as input data for subsequent expert modules.
[0042] Step 130: Generate modulation coefficients for each task using the coding features of each task, and modulate the corresponding hidden layer features using the modulation coefficients of each task to obtain the modulation features of each task.
[0043] Specifically, the modulation coefficients can be understood as parameters used to transform the hidden layer features, and their generation process depends on the encoded features obtained in step 110. The purpose of modulation is to enable the general hidden layer features to have task-aware capabilities, that is, to dynamically adjust the distribution of features according to the semantic characteristics of the current processing task, making them more suitable for router recognition.
[0044] As an alternative embodiment, the coded features can be mapped to modulation coefficients using a modulation network. This mapping can be linear or non-linear. The generated modulation coefficients typically include coefficients for scaling the features and coefficients for translating the features.
[0045] Furthermore, considering that the distribution of sample data from different tasks in the original hidden layer space may overlap or become entangled, directly inputting it into the router can easily lead to blurred classification boundaries, making it difficult to accurately assign it to the appropriate expert module. Through modulation operations, task semantic priors can be introduced, dynamically changing the geometric distribution of the feature space and making the features of different tasks more separable. Therefore, this embodiment uses modulation coefficients to modulate the hidden layer features. Specifically, the scaling coefficient can be multiplied element-wise with the hidden layer features, and the result can be added to the translation coefficient. This operation is equivalent to realigning the data in the feature space, highlighting the feature dimensions relevant to the current task and suppressing irrelevant feature dimensions. For example, for mathematical calculation tasks, modulation operations may amplify feature values related to digital logic, thereby making subsequent routing selection more accurate.
[0046] Step 140: Calculate the routing weight of each task based on the modulation characteristics of each task, and determine the corresponding target expert module from multiple routing expert modules of the multi-task model according to the routing weight of each task.
[0047] Specifically, route weight is a numerical value indicating the importance or matching degree of each route expert module to the current input data. The target expert module refers to the route expert modules that are ultimately selected to participate in the calculation.
[0048] Traditional hybrid expert models typically route data directly based on the original hidden layer features, which often makes it difficult for routers to distinguish between similar samples belonging to different tasks, leading to task confusion. For example, a text fragment containing the number "1998" could belong to either a historical task like "year recognition" or a mathematical task like "numerical calculation." If relying solely on literal features, it would be difficult for the router to decide whether to assign a "historical expert" or a "mathematical expert."
[0049] This embodiment calculates the routing weight based on the modulation features obtained in step 130. Since the modulation features have incorporated explicit prior information on task semantics, it can avoid expert misselection caused by similar local features, and thus the router can more accurately determine which experts should be activated.
[0050] As an optional implementation, the modulation features can be input into the router and, after Softmax normalization, the probability value corresponding to each routing expert module, i.e., the routing weight, can be obtained.
[0051] Furthermore, to achieve sparse computation and reduce overhead, not all routing expert modules are typically activated. A Top-K strategy can be adopted, which sorts the routing expert modules according to their weights and selects the top K weights as target expert modules. These selected target expert modules will be responsible for capturing the knowledge patterns specific to the current task, while the unselected routing expert modules remain silent, thereby achieving dynamic allocation of computing resources.
[0052] Step 150: Aggregate the output of the shared expert module in the multi-task model with the output of the target expert module of each task to obtain the prediction results of each task, and fine-tune the parameters of the multi-task model based on the prediction results of each task. The shared expert module is an expert network that participates in the calculation of all tasks.
[0053] Specifically, the shared expert module refers to the expert network that is always active in the model and participates in the computation of all tasks. Its role is to learn and consolidate the common knowledge and underlying logic shared by all tasks. The target expert module is the routing expert module selected in step 140 that is responsible for processing specific knowledge based on the specific needs of the task.
[0054] While shared expert modules are highly generalizable, they lack specificity, while routing expert modules, though highly specialized, tend to overlook fundamental common knowledge. By combining the two, a combination of general and specialized approaches can be achieved. This leverages the shared expert modules to maintain the model's underlying language capabilities and cross-task generalization, while utilizing the routing expert modules to enhance the fine-grained processing capabilities for specific tasks, thereby obtaining a more comprehensive feature representation.
[0055] As an alternative implementation, aggregation can be achieved through weighted summation. Specifically, the output of the shared expert module is added to the output of the selected target expert module to obtain the final aggregated feature. This aggregated feature continues to propagate backward in the network, eventually passing through the output layer to obtain the prediction results for each task.
[0056] Finally, based on the difference between the predicted results and the true labels, the gradient is calculated using the backpropagation algorithm, and the parameters in the multi-task model are updated. The parameter update strategy here can be set according to actual needs. It can update all parameters or only update the parameters of the inserted expert modules to achieve efficient fine-tuning of parameters.
[0057] The multi-task model fine-tuning method provided in this embodiment obtains task semantic vectors by semantically encoding task samples, and uses these vectors to generate modulation coefficients to linearly modulate the hidden layer features with task awareness. Then, based on the modulated features, it guides the dynamic selection and aggregation of routing experts in a hybrid expert structure. By introducing explicit task semantic guidance and feature modulation mechanisms, it effectively solves the problem of expert allocation errors caused by the lack of macro-level task awareness in traditional methods. Furthermore, by combining the division of labor and cooperation between shared experts and routing experts, it ensures efficient parameter updates while achieving feature decoupling and adaptive adaptation among multiple tasks. This effectively avoids gradient interference and catastrophic forgetting phenomena in multi-task learning, improving the model's generalization performance and stability.
[0058] It should be noted that the execution entity in this embodiment can be any electronic device capable of model training, fine-tuning, and inference computation, such as a server cluster, high-performance workstation, desktop computer, laptop computer, or any computing device with sufficient computing power. In this embodiment, the multi-task model can be applied to fields such as natural language processing and multimodal understanding, and can be, for example, a pre-trained language model based on the Transformer architecture.
[0059] Taking the application of a multi-task model to text processing as an example, the tasks in the aforementioned multi-task dataset can include text translation, text summarization, sentiment analysis, intent recognition, and other tasks. Sample data can be text sequences, such as sentences or paragraphs. Based on the methods described in the above embodiments, semantic encoding and feature modulation are performed on each task, enabling the model to adaptively select expert modules for processing according to the task type. Finally, the model parameters are updated based on the prediction results, resulting in a fine-tuned model with multi-task processing capabilities. This model can receive input text and output corresponding translation results, summary content, or classification labels.
[0060] Taking the application of a multi-task model to multimodal understanding as an example, the aforementioned tasks may include image description generation, visual question answering, and other tasks. Sample data may contain a combination of image features and text prompts. Based on the method described above, multimodal features are extracted and modulated to guide the model to dynamically call expert modules that process visual or linguistic information, ultimately outputting a natural language description or answer to the question that matches the image content.
[0061] Furthermore, the execution entity in this embodiment can also be a computing node containing AI acceleration chips such as GPUs (Graphics Processing Units), TPUs (Tensor Processing Units), and NPUs (Neural Processing Units). These chips are highly optimized for large-scale matrix operations and parallel computing. This embodiment, through the design of low-rank matrix factorization and sparse routing calculation, can fully utilize the parallel processing capabilities of these chips, significantly reducing memory usage and computational latency during multi-task fine-tuning, thereby achieving efficient model training and deployment.
[0062] To further clarify how to achieve spatial transformation and alignment of features, in step 130, modulation coefficients for each task are generated using the encoded features of each task, and the corresponding hidden layer features are modulated using the modulation coefficients of each task to obtain the modulation features of each task, including: The coding features of each task are projected and transformed to obtain the first modulation coefficient and the second modulation coefficient of each task. The corresponding hidden layer features are scaled using the first modulation coefficient of each task, and the scaled hidden layer features are translated using the second modulation coefficient of each task to obtain the modulation features of each task.
[0063] Considering that a single modulation parameter may be insufficient to simultaneously cover the amplitude adjustment and reference offset requirements of the features, in order to achieve a more flexible and comprehensive feature distribution adjustment, this embodiment uses projection transformation to generate two different sets of modulation parameters, namely the first modulation coefficient and the second modulation coefficient.
[0064] Here, projection transformation refers to the operation of transforming an input vector to a target space using a linear mapping matrix. The first modulation coefficient can be a scaling factor, used to selectively amplify or reduce dimensions in the hidden layer features that are critical to the current task. The second modulation coefficient can be a translation factor, used to introduce background bias information specific to the current task or adjust the center position of the feature distribution, thereby eliminating data distribution differences between different tasks.
[0065] As an alternative embodiment, the projection transformation can be implemented by constructing a modulation network containing two linear layers. The first linear layer maps the encoded features to a first modulation coefficient, and the second linear layer maps the encoded features to a second modulation coefficient. Alternatively, a single linear layer can be used to map the encoded features to a higher-dimensional combined vector, which is then divided into a first modulation coefficient and a second modulation coefficient. This embodiment does not specifically limit the implementation of this approach.
[0066] Considering that the distribution characteristics of features are mainly determined by their scale and location, scaling and translation can achieve an effect similar to affine transformation in layer normalization. However, the transformation parameters here are dynamically generated by the task semantics, which can push the feature distribution to a region that is more conducive to expert recognition according to the task requirements.
[0067] Here, scaling refers to element-wise multiplication, and translation refers to element-wise addition. As an optional embodiment, the modulation process can be represented as: in, Indicates modulation characteristics, Represents hidden layer features. Indicates the first modulation coefficient. This represents the second modulation coefficient. Since the first modulation coefficient can dynamically adjust the importance weights of each feature dimension (e.g., for sentiment classification tasks, it amplifies the feature dimensions related to sentiment words), and the second modulation coefficient can adjust the overall activation baseline of the features according to the task type (e.g., for tasks with high noise, it shifts the features to avoid noisy regions), the first and second modulation coefficients work together on the hidden layer features, achieving task-aware feature reconstruction and alignment, enabling the modulated features to carry clear task semantic fingerprint information.
[0068] To reduce the number of parameters during model fine-tuning and achieve efficient parameter fine-tuning, a projection transformation is performed on the encoding features of each task to obtain the first modulation coefficient and the second modulation coefficient for each task, including: The encoded features of each task are mapped to low-dimensional feature vectors using the first projection matrix. The dimension of the low-dimensional feature vectors is lower than that of the hidden layer features. The low-dimensional feature vector is mapped to a combined coefficient vector using the second projection matrix, and the combined coefficient vector is split into a first modulation coefficient and a second modulation coefficient. The dimension of the combined coefficient vector is twice the dimension of the hidden layer features.
[0069] Considering that directly using a full-rank matrix to map the encoded features to a high-dimensional modulation coefficient space would introduce a large number of parameters, which contradicts the original design goal of efficient parameter fine-tuning, this embodiment adopts the idea of low-rank adaptation and uses a strategy of first reducing dimensionality and then increasing it to reduce the parameter size.
[0070] Specifically, this embodiment first uses a first projection matrix to map the encoded features of each task into low-dimensional feature vectors, thereby compressing the feature dimension and removing redundant information. The first projection matrix is a parameter matrix used to perform the dimensionality reduction operation; its number of rows corresponds to the dimension of the encoded features, and its number of columns corresponds to the low-rank dimension. The low-dimensional feature vector refers to the intermediate representation vector after dimensionality reduction.
[0071] As an optional embodiment, assume the encoding feature is The first projection matrix is , It is a low-rank dimension. For the hidden layer feature dimension, Through matrix multiplication This can compress the encoded features into a low-dimensional feature vector with extremely small dimensions, which not only effectively extracts the essential information from the encoded features, but also significantly reduces the number of parameters in the first projection matrix.
[0072] Considering that the compressed information needs to be restored to a dimension sufficient to cover the entire hidden layer in order to generate effective modulation parameters, a dimensionality-upgrading operation is required to remap the low-dimensional feature vector back to the target space. Based on this, this embodiment utilizes a second projection matrix to map the low-dimensional feature vector into a combined coefficient vector. Here, the second projection matrix refers to the parameter matrix used to perform the dimensionality-upgrading operation. The combined coefficient vector refers to the aggregated vector containing all modulation parameters.
[0073] As an optional embodiment, assume the second projection matrix is By using matrix multiplication, low-dimensional eigenvectors are mapped to a matrix with dimension 1. The combined coefficient vector. Since the dimensions of both the first and second modulation coefficients should be consistent with the hidden layer feature dimensions to facilitate element-wise modulation, the total dimension of the combined coefficient vector is designed as follows: Furthermore, in order to obtain the two types of modulation coefficients separately, this embodiment splits the combined coefficient vector. Specifically, the first part of the combined coefficient vector can be split... The dimension component is determined as the first modulation coefficient, and the subsequent... The dimension component is determined as the second modulation coefficient.
[0074] In summary, by using the low-rank decomposition structure formed by the first and second projection matrices, this embodiment can generate high-dimensional task-aware modulation coefficients with minimal parameter cost, ensuring both the efficiency of fine-tuning and the fine-tuning of hidden layer features.
[0075] Alternatively, the first modulation coefficient and the second modulation coefficient can be generated by the following formula: in, Indicates the first modulation coefficient. Indicates the second modulation coefficient. Denotes the first projection matrix. Represents the second projection matrix. This indicates the encoding feature.
[0076] To achieve task-aware dynamic routing selection, step 140 calculates the routing weight of each task based on its modulation characteristics, and determines the corresponding target expert module from multiple routing expert modules according to the routing weight of each task, including: The modulation characteristics of each task are linearly mapped to obtain the initial routing score for each task. The initial routing scores of each task are normalized to obtain the routing weights of each routing expert module under the corresponding task. The routing expert modules are sorted in descending order of routing weight, and a preset number of routing expert modules at the top of the list are selected as the target expert modules for the corresponding tasks.
[0077] Considering that the modulation features have been incorporated into the task semantic information through step 130, in order to transform these high-dimensional features into preferences for the selection of each expert module, they need to be mapped to a decision space corresponding to the number of experts.
[0078] Based on this, this embodiment first performs a linear mapping on the modulation features of each task to obtain the initial routing score for each task. Here, linear mapping refers to the operation of transforming the modulation features into the initial routing score through a weight matrix. The initial routing score is the raw value that measures the correlation or matching degree between each routing expert module and the input features of the current task before probability normalization. Its dimension is usually equal to the total number of routing expert modules, and each element value in the initial routing score represents the matching score between the corresponding routing expert module and the current input feature.
[0079] As an optional embodiment, assume the modulation characteristics are The router's weight matrix is The initial route score is obtained through matrix multiplication. .
[0080] Considering that the initial route score may have a large and inconsistent range, it is difficult to directly use it as a selection probability or weighting coefficient. To ensure that the weights of each route expert module are comparable and sum to 1, they need to be normalized. The normalized route weights can intuitively reflect the probability of each expert module being selected. Here, the normalization process typically uses the Softmax function. Route weight refers to the normalized probability value.
[0081] Considering that activating all routing expert modules would result in a massive computational load, violating the design principle of sparse computation in hybrid expert models, this embodiment employs a Top-K selection strategy to reduce computational overhead while maintaining model performance. This strategy activates only the few experts most crucial to the current task. Here, the preset number is the K value in the Top-K algorithm, typically set to a small integer such as 1 or 2. The target expert module is the expert that ultimately participates in the forward computation.
[0082] As an optional implementation, assuming a preset quantity K=2, the routing weights ω are sorted in descending order, the top two expert indices are selected, and the routing expert modules corresponding to these two indices are marked as target expert modules. The remaining unselected expert modules will be masked in the current calculation step, that is, their outputs will not participate in subsequent aggregation or their weights will be set to 0, thereby significantly reducing unnecessary consumption of computing resources.
[0083] As an optional implementation, routing weight It can be calculated based on the following formula: in, Indicates the weight of the shared expert module. This indicates the weight of the first routing expert module. Indicates the first The weights of each routing expert module, Indicates will Convert to a probability distribution This indicates that the initial routing score of the shared expert module will be used. and Initial route score of the routing expert module spliced together, This represents the initial routing score of all routing expert modules. This means selecting the k routing expert modules with the highest initial route scores from all routing expert modules.
[0084] To fully integrate general and specialized knowledge and achieve complementary feature enhancement, step 150 aggregates the output of the shared expert module in the multi-task model with the output of the target expert module for each task to obtain the prediction results for each task, including: The output of the shared expert module is multiplied by the preset shared weights to obtain the shared features of each task; By using the routing weights under each task as weighting coefficients, the outputs of the corresponding target expert modules are summed in a weighted manner to obtain the routing aggregation features of each task. The shared features of each task are added to the routing aggregation features of each task to obtain the aggregate features of each task. Based on the aggregation characteristics of each task, the prediction results for each task are obtained.
[0085] Considering that the shared expert module is responsible for extracting the underlying features common to all tasks, its contribution should remain relatively stable during the aggregation process and should not be completely affected by fluctuations in the dynamic routing mechanism. To control the proportion of common features in the overall output, this embodiment introduces shared weights. These shared weights can be pre-set or learnable scalar parameters used to adjust the proportional coefficient of the shared expert module's output amplitude. Multiplying the output of the shared expert module by the preset shared weights ensures that the information flow of the shared expert module occupies a stable baseline proportion in the aggregated features, thereby preventing performance instability in processing basic common tasks due to fluctuations in the dynamic selection of the routing expert module. Here, shared features refer to the weighted output vector of the shared expert module.
[0086] As an optional embodiment, it is assumed that the output of the shared expert module is Shared weight is Then the shared features can be .
[0087] Considering that the target expert modules are dynamically selected based on task requirements, and that each target expert module has a different degree of matching with the current task (i.e., each target expert module has a different routing weight), in order to accurately reflect the differences in contribution of different target expert modules to the current task, it is necessary to use the routing weights to perform weighted fusion of the outputs of the target expert modules to obtain the routing aggregation features of each task. Here, the routing aggregation features refer to the weighted sum of the outputs of all activated target expert modules.
[0088] As an optional embodiment, assume that the first The output of the target expert module is: Its corresponding routing weight is Then the routing aggregation feature can be .
[0089] Considering that the model needs to possess both general generalization ability and task-specific adaptability, we can combine shared features representing general knowledge with routing aggregation features representing specialized knowledge to obtain aggregated features. This allows us to achieve a combination of general and specialized features and construct a more expressive comprehensive feature. Here, aggregated features refer to the feature vectors that are ultimately input into subsequent network layers of the model.
[0090] As an optional implementation, aggregation features It can be calculated using the following formula: Since the aggregated features are only the output of the current hybrid expert layer, further processing by subsequent layers of the model is usually required to obtain the final prediction result. Here, the prediction result refers to the final output of the model for the current task, such as classification probability, predicted text, etc.
[0091] As an optional implementation, aggregated features can be processed through layer normalization, residual connections, and subsequent Transformer layers, ultimately generating prediction results for each task through the model's output layer.
[0092] To address parameter interference and catastrophic forgetting issues during multi-task fine-tuning, step 150 involves fine-tuning the parameters of the multi-task model based on the prediction results of each task, including: Calculate the gradient of each parameter in the shared expert module, and calculate the gradient momentum of the corresponding parameter based on the gradient of each parameter in the shared expert module; The parameters of the shared expert module are sorted by importance based on the gradient momentum of each parameter, and the parameters that meet the preset conditions are selected for updating, while keeping the other parameters of the shared expert module unchanged. Calculate the gradient of each parameter in the target expert module, and use the gradient of each parameter in the target expert module to update all parameters of the target expert module.
[0093] Given that the shared expert module carries common knowledge across all tasks, indiscriminately updating it during fine-tuning could lead to conflicting gradient directions from different tasks, destroying the model's original knowledge and causing catastrophic amnesia. To identify and adjust the core parameters critical to model performance while protecting other parameters, gradient momentum needs to be introduced as a measure of parameter importance.
[0094] Here, gradient refers to the partial derivative of the loss function with respect to the parameters, reflecting the direction and magnitude of parameter updates. Gradient momentum, on the other hand, refers to a smoothed gradient value that incorporates historical gradients, providing a more stable reflection of the parameter update trend over a period of time.
[0095] As an alternative implementation, the gradients of each parameter in the shared expert module at the current training step can be calculated first using the backpropagation algorithm. Then, the gradient momentum is updated using an exponentially weighted moving average.
[0096] Parameters with large gradient momentum typically indicate that they have been strongly activated across multiple tasks or during long training periods, making them the key parameters with the greatest impact on the performance of the current task. By updating only these highly important parameters, we can adapt to new tasks while preserving the original general knowledge structure in the shared expert modules to the greatest extent possible.
[0097] Based on this, this embodiment sorts the parameters of the shared expert module according to their gradient momentum, selects the parameters whose importance meets the preset conditions for updating, and keeps the remaining parameters of the shared expert module unchanged. Here, importance sorting refers to arranging the parameters according to the absolute value of their gradient momentum. The preset conditions can be the top K or the momentum value exceeding a certain threshold.
[0098] As an optional implementation, all parameters of the shared expert module can be sorted in descending order of the absolute value of their gradient momentum. The top K parameters are selected as the parameters to be updated, and gradient descent updates are performed. For the remaining parameters, their gradients are set to 0 or gradient backpropagation is stopped, so that their values remain unchanged in the current update step, i.e., in a frozen state.
[0099] Given that the target expert module is designed to handle the variability of specific tasks, its parameters should be highly flexible to adapt to the specific needs of different tasks. Therefore, for the routing expert module, sparsity constraints are not required; instead, it should be allowed to learn and adjust sufficiently.
[0100] Based on this, this embodiment calculates the gradient of each parameter in the target expert module and then updates all parameters of the target expert module using the gradient of each parameter. Here, all parameters of the target expert module refer to all weight parameters in the routing expert module selected by the router.
[0101] As an optional implementation, for the selected target expert module, the gradient calculated by backpropagation can be used to fully update all its parameters. Through this hybrid strategy of "shared expert sparse update + routing expert full update", this embodiment achieves a balance between stability and flexibility, preventing forgetting while ensuring the efficiency of multi-task learning.
[0102] To obtain a stable and representative measure of parameter importance, the gradient momentum of the corresponding parameters is calculated based on the gradients of each parameter in the shared expert module, including: Obtain the gradient momentum of each parameter in the shared expert module at the previous training step; Using a preset smoothing coefficient, the gradient momentum of the previous training step and the gradient of the current training step are weighted and summed to obtain the gradient momentum of each parameter in the current training step.
[0103] Considering that the gradient of a single training step is often influenced by the distribution of the current batch of data, it contains significant randomness and noise, making it difficult to truly reflect the importance of the parameter in the global training process. To smooth out these instantaneous fluctuations, it is necessary to introduce historical cumulative information, namely the gradient momentum of the previous training step. Here, the gradient momentum of the previous training step refers to the historical gradient momentum of the parameter stored in the model's memory before the current parameter update. If it is the first training iteration, this value is usually initialized to 0.
[0104] As an optional implementation, a momentum matrix variable with the same shape as the shared expert module parameters can be maintained during the training loop. At the start of the t-th training step, the gradient momentum calculated and saved after the (t-1)-th training step is directly read from this variable. .
[0105] Considering that historical and current information should be weighted differently, an exponentially weighted moving average is used to update momentum in order to achieve long-term tracking of gradient trends. This approach retains historical gradient trend information while incorporating the latest changes in the current gradient, enabling a more accurate assessment of the long-term contribution of parameters.
[0106] Based on this, this embodiment utilizes a preset smoothing coefficient to perform a weighted summation of the gradient momentum from the previous training step and the gradient from the current training step, obtaining the gradient momentum of each parameter in the current training step. Here, the preset smoothing coefficient is a hyperparameter between 0 and 1, used to control the proportion of historical information retained. The weighted summation refers to assigning different weights to the historical momentum and the current gradient before adding them together.
[0107] Specifically, assuming the first The first training step The gradient of each parameter is , No. The first training step The gradient momentum of each parameter is Then the first The first training step Gradient momentum of each parameter for: in, This is the momentum smoothing coefficient.
[0108] To guide the model to ensure predictive performance while balancing expert utilization and decoupling expert functions, the gradients of the above parameters are determined based on the following steps: Construct a joint loss function, which includes at least one of the following: task loss for measuring prediction accuracy, load balancing loss for measuring the load balancing of expert modules, and orthogonal constraint loss for measuring parameter independence. Backpropagation is performed based on the joint loss function to obtain the gradients of each parameter in the shared expert module and the gradients of each parameter in the target expert module.
[0109] While a single task loss can optimize a model's predictive ability, it cannot constrain the behavior of the expert modules within the model. Without constraints, some expert modules may be overused, or all expert modules may learn the same features. Therefore, a multi-objective joint loss function is needed to provide comprehensive regularization constraints for model training. This joint loss function includes at least one of the following: a task loss to measure predictive accuracy, a load balancing loss to measure the degree of load balancing among expert modules, and an orthogonal constraint loss to measure parameter independence.
[0110] Here, task loss refers to the loss that measures the difference between the model output and the true label, such as cross-entropy loss. Load balancing loss is a penalty term used to prevent the router from allocating all samples to a few experts. Orthogonality constraint loss is a constraint term used to force the parameter matrices of different expert modules to remain orthogonal and uncorrelated.
[0111] As an alternative implementation, the joint loss function can be defined as a weighted sum of the above three factors, as shown in the following formula: in, Denotes the joint loss function. Indicates mission loss. This indicates load balancing losses. This represents the orthogonal constraint loss. and Hyperparameters are used to balance the weights of various losses.
[0112] Since the training of deep learning models relies on the gradient descent algorithm, and the gradient is the derivative of the loss function with respect to the parameters, backpropagation is required to pass the optimization objective defined in the joint loss function to each parameter in the model. Here, backpropagation refers to the process of calculating the gradient layer by layer from the output layer to the input layer using the chain rule.
[0113] As an optional embodiment, after calculating the value of the joint loss function, the backpropagation operation is performed using the automatic differentiation engine of the deep learning framework to automatically calculate the partial derivative of the joint loss function with respect to each weight parameter in the shared expert module, i.e., the gradient of each parameter in the shared expert module, and the partial derivative of the joint loss function with respect to each weight parameter in the currently activated target expert module, i.e., the gradient of each parameter in the target expert module.
[0114] To prevent a few routing expert modules from processing the vast majority of data or some routing expert modules from being never selected and thus unable to be trained in a hybrid expert model, this embodiment introduces load balancing loss as a regularization term to constrain the router's behavior. Specifically, the load balancing loss is determined based on the following steps: The average routing probability of each routing expert module and the average utilization rate of the actual sample data processed by each routing expert module are statistically analyzed. Calculate the product of the average routing probability and average utilization of each routing expert module, and sum the products of all routing expert modules as the load balancing loss.
[0115] To achieve load balancing, the operational status of each routing expert module needs to be quantified first. By statistically analyzing the average routing probability and average utilization rate of the actual sample data processed by each routing expert module, the uniformity of the expert distribution can be comprehensively evaluated. Here, the average routing probability refers to the average routing weight output by the router for a specific routing expert module in the current training batch, reflecting the degree to which the router tends to allocate that routing expert module for computation. The average utilization rate refers to the proportion of samples in the current training batch where a routing expert module is actually selected to participate in computation, reflecting the frequency of its actual operation.
[0116] As an optional implementation, assume there are N routing expert modules in the current batch. For the i-th routing expert module, its average routing probability is the mean of the Softmax probability values output by all samples in the batch for that routing expert module, and its average utilization rate is the proportion of the number of samples in the batch that actually select that routing expert module as a Top-K target to the total number of samples.
[0117] Considering that the utilization of computational resources and the efficiency of parallel processing are highest when each routing expert module processes an equal amount of data and the router assigns each routing expert module with equal probability, the sum of the products of all routing expert modules is used as the load balancing loss to penalize uneven distribution. Minimizing this load balancing loss can encourage routers to distribute tasks more evenly, thereby avoiding situations where some experts are overloaded while others are idle, and improving the overall training stability and convergence speed of the model.
[0118] Alternatively, the load balancing loss can be determined based on the following formula: in, This indicates the total number of routing expert modules. This represents the average utilization of the i-th routing expert module. Let represent the average routing probability of the i-th routing expert module. When the distribution is most uniform... and Both are 1 / N. Minimum. Any skewness in the distribution will increase the load balancing loss, thus creating a gradient in backpropagation, forcing routers to adjust their parameters to tend towards a more uniform distribution.
[0119] To ensure true functional decoupling of components in the hybrid expert architecture—that is, separation of general knowledge from specialized knowledge—this embodiment introduces orthogonal constraint loss, forcing the shared expert module and the routing expert module to learn non-overlapping feature representations. Specifically, the orthogonal constraint loss is determined based on the following steps: Calculate the correlation metric between the parameter matrix of the shared expert module and the parameter matrices of each routing expert module; The absolute values of the correlation metrics are summed, and the summation result is used as the orthogonal constraint loss.
[0120] Without additional constraints, routing expert modules might tend to learn similar features to shared expert modules, leading to parameter redundancy and functional overlap. To force routing expert modules to capture specific information that shared expert modules fail to capture, it is necessary to measure the similarity between their parameters.
[0121] Based on this, this embodiment first calculates the correlation metric between the parameter matrix of the shared expert module and the parameter matrices of each routing expert module. Here, the parameter matrix refers to the weight matrix used for feature transformation within the expert module. The correlation metric is a scalar that reflects the similarity between two parameter matrices in numerical distribution or direction, such as inner product, cosine similarity, etc.
[0122] As an optional embodiment, assume that the parameter matrix of the shared expert module is as follows: , No. The parameter matrix of each routing expert module is as follows Then you can use This represents a correlation metric.
[0123] Since the goal is to minimize the correlation between parameters, bringing it close to zero, the correlation metrics between all routing expert modules and the shared expert module need to be aggregated and added as a penalty term to the total loss. The summation result is the final orthogonal constraint loss.
[0124] As an optional implementation, orthogonal constraint loss It can be calculated based on the following formula: To efficiently and accurately obtain feature vectors representing the global semantic information of the task, step 110 involves semantically encoding the sample data for each task to obtain corresponding encoded features, including: For each task, a predetermined number of sample data are randomly sampled; Semantic encoding is performed on the sample data for each task to obtain the semantic features of each sample data under the corresponding task; Calculate the average of the semantic features of all sample data under each task, and use the average as the encoded feature of the corresponding task.
[0125] Given that a task typically involves tens of thousands of sample data points, encoding and computing all of them would consume enormous computational resources and time. Furthermore, different sample data points within the same task often share similar task description patterns or data distribution characteristics. Therefore, sampling a small number of representative samples can approximately capture the overall semantic attributes of the task.
[0126] Based on this, this embodiment randomly samples a preset number of data points for each task. Here, the preset number is an integer value set based on experience to balance computational efficiency and representation accuracy.
[0127] As an alternative implementation, for each task in a multi-task dataset, such as sentiment analysis, 20 sample data can be randomly drawn from its training set.
[0128] Furthermore, considering that randomly sampled data can represent the diversity of data distribution for the task, a predetermined number of sample data can be sampled from different categories or clusters of sample data through stratified sampling or cluster-based sampling strategies.
[0129] Given that the original sample data is unstructured and cannot be directly used for mathematical operations, in order to extract its deeper meaning, it is necessary to use a pre-trained model to convert the text into vectors in the semantic space. That is, semantic encoding is performed on the sample data for each task to obtain the semantic features of each sample data for the corresponding task. Here, semantic features refer to the vector representation output by the encoder after processing a single sample data.
[0130] As an alternative embodiment, an encoder can be used as a feature extractor. The sampled data is input into the encoder one by one, and the token vector output by the encoder or the average of all token vectors is taken as the semantic feature of the sample data.
[0131] Furthermore, considering that individual sample data may contain noise or incidental information specific to that sample (such as specific person names or place names), it cannot fully represent the general semantics of the entire task. By averaging the semantic features of multiple samples, individual differences can be eliminated while retaining common features, thereby obtaining a more robust task representation. Therefore, this embodiment calculates the average of the semantic features of all sample data under each task and uses the average as the encoded feature for the corresponding task. Here, the encoded feature is the task embedding vector ultimately used to generate the modulation coefficients.
[0132] As an optional implementation, the semantic feature vectors of the above sample data are added together and then divided by the number of samples. The resulting average vector is then identified as the encoding feature for the task. This encoding feature will be cached, and during subsequent model fine-tuning, whenever data belonging to the task is encountered, this feature is directly called to generate modulation coefficients.
[0133] In order to improve the model capacity by introducing a hybrid expert structure while strictly controlling the number of new parameters and avoiding memory overflow and training difficulties caused by parameter explosion, in this embodiment, both the shared expert module and the routing expert module adopt a low-rank matrix factorization structure.
[0134] Considering that the expert network in traditional hybrid expert models typically consists of fully connected layers, the number of parameters increases exponentially when multiple experts are introduced. However, in fine-tuning scenarios, the weights of pre-trained models usually already possess strong feature extraction capabilities, requiring only minor adjustments to a small number of incremental parameters to adapt to new tasks. Low-rank matrix factorization structures (such as LoRA) are based on this assumption, enabling the simulation of full parameter updates with minimal parameter overhead. Therefore, in this embodiment, both the shared expert module and the routing expert module employ low-rank matrix factorization structures.
[0135] Here, low-rank matrix decomposition refers to the process of decomposing a high-dimensional weight matrix into the product of two low-dimensional matrices. Specifically, assuming the original weight matrix has dimensions d×d, low-rank decomposition represents it as a pair of low-rank matrices. ,in , For linear layer dimensions, During forward propagation, the input feature x is first multiplied by matrix A to reduce its dimensionality to... The dimension, after passing through the activation function, is then multiplied by matrix B to restore it to its original state. The final output is the sum of the original output of the pre-trained model and the output of this low-rank path. In this way, although multiple experts are introduced, since the actual number of parameters for each expert is only 2r / d of the fully connected layer, it is possible to efficiently build a hybrid expert system containing dozens or even hundreds of experts without significantly increasing the storage burden of the model.
[0136] Figure 2 This is a schematic diagram of the framework of the multi-task model provided by the present invention, such as... Figure 2 As shown, the multi-task model includes an encoder, a feature extraction module, a feature modulation layer, a router, a shared expert module, and multiple routing expert modules. The encoder can be the encoding end of a pre-trained language model (such as T5 or BERT) used to extract high-dimensional semantic vectors from the text. The feature extraction module can be a feedforward neural network layer or a pre-linear transformation layer of the attention layer in a Transformer architecture. The feature modulation layer can be a feature-based linear modulation (FiLM) network structure containing a projection matrix for generating scaling and translation coefficients. The router can be a gated network consisting of a linear classification layer and a Softmax activation function. Both the shared expert module and the routing expert module can be neural network sub-modules using a low-rank matrix factorization structure, i.e., a bypass structure consisting of a cascaded reduced-dimensional matrix A and an increased-dimensional matrix B.
[0137] First, for different tasks in the multi-task dataset, such as Task 1, Task 2, ..., Task T, an encoder is used to semantically encode the sample data of each task to obtain the corresponding encoded features, and a feature extraction module is used to obtain the hidden layer features.
[0138] Then, the encoded features and hidden layer features are input together into the feature modulation layer. In the feature modulation layer, modulation coefficients are generated using the encoded features of each task, and linear modulation operations such as scaling and translation are performed on the hidden layer features to obtain modulation features carrying task semantic information.
[0139] Next, routing weights are calculated based on modulation characteristics. The router then determines the target expert module from multiple routing expert modules (routing expert module 1, routing expert module 2, ..., routing expert module n) based on these weights. Meanwhile, the shared expert module remains active at all times. Both the shared expert module and the routing expert module employ a low-rank matrix factorization structure.
[0140] Finally, the outputs of the shared expert modules and the selected routing expert modules are aggregated to obtain the final aggregated features. During training, a gradient-importance-based sparse update strategy is adopted for the shared expert modules, i.e., only some highly important parameters are updated, while a full update strategy is adopted for the routing expert modules. This ensures efficient parameter optimization while improving the model's resistance to forgetting and its generalization performance in multi-task scenarios.
[0141] The multi-task model fine-tuning device provided by the present invention is described below. The multi-task model fine-tuning device described below and the multi-task model fine-tuning method described above can be referred to in correspondence.
[0142] Based on any of the above embodiments Figure 3 This is a schematic diagram of the structure of the multi-task model fine-tuning device provided by the present invention, as shown below. Figure 3 As shown, the device includes: The encoding module 310 is used to perform semantic encoding on the sample data of each task to obtain the corresponding encoded features; The extraction module 320 is used to input the sample data of each task into the feature extraction module of the multi-task model to obtain the hidden layer features of each task. The modulation module 330 is used to generate modulation coefficients for each task using the coding features of each task, and to modulate the corresponding hidden layer features using the modulation coefficients of each task to obtain the modulation features of each task. The determination module 340 is used to calculate the routing weight of each task based on the modulation characteristics of each task, and determine the corresponding target expert module from multiple routing expert modules of the multi-task model according to the routing weight of each task. The fine-tuning module 350 is used to aggregate the output of the shared expert module in the multi-task model with the output of the target expert module of each task to obtain the prediction results of each task, and to fine-tune the parameters of the multi-task model based on the prediction results of each task. The shared expert module is an expert network that participates in the computation of all tasks.
[0143] Figure 4 This is a schematic diagram of the structure of the electronic device provided by the present invention, such as... Figure 4 As shown, the electronic device may include a processor 410, a communications interface 420, a memory 430, and a communication bus 440. The processor 410, communications interface 420, and memory 430 communicate with each other via the communication bus 440. The processor 410 can call logical instructions from the memory 430 to execute a multi-task model fine-tuning method.
[0144] Furthermore, the logical instructions in the aforementioned memory 430 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0145] On the other hand, the present invention also provides a computer program product, the computer program product including a computer program, the computer program being stored on a non-transitory computer-readable storage medium, and when the computer program is executed by a processor, the computer is able to execute the multi-task model fine-tuning method provided by the above methods.
[0146] In another aspect, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to perform the multi-task model fine-tuning method provided by the above methods.
[0147] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0148] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0149] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for fine-tuning a multi-task model, characterized in that, include: Semantic encoding is performed on the sample data for each task to obtain the corresponding encoded features; The sample data of each task is input into the feature extraction module of the multi-task model to obtain the hidden layer features of each task. The modulation coefficients of each task are generated using the coding features of each task, and the corresponding hidden layer features are modulated using the modulation coefficients of each task to obtain the modulation features of each task. The routing weight of each task is calculated based on the modulation characteristics of each task, and the corresponding target expert module is determined from the multiple routing expert modules of the multi-task model according to the routing weight of each task. The output of the shared expert module in the multi-task model is aggregated with the output of the target expert module of each task to obtain the prediction results of each task. Based on the prediction results of each task, the parameters of the multi-task model are fine-tuned. The shared expert module is an expert network that participates in the calculation of all tasks.
2. The multi-task model fine-tuning method according to claim 1, characterized in that, The process of generating modulation coefficients for each task using the coding features of each task, and then modulating the corresponding hidden layer features using the modulation coefficients of each task to obtain the modulation features of each task, includes: The coding features of each task are projected and transformed to obtain the first modulation coefficient and the second modulation coefficient of each task. The corresponding hidden layer features are scaled using the first modulation coefficient of each task, and the scaled hidden layer features are translated using the second modulation coefficient of each task to obtain the modulation features of each task.
3. The multi-task model fine-tuning method according to claim 2, characterized in that, The projection transformation of the coding features of each task to obtain the first modulation coefficient and the second modulation coefficient of each task includes: The encoded features of each task are mapped to low-dimensional feature vectors using the first projection matrix, wherein the dimension of the low-dimensional feature vectors is lower than the dimension of the hidden layer features. The low-dimensional feature vector is mapped to a combined coefficient vector using a second projection matrix, and the combined coefficient vector is split into a first modulation coefficient and a second modulation coefficient. The dimension of the combined coefficient vector is twice the dimension of the hidden layer features.
4. The multi-task model fine-tuning method according to any one of claims 1 to 3, characterized in that, The step of calculating the routing weight of each task based on the modulation characteristics of each task, and determining the corresponding target expert module from the plurality of routing expert modules according to the routing weight of each task, includes: The modulation characteristics of each task are linearly mapped to obtain the initial routing score for each task. The initial routing scores of each task are normalized to obtain the routing weights of each routing expert module under the corresponding task. The routing expert modules are sorted in descending order of routing weight, and a preset number of routing expert modules at the top of the list are selected as the target expert modules for the corresponding tasks.
5. The multi-task model fine-tuning method according to any one of claims 1 to 3, characterized in that, The step of aggregating the output of the shared expert module in the multi-task model with the output of the target expert module for each task to obtain the prediction results for each task includes: The output of the shared expert module is multiplied by the preset shared weights to obtain the shared features of each task; By using the routing weights under each task as weighting coefficients, the outputs of the corresponding target expert modules are summed in a weighted manner to obtain the routing aggregation features of each task. The shared features of each task are added to the routing aggregation features of each task to obtain the aggregate features of each task. Based on the aggregation characteristics of each task, the prediction results for each task are obtained.
6. The multi-task model fine-tuning method according to any one of claims 1 to 3, characterized in that, The parameter fine-tuning of the multi-task model based on the prediction results of each task includes: Calculate the gradient of each parameter in the shared expert module, and calculate the gradient momentum of the corresponding parameter based on the gradient of each parameter in the shared expert module; The parameters of the shared expert module are sorted by importance based on the gradient momentum of each parameter, and the parameters that meet the preset conditions are selected for updating, while the remaining parameters of the shared expert module remain unchanged. Calculate the gradient of each parameter in the target expert module, and update all parameters of the target expert module using the gradient of each parameter in the target expert module.
7. The multi-task model fine-tuning method according to claim 6, characterized in that, The step of calculating the gradient momentum of the corresponding parameter based on the gradient of each parameter in the shared expert module includes: Obtain the gradient momentum of each parameter in the shared expert module at the previous training step; Using a preset smoothing coefficient, the gradient momentum of the previous training step and the gradient of the current training step are weighted and summed to obtain the gradient momentum of each parameter in the current training step.
8. The multi-task model fine-tuning method according to claim 6, characterized in that, The gradients of each parameter are determined based on the following steps: Construct a joint loss function, which includes at least one of the following: task loss for measuring prediction accuracy, load balancing loss for measuring the load balancing degree of expert modules, and orthogonal constraint loss for measuring parameter independence. Backpropagation is performed based on the joint loss function to obtain the gradients of each parameter in the shared expert module and the gradients of each parameter in the target expert module.
9. The multi-task model fine-tuning method according to claim 8, characterized in that, The load balancing loss is determined based on the following steps: The average routing probability of each routing expert module and the average utilization rate of the actual sample data processed by each routing expert module are statistically analyzed. Calculate the product of the average routing probability and average utilization of each routing expert module, and sum the products of all routing expert modules as the load balancing loss.
10. The multi-task model fine-tuning method according to claim 8, characterized in that, The orthogonal constraint loss is determined based on the following steps: Calculate the correlation metric between the parameter matrix of the shared expert module and the parameter matrices of each routing expert module; The absolute values of the correlation metrics are summed, and the summation result is used as the orthogonal constraint loss.
11. The multi-task model fine-tuning method according to any one of claims 1 to 3, characterized in that, The semantic encoding of sample data for each task to obtain corresponding encoded features includes: For each task, a predetermined number of sample data are randomly sampled; Semantic encoding is performed on the sample data for each task to obtain the semantic features of each sample data under the corresponding task; Calculate the average of the semantic features of all sample data under each task, and use the average as the encoding feature of the corresponding task.
12. The multi-task model fine-tuning method according to any one of claims 1 to 3, characterized in that, Both the shared expert module and the routing expert module adopt a low-rank matrix decomposition structure.
13. A multi-task model fine-tuning device, characterized in that, include: The encoding module is used to perform semantic encoding on the sample data of each task to obtain the corresponding encoded features; The extraction module is used to input the sample data of each task into the feature extraction module of the multi-task model to obtain the hidden layer features of each task. The modulation module is used to generate modulation coefficients for each task using the coding features of each task, and to modulate the corresponding hidden layer features using the modulation coefficients of each task to obtain the modulation features of each task. The determination module is used to calculate the routing weight of each task based on the modulation characteristics of each task, and determine the corresponding target expert module from multiple routing expert modules of the multi-task model according to the routing weight of each task. The fine-tuning module is used to aggregate the output of the shared expert module in the multi-task model with the output of the target expert module of each task to obtain the prediction results of each task, and to fine-tune the parameters of the multi-task model based on the prediction results of each task. The shared expert module is an expert network that participates in the calculation of all tasks.
14. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that, When the processor executes the computer program, it implements the multi-task model fine-tuning method as described in any one of claims 1 to 12.
15. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the multi-task model fine-tuning method as described in any one of claims 1 to 12.