Code processing method and device, electronic equipment and computer readable storage medium

CN122111392APending Publication Date: 2026-05-29BEIJING 360 INTELLIGENT TECHNOLOGY CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
BEIJING 360 INTELLIGENT TECHNOLOGY CO LTD
Filing Date
2024-11-27
Publication Date
2026-05-29

Smart Images

  • Figure CN122111392A_ABST
    Figure CN122111392A_ABST
Patent Text Reader

Abstract

Embodiments of the present application disclose a code processing method and device, electronic equipment and computer readable storage medium, the method comprises: obtaining a code processing task for a multi-task code processing large model, and at least two model processing task types corresponding to the multi-task code processing large model, determining the target task type of the code processing task; when the target task type is the model processing task type, the code processing task is processed by the multi-task code processing large model using the model processing task type to obtain the code processing result; wherein the multi-task code processing large model is obtained after the basic code processing large model is subjected to target multi-task joint training. Thus, the technical problem that the large model is often limited to a specific type of code processing task after training is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a code processing method, apparatus, electronic device, and computer-readable storage medium. Background Technology

[0002] In recent years, with the rapid development of deep learning technology, large models, after being trained, can process code for specific code processing tasks. However, large models are often limited to specific types of code processing tasks after training. Summary of the Invention

[0003] This application provides a code processing method, apparatus, electronic device, and computer-readable storage medium, which can solve the technical problem that large models are often limited to specific types of code processing tasks after training.

[0004] In a first aspect, embodiments of this application provide a code processing method, the method comprising:

[0005] Obtain the code processing tasks for the multi-task code processing large model, and at least two model processing task types corresponding to the multi-task code processing large model, and determine the target task type of the code processing task.

[0006] When the target task type is the model processing task type, the multi-task code processing model uses the model processing task type to process the code processing task and obtain the code processing result.

[0007] The multi-task code processing big model is obtained by training the basic code processing big model through target multi-task joint training.

[0008] Optionally, the method further includes:

[0009] Determine the basic code processing model and obtain the task training sample set corresponding to the task type processed by each model;

[0010] The target multi-task joint training is performed on the basic code processing large model using the task training sample set corresponding to all model processing task types to obtain the multi-task code processing large model.

[0011] The loss function corresponding to the target multi-task joint training includes at least one of the following: multi-task attention weight loss term, multi-task difficulty weight loss term, and multi-task convergence speed loss term.

[0012] Optionally, the method further includes:

[0013] In the target multi-task joint training, the effective word units corresponding to each task training sample in the entire task training sample set are determined;

[0014] Obtain the model attention weights corresponding to each effective word unit in the target multi-task joint training, and construct the multi-task attention weight loss term based on the model attention weights corresponding to each effective word unit.

[0015] The loss function is constructed using at least the multi-task attention weight loss term, and the target multi-task joint training is performed on the basic code processing large model based on the loss function to obtain the multi-task code processing large model.

[0016] The loss value corresponding to the multi-task attention weight loss term is negatively correlated with the overall model attention weight corresponding to the effective word unit. The effective word unit is the word unit in the word unit corresponding to the training sample of each task that participates in the calculation of the loss function corresponding to the target multi-task joint training.

[0017] Optionally, the method further includes:

[0018] The multi-task difficulty weight loss term is determined based on at least one of the first loss term, the second loss term, and the third loss term;

[0019] The loss function is constructed using at least the multi-task attention weight loss term, and the target multi-task joint training is performed on the basic code processing large model based on the loss function to obtain the multi-task code processing large model.

[0020] The first loss term is constructed based on the negative of the weight balance factor corresponding to the task type of each model and the effective word unit learning difficulty representation term of the effective word unit in the training sample of the task type of each model. The effective word unit learning difficulty representation term is constructed based on the target unit type prediction probability value of the effective word unit and the prediction failure probability value corresponding to the target unit type prediction probability value. The weight balance factor is greater than 0 and less than 1.

[0021] The second loss term is constructed based on the negative of the weight balance factor corresponding to the task type processed by each model and the task training sample learning difficulty representation term corresponding to the task training sample processed by each model. The task training sample learning difficulty representation term is constructed based on the prediction failure probability value of the target sample type prediction probability value corresponding to the task training sample and the representation value of the target sample type prediction probability of the task training sample processed by each model.

[0022] The third loss term is constructed based on the negative of the weight balance factor corresponding to each model task type and the learning difficulty representation term corresponding to each model task type. The learning difficulty representation term is constructed based on the prediction failure probability value of the prediction probability value of the model task type and the representation value of the prediction probability of the model task type.

[0023] Optionally, the method further includes:

[0024] Determine the original loss function corresponding to the task type processed by each model;

[0025] In the target multi-task joint training, the loss gradient term of the original loss function corresponding to the task type processed by each model is determined;

[0026] Determine the task weights for each model's task type and the loss values ​​of the original loss functions corresponding to each model's task type. Based on the task weights, perform a weighted summation of the loss values ​​of the original loss functions corresponding to all model task types to obtain the total model loss term.

[0027] A multi-task convergence speed loss term is constructed based on the loss gradient term and the total model loss term. The loss function is constructed using at least the multi-task convergence speed loss term. Based on the loss function, the target multi-task joint training is performed on the basic code processing large model to obtain the multi-task code processing large model.

[0028] The convergence speed balancing loss function is negatively correlated with w, where w is the task weight of the model processing task type, which is the loss gradient term with the smallest loss gradient value among the loss gradient terms of the original loss function corresponding to each model processing task type.

[0029] Optionally, the step of using the task training sample set corresponding to all model processing task types to perform target multi-task joint training on the basic code processing large model to obtain the multi-task code processing large model includes:

[0030] The initial multi-task code processing large model is obtained by training the basic code processing large model using the task training sample set corresponding to all model processing task types.

[0031] Obtain the user's preference response features and non-preference response features for the task type processed by the model. Based on the direct preference optimization algorithm, the preference response features and the non-preference response features, perform model preference fine-tuning on the initial multi-task code processing large model to obtain the multi-task code processing large model.

[0032] Optionally, the method further includes:

[0033] The multi-task difficulty weight loss term is determined based on the first loss term, the second loss term, and the third loss term;

[0034] Wherein, the multi-task difficulty weight loss term is L1(θ), L1(θ)=a1×loss1(θ)+a2×loss2(θ)+a3×loss3(θ); where loss1(θ) is the first loss term, a1 is the first weight corresponding to loss1(θ), loss2(θ) is the second loss term, a2 is the second weight corresponding to loss2(θ), loss3(θ) is the third loss term, a3 is the third weight corresponding to loss3(θ), a1, a2 and a3 are all greater than 0 and less than 1, and a1+a2+a3=1.

[0035] Optionally, the method further includes:

[0036] The loss function is determined based on the multi-task attention weight loss term, the multi-task difficulty weight loss term, and the multi-task convergence speed loss term;

[0037] Wherein, the multi-task difficulty weight loss term is L1(θ), the multi-task attention weight loss term is L2(θ), the multi-task convergence speed loss term is L3(θ), and the loss function is L(θ), L(θ)=r1×L1(θ)+r2×L2(θ)+r3×L3(θ), where r1 is the first loss weight corresponding to L1(θ), r2 is the second loss weight corresponding to L2(θ), and r3 is the third loss weight corresponding to L3(θ). r1, r2, and r3 are all greater than 0 and less than 1, and r1+r2+r3=1.

[0038] Optionally, the at least two models handle task types including code review task type, vulnerability remediation task type, unit testing task type, and vulnerability inspection task type.

[0039] Secondly, embodiments of this application provide a code processing apparatus, the apparatus comprising:

[0040] The determination module is adapted to acquire code processing tasks for a large multi-task code processing model, and at least two model processing task types corresponding to the large multi-task code processing model, and determine the target task type of the code processing task.

