Deep learning library numerical instability problem detection and repair method based on patch and large language model
Through the method based on patch and large language models, the numerical instability problem in the deep learning library is automatically detected and repaired, and the detection and repair problems in the existing technology are solved, the model performance and security are improved, and the efficiency requirements are met.
Patent Information
- Application Number
- CN202411291165.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-14
- Publication Date
- 2024-12-31
- Estimated Expiration
- 2044-09-14
AI Technical Summary
The prior art is difficult to detect and repair numerical instability problems in deep learning libraries in comprehensively and accurately, resulting in model performance and safety hazards, and manual analysis is time-consuming and labor-intensive, making it difficult to meet the efficiency requirements of practical applications.
Using a method based on patch and large language model, automated detection and generation of repair patches are achieved through program slicing, dependency analysis, teleprompt template design and similar patch queries, improving the efficiency and accuracy of detection and repair.
It realizes efficient and automated detection and repair of numerical instability problems, improves the model performance and security of the deep learning library, and meets the efficiency requirements of practical applications.
Smart Images

Figure CN119227673A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of software engineering and deep learning security technology, and in particular, relates to a method for detecting and repairing numerical instability problems in deep learning libraries based on patches and large language models. Background Art
[0002] Deep learning technology has become one of the core methods in today's data analysis and artificial intelligence fields, and is widely used in many fields such as image recognition, natural language processing, and autonomous driving. However, in the process of using deep learning libraries for model training and deployment, numerical instability has become a key factor affecting model performance and reliability. Numerical instability may lead to problems such as failure to converge during model training, significant increase in training time, and abnormal model output results. In severe cases, it may even cause the model to fail completely. This not only affects the accuracy and robustness of the model, but may also cause safety hazards in practical applications. For example, in autonomous driving systems, numerical instability may lead to vehicle recognition errors, thereby causing traffic accidents; in medical diagnosis systems, numerical instability may lead to incorrect diagnosis results, directly endangering the safety of patients' lives.
[0003] At present, the research on the numerical instability problem of deep learning libraries mainly focuses on improving the accuracy of numerical calculations and optimizing the model structure. Although these methods can alleviate the numerical instability problem to a certain extent, due to the huge code of deep learning libraries and the complexity and diversity of numerical instability problems, it is difficult for existing methods to comprehensively and accurately detect and repair all numerical instability problems. In addition, manual analysis and repair of numerical instability problems requires a lot of professional knowledge and time, which is difficult to meet the efficiency requirements in practical applications. Therefore, it is particularly important to find an efficient and automated method to detect and repair numerical instability problems.
[0004] With the rapid development of natural language processing technology, large language models have shown great potential in the field of code analysis and automatic repair. A large language model is a large-scale language model that can understand the structure, syntax and semantic association of programming languages by learning massive code bases and document materials, and can then analyze and predict potential problems in the code. Therefore, there is great value in exploring the use of large language models to automatically detect and repair numerical instability problems in deep learning libraries. Summary of the invention
[0005] The purpose of this application is to provide a method for detecting and repairing numerical instability problems in deep learning libraries based on patches and large language models, which can automatically and efficiently detect and repair numerical instability problems in deep learning libraries.
[0006] The technical solution for implementing the present invention is as follows:
[0007] A method for detecting and repairing numerical instability problems in deep learning libraries based on patches and large language models, comprising:
[0008] S1: Collect patches of deep learning libraries, extract patch descriptions and program statements in the patches, and perform program slicing based on the program statements in the patches as the slicing standard to obtain patch-related program slices;
[0009] S2: according to the patch and its related program slices, using a large language model to judge the relevance of the patch to the numerical instability problem, and obtaining a patch related to the numerical instability problem;
[0010] S3: Design an inscription template suitable for detecting numerical instability problems in deep learning libraries using a large language model, test the performance of the designed inscription template, and select the best inscription template;
[0011] S4: using the optimal inscription template, detecting numerical instability problems on the deep learning library through a large language model, identifying numerical instability problems in the deep learning library, and recording the detection results;
[0012] S5: Query historical patches similar to the detected numerical instability problem, and use the large language model to analyze the queried similar historical patches to determine their similarity with the current numerical instability problem;
[0013] S6: Based on the detection results and the analysis results of similar patches, a large language model is used to generate a repair patch for the detected numerical instability problem and a repair solution is provided.
[0014] Furthermore, in step S1 of the present invention, program slicing is performed using the program statements in the patch as a slicing standard to obtain patch-related program slices. The specific process is as follows:
[0015] S131: parsing the program statements in the patch, respectively obtaining the program statements deleted and added by the patch and their corresponding program versions, which are used as slicing standards for vulnerability-related programs and repair-related programs, respectively;
[0016] S132: performing dependency analysis on the acquired added and deleted program statements using the corresponding program version, generating a dependency graph to describe the dependency relationships between the program statements;
[0017] S133: Analyze the influence of the slicing standard on the subsequent execution path according to the dependency graph to obtain a forward program slice;
[0018] S134: According to the dependency graph, tracking the impact of the previous execution path on the slice criterion to obtain a backward program slice;
[0019] S135: Integrate the forward program slice and the backward program slice to form a patch-related program slice.
[0020] Furthermore, the specific process of step S2 of the present invention is:
[0021] S21: Design a prompt template for large language models to determine the relevance of patches and numerical instability issues;
[0022] S22: Integrate the patch description and patch-related program slices of the patch into the prompt template, and use a large language model to determine the relevance of the patch and the numerical instability problem;
[0023] S23: Analyze the judgment results of the large language model and obtain patches related to numerical instability issues.
[0024] Furthermore, the specific process of step S21 of the present invention is: according to the prompting technology, the task information related to the numerical instability problem is integrated to obtain a prompting template for judging the correlation between the patch and the numerical instability problem, wherein the task information related to the numerical instability problem includes the definition of the numerical instability problem and common problem manifestations.
[0025] Furthermore, the specific process of step S3 of the present invention is:
[0026] S31: Design a prompting template for numerical instability problem detection based on the prompting method;
[0027] S32: dividing the patches related to the numerical instability problem collected in step S2 into a template filling data set and a test data set, using the template filling data set to fill the prompting template, and using the test data set to test the performance of the prompting template;
[0028] S33: According to the above test results, the prompting template with the best test result and the corresponding template filling patch are selected as the best prompting template, and stored for subsequent detection.
[0029] Furthermore, in step S31 of the present invention, a variety of prompting templates are designed, including zero-sample prompting, single-sample prompting, few-sample prompting, and thought chain prompting.
[0030] Furthermore, the specific process of step S4 of the present invention is:
[0031] S41: Roughly filter out functions related to numerical calculations from the deep learning library;
[0032] S42: Filling the selected numerical calculation related functions into the designed prompting template, analyzing and detecting the functions using a large language model, and identifying potential numerical instability problems;
[0033] S43: Analyze the detection results of the large language model and record the detection results, including the specific location of the detected numerical instability problem, problem description, possible impact range, and related context information.
[0034] Furthermore, S41 described in the present invention is: based on set rules, roughly screening out functions related to numerical calculations from the deep learning library; the set rules are: function name pattern matching, function call frequency, keywords in code comments, and program statement patterns.
[0035] Furthermore, the specific process of step S51 of the present invention is as follows:
[0036] S51: Design a prompt template for patch similarity analysis by combining historical patch descriptions, historical patch program statements, and the detected numerical instability related code snippets and context information;
[0037] S52: Using the text similarity algorithm and the version control system, historical patches are retrieved and the similarity between patches is calculated to select the patches that are most similar to the detected numerical instability issues;
[0038] S53: Fill the query similar patches and the functions related to the detected numerical instability problem into the prompt template, apply the large language model to judge the similarity between the query similar patches and the detected numerical instability problem, and determine the similarity between the similar patches and the current numerical instability problem.
[0039] Furthermore, the specific process of step S6 of the present invention is:
[0040] S61: extracting information related to numerical instability problems in the detection results, including the specific location of the problem, the problem description, the scope of impact, and related context information;
[0041] S62: designing an inscription template suitable for generating a repair patch according to the extracted information, and filling the template with relevant information;
[0042] S63: Analyze the filled inscription template using a large language model, generate a repair patch, and provide a repair solution, including the code of the repair patch and modification instructions.
[0043] Beneficial effects:
[0044] First, the present invention uses a large language model to screen and analyze patches in the deep learning library, which can accurately identify patches directly related to numerical instability problems, and then accurately determine the patch standards for numerical instability problems.
[0045] Second, the present invention designs an inscription template suitable for detecting numerical instability problems in a deep learning library, and uses patches to enhance the information on numerical instability problems in the inscription template, thereby improving the detection capability of a large language model for numerical instability problems and achieving high-precision and wide-coverage detection of numerical instability problems.
[0046] Third, the present invention assists the large language model in generating repair patches for numerical instability problems by querying and analyzing similar patches for detected numerical instability problems, and provides an efficient and accurate repair solution, thereby achieving the effect of automatically and efficiently detecting and repairing numerical instability problems in deep learning libraries. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0048] Figure 1 Flowchart of a method for detecting and repairing numerical instability problems in deep learning libraries based on patches and large language models. DETAILED DESCRIPTION
[0049] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0050] The terms used in this application are for the purpose of describing specific embodiments only and are not intended to limit this application. The singular forms of "a", "said" and "the" used in this application and the appended claims are also intended to include plural forms unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0051] It should be understood that although the terms first, second, third, etc. may be used in the present application to describe various information, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0052] Figure 1is a flowchart of a method for detecting and repairing numerical instability problems in a deep learning library based on patches and a large language model according to an exemplary embodiment, such as Figure 1 As shown, the method may include the following steps:
[0053] S1: Collect patches of deep learning libraries, extract patch descriptions and program statements in patches, and perform program slicing based on program statements in patches to obtain patch-related program slices.
[0054] This step may include the following sub-steps:
[0055] S11: Use distributed version control tools to collect patches of different versions of deep learning libraries;
[0056] Specifically, by using the Git distributed version control tool, pull deep learning related code libraries (for example, Pytorch, Tensorflow, etc.) from remote code repositories (such as GitHub, GitLab, etc.). Use the git clone or git pull command to download or update the latest patches.
[0057] S12: Analyze the patch using a patch analysis tool, extract the patch description of the patch and the program statements in the patch, and store the patch information;
[0058] Specifically, the PyDriller toolkit is used to parse the patch file, extract the patch description information and program statements, and store the extracted patch description and program statements in the database to ensure the integrity and traceability of the patch information.
[0059] S13: Slice the program using the program statements in the patch as a slicing standard to obtain patch-related program slices; this step may include the following sub-steps:
[0060] S131: Parse the program statements in the patch, obtain the program statements deleted and added by the patch and their corresponding program versions, and use them as slicing standards for vulnerability-related programs and repair-related programs, respectively.
[0061] Specifically, the PyDriller toolkit is used to parse the patch program statements, extract the program statements deleted and added by the patch and their corresponding program versions, obtain the variables involved in the extracted program statements, and construct the <variable, program statement, version number> triple as the program slicing standard to ensure that the obtained program slices can accurately reflect the code changes before and after the patch, and provide a basis for subsequent program slice generation and analysis.
[0062] S132: Using the corresponding program version to perform dependency analysis on the acquired added and deleted program statements, generate a dependency graph, and describe the dependency relationships between the program statements.
[0063] Specifically, the Joern tool is used to perform dependency analysis on the program statements in the slicing standard stored in the previous step. The version number in the slicing standard is read, and the program corresponding to the patch version is imported into Joern to parse the code structure and identify the dependencies between program statements. Thereafter, a dependency graph is generated using Joern, and the generated dependency graph is stored in the database.
[0064] S133: According to the dependency graph, analyze the impact of the slicing standard on the subsequent execution path to obtain forward program slices.
[0065] Specifically, based on the dependency graph, all affected subsequent program statements starting from the program statement in the slicing criterion are determined, forward program slices are generated, and stored in a database for more efficient subsequent numerical instability problem detection and repair.
[0066] S134: According to the dependency graph, trace the impact of the previous execution path on the slice criterion to obtain a backward program slice.
[0067] Specifically, based on the dependency graph, all previous execution paths related to the program statements in the slicing standard are determined, and all upstream program statements that affect the slicing standard program statements are identified. Backward program slices are generated and stored in the database to comprehensively analyze the impact of code changes on program behavior and provide support for the root cause analysis of numerical instability problems.
[0068] S135: Integrate the forward program slice and the backward program slice to form a patch-related program slice.
[0069] Specifically, by merging the program statements in the forward program slice and the backward program slice, duplicate program statements are removed to ensure the integrity and accuracy of the slice. Code integration tools are used for automatic merging to generate patch-related program slices.
[0070] S2: According to the patch and its related program slices, a large language model is used to judge the relevance of the patch to the numerical instability problem, and a patch related to the numerical instability problem is obtained.
[0071] This step may include the following sub-steps:
[0072] S21: Designing prompt templates for large language models to determine the relevance of patches to numerical instability issues.
[0073] Specifically, based on the existing prompting technology, the task information related to the numerical instability problem is integrated to obtain a prompting template for judging the relevance of the patch and the numerical instability problem. The task information related to the numerical instability problem includes the definition of the numerical instability problem and common problem manifestations, such as specific situations such as numerical calculation errors and precision loss, as well as patch features related to numerical instability problems. In the prompting template, these task information are summarized and classified. For example, the following content is added to the template description: "The patch description should include the error details related to the numerical calculation, the affected functional modules, the specific algorithms or calculation processes involved, the precision loss and its impact on the results, and the conditions and results of overflow or underflow." A prompting template specifically used for large language models to judge the relevance of patches and numerical instability problems is formed. By constructing a prompting template designed specifically for judging the relevance of numerical instability problems, the potential of large language models in this task can be fully utilized to provide more in-depth analysis results.
[0074] S22: Integrate the patch description, patch-related program slices and other related information of the patch into the prompt template, and use the large language model to judge the relevance between the patch and the numerical instability problem;
[0075] Specifically, the designed prompt template is supplemented with the patch description, patch-related program slices and other related information of the patch, and the large language model is called through the API to obtain the analysis results of the large language model on the correlation between the patch and the numerical instability problem.
[0076] S23: Analyze the judgment results of the large language model and obtain patches related to numerical instability issues.
[0077] Specifically, the judgment results returned by the large language model are parsed to obtain patches related to numerical instability issues, and the judgment results are stored in the database to provide support for subsequent detection and repair work.
[0078] S3: Design an inscription template suitable for detecting numerical instability problems in deep learning libraries using large language models, test the performance of the designed inscription templates, and select the best inscription template.
[0079] This step may include the following sub-steps:
[0080] S31: Design a prompting template for detecting numerical instability problems based on the existing mature prompting methods.
[0081] Specifically, a variety of prompting templates are designed, including zero-shot prompting, single-shot prompting, few-shot prompting, and thought chain prompting. Zero-shot prompting can detect numerical instability problems without demonstration samples, for example: "Please analyze the following code snippet and identify potential numerical instability problems, including but not limited to overflow, underflow, precision loss, etc." Single-shot and few-shot prompting use demonstration examples to enhance the large language model's ability to detect numerical instability problems, for example: "In the following code, there is a floating-point operation precision loss problem: float x = 1.0 / 3.0; please detect similar numerical instability problems in the following code." And thought chain prompting improves the large language model's ability to detect numerical instability problems by guiding the model to reason step by step, for example: "The first step is to identify all numerical operations in the code; the second step is to check whether these operations may cause precision loss or overflow; the third step is to analyze the data range and boundary conditions; the fourth step is to combine the above steps to determine whether there is a numerical instability problem in the code."
[0082] S32: Divide the patches related to the numerical instability problem collected in step S2 into a template filling data set and a test data set, use the template filling data set to fill the prompting template, and use the test data set to test the performance of the prompting template.
[0083] Specifically, the collected patches related to numerical instability issues are divided into template filling datasets and test datasets at a ratio of 2:8. The template filling dataset is used to fill various prompting templates, and the test dataset is used to test and compare the performance of each prompting template to ensure the reliability of the inscription template evaluation test.
[0084] S33: According to the above test results, the prompting template with the best test result and the corresponding template filling patch are selected as the best prompting template, and stored for subsequent detection.
[0085] Specifically, the performance of each prompt template on the test data set is comprehensively considered, and the prompt template with the best performance in numerical instability problem detection and the corresponding template filling patch are selected. The best prompt template and its filling content are stored in the database to ensure their reusability, providing the best template support for subsequent numerical instability problem detection.
[0086] S4: Using the optimal inscription template, the deep learning library is tested for numerical instability problems through a large language model, the numerical instability problems in the deep learning library are identified, and the detection results are recorded.
[0087] This step may include the following sub-steps:
[0088] S41: Design a set of heuristic rules to roughly filter out functions related to numerical computing from deep learning libraries.
[0089] Specifically, according to the characteristics of deep learning libraries and common numerical computing function patterns, a set of heuristic rules are designed, where the rules may include function name pattern matching, function call frequency, keywords in code comments, program statement patterns, etc. The deep learning library is scanned by static code analysis tools to roughly screen out functions that may involve numerical calculations, so as to reduce the number of large language model API calls in subsequent analysis.
[0090] S42: Fill the selected numerical calculation related functions into the designed prompt template, use the large language model to analyze and detect the functions, and identify potential numerical instability problems.
[0091] Specifically, the best prompt template is used to fill the selected numerical calculation related functions and their context information into the template, and the large language model is called through the API to analyze and detect numerical instability problems. By using the large language model to analyze and detect numerical instability problems, manual overhead can be reduced and detection efficiency can be improved. At the same time, relying on the powerful code understanding ability of the large language model, the detection results can be made more accurate.
[0092] S43: Analyze the detection results of the large language model and record the detection results, including the specific location of the detected numerical instability problem, problem description, possible impact range, and related context information.
[0093] Specifically, the detection results returned by the large language model are parsed to record the specific location, problem description, possible impact range and related context information of the detected numerical instability problem. The detection results are stored in the database to provide detailed reference information for subsequent repairs.
[0094] S5: Query historical patches similar to the detected numerical instability problem, and use the large language model to analyze the queried similar historical patches to determine their similarity with the current numerical instability problem.
[0095] This step may include the following sub-steps:
[0096] S51: Design of prompting templates for patch similarity analysis.
[0097] Specifically, a prompt template specifically for patch similarity analysis is designed by combining historical patch descriptions, historical patch program statements, and relevant code snippets and contexts of detected numerical instability issues. By designing a prompt template specifically for patch similarity analysis, the large language model can be better guided to make judgments on patch similarity and improve the accuracy of similarity analysis. Specifically, for example: "Please analyze the following patch descriptions and related code snippets to determine their similarity with historical patches: Patch description: Fixed a floating-point arithmetic error that caused overflow in certain circumstances; Code snippet: if(value>MAX){value=MAX;} / / Overflow handling. Please compare these contents with the descriptions and codes for solving similar problems in historical patches to find similarities."
[0098] S52: Using the text similarity algorithm and the version control system, historical patches are retrieved and the similarity between patches is calculated to select the patches that are most similar to the detected numerical instability issues.
[0099] Specifically, the historical patches are retrieved using a text similarity algorithm (such as TF-IDF, BERT, etc.) combined with the historical patch information extracted from the database. The similarity between each patch and the detected numerical instability problem is calculated, and the patch with the highest similarity is selected.
[0100] S53: Fill the query similar patches and the functions related to the detected numerical instability problem into the prompt template, apply the large language model to judge the similarity between the query similar patches and the detected numerical instability problem, and determine the similarity between the similar patches and the current numerical instability problem.
[0101] Specifically, the screened similar patches and their related function information are filled into the prompt template designed in the previous design step, and the large language model is called through the API to determine whether the queried similar patches are similar to the currently detected numerical instability problem.
[0102] S6: Based on the detection results and the analysis results of similar patches, a large language model is used to generate a repair patch for the detected numerical instability problem, and a detailed repair plan is provided.
[0103] This step may include the following sub-steps:
[0104] S61: extracting information related to numerical instability problems in the test results, including the specific location of the problem, the problem description, the possible impact range, and related context information;
[0105] Specifically, the detection results in the database are read, and detailed information related to numerical instability issues is extracted, including the specific location of the problem in the code, a detailed description of the problem, and contextual information related to the problem. By extracting the detection information stored in the database as the basis for generating repair patches, the targeted and effective repair work is ensured.
[0106] S62: designing an inscription template suitable for generating a repair patch according to the extracted information, and filling the template with relevant information;
[0107] Specifically, a word template specifically used to generate a repair patch is designed, and the information extracted in the previous step is filled into the template so that the large language model can accurately understand and process the relevant information of the numerical instability problem, and provide an accurate and easy-to-understand repair solution. For example, based on the relevant information extracted in the previous step, the word template is filled to obtain "Please generate a repair patch based on the following information: Problem location: Line 42 of code; Problem description: Precision loss caused by floating-point operations; Impact scope: Computing module; Context information: Code segment - double result = 1.0 / 3.0. Please provide a repair solution to solve the above problem, and ensure that the repaired code improves the calculation accuracy and does not introduce new numerical instability problems."
[0108] S63: Use the large language model to analyze the filled inscription template, generate a repair patch, and provide a detailed repair plan, including the repair patch code, modification instructions, etc.
[0109] Specifically, the API calls the big language model to analyze the filled inscription template, generate a repair patch, and provide a detailed repair plan. The plan includes the code, modification instructions, scope of application, and other relevant technical details of the repair patch. Generating a repair plan through a big language model can ensure the readability and understandability of the repair plan, and ensure that the repair plan includes relevant technical details and detailed explanations to help developers fix related problems.
[0110] It can be seen from the above embodiments that the present application can accurately identify patches related to numerical instability problems by using a large language model to screen patches in the deep learning library, thereby improving the accuracy and efficiency of patch screening. By designing a prompt template that is enhanced with historical patches of known numerical instability problems and suitable for detecting numerical instability problems, the detection capability of the large language model for numerical instability problems is improved, and high-precision and wide-coverage numerical instability problem detection is achieved. By querying and analyzing historical patches similar to the detected numerical instability problems, the large language model is assisted in generating repair patches for numerical instability problems, providing an efficient and accurate repair solution.
[0111] Those skilled in the art will readily appreciate other embodiments of the present application after considering the description and practicing the contents disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The description and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the claims.
[0112] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A method for detecting and repairing numerical instability problems in deep learning libraries based on patches and large language models, characterized in that: include: S1: Collect patches of deep learning libraries, extract patch descriptions and program statements in the patches, and perform program slicing based on the program statements in the patches as the slicing standard to obtain patch-related program slices; S2: according to the patch and its related program slices, using a large language model to judge the relevance of the patch to the numerical instability problem, and obtaining a patch related to the numerical instability problem; S3: Design an inscription template suitable for detecting numerical instability problems in deep learning libraries using a large language model, test the performance of the designed inscription template, and select the best inscription template; S4: using the optimal inscription template, detecting numerical instability problems on the deep learning library through a large language model, identifying numerical instability problems in the deep learning library, and recording the detection results; S5: Query historical patches similar to the detected numerical instability problem, and use the large language model to analyze the queried similar historical patches to determine their similarity with the current numerical instability problem; S6: Based on the detection results and the analysis results of similar patches, a large language model is used to generate a repair patch for the detected numerical instability problem and a repair solution is provided.
2. The method for detecting and repairing numerical instability problems in deep learning libraries based on patches and large language models according to claim 1, characterized in that: In step S1, program slicing is performed using the program statements in the patch as a slicing standard to obtain patch-related program slices. The specific process is as follows: S131: parsing the program statements in the patch, respectively obtaining the program statements deleted and added by the patch and their corresponding program versions, which are used as slicing standards for vulnerability-related programs and repair-related programs, respectively; S132: performing dependency analysis on the acquired added and deleted program statements using the corresponding program version, generating a dependency graph to describe the dependency relationships between the program statements; S133: Analyze the influence of the slicing standard on the subsequent execution path according to the dependency graph to obtain a forward program slice; S134: According to the dependency graph, tracking the impact of the previous execution path on the slice criterion to obtain a backward program slice; S135: Integrate the forward program slice and the backward program slice to form a patch-related program slice.
3. The method for detecting and repairing numerical instability problems in deep learning libraries based on patches and large language models according to claim 1, characterized in that: The specific process of step S2 is: S21: Design a prompt template for large language models to determine the relevance of patches and numerical instability issues; S22: Integrate the patch description and patch-related program slices of the patch into the prompt template, and use a large language model to determine the relevance of the patch and the numerical instability problem; S23: Analyze the judgment results of the large language model and obtain patches related to numerical instability issues.
4. The method for detecting and repairing numerical instability problems in deep learning libraries based on patches and large language models according to claim 3 is characterized in that: The specific process of step S21 is: according to the prompting technology, the task information related to the numerical instability problem is integrated to obtain a prompting template for judging the correlation between the patch and the numerical instability problem, wherein the task information related to the numerical instability problem includes the definition of the numerical instability problem and common problem manifestations.
5. The method for detecting and repairing numerical instability problems in deep learning libraries based on patches and large language models according to claim 1, characterized in that: The specific process of step S3 is: S31: Design a prompting template for numerical instability problem detection based on the prompting method; S32: dividing the patches related to the numerical instability problem collected in step S2 into a template filling data set and a test data set, using the template filling data set to fill the prompting template, and using the test data set to test the performance of the prompting template; S33: According to the above test results, the prompting template with the best test result and the corresponding template filling patch are selected as the best prompting template, and stored for subsequent detection.
6. The method for detecting and repairing numerical instability problems in deep learning libraries based on patches and large language models according to claim 5, characterized in that: In step S31, a variety of prompting templates are designed, including zero-sample prompting, single-sample prompting, few-sample prompting, and thought chain prompting.
7. The method for detecting and repairing numerical instability problems in deep learning libraries based on patches and large language models according to claim 1, characterized in that: The specific process of step S4 is: S41: Roughly filter out functions related to numerical calculations from the deep learning library; S42: Filling the selected numerical calculation related functions into the designed prompting template, analyzing and detecting the functions using a large language model, and identifying potential numerical instability problems; S43: Analyze the detection results of the large language model and record the detection results, including the specific location of the detected numerical instability problem, problem description, possible impact range, and related context information.
8. The method for detecting and repairing numerical instability problems in deep learning libraries based on patches and large language models according to claim 7, characterized in that: The S41 is: based on the set rules, roughly screening out functions related to numerical calculation from the deep learning library; the set rules are: function name pattern matching, function call frequency, keywords in code comments, and program statement patterns.
9. The method for detecting and repairing numerical instability problems of deep learning libraries based on patches and large language models according to claim 1, characterized in that: The specific process of step S51 is: S51: Design a prompt template for patch similarity analysis by combining historical patch descriptions, historical patch program statements, and the detected numerical instability related code snippets and context information; S52: Using the text similarity algorithm and the version control system, historical patches are retrieved and the similarity between patches is calculated to select the patches that are most similar to the detected numerical instability issues; S53: Fill the query similar patches and the functions related to the detected numerical instability problem into the prompt template, apply the large language model to judge the similarity between the query similar patches and the detected numerical instability problem, and determine the similarity between the similar patches and the current numerical instability problem.
10. The method for detecting and repairing numerical instability problems in deep learning libraries based on patches and large language models according to claim 1, characterized in that: The specific process of step S6 is: S61: extracting information related to numerical instability problems in the detection results, including the specific location of the problem, the problem description, the scope of impact, and related context information; S62: designing an inscription template suitable for generating a repair patch according to the extracted information, and filling the template with relevant information; S63: Analyze the filled inscription template using a large language model, generate a repair patch, and provide a repair solution, including the code of the repair patch and modification instructions.
Citation Information
Patent Citations
Security situation monitoring and early warning system for ship manufacturing workshop
CN116859804A
Warehouse-level code defect automatic repairing method based on large language model
CN117851101A
Open source software vulnerability patch detection method and device based on large language model and version submission filtering
CN118094563A
Vulnerability fixing method based on large model and related device
CN118445812A
