A program repair method, device and computer readable storage medium
By employing iterative optimization strategies for the repair model and reward model, the problems of low program repair efficiency and inconsistency in existing technologies are solved, achieving efficient and reliable program repair results.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-02
- Publication Date
- 2026-03-20
AI Technical Summary
In existing technologies, end-to-end program repair methods suffer from high edit distances and do not conform to human developer behavior patterns, making it difficult to repair programs efficiently and reliably.
By combining a repair model and a reward model, candidate solutions are generated and repaired multiple times based on a non-strictly constrained partial order relation until the final repaired program is generated.
It improves the efficiency and quality of program repair, conforms to the behavior patterns of human developers, and generates repair results that better meet actual needs.
Smart Images

Figure CN118981433B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of artificial intelligence, and in particular relates to a program repair method, device and computer readable storage medium. BACKGROUND
[0002] Program repair has been recognized as a key problem in software development and maintenance, and its purpose is to repair fragile programs to obtain more robust and robust programs. A good program repair method can not only reduce the threshold and cost of manual repair, but also improve the reliability in software development engineering.
[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 fragile 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 once through one-step modification. Second, single-step program repair does not conform to human behavior patterns: programmers often repair programs iteratively, first solving simple syntax 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 in the training process and are close to the error program. These two problems pose challenges to program repair.
[0004] Therefore, how to make the program repair process more efficient, reliable, and more in line with the needs of actual software development and the behavior patterns of human developers is one of the technical problems that the application aims to solve. SUMMARY
[0005] In view of the above analysis, the embodiments of the application aim to provide a program repair method, device and computer readable storage medium to make the program repair process more efficient, reliable, and more in line with the needs of actual software development and the behavior patterns of human developers.
[0006] The first aspect of the application provides a program repair method, comprising:
[0007] obtaining a program to be repaired;
[0008] inputting the program to be repaired into a repair model to generate a candidate solution; wherein the repair model uses known error programs and repaired programs as a training sample set to fine-tune a pre-trained large language model;
[0009] The candidate solution generated by the repair model is input into the reward model to generate an evaluation result of the program repair effect evaluation, and the repair model is iteratively repaired multiple times based on the evaluation result until a final repaired program is generated.
[0010] Optionally, the reward model defines a partial order relation for program states, and the priority order of the partial order relation is in turn: accepted, expressed error, answered error, timeout, exceeded maximum memory limit, compilation error, and runtime error.
[0011] Optionally, the training process of the reward model includes:
[0012] Based on the partial order relation, the reward model parameters φ are optimized using a pairwise ranking method:
[0013] Given K programs with states, construct For the partial order set D, after shuffling the partial order set D, the following pairwise ranking loss is minimized to train the reward model:
[0014]
[0015] Where r φ (y) is the output of the reward model, which accepts a program as input and outputs a scalar as an evaluation result of the program repair effect evaluation; (y w ,y l ) is a partial order pair, y w is a more preferred program.
[0016] Optionally, it further includes fine-tuning the repair model using a reinforcement learning proximal policy optimization algorithm;
[0017] The training target is to maximize the following reward to optimize the parameters θ of the repair model:
[0018]
[0019] Where x i+1 is the output based on the input x i 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 the improvement after repair.
[0020] Optionally, the repair model is iteratively repaired until a preset condition is met, the preset condition being that there is no improvement for P steps in a row; or a maximum number of repair steps is reached.
[0021] Optionally, the input of the repair model is x={x1,x2,…,x N} and the output is y={y1,y2,…,y N′}; based on a 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] where y <t is the repair sequence before time t, Θ is the model trainable parameter, is the expectation of the training sample set .
[0024] Optionally, the process of obtaining the training sample set comprises:
[0025] Collecting a plurality of original program samples for programming problems from a plurality of data sources;
[0026] Performing static filtering and dynamic filtering on the original program samples to obtain the training sample set.
[0027] Optionally, the static filtering of the original program samples comprises:
[0028] Removing identical or similar original program samples; deleting original program samples including malicious programs; deleting original program samples including sensitive information or personal information; ensuring that each user has at least one correct solution in the training sample set.
[0029] Optionally, the dynamic filtering of the original program samples comprises:
[0030] Using a predetermined version of the Python environment as a standard test environment, re-running the programs that have been statically filtered in the standard test environment to verify whether the execution results of the programs are consistent with the expectations;
[0031] Based on the execution results, ensuring again that each user has at least one correct solution, and generating the repaired program.
[0032] In a second aspect of the present application, a program repair device is provided, comprising a memory and a processor, the memory storing a computer program, the computer program being executed by the processor to implement any of the above-mentioned program repair methods.
[0033] In a third aspect, the present application provides a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements any of the program repair methods described above.
[0034] The program repair method provided by the present application comprises the following steps: obtaining a to-be-repaired program; inputting the to-be-repaired program into a repair model to generate a candidate solution; inputting the candidate solution generated by the repair model into a reward model to generate an evaluation result of the program repair effect evaluation, and performing multiple iterations of the repair model based on the evaluation result until a final repaired program is generated. The reward model evaluates different program states based on a non-strictly constrained partial order relation, 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] The present application evaluates program states based on a predefined partial order relation, provides more flexible and extensive evaluation dimensions, and can more comprehensively evaluate various quality attributes of the program. Moreover, the model is allowed to perform multiple-step repair, which simulates the actual behavior of human developers in the program debugging process. This iterative optimization strategy may be closer to the repair strategy of human programmers, not only improving the repair efficiency, but also enhancing the quality and adaptability of the generated code, and providing a more flexible and more practical development demand-oriented program repair strategy.
[0036] In addition, the present application also provides a program repair device and a computer readable storage medium with the above technical effects. BRIEF DESCRIPTION OF DRAWINGS
[0037] In order to more clearly illustrate the technical solutions in the embodiments or the prior art of the present application, the drawings needed in the embodiment or prior art description will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments described in the present application, and other drawings can also be obtained by those skilled in the art based on these drawings.
[0038] Figure 1 The flow chart of one specific embodiment of the program repair method provided by the present application;
[0039] Figure 2 The flow chart of another specific embodiment of the program repair method provided by the present application;
[0040] Figure 3 The implementation process schematic diagram of another specific embodiment of the program repair method provided by the present application;
[0041] Figure 4A schematic is described for a specific example of the program repair method provided in the present application;
[0042] Figure 5 A structural block diagram of the program repair device provided in the present application is shown. DETAILED DESCRIPTION
[0043] To make the purposes, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are some embodiments of the present application, rather than all the embodiments of the present application. It should be noted that, in the case of no conflict, the embodiments and the features in the embodiments in the present disclosure can be combined, separated, interchanged and / or rearranged. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor are within the scope of protection of the present application.
[0044] The terms used herein are for the purpose of describing specific embodiments and are not intended to be limiting. As used herein, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. Further, when the terms "comprises," "comprising," "includes," "including," and the like are used in the following description and claims, such terms are intended to be inclusive in a manner that the recited elements and / or components are present, but not excluding or in addition to one or more additional elements or components. It should also be noted that, as used herein, the terms "substantially," "approximately," and other similar terms are used as terms of approximation and not as terms of degree, such that they are utilized to account for inherent deviations in measurements, calculations, and / or provided values that would be recognized by those of ordinary skill in the art.
[0045] A flowchart of a specific embodiment of the program repair method provided in the present application is shown in Figure 1 The method includes the following steps:
[0046] S101: Obtain a program to be repaired.
[0047] It can be understood that the program to be repaired can be a piece of erroneous program code.
[0048] S102: Input the program to be repaired into a repair model to generate a candidate solution.
[0049] The repair model uses known erroneous programs and repaired programs as a training sample set to fine-tune a pre-trained large language model.
[0050] The repair model is a pre-trained language model fine-tuned on specific task data. The fine-tuning data includes known erroneous programs and corresponding repaired programs, enabling the model to learn how to transition from erroneous states to correct states. S103: The candidate solutions generated by the repair model are input into the reward model to generate evaluation results for the program repair effect, and the repair model is iteratively repaired based on the evaluation results until the final repaired program is generated.
[0051] The candidate repair program generated by the repair model is then input into the reward model. The reward model evaluates the repair effect of the candidate program based on the partial order relationship of the program state, and generates a score. Based on the score given by the reward model, the repair model iteratively 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 non-strict constraint partial order relationship, generates evaluation results for the program repair effect, and feeds back the evaluation results to the repair model to adjust the generation strategy based on the evaluation results.
[0053] The reward model defines a partial order relationship for program states, with the priority order of the partial order relationship being: accepted, expressed error, answered error, timeout, exceeded maximum memory limit, compilation error, runtime error.
[0054] The training process of the reward model includes:
[0055] Based on the partial order relationship, the reward model parameters φ are optimized using a pairwise ranking 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 ranking loss to train the reward model:
[0057]
[0058] where r φ is the output of the reward model, which accepts a program as input and outputs a scalar as an evaluation result for the program repair effect; (y w , y l ) is a partial order pair, y w is a more preferred program.
[0059] The reward model evaluates the intermediate code version generated at each step and provides rewards based on predefined code quality criteria such as successful compilation, runtime, memory usage, functional correctness, etc. These rewards are used to train the repair model to favor code solutions that result in higher rewards.
[0060] The output of the reward model is used to guide the training process of the repair model, optimizing the model parameters to enhance the model's performance in future tasks. In this way, the repair model gradually learns how to fix various complex programming errors.
[0061] Based on the above embodiments, the present application can further include: a process of fine-tuning the repair model using a reinforcement learning proximal policy optimization algorithm. By combining large language models and reinforcement learning methods, it can provide certain technical support for the practice of program repair, code generation, and other code intelligence fields.
[0062] Specifically, the training objective is to maximize the following reward to optimize the parameters θ of the repair model:
[0063]
[0064] where x i+1 is the input based on x i the repaired output, r φ (·) is the output of the reward model, and KL reward coefficient β controls the strength of the KL penalty, represents the judgment of the improvement after repair.
[0065] The input of the repair model is x={x1,x2,…,x N}, and 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] where y <t is the repair sequence before time t, Θ is the model trainable parameter, is the expectation of the training sample set .
[0068] The repair model performs multiple iterations of repair until a preset condition is met, which is that there is no improvement within P steps, i.e., Δ <= 0; or the maximum number of repair steps is reached. If the improvement (Δ, representing the degree of improvement) of each step does not exceed 0 in consecutive P steps, the repair process is stopped. Or set the maximum number of repair steps, if the stop condition 1 cannot be reached within P steps, it will also be terminated because the maximum number of steps is reached. Through such a setting, it is ensured that even in the worst case, the repair process will not be carried out indefinitely.
[0069] The technical solution allows the model to perform multiple-step repair until there is no significant improvement or the maximum number of steps is reached, which simulates the actual behavior of human developers in the program debugging process. This iterative optimization strategy may be closer to the repair strategy of human programmers, helping to generate more practical and maintainable code. The present 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 repaired code, and this reward model evaluates different code states (such as compilation errors, runtime errors, etc.) based on a non-strict partial order relationship. This method provides a more fine-grained feedback mechanism that can adjust the optimization strategy according to the actual code performance. The quality of the generated code is evaluated by the reward model, and the optimization strategy is adjusted to generate the results, making the repair process more dynamic and more adaptive to specific code quality requirements.
[0070] The flowchart of another specific embodiment of the program repair method provided by the present application is shown in Figure 2 The corresponding implementation process schematic diagram is shown in Figure 3 The method specifically comprises:
[0071] S201: Problem definition and formalization.
[0072] For the program repair task, the purpose is to generate a repaired program (output y) according to the repair instruction and the existing error program (input x).
[0073] The input of the repair model is the prompt template and the error program as the input x = {x1, x2, …, x N} of the repair model, and the output is the repaired program y = {y1, y2, …, y N′}. Formally, given k observed samples The generation task is to train the target to minimize the log-likelihood loss:
[0074]
[0075] Where y <t is the repair sequence before time t, and Θ is the 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 a programming problem are collected from a plurality of data sources; the original program samples are statically filtered and dynamically filtered to obtain a training sample set.
[0079] As a specific embodiment, the original program samples can be collected from an Internet platform to collect a large number of historical answer records of Python language, which are arranged according to the submission time of all answers of a programmer on a programming problem.
[0080] After obtaining the original program samples, the process-based repair dataset can be further filtered and cleaned according to the following two rules.
[0081] 1. Static filtering mainly relies on static string processing to improve program text quality.
[0082] Among them, the static filtering of the original program samples includes:
[0083] (1) Removing the same or similar original program samples.
[0084] Submissions on the network often contain random and copied submissions, and filtering duplicate submissions can effectively reduce the noise of the dataset.
[0085] (2) Delete original program samples including malicious programs.
[0086] Filtering attack programs. Attack programs attempt to attack the compiler environment in an attempt to compromise the programmer's programming environment (such as databases or file systems).
[0087] (3) Delete original program samples including sensitive information or personal information.
[0088] Some integrated development environments will automatically generate some comments that will leak user privacy. Deleting programs that include sensitive information or personal information can avoid leaking user privacy.
[0089] (4) Ensure that each user has at least one correct solution in the training sample set.
[0090] Ensure that each user has at least one acceptable submission in the process of solving the problem.
[0091] 2. Dynamic filtering. Due to different compilation environments, the execution results of programs are often not completely consistent. All programs remaining after the first static filtering are re-executed to verify the results.
[0092] Dynamic filtering of the original program sample includes: taking a predetermined version of the Python environment as a standard test environment, re-running the program after static filtering under the standard test environment to verify whether the execution result of the program is consistent with the expectation; based on the execution result, ensuring that each user has at least one correct solution again, and generating a repaired program.
[0093] For example, a Python3.11.3 environment can be set as a standard environment and re-executed for verification. Only the answer records in the original state and the execution results are consistent, and the final results are obtained by filtering again using the rule (4) in the static filtering. The final data set contains several answer records, and the answer records include the submission code arranged in time sequence, and the last submission is accepted.
[0094] S203: Establish a repair model.
[0095] S2031: Supervised fine-tuning on the program repair task. In order to ensure that the repair model can understand the program repair task, we use the prompt template for supervised fine-tuning. Given a fragile program sequence, the language model is required to output a more robust program.
[0096] S2032: Train the reward model.
[0097] The embodiments of the present application do not directly use feedback from the compiler and test cases, but train a reward model to diagnose program quality.
[0098] Specifically, the present application first empirically defines a non-strict constraint partial order relation for the program state, which is: accepted > expressed error > answered error > timeout > exceeded maximum memory limit > compilation error > runtime error.
[0099] Based on the above partial order relation, the present application uses the pairwise ranking 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 ranking loss to train the reward model:
[0100]
[0101] where r φ (·) is the reward model, which accepts the program as input and outputs a scalar as a score for the program.
[0102] In practice, the embodiments of the present application can 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 more preferred procedure. For example, y w is accepted, and y l is an incorrect 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 to be able to generate a higher quality repair procedure under a given procedure state.
[0105] The repair model acts as an actor to generate a repaired procedure (action) based on the input procedure (state). The trained reward model acts as a critic to evaluate the quality of the procedure generated by the repair model and give feedback to guide the learning of the repair model.
[0106] The goal is to maximize the following reward to optimize the parameters θ of the repair model:
[0107]
[0108] Where x i+1 is the output based on the input x i , r φ (·) is the output of the reward model, and the KL reward coefficient β controls the strength of the KL penalty, represents the judgment of the improvement after repair.
[0109] S204: Perform multi-step repair under the supervision of the reward model to generate the final repaired procedure.
[0110] The repair model continues to perform multi-step repair until one of the following two conditions is met:
[0111] (1) There is no improvement continuously within P steps, i.e., Δ <= 0;
[0112] (2) The maximum repair step is reached.
[0113] Figure 3 The system architecture and process of using a large-scale language model (LM) to automatically repair a procedure are shown in the figure, named "CodeNet4Repair".
[0114] In the figure, the pre-trained language model (Pre-trained LM) is the foundation for implementation, using a widely trained language model, which can be GPT or BERT. This model already has certain code understanding and generation capabilities.
[0115] Fine-tuned language model (Fine-tuned LM): The pre-trained model is fine-tuned on specific programming tasks 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 (Problem Description): Describes the problem of the program that needs to be repaired, such as compilation error (CE), warning (WA), performance problem (PE), and acceptable solution (AC).
[0117] Buggy solution (Buggy Solution): This is the program to be repaired, which may include one or more programming errors.
[0118] Compiler and test cases (Compiler&Test Cases): The compiler is used to detect syntax and runtime errors. Test cases are used to verify the correctness of the code, ensuring that the repaired code meets the expected behavior.
[0119] Environment (Environment): Includes the 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 buggy solution. The reward model evaluates the effectiveness of the repair. The reward model can prioritize these results based on compilation errors (CE), warnings (WA), performance problems (PE), and acceptable solutions (AC), providing feedback on the quality of the repair. The output of the reward model helps to train and fine-tune the language model to provide more effective repairs in the future.
[0121] Through the feedback mechanism of the reward model, it helps to better understand which type of repair is most effective, thereby achieving more accurate automatic program repair.
[0122] One specific example of the program repair method provided in this application is described as follows: Figure 4As shown, the diagram shows the evolution of a solution to a programming problem, including modifications to the code and the reasons for them. The problem describes a scenario where Snuke has a calculator displaying 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 needed to change x to y.
[0123] The optimal solution is found by continuously refining and optimizing the code. In this way, the developer can find the solution that meets the requirements of the problem by continuously trying and verifying the minimum number of steps. After each attempt, error analysis and logic adjustment are carried out until the final solution meets the expected effect. This is a typical algorithm optimization process, through continuous iteration of code logic, improving the efficiency and accuracy of the code.
[0124] In addition, the present application also provides a program repair device, such as Figure 5 The structure diagram of the program repair device provided by the present application is shown, which specifically comprises: a memory 51 and a processor 52, the memory 51 stores a computer program, and the computer program is executed by the processor 52 to realize the program repair method described above.
[0125] In addition, the present application also provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to realize the program repair method described above.
[0126] Computer readable storage media includes permanent and non-permanent, removable and non-removable media, which 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 disc read only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette, magnetic tape, magnetic disk storage or other magnetic storage device, or any other non-transmission medium that can be used to store information accessible by a computing device. According to the definition in this paper, computer readable medium does not include transitory computer readable medium, such as modulated data signal and carrier wave.
[0127] This application evaluates program state based on predefined partial order relations, providing more flexible and broader evaluation dimensions, and enabling a more comprehensive assessment of various quality attributes of the program. Furthermore, it allows the model to perform multi-step fixes, simulating the actual behavior of human developers during program debugging. This iterative optimization strategy is likely closer to the fix strategies of human programmers, not only improving fix efficiency but also enhancing the quality and adaptability of the generated code, providing a more flexible program fix strategy that better meets actual development needs.
[0128] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0129] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented in hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0130] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of this application. It should be understood that the above description is only a specific embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application.
Claims
1. A program repair method, characterized in that, include: Obtain the program to be repaired; The program to be repaired is input into the repair model to generate candidate solutions; wherein, the repair model uses known faulty programs and repaired programs as training sample sets to fine-tune a 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. Based on the evaluation result, the repair model is iterated and repaired multiple times until the final repaired program is generated. The reward model evaluates different program states based on a non-strictly constrained partial order relation, generates an evaluation result of the program repair effect, and feeds the evaluation result back to the repair model so that the repair model can adjust its generation strategy based on the evaluation result. The reward model defines a partial order relation for program states, and the priority order of the partial order relation is as follows: acceptance, expression error, answer error, timeout, exceeding the maximum memory limit, compilation error, and runtime error. The training process of the reward model includes: optimizing the reward model parameters using a pairwise ranking method based on the partial order relation. Given K programs with states, construct For a partially ordered set D, after shuffling the partially ordered set D, minimize the following pairwise ordering loss to train the reward model: in, The reward model is the output of which accepts the program as input and outputs a scalar as an evaluation result of the program's repair effect. As a partially ordered pair, For a more preferred program; The input to the repair model is The output is Based on the training sample set The training process involves minimizing the log-likelihood loss. Adjust model parameters This allows the repair model to predict the repaired procedure: in, It is in time The previous repair sequence, These are the trainable parameters of the model. For training sample set The expectation.
2. The program repair method according to claim 1, characterized in that, Also includes: The repair model is fine-tuned using a reinforcement learning proximal policy optimization algorithm; The training objective is to maximize the following rewards to optimize the parameters of the repair model. : in, Based on input The repaired output, It is the output of the reward model, the KL reward coefficient. Control the intensity of KL penalties. This represents the assessment of improvement after repair.
3. The program repair method according to any one of claims 1 to 2, characterized in that, The repair model performs multiple iterations until a preset condition is met, which is that there is no improvement within P steps; or the maximum number of repair steps is reached.
4. The program repair method according to claim 3, characterized in that, The process of obtaining the training sample set includes: Collect multiple original program samples from multiple data sources to address programming problems; The original program samples are subjected to static and dynamic filtering to obtain a training sample set.
5. The program repair method according to claim 4, characterized in that, The static filtering of the original program sample includes: Remove identical or similar original program samples; delete original program samples containing malware; delete original program samples containing sensitive or personal information; ensure that each user has at least one solution considered correct in the training sample set.
6. The program repair method according to claim 4, characterized in that, The dynamic filtering of the original program sample includes: The predefined version of the Python environment was used as the standard test environment. The statically filtered program was rerun in the standard test environment to verify whether the program's execution results were consistent with expectations. Based on the execution results, we ensure that each user has at least one correct solution and generate a repaired program.
7. A program repair device, characterized in that, It includes a memory and a processor, the memory storing a computer program that, when executed by the processor, implements the program repair method according to any one of claims 1-6.
8. A computer-readable storage medium, characterized in that, It stores a computer program, which, when executed by a processor, implements the program repair method according to any one of claims 1-6.
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