Program repairing method and device and computer readable storage medium

By using the iterative optimization strategy of pre-trained language model and reward model in program repair, multi-step repair is carried out based on non-strictly constrained partial order relationships, which solves the problem of low efficiency of single-step repair and inconsistent with human behavior patterns in the existing technology. , achieving efficient and reliable program repair results.

CN118981433AActive Publication Date: 2024-11-19BEIJING KNOWLEDGE ATLAS TECHNOLOGY CO LTD

Patent Information

Application Number
CN202411057044.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-02
Publication Date
2024-11-19
Estimated Expiration
2044-08-02

AI Technical Summary

Technical Problem

The existing program repair method has a high editing distance in single-step repair, making it difficult to solve multiple problems at the same time, and does not conform to the iterative repair behavior pattern of human programmers. In addition, the large-scale language model did not consider test cases during the training process, and the generated The fix does not meet actual software development requirements.

Method used

The pre-trained large language model is used for fine-tuning, and the reward model is combined with the reward model to perform multiple iteration repairs based on non-strictly constrained partial order relationships. The repair model generation strategy is adjusted through feedback from the reward model, which simulates the behavior of human developers in program debugging and improves the Repair efficiency and code quality.

Benefits of technology

It realizes a more efficient and reliable program repair process, conforms to the behavioral patterns of human developers, improves the quality and adaptability of generated code, and meets actual software development needs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118981433A_ABST
    Figure CN118981433A_ABST
Patent Text Reader

Abstract

The invention relates to a program repairing method and device and a computer readable storage medium, and belongs to the technical field of artificial intelligence. The method comprises the steps of obtaining a to-be-repaired program; inputting the to-be-repaired program into the repair model to generate a candidate solution; and inputting the candidate solutions generated by the repair model into the reward model, generating an evaluation result for evaluating the repair effect of the program, and performing multiple times of iterative repair on the repair model based on the evaluation result until a final repaired program is generated. Wherein the reward model evaluates different program states based on a non-strictly constrained partial order relationship, generates an evaluation result for evaluating a program repair effect, and feeds back the evaluation result to the repair model, so that the repair model adjusts a generation strategy based on the evaluation result. According to the method, the repairing efficiency is improved, the quality and adaptability of the generated codes can be enhanced, and a program repairing strategy which is more flexible and better meets actual development requirements is provided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of artificial intelligence technology, and specifically relates to a program repair method, device and computer-readable storage medium. Background Art

[0002] Program repair has been recognized as a key issue in software development and maintenance. Its purpose is to repair fragile programs and obtain more robust and strong programs. A good program repair method can not only reduce the threshold and cost of manual repair, but also improve the reliability of software development projects.

[0003] With the emergence of large-scale language models, developers often choose an end-to-end approach to complete program repair, that is, give repair instructions and vulnerable programs, and require the repair model to complete the repair in one step. However, this repair method has two problems: First, the edit distance required for single-step program repair is often high, and it is often difficult to solve multiple problems at the same time through one-step modification. Second, single-step program repair does not conform to human behavior patterns: programmers often repair programs in an iterative manner, first solving simple grammatical errors, and then using test cases to solve semantic errors. Large-scale language models often do not consider test cases and generate correct programs that they have seen during training and are close to incorrect programs. These two problems bring challenges to program repair.

[0004] Therefore, how to make the program repair process more efficient, reliable, and more in line with the actual software development needs and the behavior patterns of human developers is one of the technical problems that this application aims to solve. Summary of the invention

[0005] In view of the above analysis, the embodiments of the present invention aim to provide a program repair method, device and computer-readable storage medium to make the program repair process more efficient and reliable, and more in line with the actual software development needs and the behavior patterns of human developers.

[0006] In a first aspect of the present application, a program repair method is provided, comprising:

[0007] Get the program to be repaired;

[0008] Inputting the program to be repaired into a repair model to generate candidate solutions; wherein the repair model uses known faulty programs and repaired programs as training sample sets to fine-tune the pre-trained large language model;

