Method for training a code large model and electronic device

By preprocessing the enterprise codebase and establishing a code relationship graph, and combining agent tools and rules to construct a post-training dataset, the large code model is post-trained, solving the problem that existing large code models cannot understand the enterprise code structure and business needs, and achieving more efficient R&D support.

CN121187569BActive Publication Date: 2026-03-31HANGZHOU PINGPONG INTELLIGENT TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-11-26
Publication Date
2026-03-31

AI Technical Summary

Technical Problem

Existing technologies cannot effectively utilize the complex relationships between codes, resulting in limitations in understanding enterprise-specific code structures, business requirements, and system operating states of large code models. This makes it difficult to achieve automated support in key R&D scenarios such as automatic front-end page generation, back-end JIRA requirement linkage, and fault diagnosis.

Method used

By preprocessing the enterprise codebase and establishing a code relationship graph, and combining agent tools and rules to build a high-quality post-training dataset, the initial large code model is post-trained to improve its context and cross-project capabilities.

Benefits of technology

It significantly improves the usability of the large code model, enabling it to automatically generate product front-end pages, automatically build back-end scaffolding, and link code and logs to restore the problem chain in case of failure, thereby improving R&D efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121187569B_ABST
    Figure CN121187569B_ABST
Patent Text Reader

Abstract

The application discloses a code large model training method and an electronic device. The original code in a code library is preprocessed to obtain preprocessed code. An open source language model is pre-trained based on the preprocessed code in file granularity and warehouse granularity to obtain an initial code large model capable of capturing context relationships between code segments. A code relationship graph is established according to the preprocessed code. Actual business data is captured, and the actual business data and the code relationship graph are processed according to predefined Agent tools and Agent rules to construct a post-training data set. The initial code large model is post-trained based on the post-training data set according to the code relationship graph, the Agent tools and Agent rules to obtain a trained code large model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of software engineering technology, specifically to a training method and electronic device for a large code model. Background Technology

[0002] In the intersection of software engineering and artificial intelligence (AI), large code model technology is gradually becoming a key tool for improving development efficiency. These models are typically pre-trained on large-scale open-source code libraries to acquire basic capabilities such as code generation, completion, and understanding. Then, through post-training (e.g., supervised fine-tuning, reinforcement learning, etc.), the model is adapted to specific programming languages ​​or coding styles.

[0003] In existing technologies, large open-source code models (such as Qwen, CodeLlama, etc.) are typically used for pre-training and fine-tuning. To enhance the large code model's awareness of code structure, some solutions supplement the model with code development aids to achieve an AI-enabled code editor (AI-IDE). For example, open-source IDE plugins such as Continue and Cline are added to the model, or closed-source IDE plugins such as Trae and Cursor are added to support IDEs such as VS Code and JetBrains. Other solutions connect to project management data such as JIRA and Wiki through external tools (such as the Continue framework with the Model Context Protocol (MCP) plugin) and extract this project information as a reference by retrieving the Retrieval-AugmentedGeneration-contextprovider (RAG-contextprovider).

[0004] However, these existing technical solutions still have significant drawbacks: they cannot achieve cross-project RAG operations, the context window of large code models is limited, and they lack effective utilization of complex relationships between code when building post-training datasets, thus limiting the learning performance of large code models. These shortcomings prevent large code models from fully understanding enterprise-specific code structures, business requirements, and system operating states, making it difficult to achieve effective automation support in key R&D scenarios such as automatic front-end page generation, back-end JIRA requirement linkage, and troubleshooting, thereby limiting the effectiveness of large code models in real-world R&D scenarios. Summary of the Invention

[0005] This application aims to address one of the technical problems in related technologies to a certain extent. To this end, this application provides a training method and electronic device for large code models, which has the advantage of improving the practicality of large code models and thus significantly improving R&D efficiency.

[0006] To achieve the above objectives, this application adopts the following technical solution:

[0007] A method for training a large code model, comprising:

[0008] Preprocess the original code in the codebase to obtain preprocessed code;

[0009] The open-source language model is pre-trained based on the preprocessed code at both the file granularity and repository granularity to obtain an initial large code model capable of capturing the contextual relationships between code segments.

[0010] Based on the preprocessed code, a code relationship graph is established;

[0011] Capture actual business data, process the actual business data and the code relationship graph according to predefined Agent tools and Agent rules, and construct a post-training dataset;

[0012] Based on the code relationship graph, the agent tool, and the agent rules, the initial large code model is post-trained using the post-training dataset to obtain a trained large code model.

[0013] The code-based large model training method provided in this application preprocesses the original code in the code repository to obtain preprocessed code; pre-trains an open-source language model based on the preprocessed code at both file and repository granularities to obtain an initial code-based large model capable of capturing the contextual relationships between code segments; establishes a code relationship graph based on the preprocessed code; captures actual business data, processes the actual business data and the code relationship graph according to predefined Agent tools and Agent rules, and constructs a post-training dataset; and post-trains the initial code-based large model based on the code relationship graph, the Agent tools, and Agent rules, obtaining a trained code-based large model. This method enhances the contextual capabilities, cross-project capabilities, and code localization capabilities of the code-based large model, enabling it to automatically generate product front-end pages based on design drafts / screenshots, automatically build back-end scaffolding according to JIRA requirements, and reconstruct problem chains by linking code / logs and database monitoring information in case of failures. This improves the practicality of the code-based large model and significantly enhances development efficiency.