[0041] The code processing module is adapted to process the code processing task using the multi-task code processing model when the target task type is the model processing task type, and obtain the code processing result.

[0042] Thirdly, embodiments of this application provide an electronic device, which includes:

[0043] Processor; and

[0044] A memory configured to store computer-executable instructions, which, when executed, cause the processor to perform the method according to any one of the preceding descriptions.

[0045] Fourthly, embodiments of this application provide a computer-readable storage medium that stores one or more programs, which, when executed by a processor, implement the method described in any one of the above-described methods.

[0046] The beneficial effects of the technical solution provided in this application include at least the following: by conducting joint training on multiple target tasks, the basic code processing large model can learn the characteristics of code processing tasks of different model types. This solves the technical problem that large models, after training, are limited to specific code processing tasks and struggle to accurately process multiple types of code processing tasks. Attached Figure Description

[0047] To more clearly illustrate the technical solutions in the embodiments of this application 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 only some embodiments of the embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0048] Figure 1 An exemplary system architecture diagram of a data processing method provided in this application embodiment;

[0049] Figure 2 A flowchart illustrating a code processing method provided in an embodiment of this application;

[0050] Figure 3 A flowchart illustrating the determination of a large multi-task code processing model is provided for an embodiment of this application;

[0051] Figure 4 A flowchart illustrating the process of determining multi-task attention weight loss terms, provided for an embodiment of this application;

[0052] Figure 5 A flowchart illustrating the process of determining a multi-task convergence speed loss term, provided for an embodiment of this application;

[0053] Figure 6 A flowchart illustrating another method for determining a large multi-task code processing model, provided in an embodiment of this application;

[0054] Figure 7 This application provides a schematic diagram of a process for fine-tuning model preferences.

[0055] Figure 8 This application provides a schematic diagram of the structure of a code processing apparatus according to an embodiment of the present application.

[0056] Figure 9 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0057] To make the features and advantages of the embodiments of this application more apparent and understandable, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the protection scope of the embodiments of this application.

[0058] In related technologies, the generation and processing of office document data increasingly rely on intelligent agents for collaborative processing. An intelligent agent is a software, system, or entity capable of perceiving its environment, making decisions, and taking actions. Some intelligent agents perform a series of code processing steps on the generated code during the collaborative generation and processing of office document data, such as checking for and fixing code vulnerabilities. Large models, after training, can process code for specific tasks; however, large models are often limited to specific types of code processing tasks and struggle to accurately handle diverse code processing tasks.

[0059] To address the existing technical problems, this application provides a code processing method. The method includes obtaining a code processing task for a multi-task code processing large model, and at least two model processing task types corresponding to the multi-task code processing large model; determining the target task type of the code processing task; when the target task type is a model processing task type, processing the code processing task using the model processing task type through the multi-task code processing large model to obtain the code processing result; wherein the multi-task code processing large model is obtained by jointly training the basic code processing large model with the target multi-task model. This solves the technical problem that large models, after training, are limited to specific code processing tasks and struggle to accurately process multiple types of code processing tasks.

[0060] Please see Figure 1 , Figure 1 An exemplary system architecture diagram of a data processing method provided in an embodiment of this application.

[0061] like Figure 1 As shown, the system architecture may include electronic device 101, network 102, and server 103. Network 102 serves as the medium for providing a communication link between electronic device 101 and server 103. Network 102 may include various types of wired or wireless communication links, such as: wired communication links including fiber optic, twisted-pair, or coaxial cable; and wireless communication links including Bluetooth, Wi-Fi (Wireless Fidelity), or microwave communication links, etc.

[0062] Electronic device 101 can interact with server 103 via network 102 to receive messages from or send messages to server 103. Alternatively, electronic device 101 can interact with server 103 via network 102 to receive messages or data sent to server 103 by other users. Electronic device 101 can be hardware or software. When electronic device 101 is hardware, it can be various electronic devices, including but not limited to smartwatches, smartphones, tablets, laptops, and desktop computers. When electronic device 101 is software, it can be installed in the aforementioned electronic devices and can be implemented as multiple software programs or software modules (e.g., to provide distributed services) or as a single software program or software module; no specific limitation is made here.

[0063] Server 103 can be a business server providing various services. It should be noted that server 103 can be either hardware or software. When server 103 is hardware, it can be implemented as a distributed server cluster consisting of multiple servers, or as a single server. When server 103 is software, it can be implemented as multiple software programs or software modules (e.g., used to provide distributed services), or as a single software program or software module; no specific limitations are made here.

[0064] In this embodiment of the application, the electronic device 101 can acquire the code processing task for the multi-task code processing large model, and at least two model processing task types corresponding to the multi-task code processing large model, and determine the target task type of the code processing task; when the target task type is a model processing task type, the multi-task code processing large model processes the code processing task using the model processing task type to obtain the code processing result; wherein, the multi-task code processing large model is obtained by training the basic code processing large model through joint training of the target multi-task.

[0065] It should be understood that the number of electronic devices, networks, and servers described above is merely illustrative, and can be any number of electronic devices, networks, and servers depending on implementation needs. Of course, in one embodiment provided in this application, the system architecture may not include servers.

[0066] Please see Figure 2 , Figure 2 This is a flowchart illustrating a code processing method provided in an embodiment of this application. The execution entity in this embodiment can be an electronic device executing the code processing method, a processor within that electronic device, or a code processing service within the same electronic device. For ease of description, the following example uses a processor within an electronic device as the execution entity to illustrate the specific execution process of the code processing method.

[0067] The code processing methods include:

[0068] S202: Obtain the code processing task for the multi-task code processing large model, as well as at least two model processing task types corresponding to the multi-task code processing large model, and determine the target task type of the code processing task.

[0069] The system utilizes a multi-task code processing model to receive code processing tasks. This model handles code processing tasks corresponding to at least two model task types, including code review, vulnerability patching, unit testing, and vulnerability checking. It's important to note that multi-task learning allows the model to learn multiple related tasks together, benefiting from shared knowledge, thus improving model performance, enhancing generalization ability, and effectively addressing data scarcity. Therefore, the code processing tasks corresponding to the at least two model task types within the multi-task code processing model should possess task correlations. This allows the multi-task code processing model to be fine-tuned during training to simultaneously improve its processing capabilities for different types of code processing tasks, thereby enhancing its performance across various tasks.

[0070] Furthermore, the code processing tasks corresponding to the code review task type refer to reviewing code during the software code development process to ensure code quality and improve security and performance; the code processing tasks corresponding to the vulnerability remediation task type refer to patching, updating program code, or modifying configurations after discovering security vulnerabilities in the code to ensure system security and prevent attacks exploiting these vulnerabilities; the code processing tasks corresponding to the unit testing task type refer to checking and verifying the code corresponding to the smallest testable part of the program during the software code development process, that is, dividing the program code into small units and then testing these units one by one to ensure that they can execute correctly; the code processing tasks corresponding to the vulnerability inspection task type refer to finding potential security vulnerabilities when conducting security assessments of the code.

[0071] To determine whether a large multi-task code processing model can handle code processing tasks specific to it, after identifying at least two model processing task types corresponding to the large multi-task code processing model, the target task type of the code processing task is determined. This determines whether the target task type belongs to the at least two model processing task types corresponding to the large multi-task code processing model. If the target task type does not belong to the at least two model processing task types corresponding to the large multi-task code processing model, then the code processing task is not within the model processing scope of the large multi-task code processing model.

[0072] S204: When the target task type is the model processing task type, the multi-task code processing large model is used to process the code processing task by utilizing the model processing task type to obtain the code processing result; wherein, the multi-task code processing large model is obtained by the basic code processing large model after joint training of the target multi-task.