[0009] The candidate solutions generated by the repair model are input into the reward model to generate an evaluation result of the program repair effect, and the repair model is iteratively repaired multiple times based on the evaluation result until the final repaired program is generated; wherein the reward model evaluates different program states based on a partial order relationship without strict constraints, generates an evaluation result of the program repair effect, and feeds the evaluation result back to the repair model so that the repair model adjusts the generation strategy based on the evaluation result.

[0010] Optionally, the reward model defines a partial order relationship for the program status, and the priority order of the partial order relationship is: acceptance, expression error, answer error, timeout, maximum memory limit exceeded, compilation error, and runtime error.

[0011] Optionally, the training process of the reward model includes:

[0012] Based on the partial order relationship, the reward model parameter φ is optimized using the pairwise sorting method:

[0013] Given K programs with states, construct For the partial order set D, after shuffling the partial order set D, minimize the following pairwise sorting loss to train the reward model:

[0014]

[0015] Among them, r φ (·) is the output of the reward model, which accepts the program as input and outputs a scalar as the evaluation result of the program repair effect; (y w ,y l ) is a partially ordered pair, y w for a more preferred procedure.

[0016] Optionally, it also includes: fine-tuning the repair model using a reinforcement learning proximal strategy optimization algorithm;

[0017] The training goal is to optimize the parameters θ of the repair model by maximizing the following reward:

[0018]

[0019] Among them, x i+1 is based on the input x i The output after repair, r φ (·) is the output of the reward model, and the KL reward coefficient β controls the strength of the KL penalty. Represents the judgment of improvement after repair.

[0020] Optionally, the repair model performs multiple iterative repairs until a preset condition is met, wherein the preset condition is that there is no continuous improvement within P steps; or a maximum number of repair steps is reached.

[0021] Optionally, the input of the repair model is x={x1,x2,…,x N}, the output is y={y1,y2,…,y N′}; Based on the training sample set The training process is to minimize the log-likelihood loss Adjust the model parameters θ so that the repair model predicts the repaired program:

[0022]

[0023] Among them, y <t is the repair sequence before time t, Θ is the model trainable parameter, The training sample set expectations.

[0024] Optionally, the process of acquiring the training sample set includes:

[0025] Collect multiple original program samples for programming problems from multiple data sources;

[0026] Static filtering and dynamic filtering are performed on the original program samples to obtain a training sample set.

[0027] Optionally, the static filtering of the original program sample includes:

[0028] Remove identical or similar original program samples; delete original program samples that include malicious programs; delete original program samples that include sensitive information or personal information; ensure that each user has at least one solution that is considered correct in the training sample set.

[0029] Optionally, the dynamically filtering the original program sample includes:

[0030] Using a predetermined version of the Python environment as a standard test environment, re-running the statically filtered program in the standard test environment to verify whether the program execution result is consistent with expectations;

[0031] Based on the execution results, it is again ensured that each user has at least one correct solution and a repaired program is generated.

[0032] According to a second aspect of the present application, a program repair device is provided, comprising a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, any one of the program repair methods described above is implemented.

[0033] According to a third aspect of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, any one of the above-mentioned program repair methods is implemented.

[0034] The program repair method provided in the present application obtains the program to be repaired; inputs the program to be repaired into the repair model to generate candidate solutions; inputs the candidate solutions generated by the repair model into the reward model to generate an evaluation result of the program repair effect evaluation, and performs multiple iterations of repair on the repair model based on the evaluation result until the final repaired program is generated. The reward model evaluates different program states based on a partial order relationship without strict constraints, generates an evaluation result of the program repair effect evaluation, and feeds back the evaluation result to the repair model so that the repair model adjusts the generation strategy based on the evaluation result.

[0035] This application evaluates the program status based on a predefined partial order relationship, provides a more flexible and extensive evaluation dimension, and can more comprehensively evaluate the various quality attributes of the program. In addition, the model is allowed to perform multi-step repairs, which simulates the actual behavior of human developers during program debugging. This iterative optimization strategy may be closer to the repair strategy of human programmers, which not only improves the repair efficiency, but also enhances the quality and adaptability of the generated code, providing a more flexible program repair strategy that is more in line with actual development needs.