[0014] Optionally, the step of capturing actual business data involves processing the actual business data and the code relationship graph according to Agent tools and Agent rules to construct a post-training dataset, including:

[0015] Capture fragmented data from basic business operations and full-chain data from production scenarios;

[0016] Based on the Agent tool and Agent rules, supervised fine-tuning SFT samples are extracted from the basic business fragmented data and the code relationship graph;

[0017] Based on the Agent tool and Agent rules, reinforcement and fine-tuning RFT samples are extracted from the full-link data of the production scenario and the code relationship graph; wherein, the supervised fine-tuning SFT sample and the reinforcement and fine-tuning RFT sample both include input information and their corresponding expected output results.

[0018] Optionally, the basic business fragmented data includes error-level logs and code consultation information; the step of extracting supervised fine-tuning SFT samples from the basic business fragmented data and the code relationship graph according to the Agent tool and Agent rules includes:

[0019] The complete call chain and log content are extracted from the Error-level log to generate input information, and the code segment associated with the Error-level log is extracted from the code relationship graph as the corresponding expected output result.

[0020] The consultation question is extracted from the consultation information to generate input information. The code segment containing the inclusion relationship of folders and files associated with the consultation object, the parent class and child class inheritance relationship, the package import relationship and the called relationship are extracted from the code relationship graph. The business parsing result is determined as the corresponding expected output result.

[0021] Optionally, the full-link data in the production scenario includes global codebase evaluation data, JIRA-Git-SQL cross-tool project improvement data, and multi-dimensional production failure data; the extraction of reinforcement and fine-tuning RFT samples from the full-link data in the production scenario and the code relationship graph includes:

[0022] The repository global evaluation instruction is extracted from the global evaluation data of the code repository to generate input information. The call chain associated with the global evaluation instruction of the repository is extracted from the code relationship graph to determine the code framework evaluation report as the corresponding expected output result.

[0023] The jira-id, git commit record identifier, and SQL change statement are extracted from the JIRA-Git-SQL cross-tool project improvement data to generate input information. The code segments associated with the jira-id, git commit record identifier, and SQL change statement are extracted from the code relationship graph as the corresponding expected output results.

[0024] Input information is generated by extracting SLS fault logs and database monitoring information from the multi-dimensional production fault data, and code segments associated with the SLS fault logs and database monitoring information are extracted from the code relationship graph as the corresponding expected output results.

[0025] Optionally, the step of post-training the initial large code model based on the post-training dataset according to the code relationship graph, the agent tool, and the agent rules to obtain a trained large code model includes:

[0026] Based on the code relationship graph, the agent tool, and the agent rules, the initial large code model is post-trained on the post-training dataset to obtain an intermediate large code model.

[0027] Obtain the acceptance dataset;

[0028] The intermediate code large model is used to perform a preset acceptance task on the verification dataset;

[0029] If the execution result of the acceptance task meets the acceptance requirements, the intermediate code model will be used as the trained code model.

[0030] Optionally, the acceptance task includes a code completion task and a code structuring task, and the acceptance requirements are determined based on the edit distance of the code completion task, the accuracy of the code structuring task, the executable proportion of the code generated by executing the code completion task, and the test case coverage of the acceptance task.

[0031] Optionally, the node information of the code relationship graph includes repositories, files, classes, functions, and variables, and the edge information of the code relationship graph includes import, contain, inherit, and invoke.

[0032] Optionally, the Agent tool includes a tool for searching entities, a tool for traversing the graph, and a tool for obtaining the complete content of a specific entity.

[0033] Optionally, the step of preprocessing the original code in the code library to obtain preprocessed code includes:

[0034] Use the `git` command to extract the main branch of the code in the repository to obtain the original code;

[0035] The original code is categorized according to language type, which includes at least Java, JS, and SQL.

[0036] For the original code of each language type, first perform global deduplication based on file hash, and then perform fuzzy deduplication based on fuzzy hash.

[0037] Furthermore, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the training method for the large code model described in any of the above claims.

[0038] These features and advantages of this application will be disclosed in detail in the following specific embodiments and accompanying drawings. The best embodiments or means of this application will be shown in detail in conjunction with the accompanying drawings, but are not intended to limit the technical solutions of this application. In addition, each of these features, elements and components appearing in the following text and drawings is multiple and is labeled with different symbols or numbers for convenience, but all represent parts with the same or similar structure or function. Attached Figure Description

[0039] The following description, in conjunction with the accompanying drawings, further illustrates this application:

[0040] Figure 1 A flowchart illustrating one implementation of the training method for the large code model provided in this application embodiment;

[0041] Figure 2 A flowchart illustrating another implementation of the training method for the large code model provided in this application embodiment;

[0042] Figure 3 A flowchart illustrating yet another implementation of the code-large model training method provided in this application embodiment;

[0043] Figure 4 A flowchart illustrating another implementation of the code-large model training method provided in the embodiments of this application;

[0044] Figure 5 A flowchart illustrating another implementation of the training method for the large code model provided in this application embodiment;