[0073] When the target task type is determined as the model processing task type, the multi-task code processing model determines the model processing strategy for the code processing task based on the model processing task type corresponding to the target task type. Different model processing task types correspond to different model processing strategies for the code processing tasks. After determining the model processing strategy for the code processing task, the multi-task code processing model processes the code processing task accordingly based on the model processing strategy to obtain the code processing result.

[0074] To enable the multi-task code processing model to adapt to the characteristics of code processing tasks corresponding to different model task types, the basic code processing model can be jointly trained using a target multi-task approach. Specifically, the basic code processing model can be jointly trained using a target multi-task approach using a training sample set corresponding to all model task types, thus obtaining the multi-task code processing model.

[0075] To obtain a large-scale model for basic code processing, the Code Llama model can be further trained on the LLaMA-Factory framework. LLaMA-Factory is a large-scale model training framework for fine-tuning large language models, while the Code Llama model is a large-scale code generation model. This training process includes the following steps: first, pre-training; second, supervised fine-tuning via instructions; and third, training the reward model to guide reinforcement learning. The reward model training supports different training modes, including training on a single node or distributed training across multiple nodes. It can train on all data or perform lightweight fine-tuning (e.g., using LoRA). The number of training epochs can be set relatively low to prevent overtraining, thus avoiding damage to the model's original performance. Specifically, training can begin with a small learning rate to allow the neural network to become familiar with the data. As training progresses, the learning rate gradually increases, eventually returning to the initial learning rate. After several iterations, the learning rate gradually decreases again. The learning rate change can initially increase, then remain stable, and finally decrease. To obtain the base code for processing the large model, eight A100 GPUs (Graphics Processing Units) can be configured to perform the training task. The training task configuration parameters include a learning rate of 0.0001; 8 training samples per batch; 1 total training epoch; 100 warm-up steps; and a weight decay value of 0.015.

[0076] The technical solution provided in this application enables a large basic code processing model to learn the characteristics of code processing tasks of different model types through joint training of multiple tasks. This solves the technical problem that large models, after training, are limited to specific code processing tasks and struggle to accurately handle multiple types of code processing tasks.

[0077] Please see Figure 3 , Figure 3 This is a flowchart illustrating a method for determining a large-scale multi-task code processing model, as provided in an embodiment of this application. Figure 3 As shown, the method includes:

[0078] S302: Determine the basic code to process the large model, and obtain the task training sample set corresponding to the task type processed by each model.

[0079] The process for determining the large-scale model for basic code processing can be found in the relevant description in S204, and will not be repeated here. Each model processing task type corresponds to one or more task training sample sets. The task training sample set includes multiple task training samples, and each task training sample carries the sample code processing result corresponding to that task training sample. The task training sample set is used to train the large-scale model for basic code processing.

[0080] S304: Use the task training sample set corresponding to all model processing task types to perform target multi-task joint training on the basic code processing large model to obtain a multi-task code processing large model; wherein, the loss function corresponding to the target multi-task joint training includes at least one of the following: multi-task attention weight loss term, multi-task difficulty weight loss term, and multi-task convergence speed loss term.

[0081] The loss function corresponding to the multi-task joint training includes at least one of the following: multi-task attention weight loss term, multi-task difficulty weight loss term, and multi-task convergence speed loss term. Therefore, the loss function can include the multi-task attention weight loss term, the multi-task difficulty weight loss term, and the multi-task convergence speed loss term; or, the loss function can include two of the following: multi-task attention weight loss term, multi-task difficulty weight loss term, and multi-task convergence speed loss term; or, the loss function can include one of the following: multi-task attention weight loss term, multi-task difficulty weight loss term, and multi-task convergence speed loss term.

[0082] When the loss function includes a multi-task attention weight loss term, as the model loss value of the loss function continuously decreases, the multi-task attention weight loss term allows the basic code processing model to appropriately adjust the attention weights of word units when handling code processing tasks of different model processing task types. It increases the attention weights of word units involved in the loss function calculation for each model processing task type, while decreasing the attention weights of word units not involved in the loss function calculation. Because the attention weights of word units involved in the loss function calculation are increased, the multi-task attention weight loss term allows the basic code processing model to quickly adjust the model parameters related to word units involved in the loss function calculation during model parameter updates, thereby shortening the target multi-task joint training time and improving model training efficiency.

[0083] When the loss function includes a multi-task difficulty weight loss term, as the model loss value of the loss function continuously decreases, the multi-task difficulty weight loss term is used to enable the basic code processing model to allocate attention weights based on the model label prediction difficulty of the code processing task, the task training sample corresponding to the code processing task, or the word source unit corresponding to the task training sample when dealing with code processing tasks of different model processing task types. More attention weights are allocated to features that are more difficult for the basic code processing model to learn, and fewer attention weights are allocated to features that are easier for the basic code processing model to learn. This allows the basic code processing model to quickly learn the features of different model processing task types of code processing tasks during the model parameter update process through the loss function.

[0084] When the loss function includes a multi-task difficulty weight loss term, as the model loss value of the loss function continuously decreases, the multi-task difficulty weight loss term is used to maximize the weight of the code processing task with the slowest convergence speed when the basic code processing model is dealing with different code processing task types. This allows for rapid optimization of the model parameters corresponding to the code processing task with the slowest convergence speed during the joint training of the target multi-task task, thereby deepening the learning of the features corresponding to the code processing task with the slowest convergence speed by the basic code processing model, shortening the joint training time of the target multi-task task, and improving the model training efficiency.

[0085] After the basic code processing model is jointly trained with the target multi-task model, an initial multi-task code processing model is obtained. At this time, the initial multi-task code processing model can be used to process code processing tasks corresponding to at least two types of model processing tasks.

[0086] In one feasible embodiment, the loss function is determined based on the multi-task attention weight loss term, the multi-task difficulty weight loss term, and the multi-task convergence speed loss term.

[0087] The loss term is L1(θ), the multi-task difficulty weight loss term is L2(θ), the multi-task attention weight loss term is L3(θ), and the loss function is L(θ), where L(θ) = r1×L1(θ) + r2×L2(θ) + r3×L3(θ), r1 is the first loss weight corresponding to L1(θ), r2 is the second loss weight corresponding to L2(θ), and r3 is the third loss weight corresponding to L3(θ). r1, r2, and r3 are all greater than 0 and less than 1, and r1 + r2 + r3 = 1. It is easy to understand that the distribution of the loss weights can be flexibly adjusted based on the user's priorities.

[0088] In the embodiments provided in this application, during the process of updating model parameters of the basic code processing large model using the loss function through target multi-task joint training, the multi-task attention weight loss term can quickly adjust the model parameters participating in the loss function calculation in the word unit, thereby shortening the target multi-task joint training time and improving model training efficiency. Simultaneously, the multi-task difficulty weight loss term can allocate more attention weights to features that are difficult for the basic code processing large model to learn, and less attention weights to features that are easier for the basic code processing large model to learn. This allows the basic code processing large model to quickly learn the features of different model processing task types during the model parameter update process through the loss function. Furthermore, the multi-task convergence speed loss term can deepen the basic code processing large model's learning of the features corresponding to the code processing task type with the slowest convergence speed, thereby shortening the target multi-task joint training time and improving model training efficiency. This solves the technical problem that large models, after training, can process code for specific code processing tasks, but are often limited to specific types of code processing tasks after training, making it difficult to accurately process multiple types of code processing tasks.

[0089] Please see Figure 4 , Figure 4 This is a schematic diagram illustrating a process for determining multi-task attention weight loss terms, provided as an embodiment of this application. Figure 4 As shown, the method includes:

[0090] S402: In multi-task joint training of the target, determine the effective word units corresponding to each task training sample in the entire task training sample set.

[0091] Each model handles a task type and corresponds to one or more task training sample sets. Each task training sample set includes multiple task training samples, and each task training sample carries the processing result of the corresponding sample code. These task training sample sets are used to train the large-scale basic code processing model. The large-scale basic code processing model is then jointly trained using the task training sample sets corresponding to all model task types.