[0036] In addition, the present application also provides a program repair device and a computer-readable storage medium having the above-mentioned technical effects. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] In order to more clearly illustrate the embodiments of this specification or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the embodiments of this specification. For ordinary technicians in this field, other drawings can also be obtained based on these drawings.

[0038] Figure 1 A flowchart of a specific implementation of the program repair method provided by this application;

[0039] Figure 2 A flowchart of another specific implementation of the program repair method provided by the present application;

[0040] Figure 3 A schematic diagram of the implementation process of another specific implementation of the program repair method provided by the present application;

[0041] Figure 4A specific example of the program repair method provided by this application is described and illustrated;

[0042] Figure 5 This is a structural block diagram of the program repair device provided in this application. DETAILED DESCRIPTION

[0043] In order to make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described in combination with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all of the embodiments. It should be noted that, in the absence of conflict, the embodiments in the present disclosure and the features in the embodiments can be combined, separated, interchanged and / or rearranged with each other. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0044] The terms used here are for the purpose of describing specific embodiments, and are not intended to be restrictive. As used here, unless the context clearly indicates otherwise, the singular forms "one (kind, person)" and "said (the)" are also intended to include plural forms. In addition, when the terms "comprise" and / or "include" and their variations are used in this specification, it is explained that there are stated features, integral bodies, steps, operations, parts, assemblies and / or their groups, but it is not excluded that there are or add one or more other features, integral bodies, steps, operations, parts, assemblies and / or their groups. It should also be noted that, as used here, the terms "substantially", "approximately" and other similar terms are used as approximate terms and not as degree terms, so that they are used to explain the inherent deviations of the measured values, calculated values ​​and / or the values ​​provided that will be recognized by those of ordinary skill in the art.

[0045] A flowchart of a specific implementation of the program repair method provided in this application is as follows Figure 1 As shown, the method comprises the following steps:

[0046] S101: Obtain the program to be repaired.

[0047] It can be understood that the program to be repaired may be a section of program code with errors.

[0048] S102: Input the program to be repaired into a repair model to generate candidate solutions.

[0049] The repair model uses known faulty programs and repaired programs as training sample sets to fine-tune the pre-trained large language model.

[0050] The repair model is a pre-trained language model that has been fine-tuned with specific task data. The fine-tuning data includes known faulty programs and corresponding repaired programs, so that the model can learn how to convert from an error state to a correct state. S103: The candidate solutions generated by the repair model are input into the reward model to generate an evaluation result of the program repair effect, and the repair model is repaired iteratively multiple times based on the evaluation result until the final repaired program is generated.

[0051] The candidate repair programs generated by the repair model are then input into the reward model. The reward model evaluates the repair effect of the candidate program based on the partial order of the program state and generates a score. Based on the score given by the reward model, the repair model performs iterative repairs. This iterative process may involve modifying the repair strategy or adjusting the generated program to improve its quality and efficiency until a satisfactory repair result is achieved or certain stopping conditions are met. The final output is the repair program with the highest score after multiple iterations, which is considered the optimal repair result.

[0052] The reward model evaluates different program states based on a partial order relationship without strict constraints, generates an evaluation result of the program repair effect, and feeds the evaluation result back to the repair model so that the repair model adjusts the generation strategy based on the evaluation result.

[0053] The reward model defines a partial order relationship for the program status, and the priority order of the partial order relationship is: acceptance, expression error, answer error, timeout, maximum memory limit exceeded, compilation error, and runtime error.

[0054] The training process of the reward model includes:

[0055] Based on the partial order relationship, the reward model parameter φ is optimized using the pairwise sorting method:

[0056] Given K programs with states, construct For the partial order set D, after shuffling the partial order set D, minimize the following pairwise sorting loss to train the reward model:

[0057]

