Cross-model collaborative scheduling method for code generation based on large language model

By employing a cross-model collaborative scheduling method, multiple LLMs are used to generate code in parallel and self-correct errors, thus addressing the shortcomings of existing LLMs in code generation in complex scenarios and achieving efficient and accurate code generation.

CN119473245BActive Publication Date: 2025-11-18CHONGQING UNIV OF POSTS & TELECOMM
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411448711.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-17
Publication Date
2025-11-18
Estimated Expiration
2044-10-17

AI Technical Summary

Technical Problem

Existing code generation technologies based on Large Language Models (LLMs) struggle to generate suitable code snippets in complex real-world application scenarios, and individual LLMs have limitations in self-correcting errors.

Method used

A cross-model collaborative scheduling method is adopted, which divides the requirement set into multiple subsets for parallel processing, utilizes the code generation capabilities of multiple LLMs, and generates diagnostic and correction prompts during the compilation, execution and testing phases to guide LLMs to self-correct errors, thereby achieving cross-model collaborative code generation.

Benefits of technology

It improves the accuracy and efficiency of code generation, ensures that the generated code meets the expected requirements, shortens processing time and improves resource utilization efficiency, and significantly enhances the performance of LLMs in complex scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119473245B_ABST
    Figure CN119473245B_ABST
Patent Text Reader

Abstract

The application relates to a cross-model collaborative scheduling method for code generation based on large language models (LLMs), belonging to the fields of artificial intelligence and software engineering, and comprising the following steps: S1: obtaining a requirement set R and dividing the requirement set R into N subsets; S2: sequentially extracting requirements in the subsets and constructing code generation prompts; S3: loading LLMs, respectively inputting the code generation prompts into the quantified LLMs, and generating codes in parallel; S4: testing the correctness of the generated codes, and constructing a diagnosis correction prompt if an error is detected; S5: using LLMs to diagnose and correct errors in the codes according to the diagnosis correction prompt, and obtaining the diagnosis-corrected codes; S6: if the codes do not pass the test, cross-model generation is performed; and S7: the steps of S2-S6 are cyclically executed until all requirements are processed, and finally, a code set that successfully passes the test cases and a code set that does not pass the test cases are obtained; the application fully excavates the code generation performance of different LLMs, and improves the automatic code generation capability of cross-model collaboration.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of artificial intelligence and software engineering, and in particular to a method for code generation based on Large Language Models (LLMs), which enhances the performance of LLMs in code generation through cross-model collaboration. Background Technology

[0002] Automated code generation technology offers numerous advantages, including shortening software development cycles, improving software quality and consistency, and reducing human error and repetitive tasks. Therefore, it has garnered significant attention in both academia and industry. Over the past few decades, various code generation techniques have been developed, including deductive synthesis, inductive synthesis, and neural network-based synthesis. These methods have demonstrated great promise in accurately capturing user requirements and improving overall efficiency.

[0003] Large Language Models (LLMs) based on the Transformer architecture have demonstrated excellent performance across various code generation tasks. By pre-training on public code datasets such as GitHub, LLMs learn rich contextual representations, which can be effectively transferred to code generation tasks. To improve code generation performance, existing research has explored effective strategies to ensure that generated code conforms to pseudocode or natural language descriptions and passes test cases. While these studies have enhanced the code generation capabilities of LLMs, they still struggle to generate suitable code snippets in complex real-world application scenarios. Therefore, recent research has attempted to improve performance through self-correcting mechanisms, particularly by guiding LLMs to introspect and correct errors in generated code, mimicking the software engineer's process of writing, compiling, testing, and debugging. Summary of the Invention

[0004] In view of this, the purpose of this invention is to provide a cross-model collaborative scheduling method for code generation based on LLMs. Through cross-model collaboration, the code generation capability of this method is not limited to the code generation capability of a single LLM, but can combine different LLMs for code generation, thereby achieving cross-model collaborative code generation. By tracking errors in the compilation, execution, and testing phases of the code and generating diagnostic and corrective prompts, the LLMs can autonomously attempt to correct errors in the generated code, thus improving the code generation capability of the LLMs.

[0005] To achieve the above objectives, the present invention provides the following technical solution:

[0006] 1. A cross-model collaborative scheduling method for code generation based on LLMs, characterized in that the method includes the following detailed steps:

[0007] S1: Obtain the requirement set R, where requirements include natural language descriptions or pseudocode, and then divide the requirement set R into N subsets {R} based on the N (N≥2) LLMs actually invoked. A ,R B ,…,R N}, where there is no overlap between the subsets of requirements, and the requirements are represented by R. Xy Indicates; R A ={R A1 ,R A2 ,R A3 ,…,R Ai ,…,R Aa}, R B ={R B1 ,R B2 ,R B3 ,…,R Bj ,…,R Bb},…,R N ={R N1 ,R N2 ,R N3 ,…,R Nr ,…,R Nn},|R A |=a,|R B |=b,…,|R N | = n, and |R| = a + b + ... + n;

[0008] S2: In subset {R A ,R B ,…,R N Extracting one requirement at a time from} yields requirement {R} Ai ,R Bj ,…,R Nr}, where 1≤i≤a, 1≤j≤b, …, 1≤r≤n, the requirement {R} Ai ,R Bj ,…,R Nr} Build code generation suggestions to obtain code generation suggestions that include the requirements. Some task requirements necessitate corresponding test cases to construct prompts;

[0009] S3: Load LLMs{M A M B ,…,M N} and it can be decided whether to quantify it into {M} based on actual usage. QA M QB ,…,M QN To reduce computing resources, code generation hints will be provided separately. Input quantized LLMs{M QA M QB ,…,MQN Parallel code generation This invention takes quantized LLMs as an example, but is not limited to quantized LLMs. LLMs in the following text refer to quantized LLMs.

[0010] S4: Compile, execute, and test the generated code using test cases. If the tests pass, add the code to code set C. S If an error is detected, diagnostic and corrective prompts are built using error information obtained during the compilation, execution, and testing phases of the code.

[0011] S5: Pass different diagnostic and corrective suggestions into the LLMs used in the code generation phase, enabling them to self-diagnose and correct errors in the code, resulting in the diagnosed and corrected code. This diagnosed and corrected code is then compiled, executed, and tested. The code that passes the tests is added to the code set C. S ;

[0012] S6: If the code fails the test, cross-model generation will be performed. This involves trying to handle the requirements corresponding to the code using other LLMs, and continuing the code generation and diagnostic correction process. This process will sequentially try all available LLMs until the test is passed or all LLMs have been tried, resulting in the final code. The code that passes the test will be added to code set C. S Code that failed the test was added to code set C. F ;

[0013] S7: Repeat steps S2-S6 until all requirements R have been processed, ultimately resulting in the code set C that successfully passed the test cases. S and the code set C that failed the test cases F And |R|=|C S |+|C F |

[0014] Furthermore, in step S1, the method for dividing the demand set R into multiple subsets is as follows:

[0015] Method 1: When multiple LLMs are deployed on one or more GPUs, i.e., the number of GPUs is not equal to the number of LLMs, the requirement set R should be distributed as evenly as possible according to the actual number of LLMs that can be called.

[0016] Method 2: When multiple LLMs are deployed on different GPUs, i.e., the number of GPUs equals the number of LLMs, the allocation is based on the number of GPU cores and the base frequency of each core:

[0017] a / b / … / n=(N a ×f a ) / (N b ×fb ) / … / (N n ×f n )

[0018] Where a, b, ..., n represent the specific demand quantities of different subsets, and N... a N b ,…,N n These represent the number of cores in different GPUs, f a ,f b ,…f n These represent the base frequency of each core in different GPUs.

[0019] Furthermore, the code generation prompt template comprises four key parts: Role, Requirements, Requirements, and Output. The Role section assigns a specific identity to LLMs, providing crucial contextual information essential for their accurate understanding of requirements. The Requirements section specifies the exact task types LLMs need to perform, offering clear action guidelines. The Requirements section details the specific requirements for code generation to ensure the generated code meets specific quality standards, including T... C This refers to the test cases for the code; the output section specifies the output format requirements of LLMs to ensure the standardization and usability of the results so that the generated code can be identified; the prompt templates designed in this invention include, but are not limited to, Chinese and English. You only need to prepare the template according to the natural language supported by the LLMs used, and the same applies below; the prompt templates for code generation are as follows:

[0020]

[0021] Wherein, R Xy Given a specific requirement, R Xy ∈{R Ai ,R Bj ,…,R Nr}, T Xy Represents a given requirement R Xy Corresponding test cases; some task requirements require corresponding test cases to build prompts. If no test cases are required to build prompts, skip the first requirement in the above template.

[0022] Furthermore, in step S3, LLMs work in parallel, generating code according to their respective needs. The code generation process is represented by the following general formula:

[0023]

[0024] Where R Xy R represents a specific requirement that the code aims to solve. Xy Indicates that R XyThe prompt constructed according to the above prompt template, M Q G(·) represents the quantized LLMs, and G(·) represents the code generation process using LLMs. This represents the generated code.

[0025] Furthermore, in step S4, test cases are automatically compiled and executed to verify the functionality and correctness of the code. The detected code errors are categorized into the following three types:

[0026] Compilation error: An error that occurs when code does not conform to syntax rules or language specifications, causing the program to fail to compile;

[0027] Execution error: An error caused by improper program logic, resulting in timeout or abnormal termination during testing;

[0028] Test error: The program runs normally, but the output does not match the given answer, causing the test to fail or result in an error.

[0029] During the compilation, execution, and running of test cases, error messages are recorded based on compiler and interpreter error messages and differences from the expected output of the test cases. The method is as follows:

[0030]

[0031] Where C C (·), C E (·), C T (·) represent the generated code. This module collects error information during compilation, execution, and testing. The error information collected at each stage is represented by [specific symbols / methods]. and This indicates that some programming languages, such as Python, are interpreted languages ​​and do not involve a traditional compilation process. Therefore, when dealing with Python-related requirements, the compilation step must be skipped, and no diagnostic or corrective process for compilation errors will be performed.

[0032] Furthermore, the diagnostic and correction prompt template is as follows:

[0033]

[0034] Furthermore, in step S5, error analysis and repair are performed using the self-diagnostic capabilities of LLMs:

[0035]

[0036] Where L C L E , and L TThese represent the diagnostic and corrective loops for the code compilation, execution, and testing phases, respectively. The loop ends after reaching the maximum number of diagnostic and corrective attempts or after passing the tests. These represent the diagnostic correction codes generated at these stages; DC(·) refers to the diagnostic correction process.

[0037] Furthermore, different strategies should be adopted depending on the specific circumstances:

[0038] Scenario 1: If all code passes the tests; Corresponding Strategy 1: No further action is needed, simply add the correct code to code set C. S ;

[0039] Scenario 2: If some code fails the test; Corresponding Strategy 2: For each piece of code that failed the test, sequentially try to generate code using all available models for the corresponding requirements, until a model successfully passes the test or all models have been tried. Add the code that passed the test to code set C. S Code that failed the test was added to code set C. F ;

[0040] Where C S The code set that indicates the test cases passed successfully, C F This indicates the code set that failed the test cases.

[0041] The beneficial effects of this invention are as follows:

[0042] (1) This invention proposes a cross-model collaborative scheduling method based on LLMs code generation, which generates code through cross-model code generation and diagnostic correction mechanisms. It can combine the code generation capabilities of different LLMs to achieve cross-model collaborative code generation, and improve the automatic code generation capability under the cross-model method by fully exploring the code generation performance of different LLMs.

[0043] (2) In the multi-model collaborative code generation process, this invention utilizes multiple high-performance LLMs to collaboratively generate code. By dividing the requirement set into multiple subsets, multiple LLMs can generate code in parallel. This method improves the efficiency of LLMs and eliminates idle time during task execution, ensuring that different LLMs process their respective parts in parallel. This arrangement not only shortens processing time but also improves resource utilization efficiency.

[0044] (3) In the diagnostic and correction process, this invention generates diagnostic and correction prompts by tracking errors in the code during the compilation, execution, and testing phases, and enables LLMs to automatically fix errors in the code based on these prompts. By utilizing the model's self-correction capabilities, the accuracy and quality of the generated code are improved, ensuring that the final code meets the expected requirements.

[0045] (4) In the cross-model code generation process, when the current LLM encounters an error while handling a specific requirement, the system will switch to the next LLM for code diagnosis and correction. In this way, even if a single LLM cannot solve a given requirement, the collaboration between multiple LLMs can significantly improve the overall performance of the cross-model collaborative scheduling method.

[0046] Other advantages, objectives, and features of the invention will be set forth in the following description, and may be provided, in part, as guidance and assistance may be gained from the practice of the invention. The objectives and other advantages of the invention can be realized and obtained through the following description. Attached Figure Description

[0047] To make the objectives, technical solutions, and advantages of the present invention clearer, the preferred embodiments of the present invention will be described in detail below with reference to the accompanying drawings, wherein:

[0048] Figure 1 This is a schematic diagram of the overall process of the cross-model collaborative scheduling method described in this invention;

[0049] Figure 2 This is a schematic diagram of the code generation based on multi-model collaboration described in this invention;

[0050] Figure 3 This is a schematic diagram of the code diagnosis and correction process described in this invention;

[0051] Figure 4 This is a schematic diagram of the cross-model collaborative code generation process described in this invention. Detailed Implementation

[0052] The following specific examples illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of the present invention. Unless otherwise specified, the following embodiments and features can be combined with each other.

[0053] The accompanying drawings are for illustrative purposes only and are schematic diagrams, not actual pictures. They should not be construed as limiting the invention. To better illustrate the embodiments of the invention, some parts in the drawings may be omitted, enlarged, or reduced, and do not represent the actual product dimensions. It is understandable to those skilled in the art that some well-known structures and their descriptions may be omitted in the drawings.

[0054] This invention proposes a cross-model collaborative scheduling method for code generation based on LLMs, such as... Figure 1 The flowchart specifically includes the following steps:

[0055] S1: Obtain the requirement set R, where requirements include natural language descriptions or pseudocode, and then divide the requirement set R into N subsets {R} based on the N (N≥2) LLMs actually invoked. A R B , ..., R N}, where there is no overlap between the subsets of requirements, and the requirements are represented by R. Xy It means; R = {R A1 R A2 R A3 , ..., R Ai …, R Aa}, R B ={R B1 R B2 R B3 , ..., R Bj , ..., R Bb},…,R N ={R N1 R N2 R N3 , ..., R Nr , ..., R Nn},|R A |=a,|R B |=b,…,|R N |=n, and |R|=a+b+…+n; Methods for partitioning the demand set R into multiple subsets:

[0056] Method 1: When multiple LLMs are deployed on one or more GPUs, i.e., the number of GPUs is not equal to the number of LLMs, the requirement set R should be distributed as evenly as possible according to the actual number of LLMs that can be called.

[0057] Method 2: When multiple LLMs are deployed on different GPUs, i.e., the number of GPUs equals the number of LLMs, the allocation is based on the number of GPU cores and the base frequency of each core:

[0058] a / b / … / n=(N a ×f a ) / (N b ×f b ) / … / (N n ×f n )

[0059] Where a, b, ..., n represent the specific demand quantities of different subsets, and N... a N b ,…,N n These represent the number of cores in different GPUs, f af b , ...f n These represent the base frequency of each core in different GPUs.

[0060] S2: In subset {R A R B , ..., R N Extracting one requirement at a time from} yields requirement {R} Ai R B j, ..., R Nr}, where 1≤i≤a, 1≤j≤b, …, 1≤r≤n, the requirement {R} Ai R Bj , ..., R Nr} Build code generation suggestions to obtain code generation suggestions that include the requirements. Some task requirements necessitate corresponding test cases to construct prompts;

[0061] The code generation hint template comprises four key parts: Role, Requirements, Requirements, and Output. The Role section assigns a specific identity to LLMs, providing crucial contextual information essential for their accurate understanding of requirements. The Requirements section specifies the specific task types LLMs need to perform, offering clear action guidelines. The Requirements section details the specific requirements for code generation to ensure the generated code meets specific quality standards, including T... C This refers to the test cases for the code; the output section specifies the output format requirements of LLMs to ensure the standardization and usability of the results so that the generated code can be identified; the prompt templates designed in this invention include, but are not limited to, Chinese and English. You only need to prepare the template according to the natural language supported by the LLMs used, and the same applies below; the prompt templates for code generation are as follows:

[0062]

[0063]

[0064] Wherein, R Xy Given a specific requirement, R Xy ∈{R Ai ,R Bj ,…,R Nr}, T Xy Represents a given requirement R Xy Corresponding test cases; some task requirements require corresponding test cases to build prompts. If no test cases are required to build prompts, skip the first requirement in the above template.

[0065] S3: Load LLMs{M A M B ,…,MN} and it can be decided whether to quantify it into {M} based on actual usage. QA M QB ,…,M QN To reduce computing resources, code generation hints will be provided separately. Input quantized LLMs{M QA M QB ,…,M QN Parallel code generation This invention takes quantized LLMs as an example, but is not limited to quantized LLMs; LLMs in the following text refer to quantized LLMs; the code generation process is represented by the following general formula:

[0066]

[0067] Where R Xy P represents a specific requirement that the code aims to solve. Xy Indicates that R Xy The prompt constructed according to the above prompt template, M Q G(·) represents the quantized LLMs, and G(·) represents the code generation process using LLMs. The generated code represents the multi-model collaborative generation process described above. Figure 2 As shown.

[0068] S4: Compile, execute, and test the generated code using test cases. If the tests pass, add the code to code set C. S If an error is detected, diagnostic and corrective suggestions are built using error information obtained during the compilation, execution, and testing phases of the code. We obtain feedback information from errors and categorize them into the following three types:

[0069] Compilation error: An error that occurs when code does not conform to syntax rules or language specifications, causing the program to fail to compile;

[0070] Execution error: An error caused by improper program logic, resulting in timeout or abnormal termination during testing;

[0071] Test error: The program runs normally, but the output does not match the given answer, causing the test to fail or result in an error.

[0072] During the compilation, execution, and running of test cases, error messages are recorded based on compiler and interpreter error messages and differences from the expected output of the test cases. The method is as follows:

[0073]

[0074] Where C C (·), CE (·), C T (·) represent the generated code. This module collects error information during compilation, execution, and testing. The error information collected at each stage is represented by [specific symbols / methods]. and This indicates that some programming languages, such as Python, are interpreted languages ​​and do not involve a traditional compilation process. Therefore, when dealing with Python-related requirements, the compilation step must be skipped, and no diagnostic or corrective process for compilation errors will be performed.

[0075] If an error is detected, diagnostic correction tips are constructed using error information gathered during the compilation, execution, and testing phases. These tips can be used in all three phases, with corresponding templates for each. These templates guide LLMs in analyzing three types of error messages and inferring improvements to the generated code based on the analysis results. The templates are general in design and can incorporate other useful information to effectively organize error messages. For compilation errors, collected data is used, including the error line number, line context, and complete error message. For execution errors, information indicating program exceptions is used. For test errors, these are also encapsulated in the templates. These error messages provide additional context and clarity to the generated code, aiming to guide LLMs in diagnostic correction based on the provided error information. Diagnostic correction tip templates are as follows:

[0076]

[0077] S5: Different diagnostic and corrective suggestions are passed to the LLMs used in the code generation phase, enabling them to self-diagnose and correct errors in the code, resulting in diagnosed and corrected code. Specifically, corresponding diagnostic and corrective strategies are implemented at each stage of compilation, execution, and testing, as shown in the following formula:

[0078]

[0079] Where L C L E , and L T These represent the diagnostic and corrective loops for the code compilation, execution, and testing phases, respectively. The loop ends after reaching the maximum number of diagnostic and corrective attempts or after passing the tests. These represent the diagnostic correction codes generated at these stages; DC(·) refers to the diagnostic correction process.

[0080] The final result is a diagnosed and corrected code. The diagnosis and correction process described above is as follows: Figure 3 As shown. The diagnosed and corrected code is compiled, executed, and tested. The code that passes the tests is added to code set C. S.

[0081] S6: If the code fails the test, cross-model generation will be performed, which means trying to handle the requirements corresponding to the code using other LLMs, and continuing the code generation and diagnostic correction process. This process will sequentially try all available LLMs until the test is passed or all LLMs have been tried, and the final code is obtained.

[0082] Adopt corresponding strategies based on different situations:

[0083] Scenario 1: If all code passes the tests; Corresponding Strategy 1: No further action is needed, simply add the correct code to code set C. S ;

[0084] Scenario 2: If some code fails the test; Corresponding Strategy 2: For each piece of code that failed the test, sequentially try to generate code using all available models for the corresponding requirements, until a model successfully passes the test or all models have been tried. Add the code that passed the test to code set C. S Code that failed the test was added to code set C. F ;

[0085] Where C S The code set that indicates the test cases passed successfully, C F This indicates the code set that failed the test cases.

[0086] Example 1

[0087] S1: Obtain the requirement set R, and based on the N (N≥2) LLMs actually invoked, divide the requirement set R into N equal parts to obtain the requirement subset {R}. A ,R B ,…,R N}