[0092] Since the at least two task types handled by the multi-task code processing large model are interrelated, the basic code processing large model can be jointly trained on multiple tasks using the task training sample set corresponding to all task types handled by the models. This allows the multi-task code processing large model to be fine-tuned during training to simultaneously improve its processing capabilities for different types of code processing tasks, thereby enhancing the model's performance on various tasks.

[0093] In multi-task joint training, after each iteration, the word units corresponding to the training samples of each task that participate in the calculation of the model loss value of the corresponding loss function for multi-task joint training are identified. These word units are then considered the effective word units corresponding to the training samples of each task. It's easy to understand that since effective word units participate in the calculation of the model loss value of the loss function, the model parameters associated with these effective word units can be optimized to quickly improve the model loss value. Specifically, the model attention weights for effective word units can be increased, allowing the base code processing large models to fully learn the features of effective word units, thereby quickly optimizing the model loss value.

[0094] S404: Obtain the model attention weights corresponding to each effective word unit in the target multi-task joint training, and construct a multi-task attention weight loss term based on the model attention weights corresponding to each effective word unit.

[0095] Valid word units are those word units in the training samples for each task that participate in the calculation of the loss function corresponding to the multi-task joint training of the target. Invalid word units are those word units in the training samples for each task that do not participate in the calculation of the loss function.

[0096] After determining the effective lexical units, the model attention weights corresponding to each effective lexical unit in the target multi-task joint training are obtained. The model attention weights are the attention weights assigned by the self-attention mechanism of the large model for processing the basic code.

[0097] Next, a multi-task attention weight loss term is constructed using the model attention weights corresponding to each effective word unit. For example, the multi-task attention weight loss term is L2(θ).

[0098]

[0099] Where θ is the model parameter of the basic code processing large model, N is the total number of model processing task types corresponding to the basic code processing large model, and M is the model parameter of the basic code processing large model. i T represents the total number of task training samples in the task training sample set corresponding to the task type processed by the i-th model. ij Taken represents the total number of valid word units in the j-th sample of the training sample set corresponding to the task type of the i-th model. ijk For the i-th model, P is the k-th effective word unit in the j-th sample of the task training sample set corresponding to the task type. θ P is the function for calculating the model attention weights. θ (taken ijk ) is taken ijk The model attention weights.

[0100] It is easy to see that in order to reduce the value of the loss function corresponding to the multi-task joint training of the target, the loss value corresponding to the multi-task attention weight loss term needs to be gradually reduced, then P θ (taken ijk The overall model attention weight corresponding to an effective word unit continuously increases, meaning the overall model attention weight corresponding to an effective word unit can be... Therefore, the loss value corresponding to the multi-task attention weight loss term is negatively correlated with the overall model attention weight corresponding to the effective word unit.

[0101] S406: At least utilize the multi-task attention weight loss term to construct a loss function, and perform target multi-task joint training on the basic code processing large model based on the loss function to obtain the multi-task code processing large model; wherein, the loss value corresponding to the multi-task attention weight loss term is negatively correlated with the overall model attention weight corresponding to the effective word unit, and the effective word unit is the word unit in the word unit corresponding to the training sample of each task that participates in the calculation of the loss function corresponding to the target multi-task joint training.

[0102] In this embodiment, the loss function includes at least a multi-task attention weight loss term. The loss function including the multi-task attention weight loss term is used to perform joint training of the basic code processing large model on multiple targets to obtain the multi-task code processing large model.

[0103] In the embodiments provided in this application, a multi-task attention weight loss term is constructed based on the model attention weights corresponding to each effective word unit. This results in a negative correlation between the loss value corresponding to the multi-task attention weight loss term and the overall model attention weight corresponding to the effective word unit. When the loss value corresponding to the multi-task attention weight loss term decreases, the overall model attention weight corresponding to the effective word unit increases; conversely, when the loss value corresponding to the multi-task attention weight loss term increases, the overall model attention weight corresponding to the effective word unit decreases. This allows for rapid learning of the features corresponding to the effective word units involved in the loss function calculation based on the multi-task attention weight loss term, thereby enabling targeted adjustments to the model parameters, shortening the target multi-task joint training time, and improving model training efficiency.

[0104] In the embodiments provided in this application, a method for determining the multi-task difficulty weight loss term is also provided. Specifically, the multi-task difficulty weight loss term can be determined based on at least one of a first loss term, a second loss term, and a third loss term. Furthermore, a loss function is constructed using at least the multi-task attention weight loss term, and the target multi-task joint training is performed on the basic code processing large model based on the loss function to obtain the multi-task code processing large model.

[0105] The first loss term, as the model loss value of the control loss function continuously decreases, allocates more attention weights to effective word units with higher difficulty in model label prediction across different model task types. This strengthens the learning of features corresponding to effective word units with higher difficulty in model label prediction by the large model processing the base code. Specifically, the first loss term is constructed based on the inverse of the weight balance factor corresponding to each model task type and the effective word unit learning difficulty representation term in the training samples of each model task type. The effective word unit learning difficulty representation term is constructed based on the target unit type prediction probability value of the effective word unit and the prediction failure probability value corresponding to the target unit type prediction probability value. The weight balance factor is greater than 0 and less than 1.

[0106] The second loss term, while controlling the model loss value to decrease, allocates more attention weights to training samples of tasks with higher model label prediction difficulty across different task types. This strengthens the learning of features corresponding to these tasks by the large model processing the base code. Specifically, the second loss term is constructed based on the negative of the weight balance factor corresponding to each model's task type and the task training sample learning difficulty representation term. This task training sample learning difficulty representation term is constructed based on the prediction failure probability value of the target sample type prediction probability value for each task training sample and the representation value of the target sample type prediction probability value for each model's task training sample.

[0107] The third loss term, as the model loss value of the control loss function continuously decreases, allocates more attention weights to code processing tasks, which are more difficult to predict model labels among different model processing task types. This strengthens the learning of features corresponding to the more difficult model label prediction tasks by the basic code processing model. Specifically, the third loss term is constructed based on the negative of the weight balance factor corresponding to each model processing task type and the learning difficulty representation term for each model processing task type. The learning difficulty representation term for each model processing task type is constructed based on the prediction failure probability value of the prediction probability value corresponding to the model processing task type and the representation value of the prediction probability of the model processing task type.

[0108] Here, the difficulty of model label prediction can be determined based on the prediction probability when the large model in the basic code performs label prediction. It should be understood that when the prediction probability is close to 50%, such as 50% ± E, where E is greater than 0 and less than 50%, such as E being 20%, the difficulty of model label prediction is relatively high, and the large model in the basic code has difficulty learning this feature; when the prediction probability is close to 0 or 1, the difficulty of model label prediction is relatively low, and the large model in the basic code learns this feature more easily.

[0109] For example, the first loss term is Loss1(θ).

[0110]

[0111] Where θ is the model parameter for processing large models based on the basic code, N is the total number of model processing task types corresponding to the large models for processing basic code, and M is... i T represents the total number of task training samples in the task training sample set corresponding to the task type processed by the i-th model. ij α represents the total number of valid word units in the j-th sample of the training sample set corresponding to the task type of the i-th model. i α is the weight balancing factor corresponding to the task type of the i-th model. i ∈[0,1]; γ is the focal factor, γ∈[0,5]; P ijk This is the target unit type prediction probability value of the k-th effective lexical unit in the training samples of the j-th task corresponding to the i-th task type processed by the basic code processing large model. Here, the effective lexical unit learning difficulty representation term is (1-P) ijk ) γ P ijk The second loss term is Loss2(θ).

[0112]