[0045] Figure 6 This is a schematic diagram illustrating one implementation of the traversal and search edge information provided in an embodiment of this application;

[0046] Figure 7This is a schematic diagram illustrating one implementation of the basic relationship between code segments provided in the embodiments of this application;

[0047] Figure 8 A flowchart illustrating yet another implementation of the code-large model training method provided in this application embodiment;

[0048] Figure 9 A schematic diagram illustrating one embodiment of the electronic device provided in this application;

[0049] Explanation of reference numerals in the attached figures

[0050] 101: Processor; 102: Memory

[0051] 103: I / O interface; 104: Bus. Detailed Implementation

[0052] The embodiments of this application are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described are intended to explain this application and should not be construed as limiting it.

[0053] The terms "an embodiment," "example," or "example" used in this specification refer to a particular feature, structure, or characteristic described in connection with the embodiment itself that may be included in at least one embodiment disclosed in this application. The phrase "in an embodiment" appearing in various places throughout the specification does not necessarily refer to the same embodiment.

[0054] In the intersection of software engineering and artificial intelligence (AI), large code model technology is gradually becoming a key tool for improving development efficiency. These models are typically pre-trained on large-scale open-source code libraries to acquire basic capabilities such as code generation, completion, and understanding. Then, through post-training (e.g., supervised fine-tuning, reinforcement learning, etc.), the model is adapted to specific programming languages ​​or coding styles.

[0055] In existing technologies, large open-source code models (such as Qwen, CodeLlama, etc.) are typically used for pre-training and fine-tuning. To enhance the large code model's awareness of code structure, some solutions supplement the model with code development aids to achieve an AI-enabled code editor (AI-IDE). For example, open-source IDE plugins such as Continue and Cline are added to the model, or closed-source IDE plugins such as Trae and Cursor are added to support IDEs such as VS Code and JetBrains. Other solutions connect to project management data such as JIRA and Wiki through external tools (such as the Continue framework with the Model Context Protocol (MCP) plugin) and extract this project information as a reference by retrieving the Retrieval-AugmentedGeneration-contextprovider (RAG-contextprovider).

[0056] However, the applicant of this application found that the aforementioned existing technical solutions still have significant drawbacks: AI-IDE cannot achieve cross-project RAG jobs; the context information provided by the Continue framework in conjunction with the MCP plugin is limited, and the context window of the large code model is restricted; most importantly, these technical solutions all share a common drawback, namely, the inability to construct high-quality post-training datasets and the lack of effective utilization of complex relationships between code, thus limiting the learning effect of the large code model. These shortcomings prevent the large code model from fully understanding the enterprise-specific code structure, business requirements, and system operating status, making it difficult to achieve effective automated support in key R&D scenarios such as automatic front-end page generation, back-end JIRA requirement linkage, and fault diagnosis, thereby limiting the effectiveness of the large code model in actual R&D scenarios.

[0057] In response, the applicant of this application proposes that the enterprise's own code library can be combined with the capabilities of open source models. By leveraging open source models to fully understand the contextual relationships between code segments, a code relationship graph can be built based on the code to capture the correlation between code segments. Agent tools and agent rules can be predefined to construct a high-quality post-training dataset and support the linkage processing of actual business data and code, thereby improving the practicality of the large code model and significantly improving R&D efficiency.

[0058] As the first aspect of this application, a method for training large code models is provided, such as... Figure 1 As shown, the method includes:

[0059] In step S110, the original code in the code library is preprocessed to obtain preprocessed code;

[0060] In step S120, the open-source language model is pre-trained based on the preprocessed code according to file granularity and repository granularity respectively, to obtain an initial large code model that can capture the contextual relationships between code segments;

[0061] In step S130, a code relationship graph is established based on the preprocessed code;

[0062] In step S140, actual business data is captured, and the actual business data and the code relationship graph are processed according to the Agent tool and Agent rules to construct a post-training dataset;

[0063] In step S150, the initial large code model is post-trained based on the post-training dataset according to the code relationship graph, the Agent tool, and the Agent rules, to obtain a trained large code model.

[0064] Here, "code repository" refers to the code repository used by the enterprise, such as a GitLab repository. This application embodiment does not specifically limit the open-source model; any open-source language model is acceptable, such as the qwen2.5-7BBase model. In this application embodiment, the Agent rules include Agent tool call prompts, Agent system prompts, process monitoring rules, and multi-turn interaction rules.

[0065] In this embodiment, pre-training is performed at both file granularity and repository granularity. However, there is no specific limit on the number of tokens at the file granularity and repository granularity. These limits can be set according to actual conditions. For example, the number of file tokens in the pre-training at the file granularity is limited to no more than 8k, and the number of tokens in a single data set in the pre-training at the repository granularity is limited to no more than 32k.

[0066] When pre-training an open-source language model, the model mainly performs two tasks: first, FIM (Fill-in-the-Middle, which involves providing contextual information and predicting intermediate information), and second, predicting the next token.

[0067] For example, the following is the format structure of file-granularity FIM: <|fim_prefix|>{code_pre}<|fim_suffix|>{code_suf}<|fim_middle|>{code_mid}<|endoftext|>;