[0058] Among them, r φ (·) is the output of the reward model, which accepts the program as input and outputs a scalar as the evaluation result of the program repair effect; (y w ,y l ) is a partially ordered pair, y w for a more preferred procedure.

[0059] The reward model evaluates the intermediate code version generated at each step and provides rewards based on predefined code quality criteria such as compilation success, runtime, memory usage, functional correctness, etc. These rewards are used to train the repair model to bias it towards generating code solutions that receive higher rewards.

[0060] The output of the reward model is used to guide the training process of the repair model and optimize the model parameters to enhance the model's performance in future tasks. In this way, the repair model gradually learns how to repair a variety of complex programming errors.

[0061] Based on the above embodiments, the present application may further include: using a reinforcement learning proximal strategy optimization algorithm to fine-tune the repair model. By combining a large language model and reinforcement learning methods, it can provide certain technical support for the practice of code intelligence fields such as program repair and code generation.

[0062] Specifically, the training goal is to maximize the following reward to optimize the parameters θ of the repair model:

[0063]

[0064] Among them, x i+1 is based on the input x i The output after repair, r φ (·) is the output of the reward model, and the KL reward coefficient β controls the strength of the KL penalty. Represents the judgment of improvement after repair.

[0065] The input of the repair model is x = {x1, x2, ..., x N}, the output is y={y1,y2,…,y N′}; Based on the training sample set The training process is to minimize the log-likelihood loss Adjust the model parameters θ so that the repair model predicts the repaired program:

[0066]

[0067] Among them, y <t is the repair sequence before time t, Θ is the model trainable parameter, The training sample set expectations.

[0068] The repair model performs multiple iterations of repair until the preset condition is met, which is that there is no continuous improvement within P steps, that is, Δ<=0; or the maximum number of repair steps is reached. If the improvement (Δ, indicating the degree of improvement) of each step does not exceed 0 in the continuous P-step operation, the repair process is stopped. Alternatively, the maximum number of repair steps is set, and if the stop condition 1 cannot be reached within P steps, it will also be terminated because the set maximum number of steps is reached. This setting ensures that even in the worst case, the repair process will not be carried out indefinitely.

[0069] This technical solution allows the model to perform multi-step repairs until there is no significant improvement or the maximum number of steps is reached, which simulates the actual behavior of human developers during program debugging. This iterative optimization strategy may be closer to the repair strategy of human programmers and help generate more practical and maintainable code. This application not only uses a large-scale language model for code understanding and generation, but also further optimizes the repair strategy through reinforcement learning. An independent reward model is introduced to evaluate the quality of the repair code. This reward model evaluates different code states (such as compilation errors, runtime errors, etc.) based on non-strictly constrained partial order relations. This method provides a more sophisticated feedback mechanism and can adjust the optimization strategy according to the performance of the actual code. The quality of the generated code is evaluated by the reward model, and the strategy is adjusted to optimize the generated results, making the repair process more dynamic and more adaptable to specific code quality requirements.

[0070] A flowchart of another specific implementation of the program repair method provided by the present application is as follows: Figure 2 The corresponding implementation process diagram is shown in Figure 3 As shown, the method specifically includes:

[0071] S201: Problem definition and formalization.

[0072] For the program repair task, its purpose is to generate a repaired program (output y) based on the repair instructions and the existing faulty program (input x).

[0073] The input of the repair model is composed of the prompt template and the error program as the input of the repair model x = {x1, x2, ..., x N}, the output is the repaired program y = {y1,y2,…,y N′}. Formally, given k observed samples The generation task is to minimize the log-likelihood loss:

[0074]

[0075] Among them, y <t is the repair sequence before time t, and Θ is a model trainable parameter.

[0076] By minimizing the log-likelihood loss, the model parameters Θ are adjusted so that the model can more accurately predict the repaired program y.

[0077] S202: Data collection and preprocessing.

[0078] A plurality of original program samples for programming problems are collected from a plurality of data sources; static filtering and dynamic filtering are performed on the original program samples to obtain a training sample set.