[0113] Among them, F ij (P ijk ) is based on P ijk The predicted probability value of the target sample type for the j-th task training sample in the training sample set corresponding to the i-th task type processed by the model; Q ij (P ijk ) is based on P ijk The representation value of the predicted probability of the target sample type for the j-th task training sample in the training sample set corresponding to the i-th task type processed by the model. Here, the representation term of the learning difficulty of the task training sample corresponding to the task type processed by the model is (1-F ij (P ijk )) γ Q ij (Pijk )

[0114] The third loss term is Loss3(θ).

[0115]

[0116] Here, the learning difficulty representation term corresponding to the model processing task type is:

[0117] In one feasible implementation, a multi-task difficulty weight loss term can be determined based on a first loss term, a second loss term, and a third loss term. The multi-task difficulty weight loss term is L1(θ), where L1(θ) = a1 × loss1(θ) + a2 × loss2(θ) + a3 × loss3(θ). Here, a1 is the first weight corresponding to loss1(θ), a2 is the second weight corresponding to loss2(θ), and a3 is the third weight corresponding to loss3(θ). a1, a2, and a3 are all greater than 0 and less than 1, and a1 + a2 + a3 = 1. In this case, the first weight is used to adjust the weight of the first loss term, the second weight is used to adjust the weight of the second loss term, and the third weight is used to adjust the weight of the third loss term. These adjustments can be made based on the user's focus. If the user prioritizes the difficulty weight allocation corresponding to the code processing task level, a1 can be increased. If the user prioritizes the difficulty weight allocation corresponding to the task training sample level, a2 can be increased. If the user prioritizes the difficulty weight allocation corresponding to the word origin unit level of the task training sample, a3 can be increased.

[0118] Of course, in other embodiments, the multi-task difficulty weight loss term can also be determined based on at least two of the first loss term, the second loss term, and the third loss term. It is easy to understand that in this case, the weights corresponding to each loss term in the multi-task difficulty weight loss term are all greater than 0 and less than 1, and the sum of the weights corresponding to each loss term in the multi-task difficulty weight loss term is 1. Alternatively, the multi-task difficulty weight loss term can also be determined based solely on one of the first loss term, the second loss term, and the third loss term.

[0119] In the embodiments provided in this application, a multi-task difficulty weight loss term is determined based on at least one of the first loss term, the second loss term, and the third loss term. This allows attention weights to be allocated at at least one level: the code processing task level, the task training sample level corresponding to the code processing task level, and the word source unit level corresponding to the task training sample level. Attention weights are allocated based on the model label prediction difficulty of the code processing task, the task training sample, or the word source unit corresponding to the task training sample. More attention weights are allocated to features that are difficult for the basic code processing model to learn, and fewer attention weights are allocated to features that are easy for the basic code processing model to learn. This enables the basic code processing model to quickly learn the features of code processing tasks of different model processing task types during the model parameter update process through the loss function.

[0120] Please see Figure 5 , Figure 5 This is a schematic diagram illustrating a process for determining a multi-task convergence speed loss term, provided as an embodiment of this application. Figure 5 As shown, the method includes:

[0121] S502: Determine the original loss function corresponding to the task type processed by each model.

[0122] The loss value of the original loss function corresponding to each model's task type is used to characterize the accuracy of the basic code processing model in handling the code processing task corresponding to that model's task type. The original loss function corresponding to each model's task type can be pre-defined or obtained from the original model training strategy corresponding to that task type. The original loss function corresponding to the i-th model's task type can be expressed as l i (θ).

[0123] S504: In multi-task joint training, determine the loss gradient term of the original loss function corresponding to the task type handled by each model.

[0124] In each iteration, the loss gradient term of the original loss function corresponding to the task type handled by the i-th model can be expressed as: That is, the partial derivative of the original loss function with respect to the model parameter θ for the task type processed by the i-th model.

[0125] S506: Determine the task weights for each model's task type and the loss values ​​of the original loss functions corresponding to each model's task type. Based on the task weights, perform a weighted summation of the loss values ​​of the original loss functions corresponding to all model task types to obtain the total model loss term.

[0126] Wherein, the task weight corresponding to the task type processed by the i-th model can be w. iThe weighted summation of the loss values ​​of the original loss function corresponding to all model task types based on task weights can be expressed as follows: Thus, the total model loss term G is obtained. t ,

[0127] S508: Construct a multi-task convergence speed loss term based on the loss gradient term and the total model loss term. Construct a loss function using at least the multi-task convergence speed loss term. Perform joint training of the basic code processing large model on the target multi-task based on the loss function to obtain the multi-task code processing large model. Among them, the convergence speed balancing loss function is negatively correlated with w, where w is the task weight of the model processing task type corresponding to the loss gradient term with the smallest loss gradient value among the loss gradient terms of the original loss function corresponding to the task type of each model processing task.

[0128] In this embodiment, the loss function includes at least a multi-task convergence speed loss term. Based on the loss function including the multi-task convergence speed loss term, the basic code processing large model is jointly trained by multiple target tasks to obtain the multi-task code processing large model.

[0129] The multi-task convergence speed loss term, constructed based on the loss gradient term and the total model loss term, can be expressed as follows: Where α is the learning rate. The multi-task convergence speed loss term is L3(θ), then...

[0130] It is easy to see that if the loss value of the task convergence speed loss term is reduced, then The total model loss term G should be the one with the smaller gradient value in the original loss function corresponding to the task type the model is processing, and with a larger learning rate. t The weights with larger loss values ​​should be assigned larger values. It is not difficult to see that the total model loss term G... t A larger loss value corresponds to a smaller loss gradient, which keeps the loss value relatively large, thereby maximizing the task weight of the model with the smaller loss gradient. In other words, a large loss gradient value in the loss gradient term indicates fast convergence and a small task weight; a small loss gradient value in the loss gradient term indicates slow convergence and a large task weight.

[0131] In the embodiments provided in this application, as the model loss value of the control loss function continuously decreases, the multi-task difficulty weight loss term is used to enable the basic code processing large model to maximize the weight of the code processing task with the slowest convergence speed when dealing with code processing tasks of different model processing task types. This allows for rapid optimization of the model parameters corresponding to the code processing task with the slowest convergence speed during the target multi-task joint training process, thereby deepening the basic code processing large model's learning of the features corresponding to the code processing task with the slowest convergence speed, thus shortening the target multi-task joint training time and improving model training efficiency.

[0132] Please see Figure 6 , Figure 6 This is a flowchart illustrating another method for determining a large-scale multi-task code processing model, provided as an embodiment of this application. Please refer to... Figure 7 , Figure 7 This is a schematic diagram illustrating a process for fine-tuning model preferences, provided as an embodiment of this application. Figure 6 and Figure 7 As shown in S304, the basic code processing large model is jointly trained on multiple tasks using the task training sample set corresponding to all model processing task types, resulting in a multi-task code processing large model, including:

[0133] S602: Use the task training sample set corresponding to all model processing task types to train the basic code processing large model to obtain the initial multi-task code processing large model.

[0134] In the process of training the basic code processing large model using the task training sample set corresponding to all model processing task types, the basic code processing large model is trained based on the loss function. After the basic code processing large model completes the model training, the initial multi-task code processing large model is obtained. At this time, the initial multi-task code processing large model can be used to process code processing tasks corresponding to at least two model processing task types.

[0135] S604: Obtain user preference response features and non-preference response features for the model processing task type. Based on the direct preference optimization algorithm, preference response features and non-preference response features, perform model preference fine-tuning on the initial multi-task code processing large model to obtain the multi-task code processing large model.

[0136] In order to enable the initial multi-task code processing large model to output code processing results based on user preferences when processing code processing tasks corresponding to at least two model processing task types, the initial multi-task code processing large model can be fine-tuned based on the direct preference optimization algorithm, thereby enabling the initial multi-task code processing large model to learn user preference features and obtain a multi-task code processing large model.