[0068] This structured input format allows the model to learn the contextual relationships between code snippets within a single file (e.g., predicting the missing code code_mid based on the preceding code_pre and the following code_suf), thereby improving the model's ability to understand the logic of the code within the file.

[0069] For example, the following is the format structure of a warehouse-level FIM:

[0070] <|repo_name|>{repo_name}

[0071] <|file_sep|>{file_path1}

[0072] {file_content1}

[0073] <|file_sep|>{file_path2}

[0074] {file_content2}

[0075] <|file_sep|>{file_path3}

[0076] <|fim_prefix|>{code_pre}<|fim_suffix|>{code_suf}<|fim_middle|>{code_mid}<|endoftext|>;

[0077] Through this structured design, the model can learn cross-file code context relationships at the repository level (such as predicting missing code segments based on code information from multiple files), thereby improving its understanding of complex code structures and dependencies within the repository. In other words, the large code model trained through the embodiments of this application reuses the relationships between codes, resulting in a superior learning performance.

[0078] In the FIM format structure described above, `repo_name` is used to identify the repository name, and `file_sep` serves as a file separator to manage multi-file information at the repository level. These markers help the model learn diverse code structures, enabling it to effectively handle longer and more complex code contexts (such as code logic relationships within a single file, repository-level dependencies across files, etc.) during file-level and repository-level pre-training.

[0079] Among them, the Agent tool call prompt is equivalent to the usage rule guidance template of the Agent tool, the Agent system prompt is equivalent to the usage rule guidance template of the Agent system, the process monitoring rule is equivalent to the effectiveness verification of the Agent tool retrieval result, the associated reference check, and the judgment template for whether to continue searching, and the multi-round interaction rule is equivalent to the multi-round interaction process guidance template between the Agent system, the Agent tool, and the code relationship graph.

[0080] The following refers to a specific embodiment to exemplarily illustrate each part of the content in the Agent system prompt according to the functions of each part of the prompt:

[0081] / / Function 1: Agent role setting:

[0082] Please act as a useful assistant who can interact with the computer to solve tasks;

[0083] <Important>If the user provides a path, it should not be assumed that it is relative to the current working directory. Instead, the file system should be explored to find the file first, and then process it< / Important>;

[0084] According to the following problem description, the goal is to locate specific files, classes, functions, and lines of code that need to be modified or contain key information to solve the problem.

[0085] / / Function 2: Set the steps to locate the problem:

[0086] Locate the problem according to the following steps:

[0087] ##Step 1: Classify and extract key problem information:

[0088] - Classify the problem statement into the following categories: problem description, error tracking, code to reproduce the error, and additional context;

[0089] - Identify the modules in the 'astropy' package mentioned in each category;

[0090] - Use the extracted keywords and line numbers to search for relevant code references to obtain additional context.

[0091] ##Step 2: Locate the referenced modules:

[0092] - Accurately determine the specific module;

[0093] - Explore the repository to familiarize with its structure;

[0094] - Analyze the described execution flow to identify the specific module or component being referenced;

[0095] - Pay special attention to using the context and the described execution flow to distinguish between modules with similar names;

[0096] - Collected output format of relevant modules:

[0097] - Use the format: 'file_path:QualifiedName'

[0098] For example, the `calculate_sum` function of the `MathUtils` class located in `src / helpers / math_helpers.py` is represented as: 'src / helpers / math_helpers.py:MathUtils.calculate_sum'.

[0099] Step 3: Analyze and reproduce the problem:

[0100] - Define the purpose of the problem;

[0101] - If it's an extended feature: identify where and how to incorporate new behaviors, fields, or modules;

[0102] - If troubleshooting unexpected behavior: focus on locating the module containing the potential error;

[0103] - Refactor the execution flow;

[0104] - Identify the main entry point that triggers the problem;

[0105] -Trace function calls, class interactions, and event sequences;

[0106] - Identify potential breakpoints that may be causing the problem;

[0107] Important: Keep the refactoring process focused on the problem and avoid irrelevant details.

[0108] Step 4: Locate the area that needs to be modified.

[0109] - Locate the specific file, function, or line of code that needs to be changed or contains key information for solving the problem;

[0110] - Consider upstream and downstream dependencies that may be affected or impacted by the problem;

[0111] - If applicable, identify where to introduce new fields, functions, or variables;

[0112] -Think deeper: List multiple potential solutions and consider edge cases that may affect the solutions.

[0113] / / Function 3: Limit the output format; AI output must use JSON format:

[0114] ## Final output format:

[0115] The final output should list the locations that need to be modified, enclosed in three backticks;

[0116] Each location should include the file path, class name (if applicable), function name or line number, ordered by importance.

[0117] / / Function 4: Set the preset number of search files (too few will result in missing target group files, too many will affect model efficiency; based on actual testing, 5 files are set):

[0118] The answer should ideally include approximately 5 files.

[0119] / / Function 5: Informs the model of its ability to activate the Chain of Thought (COT). Generally, the longer the chain of thought, the better the model performs.

[0120] ###Example:

[0121] ①full_path1 / file1.py

[0122] line:10

[0123] class:MyClass1

[0124] function:my_function1

[0125] ②full_path2 / file2.py

[0126] line:76

