Method for Detecting and Fixing Numerical Instability Problems in Deep Learning Libraries Based on Patches and Large Language Models
Through large language model and patch analysis technology, the numerical instability problem in deep learning libraries is automatically detected and repaired, and the problem of low detection and repair efficiency in the existing technology is solved, improving the stability and security of the model.
Patent Information
- Application Number
- CN202411291165.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-14
- Publication Date
- 2025-08-01
- Estimated Expiration
- 2044-09-14
AI Technical Summary
The prior art is difficult to efficiently and automatically detect and repair numerical instability problems in deep learning libraries, resulting in reduced model performance and safety risks.
Using large language models and patch analysis technology, numerical instability problems in deep learning libraries are automatically identified and generated through program slicing, dependency analysis, teleprompt template design and similar patch queries.
It realizes high-precision, wide coverage and detection of numerical instability problems and efficient and accurate repair solutions, reducing manual analysis time and improving the stability and security of the model.
Smart Images

Figure CN119227673B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the technical fields of software engineering and deep learning security, and particularly relates to a method for detecting and fixing 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, during the process of using deep learning libraries for model training and deployment, numerical instability problems have become a key factor affecting model performance and reliability. Numerical instability problems may lead to issues such as inability to converge during model training, a significant increase in training time, abnormal model output results, etc. In severe cases, it may even cause the model to completely fail. This not only affects the accuracy and robustness of the model, but may also pose safety hazards in practical applications. For example, in an autonomous driving system, numerical instability problems may lead to incorrect vehicle recognition, thereby causing traffic accidents; while in a medical diagnosis system, numerical instability problems may lead to incorrect diagnosis results, directly endangering the life safety of patients.
[0003] Currently, research on numerical instability problems in deep learning libraries mainly focuses on aspects such as improving numerical calculation accuracy and optimizing model structures. Although these methods can alleviate numerical instability problems to a certain extent, due to the large size of deep learning library code and the complex and diverse nature of numerical instability problems, existing methods are difficult to comprehensively and accurately detect and fix all numerical instability problems. In addition, manual analysis and repair of numerical instability problems require a large amount of professional knowledge and time, and it is difficult to meet the high-efficiency requirements in practical applications. Therefore, finding an efficient and automated method to detect and fix numerical instability problems is particularly important.
[0004] With the rapid development of natural language processing technology, large language models have shown great potential in the fields of code analysis and automatic repair. A large language model is a large-scale language model that, by learning a vast amount of code libraries and documentation materials, can understand the structure, grammar, and semantic associations of programming languages, and thus can analyze and predict potential problems in code. Therefore, there is great exploration value in using large language models to automatically detect and fix 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 fixing numerical instability problems in deep learning libraries based on patches and large language models, which can automatically and efficiently detect and fix numerical instability problems in deep learning libraries.
[0006] The technical solution for realizing the present invention is as follows:
[0007] A method for detecting and fixing numerical instability problems in a deep learning library based on patches and large language models, including:
[0008] S1: Collect patches of the deep learning library, extract the patch descriptions and program statements in the patches, and perform program slicing with the program statements in the patches as the slicing criteria to obtain patch-related program slices;
[0009] S2: According to the patch and its related program slices, use a large language model to judge the relevance between the patch and the numerical instability problem, and obtain patches related to the numerical instability problem;
[0010] S3: Design an inscription template suitable for detecting numerical instability problems in a deep learning library using a large language model, and test the performance of the designed inscription template to select the best inscription template;
[0011] S4: Use the best inscription template to detect numerical instability problems in the deep learning library through a large language model, identify numerical instability problems in the deep learning library, and record the detection results;
[0012] S5: Query historical patches similar to the detected numerical instability problems, use a large language model to analyze the queried similar historical patches, and determine their similarity to the current numerical instability problems;
[0013] S6: According to the detection results and the analysis results of the similar patches, use a large language model to generate a repair patch for the detected numerical instability problem and provide a repair plan.
[0014] Further, in step S1 of the present invention, program slicing is performed with the program statements in the patch as the slicing criteria to obtain patch-related program slices. The specific process is as follows:
[0015] S131: Parse the program statements in the patch, respectively obtain the program statements deleted and added in the patch and their corresponding program versions, and use them as the slicing criteria for vulnerability-related programs and repair-related programs respectively;
[0016] S132: For the obtained added and deleted program statements, perform dependency analysis using the corresponding program versions to generate a dependency graph to describe the dependency relationships between the program statements;
[0017] S133: According to the dependency graph, analyze the influence of the slicing criteria on the subsequent execution path to obtain forward program slices;
[0018] S134: According to the dependency graph, trace the influence of the slicing criteria on the previous execution path to obtain backward program slices;
[0019] S135: Integrate the forward program slice and the backward program slice to form a patch-related program slice.
[0020] Further, the specific process of step S2 of the present invention is as follows:
[0021] S21: Design a prompting template for the large language model to judge the relevance between the patch and the numerical instability problem;
[0022] S22: Integrate the patch description and the patch-related program slice of the patch into the prompting template, and apply the large language model to judge the relevance between the patch and the numerical instability problem;
[0023] S23: Analyze the judgment result of the large language model to obtain the patch related to the numerical instability problem.
[0024] Further, the specific process of step S21 of the present invention is as follows: According to the prompting technology, integrate the task information related to the numerical instability problem to obtain a prompting template for judging the relevance between 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 the common problem manifestation forms.
[0025] Further, the specific process of step S3 of the present invention is as follows:
[0026] S31: Design a prompting template for numerical instability problem detection according to the prompting method;
[0027] 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;
[0028] S33: According to the above test results, select the prompting template with the best test result and the corresponding template filling patch as the best prompting template, and store it for subsequent detection.
[0029] Further, in step S31 of the present invention, multiple prompting templates including zero-shot prompting, one-shot prompting, few-shot prompting, and chain-of-thought prompting are designed.
[0030] Further, the specific process of step S4 of the present invention is as follows:
[0031] S41: Roughly screen out the functions related to numerical calculation from the deep learning library;
[0032] S42: Fill the screened functions related to numerical calculation into the designed prompting template, and use the large language model to analyze and detect the functions to identify 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 scope of influence, and relevant context information.
[0034] Furthermore, S41 in the present invention is: Based on set rules, roughly screen 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 in the present invention is:
[0036] S51: Combine the historical patch description, historical patch program statements, and code snippets and context information related to the detected numerical instability problem to design a prompting template for patch similarity analysis;
[0037] S52: Use the text similarity algorithm and version control system to retrieve historical patches, calculate the similarity between patches, and screen out the patches most similar to the detected numerical instability problem;
[0038] S53: Fill the retrieved similar patches and functions related to the detected numerical instability problem into the prompting template, apply the large language model to judge the similarity between the retrieved similar patches and the detected numerical instability problem, and determine its similarity to the current numerical instability problem.
[0039] Furthermore, the specific process of step S6 in the present invention is:
[0040] S61: Extract information related to the numerical instability problem in the detection results, including the specific location of the problem, problem description, scope of influence, and relevant context information;
[0041] S62: According to the extracted information, design a prompting template suitable for generating repair patches, and fill the relevant information into the template;
[0042] S63: Use the large language model to analyze the filled prompting template, generate a repair patch, and provide a repair plan, including the code of the repair patch and modification instructions.
[0043] Beneficial effects:
[0044] First, the present invention uses the large language model to screen and analyze patches in the deep learning library, can accurately identify patches directly related to the numerical instability problem, and then accurately determine the patch standard for the numerical instability problem.
[0045] Second, the present invention designs an inscriptive template suitable for detecting numerical instability problems in deep learning libraries, and uses patches to enhance the information of numerical instability problems in the inscriptive template, improving the detection ability of large language models for numerical instability problems, and achieving high-precision and wide-coverage detection of numerical instability problems.
[0046] Third, the present invention queries and analyzes similar patches for the detected numerical instability problems, assisting large language models to generate repair patches for numerical instability problems, providing efficient and accurate repair solutions, 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 herein are incorporated into the specification and constitute a part of this specification, showing embodiments consistent with the present application, and are used together with the specification to explain the principles of the present application.
[0048] Figure 1 It is a flowchart of a method for detecting and repairing numerical instability problems in deep learning libraries based on patches and large language models. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0049] Exemplary embodiments will be described in detail herein, and examples thereof are shown in the accompanying drawings. When the following description refers to the accompanying drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. On the contrary, 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 the present application are for the purpose of describing specific embodiments only and are not intended to limit the present application. The singular forms "a", "the", and "said" used in the present application and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. 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 of the 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, such 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 "when" or "while" or "in response to determining".
[0052] Figure 1It is a flowchart of a method for detecting and fixing numerical instability problems in a deep learning library based on patches and large language models shown according to an exemplary embodiment. As Figure 1 shown, the method may include the following steps:
[0053] S1: Collect patches of the deep learning library, extract the patch descriptions of the patches and the program statements in the patches, and perform program slicing with the program statements in the patches as the slicing criterion to obtain patch-related program slices.
[0054] This step may include the following sub-steps:
[0055] S11: Use a distributed version control tool to collect patches of different versions in the deep learning library;
[0056] Specifically, by using the Git distributed version control tool, pull the deep learning-related code libraries (such as Pytorch, Tensorflow, etc.) from a remote code repository (such as GitHub, GitLab, etc.). Use the git clone or git pull command to download or update the latest patches.
[0057] S12: Analyze the patches using a patch analysis tool, extract the patch descriptions of the patches and the program statements in the patches, and store the patch information;
[0058] Specifically, use the PyDriller tool kit to parse the patch files, extract the patch description information and program statements, and store the extracted patch descriptions and program statements in a database to ensure the integrity and traceability of the patch information.
[0059] S13: Perform program slicing with the program statements in the patches as the slicing criterion to obtain patch-related program slices; this step may include the following sub-steps:
[0060] S131: Parse the program statements in the patches, respectively obtain the program statements deleted and added in the patches and their corresponding program versions, and use them as the slicing criteria for vulnerability-related programs and repair-related programs, respectively.
[0061] Specifically, use the PyDriller tool kit to parse the patch program statements, extract the program statements deleted and added in the patches and their corresponding program versions, and obtain the variables involved in the extracted program statements, and construct a <variable, program statement, version number> triple as the slicing criterion of the program to ensure that the obtained program slices can accurately reflect the code changes before and after the patch and provide a basis for the subsequent generation and analysis of program slices.
[0062] S132: Analyze the obtained added and deleted program statements for dependency relationships using the corresponding program version, generate a dependency graph, and describe the dependency relationships among the program statements.
[0063] Specifically, use the Joern tool to analyze the dependency relationships of the program statements in the slicing criteria stored in the previous step. Read the version number in the slicing criteria, import the program of the corresponding patch version into Joern, parse the code structure, and identify the dependency relationships among the program statements. Then use Joern to generate a dependency graph and store the generated dependency graph in the database.
[0064] S133: Analyze the impact of the slicing criteria on the subsequent execution path based on the dependency graph to obtain a forward program slice.
[0065] Specifically, based on the dependency graph, determine all affected subsequent program statements starting from the program statements in the slicing criteria, generate a forward program slice, and store it in the database for more effective detection and repair of numerical instability problems in the subsequent steps.
[0066] S134: Trace the impact of the previous execution path on the slicing criteria based on the dependency graph to obtain a backward program slice.
[0067] Specifically, based on the dependency graph, determine all previous execution paths related to the program statements in the slicing criteria, identify all upstream program statements that affect the program statements in the slicing criteria, generate a backward program slice, and store it in the database to comprehensively analyze the impact of code changes on program behavior and provide support for 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, merge the program statements in the forward program slice and the backward program slice, remove duplicate program statements, and ensure the integrity and accuracy of the slice. Use a code integration tool for automated merging to generate a patch-related program slice.
[0070] S2: Based on the patch and its related program slice, use a large language model to judge the relevance between the patch and the numerical instability problem, and obtain a patch related to the numerical instability problem.
[0071] This step may include the following sub-steps:
[0072] S21: Design a prompting template for the large language model to judge the relevance between the patch and the numerical instability problem.
[0073] Specifically, according to the existing prompting technology, task information related to the problem of numerical instability is integrated to obtain a prompting template for judging the relevance between a 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 manifestation forms, such as specific situations like numerical calculation errors and precision loss, as well as patch features related to the numerical instability problem. In the prompting template, this task information is summarized and classified. For example, the following content is added to the template description: "The patch description should include error details related to numerical calculations, affected functional modules, specific algorithms or calculation processes involved, the situation of precision loss and its impact on the results, and the conditions and results of overflow or underflow." A prompting template dedicated to the large language model for judging the relevance between a patch and the numerical instability problem is formed. By constructing a prompting template designed specifically for judging the relevance of numerical instability problems, the potential of the large language model 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 relevant information of the patch into the prompting template, and use the large language model to judge the relevance between the patch and the numerical instability problem;
[0075] Specifically, supplement the designed prompting template with the patch description, patch-related program slices, and other relevant information of the patch, and call the large language model through the API to obtain the analysis result of the large language model's judgment on the relevance between the patch and the numerical instability problem.
[0076] S23: Analyze the judgment result of the large language model to obtain the patch related to the numerical instability problem.
[0077] Specifically, analyze the judgment result returned by the large language model to obtain the patch related to the numerical instability problem, and store the judgment result in the database to provide support for subsequent detection and repair work.
[0078] S3: Design a prompting template suitable for detecting numerical instability problems in deep learning libraries using a large language model, and test the performance of the designed prompting template to select the best prompting template.
[0079] This step may include the following sub-steps:
[0080] S31: Design a prompting template for detecting numerical instability problems according to the existing mature prompting method.
[0081] Specifically, various prompting templates are designed, including zero-shot prompting, one-shot prompting, few-shot prompting, and chain-of-thought 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." One-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 problem of floating-point operation precision loss: float x = 1.0 / 3.0; Please detect similar numerical instability problems in the following code." Chain-of-thought prompting improves the large language model's ability to detect numerical instability problems by guiding the model to reason step by step. For example: "First step, identify all numerical operations in the code; Second step, check whether these operations may cause precision loss or overflow; Third step, analyze the data range and boundary conditions; Fourth step, based on the above steps, determine whether there are numerical instability problems in the code."
[0082] S32: Divide the patches related to numerical instability problems collected in step S2 into a template filling dataset and a test dataset. Use the template filling dataset to fill the prompting templates, and use the test dataset to test the performance of the prompting templates.
[0083] Specifically, divide the patches related to numerical instability problems collected according to a ratio of 2:8 into a template filling dataset and a test dataset. Use the template filling dataset to fill various prompting templates, and use the test dataset to test and compare the performance of each prompting template to ensure the reliability of the evaluation test of the prompting templates.
[0084] S33: According to the above test results, select the prompting template with the best test results and the corresponding template filling patches as the best prompting template, and store it for subsequent detection.
[0085] Specifically, based on the performance of each prompting template on the test dataset, select the prompting template with the best performance in detecting numerical instability problems and the corresponding template filling patches. Store the best prompting template and its filling content in the database to ensure its reusability and provide the best template support for subsequent detection of numerical instability problems.
[0086] S4: Use the best prompting template to detect numerical instability problems in the deep learning library through the large language model, identify numerical instability problems in the deep learning library, and record the detection results.
[0087] This step may include the following sub-steps:
[0088] S41: Design a set of heuristic rules for roughly screening out functions related to numerical calculations from the deep learning library.
[0089] Specifically, according to the characteristics of the deep learning library and the function patterns of common numerical calculations, a set of heuristic rules are designed, which may include function name pattern matching, function call frequency, keywords in code comments, program statement patterns, etc. The deep learning library is scanned by a static code analysis tool to roughly screen out the functions that may be involved in numerical calculations, so as to reduce the number of API calls of the large language model in subsequent analysis.
[0090] S42: Fill the screened functions related to numerical calculations into the designed prompter template, and use the large language model to analyze and detect these functions to identify potential numerical instability problems.
[0091] Specifically, using the optimal prompter template, fill the screened functions related to numerical calculations and their context information into the template, and call the large language model through the API to analyze and detect numerical instability problems. By using the large language model to analyze and detect numerical instability problems, it is possible to reduce manual overhead, improve detection efficiency, and at the same time rely on the powerful code understanding ability of the large language model to make the detection results more accurate.
[0092] S43: Analyze the detection results of the large language model and record the detection results, including the specific location, problem description, possible scope of influence, and relevant context information of the detected numerical instability problems.
[0093] Specifically, analyze the detection results returned by the large language model, and record the specific location, problem description, possible scope of influence, and relevant context information of the detected numerical instability problems. Store the detection results in a database for providing detailed reference information for subsequent repair.
[0094] S5: Query historical patches similar to the detected numerical instability problems, and use the large language model to analyze the queried similar historical patches to determine their similarity to the current numerical instability problems.
[0095] This step may include the following sub-steps:
[0096] S51: Design a prompter template for patch similarity analysis.
[0097] Specifically, based on information such as historical patch descriptions, historical patch program statements, code snippets related to the detected numerical instability problem, and their contexts, a prompting template dedicated to patch similarity analysis is designed. By designing a prompting template dedicated to patch similarity analysis, it is possible to better guide the large language model to judge patch similarity and improve the accuracy of similarity analysis. Specifically, for example: "Please analyze the following patch description and related code snippets to determine their similarity to the historical patch: Patch description: Fixed a floating-point arithmetic error that caused overflow in specific situations; Code snippet: if (value > MAX) { value = MAX;} / / Overflow handling. Please compare this content with the descriptions and code in the historical patch that solved similar problems to find the similarities."
[0098] S52: Use text similarity algorithms and version control systems to retrieve historical patches, calculate the similarity between patches, and filter out the patches that are most similar to the detected numerical instability problem.
[0099] Specifically, use text similarity algorithms (such as TF-IDF, BERT, etc.) combined with historical patch information extracted from the database to retrieve historical patches. Calculate the similarity between each patch and the detected numerical instability problem, and filter out the patch with the highest similarity.
[0100] S53: Fill the retrieved similar patches and functions related to the detected numerical instability problem into the prompting template, and apply the large language model to judge the similarity between the retrieved similar patches and the detected numerical instability problem to determine its similarity to the current numerical instability problem.
[0101] Specifically, fill the filtered similar patches and their related function information into the prompting template designed in the previous steps, and call the large language model through the API to judge whether the retrieved 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, use the large language model to generate a repair patch for the detected numerical instability problem and provide a detailed repair plan.
[0103] This step may include the following sub-steps:
[0104] S61: Extract information related to the numerical instability problem in the detection results, including the specific location of the problem, problem description, possible impact scope, and relevant context information;
[0105] Specifically, read the detection results in the database and extract the detailed information related to the numerical instability problem, including the specific location of the problem in the code, the detailed description of the problem, and the context information related to the problem, etc. By extracting the detection information stored in the database as the basis for generating the repair patch, ensure the pertinence and effectiveness of the repair work.
[0106] S62: According to the extracted information, design a prompt template suitable for generating a repair patch, and fill the relevant information into this template;
[0107] Specifically, design a prompt template dedicated to generating a repair patch, and fill the information extracted in the previous step into this template, so that the large language model can accurately understand and process the information related to the numerical instability problem, and provide an accurate and easy-to-understand repair solution. For example, according to the relevant information extracted in the previous step, filling the prompt template gets "Please generate a repair patch according to the following information: Problem location: Line 42 of the code; Problem description: Precision loss caused by floating-point operations; Affected range: Calculation 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 precision and does not introduce new numerical instability problems."
[0108] S63: Use the large language model to analyze the filled prompt template, generate a repair patch, and provide a detailed repair solution, including the code of the repair patch, modification instructions, etc.
[0109] Specifically, call the large language model through the API to analyze the filled prompt template, generate a repair patch, and provide a detailed repair solution. Among them, the solution includes the code of the repair patch, modification instructions, applicable scope, and other relevant technical details. By generating a repair solution through the large language model, the readability and understandability of the repair solution can be guaranteed, and it is ensured that the repair solution includes the technical details and detailed explanations related to the execution, helping developers to repair related problems.
[0110] As can be seen from the above embodiments, the present application can accurately identify the patches related to the numerical instability problem by using the large language model to screen the patches of the deep learning library, thereby improving the accuracy and efficiency of patch screening. By designing and using a prompt template enhanced with the historical patches of known numerical instability problems and applicable to the detection of numerical instability problems, the detection ability of the large language model for numerical instability problems is improved, and high-precision and wide-coverage detection of numerical instability problems is realized. By querying and analyzing the historical patches similar to the detected numerical instability problems, assist the large language model to generate repair patches for numerical instability problems, and provide efficient and accurate repair solutions.
[0111] Other embodiments of the present application will be readily apparent to those skilled in the art upon consideration of the specification and practice of the disclosure herein. The present application is intended to cover any variations, uses, or adaptations of the present application, which follow the general principles of the present application and include known common general knowledge or conventional technical means in the technical field not disclosed in the present application. The specification and examples are only illustrative, and the true scope and spirit of the present application are pointed out by the claims.
[0112] It should be understood that the present application is not limited to the exact structures described above and shown in the drawings, and various modifications and changes can be made without departing from its scope. The scope of the present application is only limited by the appended claims.
Claims
1. A method for detecting and fixing numerical instability problems in a deep learning library based on patches and large language models, characterized in that, Including: S1: Collect patches of the deep learning library, extract the patch descriptions and program statements in the patches, and perform program slicing with the program statements in the patches as the slicing criteria to obtain patch-related program slices; S2: Based on the patch and its related program slices, use a large language model to judge the relevance between the patch and the numerical instability problem, and obtain patches related to the numerical instability problem; S3: Design an inscription template suitable for detecting numerical instability problems in the deep learning library using a large language model, and test the performance of the designed inscription template to select the best inscription template; S4: Use the best inscription template to detect numerical instability problems in the deep learning library through a large language model, identify numerical instability problems in the deep learning library, and record the detection results; S5: Query historical patches similar to the detected numerical instability problems, and use a large language model to analyze the queried similar historical patches to determine their similarity to the current numerical instability problem; S6: Based on the detection results and the analysis results of similar patches, use a large language model to generate a repair patch for the detected numerical instability problem and provide a repair solution.
2. The method for detecting and fixing the numerical instability problem of the deep learning library based on patches and large language models according to claim 1, characterized in that, In step S1, program slicing is performed with the program statements in the patch as the slicing criteria to obtain patch-related program slices. The specific process is as follows: S131: Parse the program statements in the patch, and respectively obtain the program statements deleted and added in the patch and their corresponding program versions, which are used as the slicing criteria for vulnerability-related programs and repair-related programs respectively; S132: For the obtained added and deleted program statements, perform dependency analysis using the corresponding program versions to generate a dependency graph to describe the dependency relationships between program statements; S133: According to the dependency graph, analyze the influence of the slicing criteria on the subsequent execution path to obtain forward program slices; S134: According to the dependency graph, trace the influence of the slicing criteria on the previous execution path to obtain backward program slices; S135: Integrate the forward program slices and the backward program slices to form patch-related program slices.
3. The method for detecting and fixing numerical instability problems in a deep learning library based on patches and large language models according to claim 1, wherein, The specific process of step S2 is as follows: S21: Design an inscription template for a large language model to judge the relevance between a patch and a numerical instability problem; S22: Integrate the patch description and patch-related program slices of the patch into the inscription template, and use a large language model to judge the relevance between the patch and the numerical instability problem; S23: Analyze the judgment results of the large language model to obtain patches related to the numerical instability problem.
4. The method for detecting and fixing numerical instability problems in a deep learning library based on patches and large language models according to claim 3, wherein The specific process of step S21 is as follows: According to the inscription technique, integrate the task information related to the numerical instability problem to obtain an inscription template for judging the relevance between a patch and a numerical instability problem. 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 fixing numerical instability problems in a deep learning library based on patches and large language models according to claim 1, characterized in that The specific process of step S3 is as follows: S31: Design an inscription template for detecting numerical instability problems according to the inscription method; 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 prompter template, and use the test data set to test the performance of the prompter template; S33: According to the above test results, select the prompter template with the best test results and the corresponding template filling patches as the best prompter template, and store it for subsequent detection.
6. The method for detecting and fixing numerical instability problems in a deep learning library based on patches and large language models according to claim 5, characterized in that, In step S31, multiple prompter templates including zero-shot prompting, one-shot prompting, few-shot prompting, and chain-of-thought prompting are designed.
7. The method for detecting and fixing the numerical instability problem of the deep learning library based on patches and large language models according to claim 1, wherein The specific process of step S4 is as follows: S41: Roughly screen out the functions related to numerical calculation from the deep learning library; S42: Fill the screened functions related to numerical calculation into the designed prompter template, and use the large language model to analyze and detect the functions to identify potential numerical instability problems; S43: Analyze the detection results of the large language model and record the detection results, including the specific location, problem description, possible influence range, and relevant context information of the detected numerical instability problem.
8. The method for detecting and fixing the numerical instability problem of a deep learning library based on patches and large language models according to claim 7, characterized in that, S41 is: Based on the set rules, roughly screen out the 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 fixing the numerical instability problem of the deep learning library based on patches and large language models according to claim 1, characterized in that, The specific process of step S51 is as follows: S51: Combine the historical patch description, historical patch program statements, and the code snippets and context information related to the detected numerical instability problem to design a prompter template for patch similarity analysis; S52: Use the text similarity algorithm and version control system to retrieve the historical patches, calculate the similarity between the patches, and screen out the patches most similar to the detected numerical instability problem; S53: Fill the retrieved similar patches and the functions related to the detected numerical instability problem into the prompter template, and use the large language model to judge the similarity between the retrieved similar patches and the detected numerical instability problem to determine its similarity to the current numerical instability problem.
10. The method for detecting and fixing numerical instability problems in a deep learning library based on patches and large language models according to claim 1, characterized in that, The specific process of step S6 is as follows: S61: Extract the information related to the numerical instability problem in the detection results, including the specific location, problem description, influence range, and relevant context information of the problem; S62: According to the extracted information, design a prompter template suitable for generating repair patches, and fill the relevant information into the template; S63: Use the large language model to analyze the filled prompter template, generate a repair patch, and provide a repair plan, including the code of the repair patch and the modification description.
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