[0137] During the model preference fine-tuning process, user preference response features and non-preference response features for the model's task type are obtained. The preference response features can be represented as y. w The non-preference response feature can be represented as y l The Direct Preference Optimization (DPO) algorithm fine-tunes using preference data, making the entire training process simple and efficient. In DPO, preference data can be represented as triples (prompt, chosen, rejected). The corresponding loss function for DPO is: L DPO (π θ ;π ref )=-F{(β{(π θ (y w |x)-π θ (y l |x))-β(π ref (y w |x)-π ref (y l |x)))}, where F is the loss calculation function corresponding to the direct preference optimization algorithm.

[0138] When the model parameter is θ, π θ (y w |x) represents the initial multi-task code processing of the large model to generate preference response features y given input x. w The probability of π, i.e., the chosen score 1; θ (y l |x) represents the initial multi-task code processing of a large model to generate non-preferred response features y given input x. l The probability of this is the rejected score 1. π ref (y w |x) represents the initial multi-task code processing large model generating preference response features y with the model parameters frozen given input x. w The probability of π is the chosen score 2. ref (y l|x) represents the initial multi-task code processing large model generating non-preferred response features y given input x, with the model parameters in a frozen state. l The probability of rejectionscore2 is the same as the probability of rejectionscore2.

[0139] like Figure 7 As shown, the Trained LLM is the initial large-scale multi-task code processing model, while the Frozen LLM is the initial large-scale multi-task code processing model with its parameters frozen. The Trained LLM requires training, while the Frozen LLM does not. Both models predict scores for chosen and rejected users, respectively, and then calculate the loss using the loss function of the Direct Preference Optimization (DPO) algorithm, continuously iterating and optimizing. After optimization using the DPO algorithm, the model's user preference evaluation score is effectively improved.

[0140] Please see Figure 8 , Figure 8 The present application provides a schematic diagram of the structure of a code processing apparatus.

[0141] like Figure 8 As shown, the code processing device 800 includes:

[0142] The determination module 810 is suitable for obtaining the code processing task for the multi-task code processing large model, as well as at least two model processing task types corresponding to the multi-task code processing large model, and determining the target task type of the code processing task.

[0143] The code processing module 820 is suitable for processing code processing tasks by using the model processing task type when the target task type is a model processing task type, and obtaining code processing results by using a large model with multi-task code processing to process the code processing task.

[0144] Among them, the multi-task code processing big model is obtained by training the basic code processing big model through joint training of multiple target tasks.

[0145] Optionally, the code processing device 800 includes:

[0146] The acquisition module is suitable for determining the basic code to process large models and acquiring the task training sample set corresponding to the task type processed by each model.

[0147] The target multi-task joint training module is suitable for using the task training sample set corresponding to all model processing task types to perform target multi-task joint training on the basic code processing large model to obtain a multi-task code processing large model.

[0148] The loss function corresponding to the multi-task joint training of the target includes at least one of the following: multi-task attention weight loss term, multi-task difficulty weight loss term, and multi-task convergence speed loss term.

[0149] Optionally, the code processing device 700 further includes:

[0150] The effective lexical unit determination module determines the effective lexical units corresponding to each task training sample in the target multi-task joint training.

[0151] The model attention weight acquisition module is suitable for acquiring the model attention weights corresponding to each effective word unit in the multi-task joint training of the target, and constructing a multi-task attention weight loss term based on the model attention weights corresponding to each effective word unit.

[0152] Among them, the loss value corresponding to the multi-task attention weight loss term is negatively correlated with the overall model attention weight corresponding to the effective word unit. The effective word unit is the word unit in the word unit corresponding to the training sample of each task that participates in the calculation of the loss function corresponding to the multi-task joint training of the target.

[0153] Optionally, the code processing device 800 further includes:

[0154] The multi-task difficulty weight loss term determination module is suitable for determining the multi-task difficulty weight loss term based on at least one of the first loss term, the second loss term, and the third loss term;

[0155] The model training module is suitable for constructing a loss function using at least the multi-task attention weight loss term, and for performing joint training of the basic code processing large model on the target multi-task based on the loss function to obtain the multi-task code processing large model.

[0156] The first loss term is constructed based on the negative of the weight balance factor corresponding to the task type processed by each model and the effective word unit learning difficulty representation term of the effective word unit in the training samples of the task type processed by each model. The effective word unit learning difficulty representation term is constructed based on the target unit type prediction probability value of the effective word unit and the prediction failure probability value corresponding to the target unit type prediction probability value. The weight balance factor is greater than 0 and less than 1.

[0157] The second loss term is constructed based on the negative of the weight balance factor corresponding to the task type processed by each model and the task training sample learning difficulty representation term corresponding to the task training sample processed by each model. The task training sample learning difficulty representation term is constructed based on the prediction failure probability value of the target sample type prediction probability value corresponding to the task training sample and the representation value of the target sample type prediction probability value corresponding to the task training sample processed by each model.

[0158] The third loss term is constructed based on the negative of the weight balance factor corresponding to each model's task processing type and the learning difficulty representation term corresponding to each model's task processing type. The learning difficulty representation term is constructed based on the prediction failure probability value of the prediction probability value corresponding to the model's task processing type and the representation value of the prediction probability corresponding to the model's task processing type.

[0159] Optionally, the code processing device 800 further includes:

[0160] The original loss function determination module is suitable for determining the original loss function corresponding to the task type processed by each model.

[0161] The loss gradient term determination module is suitable for determining the loss gradient term of the original loss function corresponding to the task type processed by each model in multi-task joint training of the target.

[0162] The total model loss term determination module is suitable for determining the task weights of each model for processing task types, as well as the loss values ​​of the original loss functions corresponding to each model for processing task types. Based on the task weights, the loss values ​​of the original loss functions corresponding to all model processing task types are weighted and summed to obtain the total model loss term.

[0163] The module is suitable for constructing a multi-task convergence speed loss term based on the loss gradient term and the total model loss term. At least the multi-task convergence speed loss term is used to construct a loss function. Based on the loss function, the basic code processing large model is jointly trained for target multi-tasks to obtain the multi-task code processing large model.

[0164] Among them, the convergence speed balance loss function is negatively correlated with w, where w is the task weight of the model processing task type, which is the loss gradient term with the smallest loss gradient value in the original loss function corresponding to each model processing task type.

[0165] Optionally, the target multi-task joint training module includes:

[0166] The initial multi-task code processing large model determination unit is suitable for using the task training sample set corresponding to all model processing task types to train the basic code processing large model to obtain the initial multi-task code processing large model.

[0167] The multi-task code processing large model determination unit is suitable for obtaining user preference response features and non-preference response features for the model processing task type. Based on the direct preference optimization algorithm, preference response features and non-preference response features, the initial multi-task code processing large model is fine-tuned to obtain the multi-task code processing large model.

[0168] Optionally, the code processing device 800 further includes:

[0169] The module for determining the multi-task difficulty weight loss term is suitable for determining the multi-task difficulty weight loss term based on the first loss term, the second loss term, and the third loss term.

[0170] The multi-task difficulty weight loss term is L1(θ), L1(θ)=a1×loss1(θ)+a2×loss2(θ)+a3×loss3(θ); where loss1(θ) is the first loss term, a1 is the first weight corresponding to loss1(θ), loss2(θ) is the second loss term, a2 is the second weight corresponding to loss2(θ), loss3(θ) is the third loss term, a3 is the third weight corresponding to loss3(θ), a1, a2 and a3 are all greater than 0 and less than 1, and a1+a2+a3=1.

[0171] Optionally, the code processing device 800 further includes:

[0172] The loss function determination module is suitable for determining the loss function based on the multi-task attention weight loss term, the multi-task difficulty weight loss term, and the multi-task convergence speed loss term.