[0079] As a specific implementation method, the original program sample can be obtained by collecting a large number of historical answer records of the Python language from an Internet platform, and the historical answer records are arranged according to the submission time of all the programmer's answers to a certain programming problem.

[0080] After obtaining the original program samples, they can be further filtered and cleaned according to the following two rules to construct a process-based repair dataset.

[0081] 1. Static filtering, which mainly relies on static string processing to improve the quality of program text.

[0082] The static filtering of the original program sample includes:

[0083] (1) Remove samples that are identical or similar to the original program.

[0084] Submissions on the Internet often contain random and duplicate submissions. Filtering duplicate submissions can effectively reduce the noise of the dataset.

[0085] (2) Delete the original program samples including the malicious program.

[0086] Filters have attack programs. Attack programs attempt to attack the compiler environment in an attempt to damage the executor's programming environment (such as a database or file system).

[0087] (3) Delete original program samples that include sensitive information or personal information.

[0088] Some integrated development environments automatically generate comments that may leak user privacy. Removing programs that include sensitive information or personal information can avoid leaking user privacy.

[0089] (4) Ensure that each user has at least one solution that is considered correct in the training sample set.

[0090] Ensure that every user has at least one acceptable submission in the process of solving the problem.

[0091] 2. Dynamic filtering. Due to different compilation environments, the program execution results are often not completely consistent. All remaining programs after the first step of static filtering will be re-executed to verify the results.

[0092] Dynamically filtering the original program sample includes: using a predetermined version of the Python environment as a standard test environment, re-running the statically filtered program under the standard test environment to verify whether the execution result of the program is consistent with expectations; based on the execution result, it is again ensured that each user has at least one correct solution, and a repaired program is generated.

[0093] For example, you can set the Python 3.11.3 environment as the standard environment and re-execute the verification. Only the answer records that are consistent with the original state and the execution result are retained, and the final result is obtained by filtering again using the rule (4) in the static filtering. The final data set contains several answer records, which include the submitted codes arranged in chronological order, and the last submission is accepted.

[0094] S203: Establish a repair model.

[0095] S2031: Supervised fine-tuning on the program repair task. To ensure that the repair model can understand the program repair task, we use prompt templates for supervised fine-tuning. Given a fragile program sequence, the language model is required to output a more robust program.

[0096] S2032: Train reward model.

[0097] The embodiment of the present application does not directly use feedback from the compiler and test cases, but instead trains a reward model to diagnose program quality.

[0098] Specifically, the present application first empirically defines a non-strictly constrained partial order relationship for program status, which is: acceptance>expression error>answer error>timeout>exceeded maximum memory limit>compile error>runtime error.

[0099] Based on the above partial order relationship, this application uses a pairwise sorting method to optimize the reward model parameter φ. Given K programs with states, we can construct For the partial order set D, after shuffling the partial order set D, minimize the following pairwise sorting loss to train the reward model:

[0100]

[0101] where r φ (·) is a reward model that accepts a program as input and outputs a scalar as the score of the program.

[0102] In practice, the embodiment of the present application may use another smaller pre-trained autoregressive model and replace all non-embedding layers of the original model with projection layers to output a scalar. (y w ,y l ) is a partial order pair, where y w is a preferred procedure. For example, w is accepted, and y l It is a wrong answer.

[0103] S2033: Fine-tune the repair model using the reinforcement learning PPO algorithm.

[0104] Through the Proximal Policy Optimization (PPO) algorithm, the repair model is fine-tuned so that it can generate higher quality repair programs under given program states.

[0105] The repair model acts as an actor and generates a repaired program (action) based on the input program (state). The trained reward model acts as a critic, evaluating the quality of the program generated by the repair model and giving feedback to guide the learning of the repair model.

[0106] The goal is to optimize the parameters θ of the repair model by maximizing the following reward:

[0107]

[0108] where x i+1 is based on the input x i The output after repair, r φ (·) is the output of the reward model, and the KL reward coefficient β controls the strength of the KL penalty. Represents the judgment of improvement after repair.