[0127] function:MyClass2.my_function2

[0128] ③full_path3 / file3.py

[0129] line:24

[0130] line:156

[0131] function:my_function3

[0132] Only return location information;

[0133] Note: Thinking should be thorough, so it doesn't matter if it's long.

[0134] / / Feature 6: Setting up the Agent's interactive environment, allowing the retrieval process to be completely handed over to AI without human confirmation:

[0135] ---Problem Statement Begins---

[0136] The problem is described in detail here.

[0137] ---End of Problem Statement---

[0138] Important: You should only interact with the provided environment and never seek human assistance.

[0139] / / Function 7: Control Agent permissions, restrict Agent to read permissions only, and disable write permissions:

[0140] Do not include any lambda functions;

[0141] No files should be modified.

[0142] It should be emphasized that the above content is only for illustrative purposes to illustrate the Agent system prompts. The embodiments of this application are not limited to this. Furthermore, comments such as " / / Function 1: Agent role setting:" and " / / Function 7: Control Agent permissions, restrict Agent to read permissions only, disable write permissions:" are only for explaining the function of the corresponding content and do not constitute the prompts themselves.

[0143] The following example, using a specific embodiment, illustrates the various parts of the process monitoring rules according to their functions:

[0144] / / Function 1: Tell the Agent the trigger conditions for continuing the retrieval:

[0145] Verify that the found location contains all the necessary information to resolve the issue, and check other parts of the codebase for relevant references that may not appear in the search results. If not, continue searching for other locations related to the problem.

[0146] / / Function 2: Inform the Agent of the end-of-interaction flag; once a match is found, the retrieval process ends:

[0147] The verification process has carefully analyzed the impact of the found locations on the repositories, particularly their dependencies. If the task is deemed complete, send the final answer (including previous answers and reordering) to the user via message, and then call `finish` to complete the task.

[0148] / / Feature 3: The prompt word reiterates at the end that no human intervention is required, and the model will more strictly adhere to the instructions:

[0149] Important: You should never seek help from humans.

[0150] It should be emphasized that the above content is merely an illustrative example of the process monitoring rules, and the embodiments of this application are not limited thereto. Furthermore, annotations such as " / / Function 1: Tell the Agent the triggering conditions for continuing the retrieval:" and " / / Function 3: The prompt words reiterate that no human intervention is required, and the model will more strictly follow the instructions:" are only explanations of the functions of the corresponding content and do not constitute the process monitoring rules themselves.

[0151] Based on multi-round interaction rules, the code big model can first call the Agent tool to perform multi-strategy search to obtain preliminary results based on the input information. If further analysis is needed, it will call the dependency structure exploration interface in a loop. The repo_ops code toolkit then traverses the code structure through graph index and returns dependency information. Finally, the code big model integrates all information and outputs accurate positioning results to the user.

[0152] The code-based large model training method provided in this application preprocesses the original code in the code repository to obtain preprocessed code; pre-trains an open-source language model based on the preprocessed code at both file and repository granularities to obtain an initial code-based large model capable of capturing the contextual relationships between code segments; establishes a code relationship graph based on the preprocessed code; captures actual business data, processes the actual business data and the code relationship graph according to predefined Agent tools and Agent rules, and constructs a post-training dataset; and post-trains the initial code-based large model based on the code relationship graph, the Agent tools, and Agent rules, obtaining a trained code-based large model. This method enhances the contextual capabilities, cross-project capabilities, and code localization capabilities of the code-based large model, enabling it to automatically generate product front-end pages based on design drafts / screenshots, automatically build back-end scaffolding according to JIRA requirements, and reconstruct problem chains by linking code / logs and database monitoring information in case of failures. This improves the practicality of the code-based large model and significantly enhances development efficiency.

[0153] In some embodiments, such as Figure 2 As shown, the step of capturing actual business data, processing the actual business data and the code relationship graph according to the Agent tool and Agent rules, and constructing the post-training dataset (i.e., involved in step S140) includes:

[0154] In step S210, fragmented basic business data and full-link data of production scenarios are captured;

[0155] In step S220, supervised fine-tuning SFT samples are extracted from the basic business fragmented data and the code relationship graph according to the Agent tool and Agent rules;

[0156] In step S230, reinforcement and fine-tuning RFT samples are extracted from the full-link data of the production scenario and the code relationship graph according to the Agent tool and Agent rules; wherein, the supervised fine-tuning SFT sample and the reinforcement and fine-tuning RFT sample both include input information and their corresponding expected output results.

[0157] In other words, both supervised fine-tuning of SFT samples and reinforcement fine-tuning of RFT samples belong to the post-training set.

[0158] It is understandable that Supervised Fine-Tuning (SFT) and Reinforcement Fine-Tuning (RFT) are two stages of post-training of the model.

[0159] In this context, it can be understood that the input information is equivalent to the problem description / prompt words input into the model, and the expected output result is equivalent to the label corresponding to the input information, which is used by the model for reference and learning.

[0160] It is understandable that when extracting input information and its corresponding expected output results from actual business data and code relationship graphs based on Agent tools and Agent rules, open-source large code models can be used as an aid.