[0173] The loss term for multi-task difficulty weight is L1(θ), the loss term for multi-task attention weight is L2(θ), the loss term for multi-task convergence speed is L3(θ), and the loss function is L(θ). L(θ) = r1×L1(θ) + r2×L2(θ) + r3×L3(θ), where r1 is the first loss weight corresponding to L1(θ), r2 is the second loss weight corresponding to L2(θ), and r3 is the third loss weight corresponding to L3(θ). r1, r2, and r3 are all greater than 0 and less than 1, and r1 + r2 + r3 = 1.

[0174] Optionally, at least two models handle task types including code review task type, vulnerability remediation task type, unit testing task type, and vulnerability inspection task type.

[0175] Please see Figure 9 , Figure 9 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 9 As shown, the electronic device 900 may include: at least one processor 901, at least one network interface 904, a user interface 903, a memory 905, and at least one communication bus 902.

[0176] The communication bus 902 is used to enable communication between these components.

[0177] The user interface 903 may include a display screen and a camera. Optionally, the user interface 903 may also include a standard wired interface and a wireless interface.

[0178] The network interface 904 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface).

[0179] The processor 901 may include one or more processing cores. The processor 901 connects to various parts within the electronic device 900 using various interfaces and lines, and performs various functions and processes data by running or executing instructions, programs, code sets, or instruction sets stored in the memory 905, and by calling data stored in the memory 905. Optionally, the processor 901 may be implemented using at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), or PLA (Programmable Logic Array). The processor 901 may integrate one or more of the following: CPU (Central Processing Unit), GPU (Graphics Processing Unit), and modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the content to be displayed on the screen; and the modem handles wireless communication. It is understood that the modem may also not be integrated into the processor 901 and may be implemented as a separate chip.

[0180] The memory 905 may include RAM (Random Access Memory) or ROM (Read-Only Memory). Optionally, the memory 905 may include a non-transitory computer-readable storage medium. The memory 905 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 905 may include a program storage area and a data storage area. The program storage area may store instructions for implementing an operating system, instructions for at least one function (such as touch functionality, sound playback functionality, image playback functionality, etc.), instructions for implementing the various method embodiments described above, etc.; the data storage area may store data involved in the various method embodiments described above, etc. Optionally, the memory 905 may also be at least one storage device located remotely from the aforementioned processor 901. Figure 9 As shown, the memory 905, which serves as a computer storage medium, may include an operating system, a network communication module, a user interface module, and a code processing program.

[0181] exist Figure 9 In the illustrated electronic device 900, the user interface 903 is mainly used to provide an input interface for the user and to acquire user input data; while the processor 901 can be used to call the code processing program stored in the memory 905 and specifically perform the following operations:

[0182] Obtain the code processing tasks for the large multi-task code processing model, as well as at least two model processing task types corresponding to the large multi-task code processing model, and determine the target task type of the code processing task.

[0183] When the target task type is a model processing task type, the code processing task is processed by using the multi-task code processing large model to obtain the code processing result.

[0184] Among them, the multi-task code processing big model is obtained by training the basic code processing big model through joint training of multiple target tasks.

[0185] Alternatively, processor 901 is also adapted to perform:

[0186] Determine the basic code to process the large model, and obtain the task training sample set corresponding to the task type processed by each model;

[0187] By using the task training sample set corresponding to all model processing task types, the basic code processing large model is jointly trained for multiple tasks to obtain a multi-task code processing large model.

[0188] The loss function corresponding to the multi-task joint training of the target includes at least one of the following: multi-task attention weight loss term, multi-task difficulty weight loss term, and multi-task convergence speed loss term.

[0189] Alternatively, processor 901 is also adapted to perform:

[0190] In the multi-task joint training of the target, the effective word units corresponding to each task training sample in the entire task training sample set are determined;

[0191] Obtain the model attention weights corresponding to each effective word unit in the target multi-task joint training, and construct a multi-task attention weight loss term based on the model attention weights corresponding to each effective word unit.

[0192] At least a loss function is constructed using the multi-task attention weight loss term. Based on the loss function, the basic code processing large model is jointly trained for multiple target tasks to obtain the multi-task code processing large model.

[0193] Among them, the loss value corresponding to the multi-task attention weight loss term is negatively correlated with the overall model attention weight corresponding to the effective word unit. The effective word unit is the word unit in the word unit corresponding to the training sample of each task that participates in the calculation of the loss function corresponding to the multi-task joint training of the target.

[0194] Alternatively, processor 901 is also adapted to perform:

[0195] The multi-task difficulty weight loss term is determined based on at least one of the first loss term, the second loss term, and the third loss term;

[0196] At least a loss function is constructed using the multi-task attention weight loss term. Based on the loss function, the basic code processing large model is jointly trained for multiple target tasks to obtain the multi-task code processing large model.

[0197] The first loss term is constructed based on the negative of the weight balance factor corresponding to the task type processed by each model and the effective word unit learning difficulty representation term of the effective word unit in the training samples of the task type processed by each model. The effective word unit learning difficulty representation term is constructed based on the target unit type prediction probability value of the effective word unit and the prediction failure probability value corresponding to the target unit type prediction probability value. The weight balance factor is greater than 0 and less than 1.

[0198] The second loss term is constructed based on the negative of the weight balance factor corresponding to the task type processed by each model and the task training sample learning difficulty representation term corresponding to the task training sample processed by each model. The task training sample learning difficulty representation term is constructed based on the prediction failure probability value of the target sample type prediction probability value corresponding to the task training sample and the representation value of the target sample type prediction probability value corresponding to the task training sample processed by each model.

[0199] The third loss term is constructed based on the negative of the weight balance factor corresponding to each model's task processing type and the learning difficulty representation term corresponding to each model's task processing type. The learning difficulty representation term is constructed based on the prediction failure probability value of the prediction probability value corresponding to the model's task processing type and the representation value of the prediction probability corresponding to the model's task processing type.

[0200] Alternatively, processor 901 is also adapted to perform:

[0201] Determine the original loss function corresponding to the task type processed by each model;

[0202] In the joint training of multiple tasks, the loss gradient term of the original loss function corresponding to the task type handled by each model is determined;

[0203] Determine the task weights for each model's task type and the loss values ​​of the original loss functions corresponding to each model's task type. Based on the task weights, perform a weighted summation of the loss values ​​of the original loss functions corresponding to all model task types to obtain the total model loss term.

[0204] Construct a multi-task convergence speed loss term based on the loss gradient term and the total model loss term. At least use the multi-task convergence speed loss term to construct a loss function. Based on the loss function, perform joint training of the basic code processing large model for target multi-tasks to obtain the multi-task code processing large model.

[0205] Among them, the convergence speed balance loss function is negatively correlated with w, where w is the task weight of the model processing task type, which is the loss gradient term with the smallest loss gradient value in the original loss function corresponding to each model processing task type.

[0206] Optionally, when processor 901 performs multi-task joint training on the basic code processing large model using the task training sample set corresponding to all model processing task types to obtain the multi-task code processing large model, the specific execution is as follows:

[0207] The initial multi-task code processing large model is obtained by training the basic code processing large model using the task training sample set corresponding to all model processing task types.

[0208] Obtain user preference response features and non-preference response features for the model processing task type. Based on the direct preference optimization algorithm, preference response features and non-preference response features, perform model preference fine-tuning on the initial multi-task code processing large model to obtain the multi-task code processing large model.

[0209] Alternatively, processor 901 is also adapted to perform:

[0210] The multi-task difficulty weight loss term is determined based on the first loss term, the second loss term, and the third loss term;