[0088] S2: R A For example, in subset R A Extract a requirement to obtain requirement R Ai Demand R Ai And corresponding test cases are used to generate code with suggestions, resulting in R containing the requirements. Ai Code generation suggestions

[0089]

[0090] S3: Load LLMs{M A M B ,…,M N} and quantized into {M QA M QB ,…,M QN}, which will generate code suggestions Passing M QA Conduct demand R Ai Code generation to get code

[0091]

[0092] S4: Analyze the generated code respectively. Compile, execute, and test with test cases to determine the correctness of the code.

[0093] The code encountered a test error; build test error diagnosis and correction prompts.

[0094]

[0095]

[0096] S5: Compilation error diagnosis and correction prompts The large model is input, and its self-diagnosis and automatic correction techniques are used to analyze and fix errors, resulting in a diagnosed and corrected version. Code:

[0097]

[0098] Reuse the test cases on the generated The code was compiled, executed, and tested. Compilation was successful, but an issue was found... The code encountered a test error, but the number of diagnostic correction attempts exceeded the limit, and the diagnostic correction failed.

[0099] S6: In case of situation 2, the error code will be... And its demand shifts to M QB Code C is generated after code generation and diagnostic correction. Ai :

[0100]

[0101] C Ai The code passes the test, and the C code that passes the test will be... Ai The code was added to the code set C that passed the test cases. S .