[0161] In some embodiments, such as Figure 3 As shown, the basic business fragmented data includes error-level logs and code consultation information; the step of extracting supervised fine-tuning SFT samples (i.e., those involved in step S220) from the basic business fragmented data and the code relationship graph according to the Agent tool and Agent rules includes:

[0162] In step S310, the complete call chain and log content are extracted from the Error-level log to generate input information, and the code segment associated with the Error-level log is extracted from the code relationship graph as the corresponding expected output result.

[0163] In step S320, the input information for generating consultation questions is extracted from the code consultation information, and the code segments including the inclusion relationship of folders and files associated with the consultation object, the parent-child inheritance relationship, the package import relationship, and the called relationship are extracted from the code relationship graph, and the business parsing result is determined as the corresponding expected output result.

[0164] In this process, log errors are treated as potential bugs in the code repository. Online alerts are sorted into Error-level logs according to their corresponding applications. The complete call chain and log content are extracted and filled into prompt words to generate input information. Then, the best-performing open-source code model (e.g., qwencode3-400B model) is used to perform multiple rounds of AI search until the most core related code snippet is found as the corresponding expected output result.

[0165] Among them, code consultation information refers to routine code-related consultation questions, such as "What is the function of XX class?" In this case, the consultation object is "XX class", and the final business analysis result may be "XX class is mainly used to solve the contract upload problem in the payment link. It will check whether it is a small currency, thereby distinguishing whether additional contract order information needs to be uploaded."

[0166] In some embodiments, such as Figure 4 As shown, the full-link data of the production scenario includes global evaluation data of the code repository, cross-tool project improvement data of JIRA-Git-SQL, and multi-dimensional data of production failures; the extraction of reinforcement and fine-tuning RFT samples from the full-link data of the production scenario and the code relationship graph (i.e., the step involved in S230) includes:

[0167] In step S410, the repository global evaluation instruction is extracted from the code repository global evaluation data to generate input information, the call chain associated with the repository global evaluation instruction is extracted from the code relationship graph, and the code framework evaluation report is determined as the corresponding expected output result.

[0168] In step S420, the jira-id, git code commit record identifier, and SQL change statement are extracted from the JIRA-Git-SQL cross-tool project improvement data to generate input information. The code segment associated with the jira-id, git code commit record identifier, and SQL change statement is extracted from the code relationship graph as the corresponding expected output result.

[0169] In step S430, input information is generated by extracting the SLS fault log and database monitoring information from the code relationship graph, and code segments associated with the SLS fault log and database monitoring information are extracted from the code relationship graph as the corresponding expected output results.

[0170] The global evaluation instructions for the code repository can also be used as reinforcement learning problems, and their answers can serve as expected outputs. For example, "What problems might exist in this code repository?" The call chain is extracted: starting from the main function entry point, the agent is used to find the core classes, and the relationships between the core classes are obtained by traversing the graph. Then, the best-performing open-source code model (e.g., the qwencode3-400B model) is called to provide a code framework evaluation report as the expected output.

[0171] Furthermore, JIRA code versions (JIRA-Git-SQL cross-tool project improvement data, {jira-id, git-repo-commit, sql change records}) can be incorporated as the basis for reinforcement and fine-tuning. Guided Reinforcement Proximal Optimization (GRPO) is used for post-training, enabling the large code model to parse the improvement work of the entire project. Based on reinforcement and fine-tuning, verifiable rewards are added to measure the completeness and robustness of the generated code from multiple aspects such as functionality, code style, security, and stability.

[0172] In addition, the call chain, database monitoring information and code location (multi-dimensional data of production failure and corresponding code segments, {sls log, db-monitor, code-snippets}) can be restored through log alarms to restore production failure issues and assist the large code model in troubleshooting.

[0173] It should be noted that the embodiments of this application do not impose specific limitations on the overall ratio of supervised fine-tuning SFT samples and enhanced fine-tuning RFT samples. The ratio can be set according to the actual situation. For example, the ratio of supervised fine-tuning SFT samples corresponding to error-level logs to supervised fine-tuning SFT samples corresponding to code consultation information can be 7:3, with a total of 10,000 records collected and no less than 50 records per repository. As another example, the ratio of supervised fine-tuning SFT samples corresponding to global evaluation data of the code repository to supervised fine-tuning SFT samples corresponding to JIRA-Git-SQL cross-tool project improvement data and multi-dimensional production failure data can be 7:3, with a total of 1,000 records collected and no less than 5 records per repository.

[0174] In some embodiments, such as Figure 5 As shown, the step of post-training the initial large code model based on the post-training dataset according to the code relationship graph, the Agent tool, and the Agent rules to obtain the trained large code model (i.e., the one involved in step S150) includes:

[0175] In step S510, the initial large code model is post-trained based on the post-training dataset according to the code relationship graph, the Agent tool and Agent rules, to obtain an intermediate large code model;

[0176] In step S520, the acceptance dataset is obtained;

[0177] In step S530, the intermediate code large model is used to perform a preset acceptance task on the verification dataset;

[0178] In step S540, if the execution result of the acceptance task meets the acceptance requirements, the intermediate code model is used as the trained code model.

[0179] It is understood that the acceptance dataset refers to the enterprise's own dataset, which may include code and business data.