[0211] The multi-task difficulty weight loss term is L1(θ), L1(θ)=a1×loss1(θ)+a2×loss2(θ)+a3×loss3(θ); where loss1(θ) is the first loss term, a1 is the first weight corresponding to loss1(θ), loss2(θ) is the second loss term, a2 is the second weight corresponding to loss2(θ), loss3(θ) is the third loss term, a3 is the third weight corresponding to loss3(θ), a1, a2 and a3 are all greater than 0 and less than 1, and a1+a2+a3=1.

[0212] Alternatively, processor 901 is also adapted to perform:

[0213] The loss function is determined based on the multi-task attention weight loss term, the multi-task difficulty weight loss term, and the multi-task convergence speed loss term.

[0214] The loss term for multi-task difficulty weight is L1(θ), the loss term for multi-task attention weight is L2(θ), the loss term for multi-task convergence speed is L3(θ), and the loss function is L(θ). L(θ) = r1×L1(θ) + r2×L2(θ) + r3×L3(θ), where r1 is the first loss weight corresponding to L1(θ), r2 is the second loss weight corresponding to L2(θ), and r3 is the third loss weight corresponding to L3(θ). r1, r2, and r3 are all greater than 0 and less than 1, and r1 + r2 + r3 = 1.

[0215] Optionally, at least two models handle task types including code review task type, vulnerability remediation task type, unit testing task type, and vulnerability inspection task type.

[0216] This application also provides a computer-readable storage medium that stores one or more programs, which, when executed by a processor, implement any of the methods described above.

[0217] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple modules or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or modules may be electrical, mechanical, or other forms.

[0218] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules; that is, they may be located in one place or distributed across multiple network modules. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.

[0219] Furthermore, the functional modules in the various embodiments of this application can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The integrated modules described above can be implemented in hardware or as software functional modules.

[0220] If the integrated module is implemented as a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application embodiment, in essence, or the part that contributes to the prior art, or all or 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 this application. 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.

[0221] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments of this application are not limited to the described order of actions, because according to the embodiments of this application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to the embodiments of this application.

[0222] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0223] The above is a description of a code processing method, apparatus, electronic device, and computer-readable storage medium provided in the embodiments of this application. For those skilled in the art, based on the ideas of the embodiments of this application, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation on the embodiments of this application.

Claims

1. A code processing method, wherein, The method includes: Obtain the code processing tasks for the multi-task code processing large model, and at least two model processing task types corresponding to the multi-task code processing large model, and determine the target task type of the code processing task. When the target task type is the model processing task type, the multi-task code processing model uses the model processing task type to process the code processing task and obtain the code processing result. The multi-task code processing big model is obtained by training the basic code processing big model through target multi-task joint training.

2. The method according to claim 1, wherein, The method further includes: Determine the basic code processing model and obtain the task training sample set corresponding to the task type processed by each model; The target multi-task joint training is performed on the basic code processing large model using the task training sample set corresponding to all model processing task types to obtain the multi-task code processing large model. The loss function corresponding to the target multi-task joint training includes at least one of the following: multi-task attention weight loss term, multi-task difficulty weight loss term, and multi-task convergence speed loss term.

3. The method according to claim 2, wherein, The method further includes: In the target multi-task joint training, the effective word units corresponding to each task training sample in the entire task training sample set are determined; Obtain the model attention weights corresponding to each effective word unit in the target multi-task joint training, and construct the multi-task attention weight loss term based on the model attention weights corresponding to each effective word unit. The loss function is constructed using at least the multi-task attention weight loss term, and the target multi-task joint training is performed on the basic code processing large model based on the loss function to obtain the multi-task code processing large model. The loss value corresponding to the multi-task attention weight loss term is negatively correlated with the overall model attention weight corresponding to the effective word unit. The effective word unit is the word unit in the word unit corresponding to the training sample of each task that participates in the calculation of the loss function corresponding to the target multi-task joint training.

4. The method according to claim 2, wherein, The method further includes: The multi-task difficulty weight loss term is determined based on at least one of the first loss term, the second loss term, and the third loss term; The loss function is constructed using at least the multi-task attention weight loss term, and the target multi-task joint training is performed on the basic code processing large model based on the loss function to obtain the multi-task code processing large model. The first loss term is constructed based on the negative of the weight balance factor corresponding to the task type of each model and the effective word unit learning difficulty representation term of the effective word unit in the training sample of the task type of each model. The effective word unit learning difficulty representation term is constructed based on the target unit type prediction probability value of the effective word unit and the prediction failure probability value corresponding to the target unit type prediction probability value. The weight balance factor is greater than 0 and less than 1. The second loss term is constructed based on the negative of the weight balance factor corresponding to the task type processed by each model and the task training sample learning difficulty representation term corresponding to the task training sample processed by each model. The task training sample learning difficulty representation term is constructed based on the prediction failure probability value of the target sample type prediction probability value corresponding to the task training sample and the representation value of the target sample type prediction probability of the task training sample processed by each model. The third loss term is constructed based on the negative of the weight balance factor corresponding to each model task type and the learning difficulty representation term corresponding to each model task type. The learning difficulty representation term is constructed based on the prediction failure probability value of the prediction probability value of the model task type and the representation value of the prediction probability of the model task type.

5. The method according to claim 2, wherein, The method further includes: Determine the original loss function corresponding to the task type processed by each model; In the target multi-task joint training, the loss gradient term of the original loss function corresponding to the task type processed by each model is determined; Determine the task weights for each model's task type and the loss values ​​of the original loss functions corresponding to each model's task type. Based on the task weights, perform a weighted summation of the loss values ​​of the original loss functions corresponding to all model task types to obtain the total model loss term. A multi-task convergence speed loss term is constructed based on the loss gradient term and the total model loss term. The loss function is constructed using at least the multi-task convergence speed loss term. Based on the loss function, the target multi-task joint training is performed on the basic code processing large model to obtain the multi-task code processing large model. The convergence speed balancing loss function is negatively correlated with w, where w is the task weight of the model processing task type, which is the loss gradient term with the smallest loss gradient value among the loss gradient terms of the original loss function corresponding to each model processing task type.

6. The method according to claim 2, wherein, The step of jointly training the basic code processing large model using the task training sample set corresponding to all model processing task types to obtain the multi-task code processing large model includes: The initial multi-task code processing large model is obtained by training the basic code processing large model using the task training sample set corresponding to all model processing task types. Obtain the user's preference response features and non-preference response features for the task type processed by the model. Based on the direct preference optimization algorithm, the preference response features and the non-preference response features, perform model preference fine-tuning on the initial multi-task code processing large model to obtain the multi-task code processing large model.

7. The method according to claim 4, wherein, The method further includes: The multi-task difficulty weight loss term is determined based on the first loss term, the second loss term, and the third loss term; Wherein, the multi-task difficulty weight loss term is L1(θ), L1(θ)=a1×loss1(θ)+a2×loss2(θ)+a3×loss3(θ); where loss1(θ) is the first loss term, a1 is the first weight corresponding to loss1(θ), loss2(θ) is the second loss term, a2 is the second weight corresponding to loss2(θ), loss3(θ) is the third loss term, a3 is the third weight corresponding to loss3(θ), a1, a2 and a3 are all greater than 0 and less than 1, and a1+a2+a3=1.

8. A code processing apparatus, wherein, The device includes: The determination module is adapted to acquire code processing tasks for a large multi-task code processing model, and at least two model processing task types corresponding to the large multi-task code processing model, and determine the target task type of the code processing task. The code processing module is adapted to process the code processing task using the multi-task code processing model when the target task type is the model processing task type, and obtain the code processing result. The multi-task code processing big model is obtained by training the basic code processing big model through target multi-task joint training.

9. An electronic device, wherein, The electronic device includes: Processor; and A memory configured to store computer-executable instructions, which, when executed, cause the processor to perform the method according to any one of claims 1 to 7.

10. A computer-readable storage medium, wherein, The computer-readable storage medium stores one or more programs that, when executed by a processor, implement the method of any one of claims 1 to 7.