[0102] S7: Repeat S2-S6 until all requirements have been processed, finally obtaining the code set C that passes the test cases. S and the code set C that failed the test cases F .

[0103] The above-described embodiments further illustrate the purpose, technical solution, and advantages of the present invention. It should be understood that the above-described embodiments are merely preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made to the present invention within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A cross-model collaborative scheduling method for code generation based on large language models (LLMs), characterized in that, The method includes the following detailed steps: S1: Obtain the requirement set R, where requirements include natural language descriptions or pseudocode. Then, based on the N LLMs actually invoked (N≥2), divide the requirement set R into N subsets {R... A ,R B ,…,R N }, where there is no overlap between the subsets of requirements, and the requirements are represented by R. Xy express; S2: respectively in subset {R A ,R B ,…,R N Extracting one requirement at a time from} yields requirement {R} Ai ,R Bj ,…,R Nr }, will the requirement {R Ai ,R Bj ,…,R Nr } Build code generation suggestions to obtain code generation suggestions that include the requirements. Some task requirements necessitate corresponding test cases to construct prompts; S3: Load LLMs{M A M B ,…,M N } and quantize it as {M QA M QB ,…,M QN }, respectively generate code suggestions Input LLMs and generate code in parallel. S4: Compile, execute, and test the generated code using test cases. If the tests pass, add the code to code set C. S If an error is detected, diagnostic and corrective prompts are built using error information obtained during the compilation, execution, and testing phases of the code. S5: Pass different diagnostic and corrective suggestions into the LLMs used in the code generation phase, enabling them to self-diagnose and correct errors in the code, resulting in the diagnosed and corrected code. This diagnosed and corrected code is then compiled, executed, and tested. The code that passes the tests is added to the code set C. S ; S6: If the code fails the test, cross-model generation will be performed. This involves trying to handle the requirements corresponding to the code using other LLMs, and continuing the code generation and diagnostic correction process. This process will sequentially try all available LLMs until the test is passed or all LLMs have been tried, resulting in the final code. The code that passes the test will be added to code set C. S Code that failed the test was added to code set C. F ; S7: Repeat steps S2-S6 until all requirements R have been processed, ultimately resulting in the code set C that successfully passed the test cases. S and the code set C that failed the test cases F And |R|=|C S |+|C F | 2. The cross-model collaborative scheduling method for code generation based on LLMs according to claim 1, characterized in that: In step S1, the method for dividing the demand set R into multiple subsets is as follows: Method 1: When multiple LLMs are deployed on one or more GPUs, i.e., the number of GPUs is not equal to the number of LLMs, the requirement set R should be distributed as evenly as possible according to the actual number of LLMs that can be called. Method 2: When multiple LLMs are deployed on different GPUs, i.e., the number of GPUs is equal to the number of LLMs, they are allocated according to the number of GPU cores and the base frequency of each core.