[0109] S204: Perform multi-step repair under the supervision of the reward model to generate a final repaired program.

[0110] The repair model continues to perform multiple repair steps until one of the following two conditions is met:

[0111] (1) There is no improvement within P steps, that is, Δ <= 0;

[0112] (2) Reach the maximum number of repair steps.

[0113] Figure 3 The system architecture and process of using a large-scale language model (LM) to automatically repair programs are shown, named "CodeNet4Repair" in the figure.

[0114] In the figure, the pre-trained language model (Pre-trained LM) is used as the basis for implementation. A widely trained language model is used, which can be specifically GPT or BERT. This model already has certain code understanding and generation capabilities.

[0115] Fine-tuned Language Model (Fine-tuned LM): A pre-trained model is fine-tuned on a specific programming task to adapt to the specific needs of code repair. The model is fine-tuned to understand the specific syntax and semantics of the programming language, as well as common programming errors.

[0116] Problem Description: Describes the problem with the program that needs to be fixed, such as compilation errors (CE), warnings (WA), performance issues (PE), and acceptable solutions (AC).

[0117] Buggy Solution: This is a pending fix that may contain one or more programming errors.

[0118] Compiler & Test Cases: The compiler is used to detect syntax and runtime errors. Test cases are used to verify the functional correctness of the code and ensure that the repaired code can meet the expected behavior.

[0119] Environment: includes a compiler and multiple test cases, providing an environment for the model to execute and verify the code.

[0120] In the process-based feedback process, a fine-tuned large language model is used to generate candidate solutions. The candidate solutions generated by the fine-tuned model are modifications of the wrong solution. The reward model evaluates the effectiveness of the fix. The reward model can prioritize these results according to compilation errors (CE), warnings (WA), performance issues (PE), and acceptable solutions (AC), thereby giving feedback on the quality of the fix. The output of the reward model helps train and fine-tune the language model so that it can provide more effective fixes in the future.

[0121] Through the feedback mechanism of the reward model, we can better understand which types of repairs are most effective, thereby achieving more accurate automatic program repairs.

[0122] A specific example of the program repair method provided in this application is described as follows: Figure 4The figure shows the gradual evolution of a solution to a programming problem, including changes to the code and their reasons. The problem describes a situation where Snuke has a calculator that displays an integer x and has two buttons that can be pressed. One button increases the displayed value and the other button changes the sign of the value. The task is to find the minimum number of button presses required to change x to y.

[0123] By constantly revising and optimizing the code, we try to find the optimal solution. In this way, developers can find the solution with the minimum number of steps to meet the requirements of the problem through continuous trial and error and verification. After each attempt, error analysis and logic adjustment are performed until the final solution meets the expected results. This is a typical algorithm optimization process, which improves the efficiency and accuracy of the code through continuous iteration of the code logic.

[0124] In addition, the present application also provides a program repair device, such as Figure 5 As shown in the structural block diagram of the program repair device provided in the present application, the program repair device specifically includes: a memory 51 and a processor 52, the memory 51 stores a computer program, and when the computer program is executed by the processor 52, any one of the above-mentioned program repair methods is implemented.

[0125] In addition, the present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, any of the above-mentioned program repair methods is implemented.

[0126] Computer readable storage media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.

[0127] This application evaluates the program status based on a predefined partial order relationship, provides a more flexible and extensive evaluation dimension, and can more comprehensively evaluate the various quality attributes of the program. In addition, the model is allowed to perform multi-step repairs, which simulates the actual behavior of human developers during program debugging. This iterative optimization strategy may be closer to the repair strategy of human programmers, which not only improves the repair efficiency, but also enhances the quality and adaptability of the generated code, providing a more flexible program repair strategy that is more in line with actual development needs.

[0128] The professionals should also be further aware that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented with electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0129] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0130] The specific implementation methods described above further illustrate the purpose, technical solutions and beneficial effects of the present application in detail. It should be understood that the above description is only the specific implementation method of the present application and is not intended to limit the scope of protection of the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the scope of protection of the present application.