[0180] In some embodiments, the acceptance task includes a code completion task and a code structuring task, and the acceptance requirements are determined based on the edit distance of the code completion task, the accuracy of the code structuring task, the executable proportion of the code generated by executing the code completion task, and the test case coverage of the acceptance task.

[0181] The code completion task involves providing any given code segment and having the large code model complete either the intermediate tokens (e.g., 100 tokens) or continue writing the tokens (e.g., 100 tokens). The code structuring task involves providing any given class segment and having the large code model find the parent-child class relationships. The code generated by the code completion task is executed in the online package and environment to calculate the executable percentage. The acceptance task is performed in the test environment to calculate test case coverage.

[0182] In this embodiment of the application, no specific limitations are made on how to determine the acceptance requirements based on the edit distance of the code completion task, the accuracy of the code structuring task, the executable ratio of the code generated by executing the code completion task, and the test case coverage of the acceptance task. For example, a comprehensive score can be calculated, and when the comprehensive score exceeds a reference threshold (e.g., 80 points), the acceptance requirements can be considered met.

[0183] In some embodiments, the node information of the code relationship graph includes repositories, files, classes, functions, and variables, and the edge information of the code relationship graph includes import, contain, inherit, and invoke.

[0184] Specifically, file and repository nodes only need to record the corresponding paths (such as repository paths and file paths) to locate their positions in the project structure; class and function nodes, in addition to basic identifiers, also need to include line number information (such as the definition line number of the class and the start and end line numbers of the function) to accurately locate the specific location of the code in the file; unified node naming format: all nodes are named in the format of "full file path: class.function" (e.g., "src / utils / tool.py:FileProcessor.read_file"), which uniquely distinguishes different nodes through hierarchical identifiers, facilitating association and retrieval.

[0185] For import, inheritance, and function call relationships in the preprocessed code, a fuzzy hashing approach is used for traversal and searching. Since these relationships often involve different files (e.g., a function in file A calls a class in file B, or class C inherits a parent class from file D), direct matching by filename may be inaccurate (e.g., filename changes, complex path nesting). Therefore, fuzzy hashing is used to generate fuzzy hash values ​​for target files / classes / functions. By calculating the similarity between code segments (e.g., structural and content features), related files are located. Even with subtle differences in filenames or paths, the most likely related objects can be efficiently matched, ensuring accurate traversal of cross-file dependencies. Figure 6 The diagram illustrates one implementation of the traversal search edge information provided in this application. First, the current file is parsed, then import / inheritance / function call information is extracted, and then it is determined whether it crosses files. If not, the current file call is parsed, and then the traversal is completed and the process ends. If yes, candidate files are determined based on the path / name, then a fuzzy hash of the target function / class is generated, then the similarity is calculated in the code library, and then it is determined whether the file with the highest similarity is found. If not, it is recorded that it was not found and the branch ends. If yes, the matching file is entered, and then the parsing process is recursively executed.

[0186] By constructing repositories, files, classes, functions, and variables as graph nodes, and imports, contain, inheritance, and invokes as graph edges, the relationships between code segments can be clearly captured. For example... Figure 7 The diagram illustrates a core basic relationship between code segments (not the only one, and can be expanded according to business needs and code characteristics).

[0187] In some embodiments, the Agent tool includes a tool for searching entities, a tool for traversing a graph, and a tool for obtaining the complete content of a specific entity.

[0188] Among them, the entity search tool (search_code_snippets) uses the bm25 algorithm to search for entity information in code. The graph traversal tool (explore_tree_structure) allows the large code model to automatically determine the search depth based on a specific entity based on tool calls: depth-first or breadth-first search, entity type filtering rules, dependency filtering rules, etc. The tool to obtain the complete content of a specific entity (get_entity_content) can find the complete code corresponding to a class name based on the code relationship graph. These agent tools form an AI code intelligence, automatically locating task-related code snippets (supporting different granularities such as files, classes, and functions).

[0189] In some embodiments, such as Figure 8 As shown, the preprocessing of the original code in the code library to obtain preprocessed code (i.e., the part involved in step S110) includes:

[0190] In step S610, the main branch of the code in the code repository is extracted using the git command to obtain the original code;

[0191] In step S620, the original code is classified according to the language type, which includes at least Java, JS, and SQL.

[0192] In step S630, for the original code of each language type, global deduplication is first performed according to file hash, and then fuzzy deduplication is performed according to fuzzy hash.

[0193] In this process, only the main branch is extracted when obtaining the original code, while the code of the other branches is discarded to avoid interfering with model training.

[0194] Meanwhile, this embodiment also provides an electronic device, wherein, as Figure 9 As shown, the electronic device includes:

[0195] One or more processors 101;

[0196] The memory 102 stores one or more computer programs that, when executed by the one or more processors 101, cause the one or more processors 101 to implement the code large model training method provided in the first aspect of the embodiments of this application.

[0197] The electronic device may also include one or more I / O interfaces 103 connected between the processor 101 and the memory 102, configured to enable information interaction between the processor 101 and the memory 102.

[0198] The processor 101 is a device with data processing capabilities, including but not limited to a central processing unit (CPU); the memory 102 is a device with data storage capabilities, including but not limited to random access memory (RAM, more specifically SDRAM, DDR, etc.), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), and flash memory (FLASH); the I / O interface (read-write interface) is connected between the processor and the memory, enabling information exchange between the processor and the memory, including but not limited to a data bus (Bus).