3. The cross-model collaborative scheduling method for code generation based on LLMs according to claim 1, characterized in that: In step S2, the code generation prompt template contains four key parts: Role, Requirements, Requirements, and Output. The Role part is designed to assign a specific identity to LLMs, providing crucial contextual information that is essential for LLMs to accurately understand the requirements. The Requirements part is designed to specify the specific task types that LLMs need to perform, providing clear action guidance. The Requirements part details the specific requirements for code generation to ensure that the generated code meets specific quality standards. The Output part specifies the output format requirements for LLMs, ensuring the standardization and usability of the results so that the generated code can be identified.

4. The cross-model collaborative scheduling method for code generation based on LLMs according to claim 1, characterized in that: In step S4, test cases are automatically compiled and executed to verify the functionality and correctness of the code. The detected code errors are categorized into the following three types: Compilation error: An error that occurs when code does not conform to syntax rules or language specifications, causing the program to fail to compile; Execution error: An error caused by improper program logic, resulting in timeout or abnormal termination during testing; Test error: The program runs normally, but the output does not match the given answer, causing the test to fail or result in an error; During the compilation, execution, and running of test cases, error information is recorded based on the error messages from the compiler and interpreter, as well as the differences between the output and the expected output of the test cases.

5. The cross-model collaborative scheduling method for code generation based on LLMs according to claim 1, characterized in that: In step S4, the diagnostic correction template provides three key pieces of information: details of the error generated by the compiler, the code segment currently causing the error, and a requirement reference; the execution error diagnostic correction template provides three aspects of information: error information generated during program execution, the code segment currently causing the error, and a requirement reference; the test error diagnostic correction template provides four key pieces of information: the provided test cases, the difference between expected and actual output, the currently generated code, and the requirement. Its purpose is to help LLMs identify the causes of failures in the code, perform targeted optimizations, and enable the program to achieve the expected results.

6. The cross-model collaborative scheduling method for code generation based on LLMs according to claim 1, characterized in that: In step S5, error analysis and repair are performed using the self-diagnostic capabilities of LLMs: Where L C L E , and L T These represent the diagnostic and corrective loops for the code compilation, execution, and testing phases, respectively. The loop ends after reaching the maximum number of diagnostic and corrective attempts or after passing the tests. This represents the diagnostic correction codes generated at these stages. DC(·) refers to the diagnostic correction process. This indicates a compilation error message. This indicates an execution error message. This indicates a test error message. The code indicates that the diagnostic failed, R Xy P represents demand. Xy The M indicates a prompt for using LLMs' self-diagnostics for error analysis and repair. Q This represents the quantized LLMs.

7. The cross-model collaborative scheduling method for code generation based on LLMs according to claim 1, characterized in that: In step S6, corresponding strategies are adopted according to different situations: Scenario 1: If all code passes the tests; Corresponding Strategy 1: No further action is needed, simply add the correct code to code set C. S ; Scenario 2: If some code fails the test; Corresponding strategy 2: For each piece of code that failed the test, try generating code using all available models in sequence, until a model successfully passes the test or all models have been tried. The code that passes the test is added to code set C. S Code that failed the test was added to code set C. F ; Where C S The code set that indicates the test cases passed successfully, C F This indicates the code set that failed the test cases.

Citation Information

Patent Citations

  • Method for automatically generating instruction data set based on LLM

    CN117667202A

  • Code generation method and device, equipment and medium

    CN118363574A