Multi-task deep optimization method based on dynamic weight distribution
By introducing uncertainty estimation and gradient smoothing mechanisms into multi-task deep learning, and dynamically adjusting task weights, the problem of training instability in multi-task learning is solved, and the overall optimization effect of the model is improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HANGZHOU WEIYUNKE NETWORK TECHNOLOGY CO LTD
- Filing Date
- 2025-08-11
- Publication Date
- 2026-05-29
AI Technical Summary
Existing multi-task deep learning methods are prone to some tasks dominating the training process when faced with differences in learning difficulty, convergence speed and loss magnitude among different tasks, resulting in a decline in the overall performance of the model. Furthermore, existing dynamic weight allocation methods are sensitive to micro-batch gradient noise, leading to training instability.
By obtaining task-shared feature representations and average uncertainty through forward propagation and uncertainty estimation, stabilized gradient norm signals and historical exponential moving averages are calculated. Combined with gradient information gating and temporal smoothing, task weights are dynamically adjusted to suppress noise interference, ensuring training stability and convergence performance.
It effectively suppresses the influence of micro-batch gradient noise, achieves stability in the multi-task learning process and stability and convergence in model optimization, and improves overall performance.
Smart Images

Figure CN120994339B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of task optimization, and more specifically, to a multi-task deep optimization method based on dynamic weight allocation. Background Technology
[0002] In the field of deep learning, multi-task learning, by sharing model parameters across multiple related tasks, can effectively improve the learning efficiency and generalization ability of a model, and has been widely applied in scenarios such as recommender systems and computer vision. However, a core challenge of multi-task learning lies in how to balance the learning processes of different tasks. Since the learning difficulty, convergence speed, and loss magnitude of each task vary significantly, simply using static weights to sum the losses of each task for optimization can easily lead to some tasks dominating the training process while others are under-learned, ultimately harming the overall performance of the model. Therefore, dynamically adjusting the weights of each task during training is crucial for achieving efficient multi-task optimization.
[0003] To address this, some dynamic weight allocation methods based on gradient information have emerged in existing technologies, attempting to coordinate their learning rates by balancing the gradient norms of different tasks. However, these methods reveal inherent flaws when applied to real, noisy data and random micro-batch training. Specifically, such methods typically rely directly on the instantaneous gradient signal calculated in the current micro-batch to update weights. Due to the randomness of micro-batch data sampling, training data inevitably contains noisy or anomalously distributed samples, causing drastic and unrepresentative fluctuations in the gradients of certain tasks in specific batches. Existing methods are exceptionally sensitive to such instantaneous gradient noise signals, immediately making drastic weight adjustments, much like constantly making rapid corrections on the optimization path, resulting in violent oscillations in weight allocation. This lack of temporal smoothing and signal reliability judgment mechanisms excessively amplifies local, noisy instantaneous signals as the basis for global adjustments, severely impacting the stability and convergence of model training.
[0004] Therefore, how to effectively suppress the interference of micro-batch gradient noise and make smooth and stable dynamic adjustments to the weight allocation based on historical training states, so as to improve the overall optimization stability and final performance of the model while ensuring balanced learning of each task, has become a technical problem that urgently needs to be solved in the field of multi-task deep optimization. Summary of the Invention
[0005] To address the aforementioned problems in the existing technology, according to one aspect of this application, a multi-task depth optimization method based on dynamic weight allocation is provided, comprising:
[0006] Acquire micro-batch input data and micro-batch multi-task label data;
[0007] Forward propagation and uncertainty estimation are performed on micro-batch input data and micro-batch multi-task label data to obtain task-shared feature representations, the original loss of each task, and the average uncertainty of each task.
[0008] Calculate the gradient of the original loss for each task relative to the parameters of the shared model to obtain the original gradient of the loss for each task.
[0009] Based on the average uncertainty of each task, gradient information gating and smoothing are performed on the original gradient of the loss of each task to obtain the stable gradient norm signal of each task and the historical exponential moving average of the loss of each task.
[0010] Dynamic task weights are calculated by using the stabilized gradient norm signal of each task and the historical exponential moving average of the loss of each task to obtain the final weight of each task.
[0011] The final weights of each task and the original gradients of the loss of each task are weighted and aggregated to obtain the aggregated gradient, and the aggregated gradient is applied to the shared model.
[0012] Compared with existing technologies, this application provides a multi-task deep optimization method based on dynamic weight allocation. To address the training instability caused by micro-batch gradient noise in dynamic weight allocation, this application introduces a dual stabilization mechanism. First, the task uncertainty estimated in forward propagation is used as a gating signal for gradient information. By evaluating the model's reliability for the current data batch, drastic gradient fluctuations caused by noise or outliers are actively suppressed. Second, based on gating adjustment, the gradient norm signal is further smoothed temporally. Combined with historical training information (such as generating a stable signal based on the moving average of the gradient norm from the previous training step), instantaneous disturbances are eliminated, thereby generating a stable gradient signal for final weight calculation. This strategy, combining uncertainty gating and temporal smoothing, effectively avoids drastic oscillations in task weights due to instantaneous noise, ensuring the training stability and convergence performance of the shared model in the multi-task optimization process. Attached Figure Description
[0013] The above and other objects, features, and advantages of this application will become more apparent from the more detailed description of the embodiments of this application in conjunction with the accompanying drawings. The drawings are provided to further illustrate the embodiments of this application and form part of the specification. They are used together with the embodiments of this application to explain this application and do not constitute a limitation thereof. In the drawings, the same reference numerals generally represent the same components or steps.
[0014] Figure 1 This is a flowchart of a multi-task deep optimization method based on dynamic weight allocation according to an embodiment of this application.
[0015] Figure 2 This is a schematic diagram of data flow in a multi-task depth optimization method based on dynamic weight allocation according to an embodiment of this application.
[0016] Figure 3 This is a flowchart of step 2 in the multi-task depth optimization method based on dynamic weight allocation according to an embodiment of this application.
[0017] Figure 4 This is a flowchart of step 4 in the multi-task depth optimization method based on dynamic weight allocation according to an embodiment of this application. Detailed Implementation
[0018] Embodiments of this disclosure will now be described in more detail with reference to the accompanying drawings. While some embodiments of this disclosure are shown in the drawings, it should be understood that this disclosure can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of this disclosure. It should be understood that the accompanying drawings and embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of protection of this disclosure.
[0019] To address the problems mentioned in the background section, this application proposes a multi-task deep optimization method based on dynamic weight allocation. Figure 1 This is a flowchart of a multi-task deep optimization method based on dynamic weight allocation according to an embodiment of this application. Figure 2 This is a schematic diagram of the data flow in a multi-task depth optimization method based on dynamic weight allocation according to an embodiment of this application. Figure 1 and Figure 2 As shown, the multi-task deep optimization method based on dynamic weight allocation according to an embodiment of this application includes: Step 1, acquiring micro-batch input data and micro-batch multi-task label data; Step 2, performing forward propagation and uncertainty estimation on the micro-batch input data and micro-batch multi-task label data to obtain task-shared feature representations, the original loss of each task, and the average uncertainty of each task; Step 3, calculating the gradient of the original loss of each task relative to the parameters of the shared model to obtain the original gradient of the loss of each task; Step 4, based on the average uncertainty of each task, performing gradient information gating and smoothing on the original gradient of the loss of each task to obtain the stable gradient norm signal of each task and the historical exponential moving average of the loss of each task; Step 5, performing dynamic task weight calculation on the stable gradient norm signal of each task and the historical exponential moving average of the loss of each task to obtain the final weight of each task; Step 6, performing weighted gradient aggregation on the final weight of each task and the original gradient of the loss of each task to obtain the aggregated gradient, and applying the aggregated gradient to the shared model.
[0020] In step 1, micro-batch input data and micro-batch multi-task label data are acquired. It should be understood that when using deep learning models for multi-task optimization, training is typically based on massive amounts of sample data. Due to limitations in computing resources and memory, loading the entire dataset at once and performing gradient calculations is impractical. Therefore, modern deep learning frameworks generally employ an optimization strategy based on stochastic gradient descent. This strategy divides large-scale datasets into several small data batches, i.e., micro-batches, for iterative training. In each iteration, the model processes only one micro-batch of data, calculates the loss and gradient, and updates the model parameters. Therefore, acquiring a micro-batch of input data and its corresponding multi-task label data before the entire optimization process begins is a fundamental step driving a single training iteration and enabling incremental updates of model parameters. It provides the necessary and processable data units for subsequent forward propagation, gradient calculation, and dynamic weight allocation.
[0021] In one specific implementation, step 1 is performed as follows: In a specific implementation of the present invention, the multi-task deep optimization method based on dynamic weight allocation can be applied to a scenario for online retail product analysis. This scenario aims to efficiently execute two intrinsically related but different tasks simultaneously through a unified model: one is a classification task, the goal of which is to accurately determine the predefined category to which the product belongs, such as electronic products, clothing and footwear, or household goods; the other is a regression task, the goal of which is to accurately predict the user rating of the product, which is expressed as a continuous value from 1.0 to 5.0.
[0022] First, a large-scale, high-quality training dataset needs to be constructed. Each independent sample in this dataset consists of an input data point and a set of strictly corresponding multi-task labels. Specifically, in this scenario, a sample represents a product, and its input data includes two modalities: a main product image and a product description text. The corresponding multi-task labels include the product's true category (classification task label) and its historical average user rating (regression task label). Therefore, each entry stored in the dataset is logically a tuple containing the product image, product description, product category, and product rating. Before training begins, a crucial hyperparameter needs to be set: the micro-batch size. This value requires careful consideration of computational resources, especially the GPU's memory capacity and number of cores. Setting it to a power of 2 optimizes hardware utilization; for example, 64. That is, in each training iteration, the model will process 64 product samples in parallel, aiming to maximize parallel computing efficiency while avoiding training interruptions due to insufficient memory.
[0023] The specific execution process of data acquisition heavily relies on a data loader module, which acts as a bridge connecting the statically stored dataset with the dynamic training loop. At the beginning of each training cycle, the data loader first performs a global randomized sorting of the indices of the entire training dataset, i.e., data shuffling, to completely disrupt the original order of the data in physical storage. This effectively destroys any potential sequence correlations between samples, preventing the model from learning such task-irrelevant spurious patterns during training, thereby significantly enhancing the model's generalization ability. After index shuffling, the data loader then divides the shuffled index sequence into multiple non-overlapping index blocks according to a set micro-batch size, such as 64.
[0024] When the main training loop enters a new iteration, it requests the next batch of data from the data loader. The data loader, acting as an iterator, locates and extracts the corresponding 64 raw data tuples from the dataset based on the current index block and outputs them to the training process. This output micro-batch data is internally constructed into two logical parts: micro-batch input data and micro-batch multi-task label data. After obtaining the raw data, a series of rigorous preprocessing and tensor quantization operations are required to convert it into a numerical format that the model can directly process. For the 64 product samples in the micro-batch input data, the processing flow is as follows: For product images, each image file, such as JPEG format, is read from the disk and decoded into a pixel matrix. Then, its size is uniformly adjusted to a fixed height and width, for example, 224x224 pixels, to ensure the consistency of the input size. Subsequently, it is numerically normalized, for example, by linearly scaling the pixel values from the integer range [0,255] to the floating-point range [0,1], and further standardized based on the image channel mean and standard deviation pre-calculated from the entire training dataset. Ultimately, these 64 fully processed images are stacked into a four-dimensional floating-point tensor with the shape [64, 3, 224, 224], where the dimensions correspond to the batch size, number of color channels, image height, and width, respectively. For product description text, unstructured natural language needs to be converted into a numerical sequence that the model can understand. Each text string first undergoes standard word segmentation, breaking down consecutive sentences into independent words or sub-words. After segmentation, each word in the resulting word sequence is searched in the vocabulary and replaced with its unique integer index, thus completely converting the entire text sequence into a sequence of integer indices that retains sequential information but lacks semantic meaning. Since neural network models require input tensors to have regular, uniform dimensions during batch processing, and the original lengths of different product descriptions vary, this variable-length sequence problem needs to be addressed. Specifically, a preset maximum sequence length, such as 100, is set. For integer index sequences with a length exceeding 100 after conversion, the sequence is truncated from the end, discarding the excess portion. For sequences with a length less than 100, the end is padded with index values corresponding to predefined special padding characters until the length reaches 100. This padding and truncation operation ensures that all 64 text data entries in the micro-batch are ultimately constructed into two-dimensional integer tensors with a completely uniform shape of [64, 100]. The final output micro-batch input data is a structured collection containing the aforementioned image and text tensors.
[0025] Meanwhile, the micro-batch multi-task label data corresponding to these 64 input samples also underwent corresponding tensor processing. For the product category classification task, the original labels, such as electronic products, were converted into corresponding integer indices, such as 2. These 64 category indices were constructed into a one-dimensional long integer tensor with shape
[64] . For the product rating regression task, the original floating-point rating values were collected and constructed into a two-dimensional floating-point tensor with shape [64,1]. The added dimension was to maintain consistency with the format of the model output. The final output micro-batch multi-task label data is a structured set containing the above category label tensor and rating label tensor.
[0026] In step 2, forward propagation and uncertainty estimation are performed on the micro-batch input data and micro-batch multi-task label data to obtain the task-shared feature representation, the original loss of each task, and the average uncertainty of each task. Correspondingly, in any gradient descent-based optimization algorithm, the update of model parameters depends on the gradient of the loss function with respect to the parameters. Therefore, a complete forward computation process needs to be completed before gradient calculation and subsequent weight allocation. The core of this process is to allow the model to generate predictions based on the current input data and compare these predictions with the true labels to quantify the model's performance, i.e., calculate the loss. However, this application not only calculates the loss but also simultaneously evaluates the model's confidence in the current micro-batch data predictions. This is because the inherent noise and randomness in the micro-batch data directly manifest in gradient instability. Therefore, through a unified forward propagation process, three key pieces of information are simultaneously produced: the shared feature representation used for subsequent task-specific processing, the original loss of each task as the basis for gradient calculation, and the average uncertainty of each task as the key basis for subsequent gradient stabilization processing. This lays the necessary data and signal foundation for effectively suppressing gradient noise and achieving stable dynamic weight allocation.
[0027] In one specific implementation plan, Figure 3 This is a flowchart of step 2 in the multi-task depth optimization method based on dynamic weight allocation according to an embodiment of this application. Figure 3 As shown, step 2, performing forward propagation and uncertainty estimation on the micro-batch input data and micro-batch multi-task label data to obtain the task-shared feature representation, the original loss of each task, and the average uncertainty of each task, includes: step 21, inputting the micro-batch input data into the shared model to obtain the task-shared feature representation; step 22, inputting the task-shared feature representation into each task head network to obtain the prediction result of each task and the average uncertainty of each task; step 23, calculating the original loss of each task based on the prediction result of each task and the micro-batch multi-task label data.
[0028] In the above implementation scheme, step 2 is performed as follows: First, the processing in step 21 is performed. It is worth noting that the shared model is essentially a deep multimodal feature extraction network, comprising three main parts: an image feature extraction branch, a text feature extraction branch, and a multimodal feature fusion module. The image feature extraction branch is responsible for processing image tensors. In this embodiment, a convolutional neural network (CNN) can be used as its backbone, such as a ResNet-50 residual network with 50 weight layers. To leverage large-scale general knowledge to accelerate model convergence and improve performance, the weight parameters of the ResNet-50 network are not randomly initialized from zero, but are initialized by loading a pre-trained weight file on a large public image dataset such as ImageNet. When an image tensor of shape [64,3,224,224] is input to this branch, it sequentially flows through a series of convolutional layers, batch normalization layers, activation functions such as ReLU, and pooling layers. Through these operations, the network can abstract complex visual patterns from raw pixels, ranging from low-level edges and textures to high-level object parts. Finally, after processing by the global average pooling layer, the visual information of each sample is compressed into a high-dimensional feature vector. For example, the output of ResNet-50 is a 2048-dimensional vector. Therefore, this branch outputs an image feature tensor of shape [64, 2048] for the 64 images in the batch. The text feature extraction branch is responsible for parallel processing of the text tensor. A deep language model based on the Transformer architecture, such as the BERT model, can be used. Similar to the image branch, the weight parameters of this BERT model are initialized by loading publicly available model parameters pre-trained on massive text corpora, thus giving it powerful general language understanding capabilities. When the text index tensor of shape [64, 100] is input into this branch, the discrete integer indices are first converted into dense floating-point vectors through an embedding layer. Subsequently, these vector sequences undergo complex contextual interaction calculations in a multi-layer bidirectional self-attention mechanism, enabling the model to deeply understand the precise meaning of each word in a specific context. The output vector of the special marker [CLS] corresponding to the start position of each sequence in the final output layer is taken as the aggregate representation of the entire text sequence. If the hidden layer dimension of the base version of this BERT model is 768, then this branch will output a text feature tensor of shape [64, 768] for the 64 text segments in the batch. The multimodal feature fusion module is the key hub of the shared model. Its responsibility is to receive feature tensors of different modalities and dimensions from the above two branches and effectively integrate them into a unified, multimodal shared feature representation. This module consists of several fully connected layers.Since its weight parameters lack pre-training capabilities, standard random initialization methods, such as Xavier initialization or He initialization, are used to set their initial values to ensure gradient stability during the initial training phase. The fusion process can be designed as follows: First, a linear layer projects the 2048-dimensional image feature vector to a lower common dimension, such as 512 dimensions; simultaneously, another independent linear layer projects the 768-dimensional text feature vector to the same 512 dimensions. This yields two feature tensors, both [64, 512], aligned in the same semantic space. These two tensors are then concatenated to form a pre-fusion feature tensor of shape [64, 1024]. Finally, this concatenated tensor is passed through one or more non-linear fully connected layers (e.g., a linear layer from 1024 to 512 dimensions followed by a ReLU activation function) for deep fusion and information extraction. After the above processing, the final output of the shared model is the task-shared feature representation. This is a two-dimensional floating-point tensor of shape [64, 512]. Each row in this tensor is a deep, abstract, and fused numerical description of a product sample image and text information.
[0029] Next, step 22 is executed. It's worth noting that task head networks refer to a series of relatively simple neural network modules with few parameters, attached to the ends of a shared model backbone. Each task head network has independent, non-shared weight parameters. Since these networks are structured for specific tasks, their weights and bias parameters cannot be initialized by loading a general pre-trained model. Therefore, standard random initialization methods, such as Xavier uniform initialization or Kaiming normal initialization, are commonly used to ensure a good parameter distribution at the start of training, which is beneficial for stable gradient propagation. In this embodiment, two parallel task head networks exist. The first is a classification task head network, which converts a 512-dimensional shared feature vector into a probability judgment of belonging to 10 predefined product categories. This network can be implemented using a multilayer perceptron. Its specific architecture is: a 512-dimensional input layer that perfectly matches the input feature dimension; a hidden layer containing 256 neurons using the modified linear unit ReLU as the activation function; and an output layer with the number of neurons equal to the total number of categories to be classified, such as 10 in this example. This output layer does not have any activation function applied, and its raw output value is called logits. When the task-shared feature representation tensor of shape [64, 512] is input into this classification task head network, it undergoes a nonlinear transformation and is finally mapped by the output layer to a two-dimensional floating-point tensor of shape [64, 10], which is the prediction result for the classification task. For example, for a sample in a batch, its output 10-dimensional prediction result vector might be [1.2, -0.5, 3.4, 0.1, -2.0, 1.5, 0.8, -1.1, 2.1, 0.3]. For the uncertainty of the classification task, the prediction result can be converted into a probability distribution by applying the Softmax function, i.e., [0.08, 0.01, 0.65, 0.02, 0.00, 0.11, 0.05, 0.01, 0.22, 0.02], and then the information entropy of this probability distribution can be calculated. In this example, the calculated information entropy is approximately 1.34. A high entropy value indicates a relatively uniform distribution of predicted probabilities across all categories, suggesting high uncertainty. The average uncertainty for a classification task can be obtained by arithmetically averaging the entropy values of the 64 samples in a batch, for example, yielding a scalar value of 1.58. The second is the regression task head network, which simultaneously predicts a continuous score and its uncertainty. This network can also be implemented using an MLP, with an architecture consisting of a 512-dimensional input layer and a 128-dimensional hidden layer activated by ReLU. The key difference lies in the output layer, which contains two neurons and does not use any activation function. When a shared feature tensor of [64, 512] is input, the network ultimately outputs a two-dimensional floating-point tensor of shape [64, 2]. The two columns of this tensor have different physical meanings.Taking a sample from the batch as an example, its output 2D vector might be [3.8, -1.2]. The first column, 3.8, represents the model's direct prediction of the user rating for that product, which is the prediction result for the regression task. The second column, -1.2, represents the logarithmic variance of the model's prediction, used to characterize the uncertainty of the prediction. To obtain the actual variance, this value needs to be taken as an exponential function, i.e., exp(-1.2), approximately equal to 0.30. A larger variance indicates greater uncertainty in the model's prediction. Finally, the arithmetic mean of the variances calculated from the 64 samples is taken to obtain a single scalar value, for example, 0.45, which is the average uncertainty of the regression task. Ultimately, we obtain a classification task prediction result tensor of shape [64, 10], a regression task prediction result tensor of shape [64, 1], and two scalar values representing the average uncertainty of the overall prediction confidence for the classification and regression tasks, respectively.
[0030] Finally, step 23 is executed. For the product classification task, the input to this process is the prediction result tensor [64, 10] and the true class index tensor
[64] . The cross-entropy loss function is used here. Internally, a softmax function is first applied to the input prediction results to convert them into a probability distribution. Subsequently, the function extracts the predicted probability of each sample in the correct class based on the true class index and calculates its negative logarithm. Taking the aforementioned sample as an example, its prediction result is [1.2, -0.5, 3.4, ...]. If the true class index is 2, corresponding to the third class, then the model's predicted probability in that class is approximately 0.65, and the corresponding cross-entropy loss is -log(0.65), approximately equal to 0.43. A higher correct prediction probability leads to a lower loss. After this calculation is completed on all samples in the batch, the 64 loss values are arithmetically averaged to obtain a single scalar value, for example, 0.87, which is the original loss for the classification task. For the product rating regression task, its loss calculation needs to utilize both the model's predicted values and its uncertainty. The input to this process is the [64,2] tensor output by the regression task head network and the [64,1] true score tensor. A Gaussian negative log-likelihood loss function is used, which treats the model's predictions as a Gaussian distribution with the predicted score as the mean and the prediction uncertainty as the variance. For each sample in a batch, the loss consists of two parts: the first part is the square of the prediction error, i.e., (true score - predicted score)², but this term is adjusted by the variance of the prediction, specifically divided by twice the variance; the second part is the regularization term of the variance itself, i.e., half of the log-variance. These two parts are added together to obtain the loss for that sample. Taking the aforementioned sample as an example, its predicted score is 3.8, and the prediction variance is 0.30. If the true score is 4.1, then the loss for this sample is: (4.1 - 3.8). 2 / (2*0.30)+0.5*log(0.30) is approximately equal to -0.45. This loss function design incentivizes the model to learn an honest strategy: when the model's prediction for a sample is highly uncertain (large prediction variance), even with a large prediction error, the error term will be suppressed by the large denominator, preventing the total loss from becoming excessive. Simultaneously, the regularization term penalizes the model for unjustifiably giving excessive uncertainty. This calculation is also performed on all 64 samples, and the arithmetic mean is taken, ultimately yielding a scalar value representing the overall performance of the entire micro-batch on the regression task, for example, -0.33, which is the original loss for the regression task.
[0031] In step 3, the gradient of the original loss for each task relative to the parameters of the shared model is calculated to obtain the original gradient of the loss for each task. It is understandable that after completing forward propagation and calculating the original loss for each task, the core objective of model optimization is to adjust the internal parameters of the model based on these loss values in order to achieve a lower loss in the next iteration. However, the loss value itself is only a scalar; it can only measure the current performance of the model, but it cannot indicate how to specifically and efficiently adjust the millions of parameters in the model. To achieve systematic optimization, it is necessary to determine the contribution and direction of influence of each parameter to the final loss. Therefore, this application obtains this crucial, directional guidance information by calculating the gradient of the loss for each task relative to the parameters of the shared model. This gradient reveals the local topography of the loss function in the parameter space, pointing in the direction of the fastest loss growth, thus indicating the correct path for parameter updates for subsequent gradient descent-based optimization algorithms and providing the most original, unprocessed signal input for the core dynamic weight allocation mechanism of this invention.
[0032] In one specific implementation, step 3, calculating the gradient of the original loss of each task relative to the parameters of the shared model to obtain the original gradient of the loss of each task, includes: calculating the gradient of the original loss of each task relative to the parameters of the shared model using an automatic differentiating function to obtain the original gradient of the loss of each task.
[0033] In the above implementation scheme, step 3 is executed as follows: Automatic differentiation is a computational technique that can automatically and accurately calculate the derivative of a complex function consisting of a series of basic operations, such as the entire forward propagation process of a neural network. During the forward propagation in step 2, the automatic differentiation mechanism simultaneously constructs a computational graph, which is a directed acyclic graph where nodes represent data tensors or computational operations, and edges represent the direction of data flow. When step 3 begins execution, it independently calls the automatic differentiation function for the original loss of each task. This process is called backpropagation because it calculates the gradient layer by layer backward along the computational graph in the opposite direction to forward propagation, starting from the final loss node.
[0034] In this embodiment, the computation process is divided into two parallel parts: First, the original gradient of the loss for the classification task is calculated. The original loss scalar for the classification task, calculated above, for example, 0.87, is used as the starting point for backpropagation. After calling the automatic differentiation function, the gradient information flows backward along the computation graph from this loss value. It first passes through the classification task head network, calculating the gradient of the loss relative to the parameters of each layer of the task head network according to the chain rule. However, the key to this step is obtaining the gradient of the loss relative to the parameters of the shared model; therefore, the gradient flow does not stop at the task head network. It continues to propagate backward, from the input of the classification task head, i.e., the shared feature representation of the task, into the feature fusion module of the shared model. The gradient continues to pass through each fully connected layer of the fusion module and is further distributed to the image feature extraction branch ResNet-50 and the text feature extraction branch BERT. Within each branch, the gradient flows backward layer by layer until it reaches the input of the shared model, calculating the partial derivatives of the classification loss 0.87 with respect to all parameters in the shared model that participated in the forward computation along the way. For example, for a certain weight parameter in the first convolutional layer of a ResNet-50 shared model, its current value is 0.05, and the gradient calculated based on the classification loss might be -0.0012. This numerically indicates that, in order to reduce the loss for the classification task, the value of this weight parameter needs to be slightly increased, because optimization typically involves subtracting the gradient multiplied by the learning rate. After this process, a complete set of gradients is obtained, whose structure is completely consistent with the parameter structure of the shared model; that is, each parameter tensor has a gradient tensor with the exact same shape. This set is the original gradient of the loss for the classification task.
[0035] Secondly, the original gradient of the regression task loss is calculated in the exact same way. Before performing this backpropagation, it is necessary to ensure that the gradient information generated by the previous calculation in the model parameters has been cleared to avoid the accumulation of the two gradients, thus ensuring the independence of the gradients for each task. Using the original regression task loss scalar calculated above, for example -0.33, as the starting point for this backpropagation, the automatic differentiation function is called independently again. The gradient flow travels through the network along the exact same path as the classification task, calculating the partial derivative of the original regression task loss with respect to each parameter in the shared model. For the same weight parameter in the shared model, the current value is 0.05, and the gradient calculated based on the regression loss may be a different value, for example +0.0008. This indicates that, in order to reduce the loss of the regression task, the value of this weight parameter actually needs to be slightly reduced. After this process, a second independent set of gradients is obtained, whose structure is also consistent with the parameter structure of the shared model; this is the original gradient of the regression task loss.
[0036] The final output consists of two independent, structured sets of gradients. Each set represents a task's initial opinion on how to tune the shared model parameters. These sets may differ significantly or even conflict in value and direction; for example, the gradients of one task might indicate that the model should focus more on a specific region in an image, while the gradients of another task might indicate that the model should focus more on understanding a particular sentiment word in a text description.
[0037] In step 4, based on the average uncertainty of each task, gradient information gating and smoothing are applied to the original gradient loss of each task to obtain the stable gradient norm signal and the historical exponential moving average of the loss for each task. It should be understood that while the original gradient accurately reflects the adjustment requirements of the current micro-batch data for model parameters, it is inherently instantaneous and high-variance. Due to the randomness of micro-batch sampling and the unavoidable noise in the data, these gradient signals often fluctuate dramatically. If directly used to guide the allocation of task weights, it will lead to abrupt and potentially erroneous directional corrections in the optimization process, severely impairing the stability of training. Therefore, to deeply purify and refine these original and noisy gradient signals, gradient information gating and smoothing are applied to the original gradient loss of each task. This utilizes the model's own uncertainty assessment as a gate to determine the reliability of the current gradient signal, suppressing unreliable gradients generated by uncertain predictions. Simultaneously, temporal smoothing filters out random noise in a single iteration, extracting the long-term, stable trend of gradient changes, thus providing a high-quality, high-stability decision-making basis for subsequent dynamic weight calculations.
[0038] In one specific implementation plan, Figure 4This is a flowchart of step 4 in the multi-task depth optimization method based on dynamic weight allocation according to an embodiment of this application. Figure 4 As shown, step 4, based on the average uncertainty of each task, performs gradient information gating and smoothing on the original gradient of the loss of each task to obtain the stable gradient norm signal of each task and the historical exponential moving average of the loss of each task, including: step 41, inputting the original gradient of the loss of each task into the gradient norm calculation submodule to obtain the current overall magnitude scalar value of the gradient of each task; step 42, inputting the average uncertainty of each task into the gating factor generation submodule to obtain the gating factor of each task; step 43, inputting the current overall magnitude scalar value of the gradient of each task and the gating factor of each task into the gating adjustment submodule to obtain the current gradient norm of each task; step 44, performing time-series smoothing-based stable gradient signal generation on the current gradient norm of each task to obtain the stable gradient norm signal of each task and the historical exponential moving average of the loss of each task.
[0039] In the above implementation scheme, step 4 is executed as follows: First, the processing of step 41 is performed. In a specific implementation scheme, step 41, inputting the original gradient of the loss of each task into the gradient norm calculation submodule to obtain the current overall magnitude scalar value of the gradient of each task, includes: step 411, vectorizing all gradient tensors in the original gradient of the loss of each task and concatenating the vectors to obtain the concatenated vector of the original gradient of the loss of each task; step 412, calculating the L2 norm of the concatenated vector of the original gradient of the loss of each task to obtain the current overall magnitude scalar value of the gradient of each task.
[0040] Specifically, first, step 411 is performed. This process is performed independently for the gradient set of each task. Taking the classification task as an example, its original set of loss gradients corresponds completely to the shared model parameter structure. This set contains gradient tensors, for example, the gradient tensor corresponding to the weights of a convolutional layer in the ResNet-50 branch of the shared model, whose shape may be [64,32,3,3]; the gradient tensor corresponding to the weight matrix of a self-attention mechanism in the BERT branch, whose shape may be [768,768]; and the gradient vector corresponding to the bias of a fully connected layer in the multimodal feature fusion module, whose shape may be
[512] . The vectorization operation flattens or straightens these gradient tensors with different dimensions and shapes one by one, transforming them into one-dimensional vectors. For example, a tensor with the shape [64,32,3,3] will be transformed into a one-dimensional vector containing 64*32*3*3=18432 elements. After vectorizing all gradient tensors in the set, the concatenation operation joins these one-dimensional vectors together in a predetermined order that remains unchanged throughout the training process, forming a single, high-dimensional one-dimensional long vector. This long vector is the concatenated original gradient loss vector for the classification task. The same series of vectorization and concatenation operations are performed on the original gradient loss set for the regression task in the same way, resulting in the concatenated original gradient loss vector for the regression task. Next, step 412 is executed. The L2 norm, also known mathematically as the Euclidean norm, is a commonly used method for measuring vector length. Its calculation process involves squaring each element of the vector, summing all the squared results, and finally taking the square root of the sum. This calculation process is applied to the two concatenated original gradient loss vectors obtained in the previous step. For the concatenated vector for the classification task, calculating its L2 norm yields a non-negative scalar value. Geometrically, this value represents the length of the gradient vector for the classification task in the ultra-high-dimensional parameter space, intuitively reflecting the overall strength of the shared model parameters required for adjustment in the current micro-batch. For example, the calculated overall magnitude scalar value of the current gradient for the classification task might be 15.8. Similarly, calculating the L2 norm of the concatenated vector for the regression task also yields an independent non-negative scalar value, representing the gradient strength of the regression task. For example, this value might be 8.2.
[0041] Next, step 42 is executed. The calculation process in this step follows a specific mathematical formula. In one specific implementation, step 42 involves inputting the average uncertainty of each task into the gating factor generation submodule to obtain the gating factor for each task, including: calculating the gating factor for each task using the following formula:
[0042] C i =exp(-Ui )
[0043] Among them, U i For the average uncertainty of each task, exp is the value of an exponential function with the natural constant e as the base, C i These are the gating factors for each task. In this formula, U i C represents the average uncertainty of task i, while C i This is the final calculated gating factor used for task i. Specifically, firstly, due to the average uncertainty U... i It is a non-negative value, and its opposite is -U i It must be a non-positive value. Therefore, exp(-U i The calculation result C) i It will be strictly limited to the interval (0,1]. This property makes C i To become an ideal multiplication modifier, i.e., a gating factor, it can be directly multiplied by the gradient norm to scale its size without changing its sign or introducing a dramatic change in magnitude. Secondly, the formula establishes an inverse nonlinear relationship between uncertainty and the gating factor. When the average uncertainty U of the task... i When -U is very high, it indicates that the model generally lacks confidence in the prediction results of the current micro-batch; at this time, -U i It is a negative number with a large absolute value, and its exponential function value is exp(-U i The value will be very close to 0. Conversely, when the average uncertainty U of the task is much higher... i A very low value indicates a high confidence level in the model's predictions; at this point, -U i Approaching 0, its exponential function value exp(-U i The value will then be very close to 1. In a specific embodiment of this application, the average uncertainty U of the classification task... i The value (calculated based on entropy) is 1.58, while the average uncertainty U of the regression task is... i (Based on the mean of the prediction variance) is 0.45. Substituting these two values into the above formula for calculation: For a classification task, its gating factor C i =exp(-1.58). The calculated value is approximately 0.206. Due to its high uncertainty, the obtained gating factor is a small value. For regression tasks, the gating factor C... i =exp(-0.45). The calculation yields approximately 0.638. Due to its relatively low uncertainty, the resulting gating factor is also relatively large.
[0044] Then, step 43 is executed. This step is accomplished through a gating adjustment submodule, which is functionally equivalent to a task-by-task multiplier. It receives scalar values from previous steps and performs a multiplication operation independently for each task. In a specific embodiment of this application, the current total gradient magnitude scalar value for the classification task is 15.8; and the current total gradient magnitude scalar value for the regression task is 8.2. The input from step 42 is: a gating factor of 0.206 for the classification task; and a gating factor of 0.638 for the regression task. The calculation process of the gating adjustment submodule is as follows: For the classification task, its current total gradient magnitude scalar value of 15.8 is multiplied by the calculated gating factor of 0.206. The calculation result is 15.8 * 0.206 ≈ 3.25. This calculated value of 3.25 is the gradient norm of the classification task at the current time step. For the regression task, in the same way, its current total gradient magnitude scalar value of 8.2 is multiplied by the calculated gating factor of 0.638. The calculation result is 8.2 * 0.638 ≈ 5.23. This calculated value of 5.23 is the gradient norm of the regression task at the current time step. It is worth noting that before gating, the original gradient magnitude of the classification task (15.8) is much larger than that of the regression task (8.2), indicating that the classification task generated a stronger parameter update request in the current micro-batch. However, because the classification task's prediction is accompanied by a high average uncertainty of 1.58, its gating factor of 0.206 is very small, thus exerting a strong suppression effect on its original gradient magnitude. Conversely, the regression task's prediction has a lower average uncertainty of 0.45, and its gating factor of 0.638 is relatively large, allowing its original gradient magnitude to be preserved to a greater extent. Finally, after gating, the situation is reversed: the current gradient norm of the classification task (3.25) is actually smaller than that of the regression task (5.23). This enables adaptive evaluation and utilization of gradient information quality, effectively preventing the model from being dominated by unreliable gradient signals that may be caused by outlier samples or regions that the model has not fully learned. It ensures that only gradient signals originating from high-confidence predictions of the model can have a major impact on the subsequent optimization process.
[0045] Finally, step 44 is executed. In one specific implementation, step 44 involves generating a stable gradient signal based on time-series smoothing for the current gradient norm of each task to obtain the stable gradient norm signal of each task and the historical exponential moving average of the loss of each task. This includes: step 441, extracting the exponential moving average of the gradient norm of each task from the previous training step; and step 442, performing an exponential moving average on the current gradient norm of each task based on the exponential moving average of the gradient norm of each task from the previous training step to obtain the stable gradient norm signal of each task and the historical exponential moving average of the loss of each task.
[0046] Specifically, before performing this step, a key hyperparameter, the smoothing factor α, needs to be preset. This parameter controls the weight of historical and current information in calculating the smoothed value. The value of α ranges from 0 to 1, and is set to a decimal close to 0, such as 0.1. A smaller α value means that historical information has a greater weight, the smoothing effect is stronger, and it can better suppress short-term fluctuations, but the response to changes in the real trend will be relatively lagging; conversely, a larger α value means that current information has a greater weight, the response to trend changes is more sensitive, but the smoothing effect is weaker. The choice of this value needs to be empirically adjusted according to the specific task and the characteristics of the dataset. This process uses the exponential moving average (EMA) method. This method generates a new smoothed value by recursively weighting the current observation with the smoothed value of the previous time step. In this application, this step includes two parallel and independent EMA calculation processes, one for the gradient norm and the other for the loss value. The first EMA process is for the gated gradient norm, aiming to generate a stable gradient norm signal. The input to this process is the gradient norm of the current time step from step 43: 3.25 for the classification task and 5.23 for the regression task. The execution process is as follows: First, step 441 is executed. This is a state maintenance operation that needs to be saved and retrieved in each iteration. In the first iteration of training (t=0), since there are no historical values, this value can be initialized to 0, or initialized to the gradient norm value calculated for the first time step. For example, in the previous training step, the exponential moving average of the gradient norm for the classification task and the regression task were 3.5 and 5.0, respectively. Next, step 442 is executed. The update formula is: New stabilized gradient norm signal = α * current time step gradient norm + (1-α) * exponential moving average of the gradient norm from the previous training step. Substituting the specific values: for the classification task, its new stabilized gradient norm signal = 0.1 * 3.25 + (1-0.1) * 3.5 = 3.475. For the regression task, the new stable gradient norm signal is 0.1 * 5.23 + (1 - 0.1) * 5.0 = 5.023. These two time-smoothed values, 3.475 and 5.023, are the final output stable gradient norm signals for each task. In parallel with the gradient norm smoothing process, this step also performs the same exponential moving average processing on the original loss values from step 23 for each task to obtain the historical exponential moving average of the loss for each task. This is to obtain a smooth loss benchmark representing the long-term learning difficulty of the task in subsequent weight calculations, so that the weight adjustment can take into account the relative difficulty of the task. The input to this process is two original loss scalar values from step 23: 0.87 for the classification task and -0.33 for the regression task. Its execution process is completely consistent with the gradient norm smoothing: first, the exponential moving average of the loss saved in the previous training step is extracted.In the previous training step, the EMA losses for the classification and regression tasks were 0.90 and -0.30, respectively. Then, updates are performed based on these historical and current values. The update formula is: New historical exponential moving average of loss = α * original scalar loss value + (1-α) * exponential moving average of loss saved in the previous training step. Substituting the specific values: For the classification task, the new historical exponential moving average of loss = 0.1 * 0.87 + (1-0.1) * 0.90 = 0.897. For the regression task, the new historical exponential moving average of loss = 0.1 * (-0.33) + (1-0.1) * (-0.30) = -0.303. These two values, 0.897 and -0.303, are the historical exponential moving averages of the loss for each task.
[0047] The final output consists of four key scalar values: the stable gradient norm signal for the classification task (3.475), the stable gradient norm signal for the regression task (5.023), the historical exponential moving average of the loss for the classification task (0.897), and the historical exponential moving average of the loss for the regression task (-0.303).
[0048] In particular, during the training of deep neural networks, model parameters exhibit high heterogeneity. For example, shallow parameters at the front of the network are typically responsible for learning general, relatively robust low-level features across different data samples, such as image edges and textures; while deep parameters at the back of the network focus on learning higher-level semantic features that are more closely related to specific tasks, more abstract, but potentially less stable. When the model faces difficult or noisy samples and generates high prediction uncertainty, using a single global gradient norm to measure the update intensity of the entire task will ignore these differences between parameters, potentially leading to indiscriminate suppression of the gradients of all parameters. This one-size-fits-all approach will incorrectly penalize shallow parameters that could continue to learn effectively, hindering the model from consolidating its fundamental knowledge. To overcome these limitations, a shift from calculating a single, unweighted global gradient norm and gating factor is needed to a fine-tuning mechanism that calculates a weighted gradient norm signal that better reflects the importance and sensitivity of parameters. This application introduces sensitivity-aware gradient information gating and smoothing, which no longer assumes that every gradient value in the gradient tensor is equivalent. Instead, it assigns a weight to the gradient of each parameter that is directly related to its sensitivity to model uncertainty. This allows for fine-grained differential adjustment of the gradient signal, avoiding drastic changes in the overall task weights due to sharp fluctuations in the gradients of a few key parameters. This enables the model to allocate its learning bandwidth more effectively: fully updating all parameters on high-deterministic data, while primarily updating and consolidating the basic model parameters on low-deterministic data, reducing exploration in incorrect directions, and thus potentially converging to a high-quality solution faster.
[0049] Based on this, in a preferred embodiment, step 4-1, based on the average uncertainty of the regression task, performs sensitivity-aware gradient information gating and smoothing on the original gradient of the regression task loss to obtain the stable gradient norm signal of the regression task and the historical exponential moving average of the regression task loss, including:
[0050] Step 4-11 involves probabilizing the variance set of each sample generated by the regression task head network, representing the shared features of the task, to obtain the probabilistic distribution of the regression task. It should be understood that the absolute value of the raw variance output by the regression task head network may vary depending on the data scale or model state, making direct use inconvenient for uniform sensitivity analysis. Therefore, to transform the raw, absolute measure of the prediction uncertainty (i.e., variance) for each sample into a standardized, relative, and comparable measure within the current micro-batch, it is probabilized using the following formula: Where n is the total number of samples in the current micro-batch, for example, it can be set to 64. This is the original variance predicted by the model for the i-th sample. Through the above probabilistic transformation, the original variance of each sample is converted into its contribution proportion to the total uncertainty of the entire batch, i.e., the probabilistic distribution. The sum of this distribution is 1, which makes subsequent calculations no longer affected by the magnitude of the absolute value of the original variance. This provides a stable and standardized input basis for calculating parameter sensitivity at a uniform scale, clearly identifying which samples in the current batch are the main sources of model uncertainty.
[0051] Step 4-12: Based on the probabilistic distribution of the regression task, calculate the weighting factors of each gradient in the original gradient of the regression task's loss. Accordingly, before weighting the gradients, the gradient θ of each parameter j in the shared model must first be quantized. j The degree of influence of uncertainty on each sample i in the micro-batch. This degree of influence is the sensitivity of the parameter. Only by accurately measuring this sensitivity can a precise suppression strategy be implemented subsequently. Therefore, this step is broken down into two core steps: First, calculate the sensitivity index for each parameter-sample pair; then, based on this sensitivity index, calculate the final weighting factor representing the average robustness of the parameters. The specific calculation process is as follows: First, calculate the Fisher information distribution of each gradient in the gradient tensor with respect to the log-likelihood concept rate, which can be understood as calculating the gradient θ of parameter j. j Sensitivity index S to the uncertainty of sample i i,j This sensitivity can be estimated by the response of the log-likelihood gradient (i.e., the square of the log-probabilistic variance) to the expected value of the current gradient, and the original gradient of the loss at the current time step can be approximated as the expected value of the current gradient. The calculation formula is as follows: Among them, S i,jThis is the sensitivity index of parameter j relative to sample i. A larger S i,j The value implies that parameter j is a lever parameter, and changes in its gradient significantly affect the model's judgment of uncertainty regarding sample i. Next, based on the calculated sensitivity index S... i,j The final weighting factor w is obtained by calculating the mean of its reciprocal over the entire micro-batch. j This inverse application (taking the reciprocal) can suppress the gradient of highly sensitive parameters. The calculation formula is as follows: Here, w j It is the factor ultimately used for weighting; θ j It is the original gradient of the regression task loss with respect to the j-th parameter of the shared model; This is the probabilistic variance of the i-th sample calculated in the previous step; i is the sample index, and j is the parameter index. Thus, through a two-stage calculation process, an independent scalar weighting factor w is ultimately generated for each parameter j in the shared model. j This w j It is no longer a black-box computational result, but rather a clear manifestation of the quantification and reverse application of parameter sensitivity. A smaller w j A value explicitly indicates that the corresponding parameter j is highly sensitive to model uncertainty, and its gradient should be suppressed in subsequent updates; conversely, a large w indicates that the parameter j is highly sensitive to model uncertainty. j The value indicates that the parameter is relatively robust, and its gradient should be protected. This process transforms the abstract concept of parameter importance into a concrete numerical value that can be directly used for gradient adjustment.
[0052] Step 4-13 involves weighting each gradient based on its weighting factor to obtain the weighted gradients, which serve as the original weighted gradients for the regression task's loss. It should be understood that the preceding steps have already prepared the weighting factor w for each parameter gradient. j To apply this adjustment factor to the corresponding gradient and modify the original gradient set, a parameter-wise multiplication operation is performed, transforming the original gradient θ... j With weighting factor w jMultiplying these results in a new weighted gradient. This yields a completely new set of gradients, the original weighted gradients of the regression task's loss. Compared to the original set, the gradient values within this new set have undergone uncertainty-aware differential scaling. Gradients of high-sensitivity parameters (typically in deeper layers) are effectively suppressed, while gradients of low-sensitivity parameters (typically in shallower layers) are preserved or even slightly enhanced. This weighted original loss gradient achieves precise suppression of uncertainty; when the model is uncertain about batch data, this uncertainty likely stems from certain high-level feature extraction layers (deeper layers) failing to properly process the input, rather than the entire network failing. Therefore, instead of indiscriminately suppressing gradients of all parameters, it more accurately and extensively suppresses the gradient signals of high-sensitivity parameters (typically in deeper layers) while less affecting the signals of low-sensitivity parameters (typically in shallower layers). Even in batches with high uncertainty, the low-level features (such as edges and textures) extracted by the shallow network may still be effective. By protecting the gradients of these parameters from being excessively weakened, the model can still consolidate and learn general basic knowledge when faced with difficult samples, preserving effective learning signals instead of stopping learning completely.
[0053] Step 4-14: Vectorize all gradient tensors in the original weighted gradient of the regression task loss and concatenate them to obtain the concatenated original gradient vector of the regression task loss. Step 4-15: Calculate the L2 norm of the concatenated original gradient vector of the regression task loss to obtain the current overall gradient magnitude scalar value of the regression task. Step 4-16: Input the average uncertainty of the regression task into the gating factor generation submodule to obtain the gating factor of the regression task. Step 4-17: Input the current overall gradient magnitude scalar value of the regression task and the gating factor of the regression task into the gating adjustment submodule to obtain the current gradient norm of the regression task. Step 4-18: Generate a stable gradient signal based on time-series smoothing from the current gradient norm of the regression task to obtain the stable gradient norm signal of the regression task and the historical exponential moving average of the regression task loss. In other words, by further integrating the gradient information that has undergone parameter-level fine-weighting, and performing task-level macro-control and time-series smoothing. First, by vectorizing and concatenating all weighted gradient tensors and calculating their L2 norm, a single scalar value representing the effective update intensity of the current task is obtained. This value inherently suppresses fluctuations caused by highly sensitive parameters. Then, the average uncertainty of the task is introduced as a gating factor to further adjust this refined gradient norm. This provides an additional safety mechanism, ensuring that the update amplitude is further limited and robustness is enhanced when the overall uncertainty of the task is extremely high. Finally, the adjusted gradient norm and task loss are smoothed by exponential moving average to filter out instantaneous noise and obtain a stable and representative learning signal, providing a reliable basis for subsequent dynamic task weight allocation, thereby ensuring the stability and convergence of the multi-task learning process. Specifically, the implementation of steps 4-14-4-18 here is the same as steps 41-44 in the above implementation scheme. It is worth mentioning that the above core method of gradient adjustment based on parameter sensitivity is not limited to regression models. Its core idea also applies to classification models. In this case, the uncertainty of the model's sample prediction is no longer measured by variance, but by information entropy. By using information entropy as a measure of uncertainty and performing similar probabilistic processing and sensitivity calculations, this method can perform equally fine-grained, parameter-sensitive weighted smoothing of gradients for classification tasks, thereby improving the training stability and performance of multi-task classification models.
[0054] In step 5, dynamic task weights are calculated using the stabilized gradient norm signal and the historical exponential moving average of the loss for each task to obtain the final weights for each task. Correspondingly, through the deep refinement of the gradient and loss signals in the preceding steps, stable values characterizing the long-term learning rate and learning difficulty of each task have been obtained. However, these independent signals have not yet been integrated into a unified final decision instruction to guide model updates. The core of multi-task optimization lies in dynamically balancing the training processes of different tasks, avoiding any one task from dominating or being ignored. This step is used to comprehensively consider and normalize the learning rate and relative difficulty of tasks based on these high-quality smoothed signals through a calculation rule, thereby generating a dynamic final weight with clear physical meaning for each task. This weight will directly determine the proportion of gradient information for each task in the next parameter update, serving as the final execution basis for achieving multi-task learning balance and collaborative optimization.
[0055] In one specific implementation, step 5 is performed as follows: First, the relative learning rate of each task is calculated. The purpose of this stage is to measure whether the learning speed of each task is faster or slower than the average level of all tasks. The first step is to calculate the arithmetic mean of the stable gradient norm signals of all tasks. In this embodiment, the average gradient norm = (stable gradient norm signal of the classification task + stable gradient norm signal of the regression task) / 2, i.e., (3.475 + 5.023) / 2 = 4.249. The second step is to divide the stable gradient norm signal of each task by this average to obtain its relative learning rate. The relative learning rate of the classification task = 3.475 / 4.249 ≈ 0.818. The relative learning rate of the regression task = 5.023 / 4.249 ≈ 1.182. These two values provide an intuitive comparison: a relative learning rate of less than 1 for the classification task indicates that its learning process is relatively slow; while a relative learning rate of greater than 1 for the regression task indicates that its learning process is relatively fast.
[0056] Next, the unnormalized weights for each task are calculated. This stage aims to generate an initial weight value by combining the relative learning rate of the task with its long-term average loss. This calculation can follow a pre-defined formula, for example: wi = L i / (ri^β), where wi is the unnormalized weight of task i, L iri is the historical exponential moving average of the loss of task i, ri is the relative learning rate of task i, and β is a hyperparameter used to adjust the sensitivity to differences in learning rate. When β is set to 1, it means that the weights are simply inversely proportional to the relative learning rate; when β is greater than 1, tasks that learn too quickly will be penalized more strongly; when β is less than 1, the penalty is weaker. In this embodiment, β can be set to 1. The unnormalized weights of the classification task = historical exponential moving average of the loss of the classification task / (relative learning rate of the classification task^1), i.e., 0.897 / (0.818^1) ≈ 1.097. The unnormalized weights of the regression task = historical exponential moving average of the loss of the regression task / (relative learning rate of the regression task^1), i.e., -0.303 / (1.182^1) ≈ -0.256.
[0057] This calculation result shows that classification tasks, due to their slower learning rate (<1), have a smaller denominator in their weight calculations, resulting in higher unnormalized weights; simultaneously, their higher historical average loss also contributes significantly to the numerator. Conversely, although regression tasks have a negative historical average loss, their faster learning rate (>1) increases the denominator, further reducing their unnormalized weights.
[0058] Finally, the unnormalized weights are normalized to obtain the final weights for each task. Since the unnormalized weights *wi* calculated in the previous step have uncertain ranges and their sum is not equal to 1, they cannot be directly used as coefficients for the weighted summation. Therefore, a normalization function is needed to convert them into a set of positive numbers that sum to 1. The Softmax function is ideal for this purpose. This function can map a set of arbitrary real numbers to the interval (0,1) and guarantees that their sum is 1. The calculation process is as follows: First, take the exponent for each unnormalized weight. exp(unnormalized weights for classification tasks) = exp(1.097) ≈ 2.995, exp(unnormalized weights for regression tasks) = exp(-0.256) ≈ 0.774. Then, calculate the sum of all exponent terms = 2.995 + 0.774 = 3.769. Finally, divide each exponent term by this sum to obtain the final weight. The final weight for the classification task is approximately 0.795 (2.995 / 3.769), and the final weight for the regression task is approximately 0.205 (0.774 / 3.769).
[0059] In step 6, the final weights of each task and the original loss gradients of each task are weighted and aggregated to obtain the aggregated gradient, which is then applied to the shared model. In other words, during the decision-making phase of the method, the complex, multi-dimensional learning signals have been successfully refined and synthesized into a concise, dynamic set of final weights. Simultaneously, in the early stages of the method, the original, independent modifications to the shared model parameters for each task, i.e., the original loss gradients, have been calculated. At this point, all the necessary elements for model updating are ready, but the final physical operation that changes the model state has not yet been executed. To execute the final chapter of the entire optimization loop, i.e., decision execution, this application uses dynamically calculated final weights as coefficients to weight and sum the original gradients of each task, thereby merging conflicting or synergistic opinions from multiple tasks into a unified, well-considered update direction. This aggregated instruction is then applied to the shared model, completing an effective and balanced learning iteration.
[0060] In one specific implementation, step 6 is performed as follows: The first stage is weighted gradient aggregation. The purpose of this stage is to merge two independent gradient sets representing different task update directions into a single aggregated gradient representing the overall update direction, based on the final weights calculated in step 5. This process is a parameter-wise linear combination. Its inputs are: the final weights of the classification task (e.g., 0.795), the final weights of the regression task (e.g., 0.205), and the original gradient sets of the classification task loss and regression task loss from step 3. The aggregation calculation process is as follows: For each trainable parameter in the shared model (whether it is a weight matrix or a bias vector), there are two corresponding original gradient tensors, one from the backpropagation of the self-classification task and the other from the backpropagation of the autoregression task. The aggregation operation is to perform a weighted summation of these two gradient tensors. Specifically, the gradient tensor of the classification task is taken out, and all its elements are multiplied by the final weight of the classification task (0.795); at the same time, the gradient tensor of the regression task is taken out, and all its elements are multiplied by the final weight of the regression task (0.205). Then, the two weighted and scaled gradient tensors are summed element-wise to obtain the aggregated gradient of that specific parameter. To illustrate this more clearly, let's take a specific example from a patent application and work backwards. Consider a specific weight parameter in a shared model, with a current value of 0.05. In step 3, the original gradient of the classification task loss with respect to this parameter is calculated as -0.0012, while the original gradient of the regression task loss with respect to this parameter is +0.0008. These two gradients are in opposite directions, reflecting the conflict between tasks. The calculation process for weighted gradient aggregation is: Aggregated gradient = (Final weight of classification task * Original gradient of classification task) + (Final weight of regression task * Original gradient of regression task) = (0.795 * (-0.0012)) + (0.205 * (+0.0008)) = -0.00079. This calculation result is the final aggregated gradient of that specific parameter. It's a compromise: because the classification task receives higher weights, the final update direction is consistent with the original gradient direction of the classification task (both are negative), but its magnitude (-0.00079) is smaller than the original gradient magnitude (-0.0012), which is a result of the regression task exerting its influence with smaller weights. It's worth noting that this calculation process is performed in parallel on all trainable parameters of the shared model. Ultimately, a new set of gradients is obtained that is completely consistent with the parameter structure of the shared model; this is the aggregated gradient. This aggregated gradient represents the unified and comprehensive adjustment direction that the model parameters should follow in the current iteration to simultaneously optimize all tasks.
[0061] The second stage involves applying the aggregated gradients to the shared model, i.e., parameter updates. This stage utilizes an optimizer to perform the actual parameter tuning. An optimizer is an algorithm that updates the parameters of the neural network based on the calculated gradients, aiming to minimize the loss function. Commonly used optimizers include stochastic gradient descent (SGD), Adam, and RMSprop. In this embodiment, the Adam optimizer can be chosen because it combines the advantages of momentum and adaptive learning rate, typically exhibiting fast convergence and robust performance. Before using the Adam optimizer, its related hyperparameters need to be set. The most critical parameter is the learning rate, a global scalar that controls the step size of each parameter update. The setting of the learning rate is crucial to the training effect; too large a rate may lead to unstable training or even divergence, while too small a rate may result in slow convergence. Its value needs to be determined through experimental tuning; a common initial setting range is between 1e-5 and 1e-3, for example, it can be set to 0.0001. The Adam optimizer also includes other hyperparameters, such as the exponential decay rates β1 and β2 used to calculate the first and second moment estimates of the gradient, which are defaulted to 0.9 and 0.999 respectively, and a minimum value epsilon (set to 1e-8) added to prevent division by zero. These default settings were ultimately determined through extensive empirical experiments on diverse deep learning tasks. The parameter update process is as follows: The aggregated gradient set calculated in the previous step is input into the configured Adam optimizer. The optimizer maintains a first-moment estimate (exponential moving average of the gradient) and a second-moment estimate (exponential moving average of the squared gradient) of the gradient for each parameter in the model. At each iteration, the optimizer first updates these two moment estimates using the current aggregated gradient. Then, it corrects the bias of these moment estimates to address the problem of them being biased towards zero in the early stages of training. Finally, the optimizer calculates the final update amount for each parameter based on the corrected first-moment estimate, the square root of the second-moment estimate, and the global learning rate. The update rule is roughly as follows: the parameter update amount is proportional to the corrected first-order moment estimate and inversely proportional to the square root of the corrected second-order moment estimate. This mechanism allows the optimizer to automatically adapt to different learning rates for different parameters, using a larger update step size for parameters with gentle gradient changes and a smaller update step size for parameters with drastic gradient changes. Specifically, if the aggregated gradient is -0.00079, the Adam optimizer will calculate a specific update amount, such as -0.00009, based on this value and its internally maintained historical state. Subsequently, the new value of the parameter will be calculated as: new parameter value = old parameter value - update amount = 0.05 - (-0.00009) = 0.05009. This update operation will be applied to all trainable parameters in the shared model simultaneously. In this way, all parameters of the shared model undergo a small but beneficial adjustment based on a unified gradient direction that integrates all task requirements and is dynamically weighted.This marks the end of a complete training iteration cycle. Next, the entire process will return to step 1, obtain the next micro-batch of data, and begin a new round of iterations, repeating this process continuously until the model converges or reaches the preset number of training cycles.
[0062] In summary, the multi-task deep optimization method based on dynamic weight allocation, as described in this application, is explained. To address the training instability caused by micro-batch gradient noise in dynamic weight allocation, this application introduces a dual stabilization mechanism. First, the task uncertainty estimated during forward propagation is used as a gating signal for gradient information. By evaluating the model's reliability for the current data batch, drastic gradient fluctuations caused by noise or outliers are actively suppressed. Second, based on gating adjustment, the gradient norm signal is further subjected to temporal smoothing. Combined with historical training information (such as generating a stable signal based on the moving average of the gradient norm from the previous training step), instantaneous disturbances are eliminated, thereby generating a stable gradient signal for final weight calculation. This strategy, combining uncertainty gating and temporal smoothing, effectively avoids drastic oscillations in task weights due to instantaneous noise, ensuring the training stability and convergence performance of the shared model during multi-task optimization.
Claims
1. A multi-task deep optimization method based on dynamic weight allocation, characterized in that, include: Obtain micro-batch input data and micro-batch multi-task label data. The micro-batch input data is a structured set containing product image tensors and text tensors, and the micro-batch multi-task label data is a structured set containing product category label tensors and rating label tensors. Forward propagation and uncertainty estimation are performed on micro-batch input data and micro-batch multi-task label data to obtain task-shared feature representations, the original loss of each task, and the average uncertainty of each task. Calculate the gradient of the original loss for each task relative to the parameters of the shared model to obtain the original gradient of the loss for each task. Based on the average uncertainty of each task, gradient information gating and smoothing are performed on the original gradient of the loss of each task to obtain the stable gradient norm signal of each task and the historical exponential moving average of the loss of each task. Dynamic task weights are calculated by using the stabilized gradient norm signal of each task and the historical exponential moving average of the loss of each task to obtain the final weight of each task. The final weights of each task and the original gradients of the loss of each task are weighted and aggregated to obtain the aggregated gradient, and the aggregated gradient is applied to the shared model.
2. The multi-task deep optimization method based on dynamic weight allocation according to claim 1, characterized in that, Forward propagation and uncertainty estimation are performed on micro-batch input data and micro-batch multi-task label data to obtain task-shared feature representations, the original loss of each task, and the average uncertainty of each task, including: The micro-batch input data is input into the shared model to obtain the task-shared feature representation; The task-shared feature representation is input into each task head network to obtain the prediction results for each task and the average uncertainty of each task. Based on the prediction results of each task and the micro-batch multi-task label data, the original loss of each task is calculated.
3. The multi-task deep optimization method based on dynamic weight allocation according to claim 1, characterized in that, Calculating the gradient of the original loss of each task relative to the parameters of the shared model to obtain the original gradient of the loss for each task includes: calculating the gradient of the original loss of each task relative to the parameters of the shared model using an automatic differentiating function to obtain the original gradient of the loss for each task.
4. The multi-task deep optimization method based on dynamic weight allocation according to claim 3, characterized in that, Based on the average uncertainty of each task, gradient information gating and smoothing are applied to the original gradient of the loss for each task to obtain the stable gradient norm signal and the historical exponential moving average of the loss for each task, including: The original gradients of the loss for each task are input into the gradient norm calculation submodule to obtain the current overall gradient magnitude scalar value for each task. The average uncertainty of each task is input into the gating factor generation submodule to obtain the gating factor for each task; The current gradient total magnitude scalar value of each task and the gating factor of each task are input into the gating adjustment submodule to obtain the current gradient norm of each task. A stable gradient signal based on time-series smoothing is generated for the current gradient norm of each task to obtain the stable gradient norm signal of each task and the historical exponential moving average of the loss of each task.
5. The multi-task deep optimization method based on dynamic weight allocation according to claim 4, characterized in that, The original gradients of the losses for each task are input into the gradient norm calculation submodule to obtain the current overall gradient magnitude scalar value for each task, including: Vectorize all gradient tensors in the original gradient of the loss of each task and concatenate the vectors to obtain the concatenated vector of the original gradient of the loss of each task. Calculate the L2 norm of the original gradient concatenation vector for each task loss to obtain the current overall gradient magnitude scalar value for each task.
6. The multi-task deep optimization method based on dynamic weight allocation according to claim 4, characterized in that, The average uncertainty of each task is input into the gating factor generation submodule to obtain the gating factor for each task, including: calculating the gating factor for each task using the following formula: in, The average uncertainty of each task, It is the value of an exponential function with the natural constant e as its base. These are the gating factors for each task.
7. The multi-task deep optimization method based on dynamic weight allocation according to claim 4, characterized in that, The current-time gradient norm of each task is used to generate a stable gradient signal based on time-series smoothing to obtain the stable gradient norm signal of each task and the historical exponential moving average of the loss of each task, including: Extract the gradient norm exponential moving average of the previous training step for each task; Based on the exponential moving average of the gradient norm of each task in the previous training step, the current gradient norm of each task is exponentially moved averaged to obtain the stable gradient norm signal of each task and the historical exponential moving average of the loss of each task.