[0199] In some embodiments, the processor 101, memory 102, and I / O interface 103 are interconnected via bus 104, and thus connected to other components of the computing device.

[0200] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. Accordingly, the computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can implement the methods of any of the above embodiments. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0201] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Those skilled in the art should understand that this application includes, but is not limited to, the contents described in the accompanying drawings and the specific embodiments above. Any modifications that do not depart from the functional and structural principles of this application will be included within the scope of the claims.

Claims

1. A method for training a large language model, comprising: The method comprises the following steps: preprocessing original code in a code library to obtain preprocessed code; pre-training an open source language model based on the preprocessed code according to file granularity and repository granularity to obtain an initial code large model capable of capturing context relationships between code segments; establishing a code relationship graph based on the preprocessed code; capturing actual business data, processing the actual business data and the code relationship graph according to predefined Agent tools and Agent rules to construct a post-training data set; post-training the initial code large model based on the post-training data set according to the code relationship graph, the Agent tools and the Agent rules to obtain a trained code large model; wherein the capturing actual business data, processing the actual business data and the code relationship graph according to Agent tools and Agent rules to construct a post-training data set comprises: capturing basic business fragmentation data and production scenario full-link data; extracting supervision fine-tuning SFT samples from the basic business fragmentation data and the code relationship graph according to the Agent tools and the Agent rules; extracting reinforcement fine-tuning RFT samples from the production scenario full-link data and the code relationship graph according to the Agent tools and the Agent rules; wherein the supervision fine-tuning SFT samples and the reinforcement fine-tuning RFT samples both include input information and corresponding expected output results.

2. The method of claim 1, wherein, The basic business fragmentation data includes Error level logs and code consultation information; the extracting supervision fine-tuning SFT samples from the basic business fragmentation data and the code relationship graph according to the Agent tools and the Agent rules comprises: extracting complete call links and log content from the Error level logs to generate input information, and extracting code segments associated with the Error level logs from the code relationship graph as corresponding expected output results; extracting consultation questions from the code consultation information to generate input information, and extracting code segments including folder and file inclusion relationships, parent-child class inheritance relationships, package import relationships and called relationships associated with consultation objects from the code relationship graph to determine business analysis results as corresponding expected output results.

3. The method of claim 1, wherein, The production scenario full-link data includes code library global evaluation data, JIRA-Git-SQL cross-tool project improvement data and production fault multi-dimensional data; the extracting reinforcement fine-tuning RFT samples from the production scenario full-link data and the code relationship graph comprises: extracting repository global evaluation instructions from the code library global evaluation data to generate input information, and extracting call chains associated with the repository global evaluation instructions from the code relationship graph to determine code framework evaluation reports as corresponding expected output results; extracting a jira-id, a git code commit record identifier, and SQL change statement generation input information from the JIRA-Git-SQL cross-tool project improvement data, and extracting a code segment associated with the jira-id, the git code commit record identifier, and the SQL change statement from the code relationship graph as a corresponding expected output result; extracting SLS fault log and database monitoring information generation input information from the production fault multidimensional data, and extracting a code segment associated with the SLS fault log and the database monitoring information from the code relationship graph as a corresponding expected output result.

4. The method of claim 1, wherein, The post-training of the initial code large model based on the code relationship graph, the Agent tool, and the Agent rule, includes: post-training of the initial code large model based on the code relationship graph, the Agent tool, and the Agent rule, to obtain an intermediate code large model; obtaining an acceptance data set; performing a preset acceptance task on the acceptance data set using the intermediate code large model; in the case where the execution result of the acceptance task meets the acceptance requirement, the intermediate code large model is used as the trained code large model.

5. The method of claim 4, wherein, The acceptance task includes a code completion task and a code structuring task, and the acceptance requirement is determined according to the edit distance of the code completion task, the accuracy of the code structuring task, the executable proportion of the code generated by performing the code completion task, and the test case coverage of the acceptance task.

6. The method according to any one of claims 1-5, characterized in that, The node information of the code relationship graph includes repositories, files, classes, functions, and variables, and the edge information of the code relationship graph includes import, contain, inherit, and invoke.

7. The method according to any one of claims 1-5, characterized in that, The Agent tool includes a search entity tool, a traversal graph tool, and a specific entity complete content acquisition tool.

8. The method according to any one of claims 1-5, characterized in that, The preprocessing of the original code in the code library to obtain preprocessed code includes: extracting the main branch of the code in the code library through a git command to obtain the original code; classifying the original code according to language types, the language types including at least Java, JS, and SQL; for each language type of the original code, first globally de-duplicating according to file hash, and then fuzzy de-duplicating according to fuzzy hash.

9. An electronic device, comprising: comprise: one or more processors; a memory having one or more computer programs stored thereon, when the one or more computer programs are executed by the one or more processors, so that the one or more processors implement the training method of the code large model according to any one of claims 1-8.

Citation Information

Patent Citations

  • Training method and device of vertical field large model

    CN120338030A

  • Code generation method and related device

    WO2025145584A1