Claims

1. A program repair method, characterized in that: include: Get the program to be repaired; Inputting the program to be repaired into a repair model to generate candidate solutions; wherein the repair model uses known faulty programs and repaired programs as training sample sets to fine-tune the pre-trained large language model; The candidate solutions generated by the repair model are input into the reward model to generate an evaluation result of the program repair effect, and the repair model is iteratively repaired multiple times based on the evaluation result until the final repaired program is generated; wherein the reward model evaluates different program states based on a partial order relationship without strict constraints, generates an evaluation result of the program repair effect, and feeds the evaluation result back to the repair model so that the repair model adjusts the generation strategy based on the evaluation result.

2. The program repair method according to claim 1, characterized in that: The reward model defines a partial order relationship for the program status, and the priority order of the partial order relationship is: acceptance, expression error, answer error, timeout, maximum memory limit exceeded, compilation error, and runtime error.

3. The program repair method according to claim 2, characterized in that: The training process of the reward model includes: Based on the partial order relationship, the reward model parameter φ is optimized using the pairwise sorting method: Given K programs with states, construct For the partial order set D, after shuffling the partial order set D, minimize the following pairwise sorting loss to train the reward model: Among them, r φ (·) is the output of the reward model, which accepts the program as input and outputs a scalar as the evaluation result of the program repair effect; (y w ,y l ) is a partially ordered pair, y w for a more preferred procedure.

4. The program repair method according to claim 3, characterized in that: Also includes: Using a reinforcement learning proximal strategy optimization algorithm to fine-tune the repair model; The training goal is to optimize the parameters θ of the repair model by maximizing the following reward: Among them, x i+1 is based on the input x i The output after repair, r φ (·) is the output of the reward model, and the KL reward coefficient β controls the strength of the KL penalty. Represents the judgment of improvement after repair.

5. The program repair method according to any one of claims 1 to 4, characterized in that: The repair model performs multiple iterations of repair until a preset condition is met, wherein the preset condition is that there is no continuous improvement within P steps; or a maximum number of repair steps is reached.

6. The program repair method according to claim 5, characterized in that: The input of the repair model is x = {x1, x2, ..., x N }, the output is y={y1,y2,…,y N′ }; Based on the training sample set The training process is to minimize the log-likelihood loss Adjust the model parameters θ so that the repair model predicts the repaired program: Among them, y <t is the repair sequence before time t, Θ is the model trainable parameter, The training sample set expectations.

7. The program repair method according to claim 5, characterized in that: The process of obtaining the training sample set includes: Collect multiple original program samples for programming problems from multiple data sources; Static filtering and dynamic filtering are performed on the original program samples to obtain a training sample set.

8. The program repair method according to claim 7, characterized in that: The static filtering of the original program sample comprises: Remove identical or similar original program samples; delete original program samples that include malicious programs; delete original program samples that include sensitive information or personal information; ensure that each user has at least one solution that is considered correct in the training sample set.

9. The program repair method according to claim 7, characterized in that: The dynamically filtering the original program sample comprises: Using a predetermined version of the Python environment as a standard test environment, re-running the statically filtered program in the standard test environment to verify whether the program execution result is consistent with expectations; Based on the execution results, it is again ensured that each user has at least one correct solution and a repaired program is generated.

10. A program repair device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the program repair method according to any one of claims 1 to 9 is implemented.

11. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed by a processor, the program repair method according to any one of claims 1 to 9 is implemented.

Citation Information

Patent Citations

  • Program defect automatic repairing method and system based on code language model

    CN116755753A

  • Program vulnerability automatic repairing method based on generative adversarial network

    CN117828615A

  • Systems and methods for retrieval-augmented patch generation for automatic program repair

    WO2023224819A1

Cited By

  • Method and system for automatically repairing control system based on large language model

    CN120065871A

  • Control system automation repair method and system based on large language model

    CN120065871B