Model training method and device, medium, equipment and computer program product

By constructing a dependency tree to filter test files and generate training samples, and combining fine-grained sub-capability learning and mind chain feature fine-tuning, the problem of insufficient accuracy of training samples for unit testing of large language models is solved, thereby improving the training efficiency and accuracy of unit testing models.

CN121456479APending Publication Date: 2026-02-03BYTEDANCE TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511622194.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-06
Publication Date
2026-02-03

AI Technical Summary

Technical Problem

Existing technologies suffer from insufficient accuracy and effectiveness of training samples when performing unit testing based on large language models, resulting in low training efficiency of the unit testing model.

Method used

By constructing a dependency tree between the test function and the objective function, test files are filtered to generate training samples, ensuring the accuracy and effectiveness of the training samples. Furthermore, fine-grained sub-capability learning and mind chain feature fine-tuning are used to improve the accuracy and efficiency of the unit test model.

Benefits of technology

It improves the quality of supervision signals for training samples, enhances the training efficiency and accuracy of unit test models, enables fine-grained enhancement and repair of unit test models, and improves the interpretability and accuracy of model output results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121456479A_ABST
    Figure CN121456479A_ABST
Patent Text Reader

Abstract

The invention discloses a model training method and device, a medium, equipment and a computer program product. The method comprises the following steps: acquiring a test file for unit test; a first dependency tree of a test function in the test file is determined, a second dependency tree of a target function called by the test file is determined, and the test function is used for performing unit testing on the target function; screening the test file based on the first dependency tree and the second dependency tree, and determining candidate samples for generating training samples; generating a first training sample set for model training based on the candidate samples; based on the first training sample set, a large language model is trained, a trained unit test model is obtained, and the unit test model is used for generating a target test file of unit test.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the fields of computer technology and large language models, and more specifically, to a model training method, apparatus, medium, device, and computer program product. Background Technology

[0002] Unit testing typically refers to the inspection and verification of the smallest testable unit in software. With the development of large language model technology, test files for unit testing can be written using large language models.

[0003] When performing unit testing based on a Large Language Model (LLM), it is typically necessary to first define the core objectives of the unit test, and then provide the LLM with sufficient contextual information to guide it in generating test cases for unit testing. In related technologies, the large language model is usually trained and fine-tuned directly based on the unit test files, so that the resulting large language model can be used in the unit testing scenario. Summary of the Invention

[0004] This summary section is provided to briefly introduce the concepts, which will be described in detail in the subsequent detailed description section. This summary section is not intended to identify key or essential features of the claimed technical solution, nor is it intended to limit the scope of the claimed technical solution.

[0005] Firstly, this disclosure provides a model training method, the method comprising: Obtain the test files for unit testing; Determine the first dependency tree of the test functions in the test file, and determine the second dependency tree of the target function called by the test file, wherein the test functions are used to perform unit tests on the target function; The test files are filtered based on the first dependency tree and the second dependency tree to determine candidate samples for generating training samples; Based on the candidate samples, a first training sample set for model training is generated; The large language model is trained based on the first training sample set to obtain the trained unit test model, wherein the unit test model is used to generate the target test file for unit testing.

[0006] Secondly, this disclosure provides a model training apparatus, the apparatus comprising: The first acquisition module is used to acquire test files for unit testing; The first determining module is used to determine the first dependency tree of the test functions in the test file and to determine the second dependency tree of the target function called by the test file, wherein the test functions are used to perform unit tests on the target function; The second determining module is used to filter the test files based on the first dependency tree and the second dependency tree to determine candidate samples for generating training samples; The first generation module is used to generate a first training sample set for model training based on the candidate samples; The training module is used to train the large language model based on the first training sample set to obtain the trained unit test model, wherein the unit test model is used to generate the target test file for unit testing.

[0007] Thirdly, this disclosure provides a computer-readable medium having a computer program stored thereon, which, when executed by a processing device, implements the steps of the method described in the first aspect.

[0008] Fourthly, this disclosure provides an electronic device, comprising: A storage device on which computer programs are stored; A processing device for executing the computer program in the storage device to implement the steps of the method described in the first aspect.

[0009] Fifthly, this disclosure provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the method described in the first aspect.

[0010] In the above technical solution, by constructing dependency trees for the test functions and the target function under test, test files are filtered, and training samples can be generated based on the filtered test files to train the large language model. This ensures the accuracy and effectiveness of the test files used to construct training samples, thereby mitigating the impact of auxiliary dependencies that may arise during the writing of test functions on the training samples, improving the quality of the supervision signals in the training samples, and simultaneously increasing the training efficiency of the unit test model.

[0011] Other features and advantages of this disclosure will be described in detail in the following detailed description section. Attached Figure Description

[0012] The above and other features, advantages, and aspects of the embodiments of this disclosure will become more apparent from the accompanying drawings and the following detailed description. Throughout the drawings, the same or similar reference numerals denote the same or similar elements. It should be understood that the drawings are schematic, and the originals and elements are not necessarily drawn to scale. In the drawings: Figure 1This is a flowchart of a model training method provided according to one embodiment of the present disclosure; Figure 2 This is a flowchart of generating the candidate sample according to one embodiment of the present disclosure; Figure 3 This is a flowchart of fine-tuning a unit test model based on a second training sample set according to one embodiment of the present disclosure; Figure 4 This is a flowchart of a model training method provided according to one embodiment of the present disclosure; Figure 5 This is a block diagram of a model training apparatus provided according to one embodiment of the present disclosure; Figure 6 A schematic diagram of the structure of an electronic device suitable for implementing embodiments of the present disclosure is shown. Detailed Implementation

[0013] Embodiments of this disclosure will now be described in more detail with reference to the accompanying drawings. While some embodiments of this disclosure are shown in the drawings, it should be understood that this disclosure can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of this disclosure. It should be understood that the accompanying drawings and embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of protection of this disclosure.

[0014] It should be understood that the steps described in the method embodiments of this disclosure may be performed in different orders and / or in parallel. Furthermore, the method embodiments may include additional steps and / or omit the steps shown. The scope of this disclosure is not limited in this respect.

[0015] The term "comprising" and its variations as used herein are open-ended inclusions, meaning "including but not limited to". The term "based on" means "at least partially based on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Definitions of other terms will be given in the description below.

[0016] It should be noted that the concepts of "first" and "second" mentioned in this disclosure are used only to distinguish different devices, modules or units, and are not used to limit the order of functions performed by these devices, modules or units or their interdependencies.

[0017] It should be noted that the terms "a" and "a plurality of" used in this disclosure are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise expressly indicated in the context, they should be understood as "one or more".

[0018] The names of messages or information exchanged between multiple devices in the embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of such messages or information.

[0019] It is understood that before using the technical solutions disclosed in the various embodiments of this disclosure, users should be informed of the types, scope of use, and usage scenarios of the personal information involved in this disclosure in an appropriate manner in accordance with relevant laws and regulations, and user authorization should be obtained.

[0020] For example, upon receiving a user's active request, a prompt message is sent to the user to explicitly inform them that the requested operation will require the acquisition and use of the user's personal information. This allows the user to independently choose whether to provide personal information to the software or hardware, such as the electronic device, application, server, or storage medium performing the operations of this disclosed technical solution, based on the prompt message.

[0021] As an optional but non-limiting implementation, in response to a user's active request, sending a prompt message to the user can be done via a pop-up window, where the prompt message can be presented in text format. Furthermore, the pop-up window can also include a selection control allowing the user to choose "agree" or "disagree" to provide personal information to the electronic device.

[0022] It is understood that the above notification and user authorization process are merely illustrative and do not constitute a limitation on the implementation of this disclosure. Other methods that comply with relevant laws and regulations may also be applied to the implementation of this disclosure.

[0023] Meanwhile, it is understood that the data involved in this technical solution (including but not limited to the data itself, the acquisition or use of the data) shall comply with the requirements of relevant laws, regulations and related provisions.

[0024] Figure 1 The diagram shown is a flowchart of a model training method according to one embodiment of this disclosure. Figure 1 As shown, the method may include: In step 11, the test files for unit testing are obtained.

[0025] Specifically, test files can be extracted from the unit test codebase, and unit tests can be implemented by compiling and executing these test files. For example, test files that have been reviewed and confirmed by users to be suitable for unit testing can be stored in the codebase to achieve unified storage of test files and provide training data for model training. Alternatively, they can be obtained from open-source codebases in this field. The number of test files can be set based on the actual application scenario, and this disclosure does not limit this number.

[0026] In step 12, a first dependency tree of the test functions in the test file is determined, and a second dependency tree of the target function called by the test file is determined, wherein the test functions are used to perform unit tests on the target function.

[0027] As an example, the target function represents the function under test that needs to be unit tested, while the test function is the function containing the test logic for unit testing. For instance, if a business system contains a business function A, it can serve as the target function. During unit testing, testers can write a test function B, which is used to determine whether the execution of business function A satisfies its functional requirements.

[0028] In this embodiment, for test function B in the unit test, an Abstract Syntax Tree (AST) can be constructed based on syntax tree construction techniques to extract the function definitions, type definitions, variable definitions, and constant definitions that the test function depends on, and to remove recursive calls. A Directed Acyclic Graph (DAG) is then generated based on the remaining definitions, serving as the first dependency tree, denoted as Gt. Similarly, for target function A, a corresponding DAG can be constructed in the same way, serving as the second dependency tree, denoted as Gf.

[0029] It should be noted that the above directed acyclic graph is only an illustrative example of a dependency tree. A dependency tree can be represented by a combination of an abstract syntax tree (AST) and a control flow graph (CFG), or it can be represented by a combination of an AST and a program dependency graph (PDG).

[0030] In step 13, candidate samples for generating training samples are determined based on the first dependency tree and the second dependency tree.

[0031] The first dependency tree represents the syntax tree built with the test function as the root node, and the second dependency tree represents the syntax tree built with the target function as the root node. Based on the requirements of unit testing in this field, the nodes in the first dependency tree and the nodes in the second dependency tree should be consistent. Therefore, in this step, test files can be filtered based on the first and second dependency trees corresponding to the test files to obtain candidate samples.

[0032] In step 14, a first training sample set for model training is generated based on the candidate samples.

[0033] For example, for each candidate sample, the function code of the test function in the test file of the candidate sample can be extracted as the target output. The extracted code is then deleted from the test file to obtain an updated test file. The target function, context information, and the updated test file are then used as input to generate training samples, which are then added to the first training sample set.

[0034] In step 15, the large language model is trained based on the first training sample set to obtain the trained unit test model, wherein the unit test model is used to generate the target test file for unit testing.

[0035] The large language model can be a general model in this field. In this step, the input from the training samples can be used as the model input to obtain the model's predicted output. Furthermore, the loss between the predicted output and the target output can be determined, such as by using the cross-entropy loss function, and the parameters of the large language model can be adjusted based on this loss. The method of adjusting the parameters of the large language model based on the loss can be implemented based on the general training method of large language models in this field, and this disclosure does not limit it.

[0036] Therefore, in the above technical solution, by constructing the dependency tree of the test function and the dependency tree of the target function under test, the test files are screened, and training samples can be generated based on the screened test files to train the large language model. This ensures the accuracy and effectiveness of the test files used to construct the training samples, thereby avoiding, to some extent, the impact of auxiliary dependencies that occur during the writing of the test functions on the training samples, improving the quality of the supervision signals in the training samples, and also improving the training efficiency of the unit test model.

[0037] In some possible embodiments, the step of filtering the test files based on the first dependency tree and the second dependency tree to determine candidate samples for generating training samples may include: If the similarity between the first dependency tree and the second dependency tree of the test file exceeds a first threshold, then the test file is selected as a candidate file.

[0038] The similarity between the first dependency tree and the second dependency tree can be the overlap rate of nodes in the first dependency tree and the second dependency data, such as the ratio of the number of overlapping nodes in the first dependency tree and the number of deduplicated nodes in the first dependency tree and the second dependency tree. Alternatively, the similarity can be obtained by calculating the graph edit distance between the first dependency tree and the second dependency tree. Another example is determining the similarity by identifying the maximum common subgraph between the first dependency tree and the second dependency tree, such as setting quantitative similarity indicators based on the node size, edge size, and attribute importance of the maximum common subgraph, and finally obtaining the similarity through weighted processing of multiple similarity indicators. The first threshold can be set based on the actual application scenario, and this disclosure does not limit it.

[0039] Next, the nodes in the second dependency tree corresponding to the candidate file are sorted, and the source code of the nodes is concatenated based on the obtained order to serve as the context information of the objective function corresponding to the candidate file; the objective function corresponding to the candidate file, the context information of the function, and the candidate file are determined as the candidate sample.

[0040] The first and second dependency trees contain dependency information of the objective function. The context information of the objective function can be determined based on nodes in either the first or second dependency tree. For example, the order of nodes in the second dependency tree can be obtained by topologically sorting them. For instance, a depth-first search or an in-degree-first Kahn algorithm can be used for sorting; the specific sorting method is not limited here. Then, the source code implementation of each node is obtained from the source code. If the determined topological order is A, A1, A2, A3, A4, the source code of A, A1, A2, A3, A4 can be concatenated to obtain a text representation, which serves as the context information. Therefore, the candidate samples generated from the candidate files can be represented as (objective function and context information for unit tests, and test files for unit tests). Figure 2 The diagram shown is a flowchart for generating this candidate sample.

[0041] Therefore, by constructing dependencies from both the test function side and the target function side of the unit test, and filtering test files using a dependency consistency matching criterion, and by determining the similarity between the dependencies of the test function and the target function of the test files, test files with high similarity are retained. This effectively reduces noise in the test files, further improves the accuracy of candidate samples, and ensures the effectiveness of the subsequently generated training samples, thus enabling the training of the unit test model.

[0042] In some possible embodiments, generating a first training sample set for model training based on the candidate samples may include: For each candidate sample, the code of the target item in the test file of the candidate sample is extracted, and the code of the target item in the test file is deleted to obtain an updated test file. The code of the target item in the updated test file can be represented by a mask identifier to mark that the sub-part needs to be generated subsequently.

[0043] The target item can be used to represent the part that needs to be inferred during the generation of unit test code from a large language model. Therefore, the target item can be set based on the actual application scenario. For example, the target item includes the function body of the test function, and the target item also includes at least one of the following: Simulation items are used to create simulation objects in the test file; Test scenario items are used to determine the test logic of the unit test; Assertion terms are used to determine the target result of the unit test.

[0044] As an example, the following is a partial representation of a unit test file: func Test_Divide( ) { mockey.PatchConvey("Test_Divide", t, func() { mockey.PatchConvey("Normal case - dividend can be divisible by divisor", func() { a := 10 b := 2 mockey.Mock(IsProd).Return(false).Build() result := Divide(a, b) convey.So(result, convey.ShouldEqual, 5) }) } Therefore, when the target item is a function body, the corresponding updated test file is represented as follows: func Test_Divide( ) { [MASK] } When the target item is a simulation item, the corresponding updated test file is represented as follows: func Test_Divide( ) { mockey.PatchConvey("Test_Divide", t, func() { mockey.PatchConvey("Normal case - dividend can be divisible by divisor", func() { a := 10 b := 2 [MASK] result := Divide(a, b) convey.So(result, convey.ShouldEqual, 5) }) } The target item is the test scenario item, and the corresponding updated test file is represented as follows: func Test_Divide( ) { mockey.PatchConvey("Test_Divide", t, func() { mockey.PatchConvey("Normal case - dividend can be divisible by divisor", func() { [MASK] }) } When the target item is an assertion item, the corresponding updated test file is represented as follows: func Test_Divide( ) { mockey.PatchConvey("Test_Divide", t, func() { mockey.PatchConvey("Normal case - dividend can be divisible by divisor", func() { a := 10 b := 2 mockey.Mock(IsProd).Return(false).Build() result := Divide(a, b) [MASK] }) } It should be noted that the code of multiple target items mentioned above can be extracted simultaneously, and the corresponding code can be updated with the mask identifier after extraction.

[0045] The code of the target item is used as the target output, and the target function and context information corresponding to the test file in the candidate sample, as well as the updated test file, are used as input to obtain the first training sample. The first training sample set contains multiple first training samples.

[0046] For example, the target function and context information corresponding to the test file in the candidate sample, along with the updated test file, can be concatenated as input, denoted as prompt1. The code of the extracted target item can be used as the target output, denoted as label1. Then, the first training sample can be represented based on the tuple (prompt1, label1).

[0047] Therefore, by extracting the code of the target item in the test file, multiple training samples can be generated based on the same test file, thereby achieving data augmentation of the training samples and increasing the diversity of the training samples. Furthermore, the generation process of unit tests can be decomposed into the generation of code of the target item, realizing fine-grained and independently augmentable sub-capability learning. This allows for the explicit separation of the sub-capabilities generated for the target item in the unit test model, enabling independent enhancement and repair of the sub-capabilities of the unit test model and improving the accuracy of the unit test model.

[0048] In some possible embodiments, training the large language model based on the first training sample set to obtain the trained unit test model may include: For each of the first training samples, the input from the first training sample is used as the input to the large language model to obtain the prediction output of the large language model.

[0049] Based on the predicted output, the predicted sub-output corresponding to the target item is determined.

[0050] In this embodiment, each first training sample is associated with a target item that needs to be inferred. For example, training sample Y1 corresponds to a function body and a simulation item as target items, so the predicted code of the function body and the code of the simulation item can be obtained from the prediction output based on Y1. Similarly, training sample Y2 corresponds to a function body and a test scenario item as target items, so the predicted code of the function body and the code of the test scenario item can be obtained from the prediction output based on Y2.

[0051] Based on the function code corresponding to the target item in the first training sample and the prediction sub-output, the target loss of the large language model is determined; the large language model is trained based on the target loss to obtain the unit test model.

[0052] In this embodiment, content prediction and reconstruction can be performed only on the code of the target item. For each target item, the sub-loss of the target item can be calculated using the cross-entropy loss function, and the target loss can be obtained by weighted summation of the sub-losses. Then, the large language model is trained using the target loss. This training process has been described above and will not be repeated here.

[0053] Therefore, through this technical solution, the generation process of unit tests can be broken down into the generation of code for target items, enabling fine-grained and independently enhanceable sub-capability learning. This allows for the explicit separation of sub-capabilities generated for target items in the unit test model, enabling independent enhancement and repair of the sub-capabilities of the unit test model, thereby improving the accuracy of the unit test model.

[0054] In some possible embodiments, the method may further include: Based on the candidate samples, a second training sample set is generated for model fine-tuning. The second training sample set contains multiple second training samples, and the second training samples contain the thought chain features corresponding to the test file. The thought chain features are used to represent the generation logic of the test file.

[0055] Among them, Chain of Thought (CoT) is a technique that enhances the ability of large language models to solve complex problems through step-by-step logical reasoning. Explicit Chain of Thought improves the effectiveness of complex reasoning and structured generation by reasoning first and then answering, such as outputting the reasoning steps of the large language model first and then outputting the answer of the large language model. Latent Chain of Thought (Latent CoT), on the other hand, uses the features of the chain of thought as conditions of the large language model to obtain the answer of the model's reasoning.

[0056] As an example, generating a second training sample set for model fine-tuning based on the candidate samples may include: Based on the objective function and context information corresponding to the test file, and the test file itself, the thought chain characteristics corresponding to the test file are determined.

[0057] As an example, open-source samples may contain thought chains corresponding to test files. In this scenario, the thought chains associated with the test files can be applied. Alternatively, thought chains can be labeled manually, and these thought chains can serve as explicit thought chains to represent the reasoning steps output when the model outputs results. Furthermore, to reduce manual workload, automated analysis can be performed using the model. For instance, prompts for generating thought chain features can be pre-set. Input information can then be obtained based on these prompts, the objective function corresponding to the test file, context information, and the test file itself. The input information is represented as follows: Please read the following objective function, context information, and test file: ### Objective Function and Context <context> ### Unit test test files <test> Please provide your reasoning from a developer's perspective, outlining the thought process behind constructing the test file for this unit test. The output must include the following conditions: XX1, XX2, XX3, XX4; The output format must meet the following requirements: XX5.

[0058] The conditions for performing thought chain analysis and the output format of thought chain features can be configured based on actual application scenarios and set as prompt words to constrain the reasoning process of the large language model. Therefore, in this embodiment, the thought chain features for constructing test files can be obtained by analyzing input information using a large language model in this field, and these thought chain features serve as potential thought chains.

[0059] Subsequently, training input is generated based on the objective function and context information corresponding to the test file and the thought chain features. The test file is used as the target output to obtain a second training sample. The second training sample set contains multiple second training samples.

[0060] As an example, the training input can be obtained by directly concatenating the objective function and context information corresponding to the test file, as well as the thought chain features. As another example, a template for generating the training input can be pre-set, allowing the objective function, context information, and thought chain features corresponding to the test file to be filled into the corresponding positions in the template, thus obtaining the training input. This template can be set based on the actual application scenario, and this disclosure does not limit it. Therefore, the annotation cost of the second training sample set can be effectively reduced.

[0061] Then, the unit test model is fine-tuned based on the second training sample set.

[0062] The training samples in the second training sample set contain the thought chain features for constructing test files. Therefore, the unit test model can be fine-tuned based on the second training sample set to improve the model's reasoning guidance and, to a certain extent, improve the interpretability of the unit test model's output results, thereby improving the usability and accuracy of the output results.

[0063] In some possible embodiments, fine-tuning the unit test model based on the second training sample set may include: A first subset and a second subset are determined in the second training sample set, wherein the thought chain feature of the second training sample in the first subset is an explicit thought chain, and the thought chain feature of the second training sample in the second subset is a latent thought chain.

[0064] For example, the second training samples can be grouped based on the different features of the thought chain. As mentioned above, the second training samples associated with thought chains in manual annotation or open source libraries can be classified into the first subset, and the second training samples associated with thought chain features output by the model can be classified into the second subset.

[0065] The unit test model is fine-tuned based on the second training samples in the first subset to obtain the fine-tuned test model.

[0066] This step may include: The training input from the second training sample in the first subset is used as the input to the unit test model to obtain the predictive thought chain and predictive test file output by the unit test model.

[0067] Based on the predicted thought chain, the predicted test file, the thought chain features, and the test file, a first loss of the unit test model is determined, and the unit test model is fine-tuned based on the first loss. As an example, a first sub-loss can be generated based on the predicted thought chain and thought chain features, and a second sub-loss can be generated based on the predicted test file and the test file. Both the first and second sub-losses can be calculated using the cross-entropy loss function. The first and second sub-losses are then weighted to obtain the first loss, and the parameters of the unit test model are fine-tuned based on the first loss. The method of fine-tuning the parameters of the large language model based on the loss can be implemented using common methods in this field, which will not be elaborated here.

[0068] Therefore, by learning the characteristics of the thought chain and the test files through the unit test model, the unit test model can be guided to explicitly learn the mapping relationship between the reasoning path and the output result, thereby reducing the learning difficulty and improving the optimization efficiency of the unit test model.

[0069] Then, the fine-tuned test model is fine-tuned based on the second training samples in the second subset to obtain the fine-tuned unit test model.

[0070] As an example, this step may include: using the training input from the second training samples in the second subset as the input to the unit test model to obtain the output prediction test file of the unit test model; determining the second loss of the fine-tuning test model based on the prediction test file and the test file; and fine-tuning the fine-tuning test model based on the second loss.

[0071] In other words, in this embodiment, the thought chain feature is used as a condition for the unit test model to determine the predicted test file. A second loss is generated based on the predicted test file and the test file, but no loss calculation is performed based on the thought chain feature. This second loss can be calculated using the cross-entropy loss function. Then, the parameters of the fine-tuned test model are further optimized based on the second loss to obtain the fine-tuned unit test model. Figure 3 The diagram shows a flowchart of fine-tuning the unit test model based on the second training sample set.

[0072] Therefore, using the above technical solution, the unit test model can be fine-tuned based on training samples containing thought chain features, enabling the model to better learn the relationship between inference paths and output results, thereby further improving the accuracy of the model's output results. Furthermore, during the fine-tuning process, fine-tuning can first be performed based on training samples with associated labeled thought chain features to reduce learning difficulty and quickly guide the inference path. Then, training can be performed based on training samples with associated thought chain features of the model's output, where the thought chain features serve only as conditions for the model, further enhancing the model's inference ability, reducing format overfitting, and improving training efficiency.

[0073] In some possible embodiments, the method may further include: For each test file, the corresponding test information is determined, and the test information includes at least one of the code language of the test code in the test file, the test framework used by the test file, and the simulation framework.

[0074] Test information can be determined by matching the content of the test file with rules. For example, language matching rules can be pre-set to determine the code language, test framework matching rules can be set to identify the test framework, and simulation framework matching rules can be set to identify the simulation framework. These matching rules are set based on actual application scenarios, such as setting language matching rules based on the format and keywords of different code languages.

[0075] Therefore, in this embodiment, the code language, testing framework, and simulation framework of a test file can be determined by traversing each test file in the code library.

[0076] For example, the code language of test file 1 is D1, the test framework is T1, and the simulation framework is M1; the code language of test file 2 is D1, the test framework is T1, and the simulation framework is M1; the code language of test file 3 is D2, the test framework is T1, and the simulation framework is M2; and the code language of test file 4 is D2, the test framework is T1, and the simulation framework is M2.

[0077] Furthermore, the test file can be represented by triplets generated from its test information, as follows: X1(D1, T1, M1), X2(D1, T1, M1), X3(D2, T1, M2), X4(D2, T1, M2). The test file can then be grouped based on these triplets, resulting in multiple groups of test files. Test files within the same group have identical test information. For example, X1 and X2 can be grouped into the same group, and X3 and X4 into the same group.

[0078] As an example, the test files obtained in step 11 can be test files from the same group, so that training can be performed on test files under a specific test information. As another example, the obtained test files can also be test files from different groups. Accordingly, generating training input based on the objective function and context information corresponding to the test files and the thought chain features can include: Training input is generated based on the objective function and context information corresponding to the test file, the test information, and the thought chain features.

[0079] For example, a field for test information can be included in the template, thereby adding the target function and context information corresponding to the test file, the test information, and the thought chain features to the corresponding positions in the template to generate training input.

[0080] Therefore, by using the above technical solution and extracting test files from the test files, it is possible to construct a single dataset with multiple language styles and multiple frames, realize cross-language transfer and unified representation of test files, improve the support of the trained unit test model for test scenarios with custom styles, and expand the application scenarios of the unit test model.

[0081] In some possible embodiments, the method may further include: Obtain a third training sample, wherein the third training sample contains an objective function for unit testing and context information of the objective function.

[0082] The objective function in the third training sample can be obtained from the code library or from the test sample library. The method for determining the context information of the objective function has been described in detail above and will not be repeated here.

[0083] Then, the third training sample is input into the unit test model and decoded based on multiple decoding strategies to obtain multiple candidate prediction files.

[0084] For example, the objective function and its context information can be input into the unit test model. This unit test model can be a model trained on a first training sample set, or a model fine-tuned on a second training sample set.

[0085] As an example, the predicted features of the unit test model can be obtained, and these features can be used for decoding to obtain the predicted output. In this embodiment, decoding can be performed based on various decoding strategies, thereby obtaining a variety of different candidate prediction files. For example, decoding can be performed using temperature sampling, Top-K sampling, and TOP-P (Nucleus Sampling) sampling strategies. These decoding strategies are well-known in the art and will not be elaborated further here.

[0086] Among them, different decoding strategies are used to control the randomness and diversity of the model output. Based on different decoding strategies, the probability of the model selecting the next word is adjusted to improve the diversity and richness of candidate prediction files.

[0087] Subsequently, positive and negative samples are determined based on the candidate prediction file, and the unit test model is optimized using the positive and negative samples to obtain the optimized unit test model.

[0088] As an example, this step may include: The candidate prediction file is segmented using a sliding window to obtain a segmentation set. Segmentation can be performed using an N-gram model, and the length N of the sliding window can be set based on the actual application scenario; this disclosure does not impose any limitations on this.

[0089] Determine the similarity between adjacent word segments in the word segmentation set. As an example, the Jaccard distance between adjacent word segments can be calculated, which measures the difference between two sets. In this step, the characters in each word of the adjacent word segment can be taken as the set corresponding to that word segment, and the Jaccard distance can be used as the similarity between the adjacent word segments.

[0090] Subsequently, if adjacent word segments with similarity exceeding the second threshold are consecutive, and the number of consecutive word segments exceeds the third threshold, then the candidate prediction file is determined to be the negative sample.

[0091] The second and third thresholds can be set based on the requirements of the actual application scenario. If the similarity between adjacent word segments exceeds the second threshold, the adjacent word segments are considered to be duplicates. If the number of duplicate adjacent word segments exceeds the third threshold, the content of the candidate prediction file is considered to have high repetition, and it is then treated as a negative sample. For example, if the similarity between the word segments at positions 1 and 2, and between positions 2 and 3 in the candidate prediction file, and continuing backwards to the word segments at positions W-1 and W, all exceed the second threshold, and the number of consecutive word segments (from position 1 to position W) exceeds the third threshold, then these segments are treated as negative samples.

[0092] The candidate prediction files are detected based on preset structural rules, and the candidate prediction files that pass the detection of the structural rules are used as positive samples.

[0093] In unit tests, test files typically ensure structural integrity. For example, structural rules can be set based on the compilation requirements of the test files, such as functions containing opening and closing parentheses. Therefore, candidate prediction files and predefined structural rules can be statically tested, and the candidate prediction files that pass the test are used as the positive samples.

[0094] Then, reinforcement learning can be applied to the unit test model based on the positive and negative samples. For example, reinforcement learning can be performed using the DPO (Direct Preference Optimization) algorithm, which optimizes the model so that the conditional probability of positive samples is much greater than the conditional probability of negative samples, thereby improving the accuracy of the model's output. Alternatively, reinforcement learning can be performed using the IPO (Iterative Preference Optimization) algorithm. In this embodiment, reinforcement learning algorithms based on positive and negative samples in this field can be used, and there is no limitation on this approach.

[0095] Therefore, by using the above technical solution, the unit test model can be further optimized through reinforcement learning by identifying the positive and negative samples in its output, making the model's output more biased towards positive samples, thereby improving the accuracy of the model's output results. Furthermore, this optimization process, using positive and negative samples, eliminates the need for parameter tuning of the reward function, thus improving the efficiency and reducing the complexity of model optimization.

[0096] In some possible embodiments, the method may further include: A fourth training sample is obtained, wherein the fourth training sample contains an objective function for unit testing and context information of the objective function. The method for obtaining the fourth training sample is similar to that for obtaining the third training sample.

[0097] The fourth training sample is input into the optimized unit test model to obtain multiple unit test files output by the optimized unit test model. In this step, the same training sample can be input into the optimized unit test model multiple times to obtain multiple unit test files.

[0098] Subsequently, each unit test file is compiled and executed in a virtual isolation environment to obtain execution metrics for each unit test file. The execution metrics include at least one of compilation metrics, execution metrics, and test coverage.

[0099] The virtual isolation environment can be a sandbox environment, container, virtual machine environment, etc., used to reasonably separate the execution environment and system environment of the unit test file. For example, environment isolation can be achieved based on a container, in which the execution environment (including dependency installation, configuration loading, etc.) is automatically built according to the dependencies and runtime environment requirements of the target function, and the virtual isolation environment is consistent with the execution environment of the test file. The compilation and execution of the unit test file can be achieved using common compilation and execution tools in the art, and this disclosure does not limit this.

[0100] Furthermore, after executing the unit test file, execution metrics can be obtained based on its test results. For example, if the unit test file compiles successfully, its corresponding execution metric is 1; if the unit test file fails to compile, its corresponding execution metric is 0. Similarly, if the unit test file executes successfully, its corresponding execution metric is 1; if the unit test file fails to execute, its corresponding execution metric is 0. Test coverage is determined based on the execution results of the unit test file. This test coverage can be line coverage, branch coverage, condition coverage, mutation score, or semantic coverage, etc., and can be determined based on coverage determination methods in this field.

[0101] The target reward is determined based on multiple performance metrics, and the optimized unit test model is then optimized using a second reinforcement learning method based on the target reward to obtain a new optimized unit test model.

[0102] Accordingly, the target reward can be a weighted sum of multiple performance metrics, such as target reward R = α × compilation metric + β × execution metric + γ × test coverage, where α, β, and γ represent the weight coefficients of the compilation metric, execution metric, and test coverage, respectively. As an example, in this embodiment, reinforcement learning can be performed using the GRPO (Group Relative Policy Optimization) algorithm. This algorithm compares multiple unit test files obtained from the same training sample within a group to determine the relative reward to guide model optimization, thereby effectively reducing training variance. During its optimization process, the update magnitude is limited by policy probability ratio truncation in the PPO (Proximal Policy Optimization) style to achieve stable and efficient optimization. The methods for optimizing model parameters based on GRPO and PPO reinforcement learning can be based on implementations commonly used in the field, and will not be elaborated further here.

[0103] Therefore, by compiling and executing the unit test files output by the model, training data for model optimization can be constructed based on the execution metrics of the unit test files. Reinforcement learning can then be performed based on the training data to improve the execution metrics of the optimized unit test model, increase the probability and stability of the model output test files in terms of compilation, execution, and high test coverage, and enhance the accuracy and effectiveness of the test files.

[0104] like Figure 4 The diagram shows a flowchart of a model training method based on an embodiment of this disclosure. The implementation of each step has been detailed above and will not be repeated here. Step P1 is used to determine the training samples, and step P2 is used to train and optimize the large language model based on the training samples.

[0105] Based on the same inventive concept, this disclosure also provides a model training device, such as... Figure 5 As shown, the device includes: The first acquisition module 100 is used to acquire test files for unit testing; The first determining module 200 is used to determine the first dependency tree of the test functions in the test file and to determine the second dependency tree of the target function called by the test file, wherein the test functions are used to perform unit tests on the target function; The second determining module 300 is used to filter the test files based on the first dependency tree and the second dependency tree to determine candidate samples for generating training samples; The first generation module 400 is used to generate a first training sample set for model training based on the candidate samples; The training module 500 is used to train the large language model based on the first training sample set to obtain the trained unit test model, wherein the unit test model is used to generate the target test file for unit testing.

[0106] Optionally, the second determining module includes: The first determining submodule is used to select the test file as a candidate file if the similarity between the first dependency tree and the second dependency tree of the test file exceeds a first threshold. The first processing submodule is used to sort the nodes in the second dependency tree corresponding to the candidate file, and to concatenate the source code of the nodes based on the obtained order as the context information of the target function corresponding to the candidate file. The second determining submodule is used to determine the target function corresponding to the candidate file, the context information of the function, and the candidate file as the candidate sample.

[0107] Optionally, the first generation module includes: The second processing submodule is used to extract the code of the target item in the test file of each candidate sample, and delete the code of the target item in the test file to obtain an updated test file. The third determining submodule is used to take the code of the target item as the target output, and take the target function and context information corresponding to the test file in the candidate sample and the updated test file as input to obtain the first training sample. The first training sample set contains multiple first training samples. The target item includes the function body of the test function, and the target item also includes at least one of the following: Simulation items are used to create simulation objects in the test file; Test scenario items are used to determine the test logic of the unit test; Assertion terms are used to determine the target result of the unit test.

[0108] Optionally, the training module includes: The third processing submodule is used to take the input of the first training sample as the input of the large language model for each first training sample and obtain the prediction output of the large language model. The fourth determining submodule is used to determine the prediction sub-output corresponding to the target item based on the prediction output; The fifth determining submodule is used to determine the target loss of the large language model based on the code of the target item in the first training sample and the predicted sub-output; The training submodule is used to train the large language model based on the target loss to obtain the unit test model.

[0109] Optionally, the device further includes: The second generation module is used to generate a second training sample set for model fine-tuning based on the candidate samples. The second training sample set contains multiple second training samples, and the second training samples contain the thought chain features corresponding to the test file. The thought chain features are used to represent the generation logic of the test file. The fine-tuning module is used to fine-tune the unit test model based on the second training sample set.

[0110] Optionally, the second generation module includes: The sixth determination submodule is used to determine the thought chain features corresponding to the test file based on the objective function and context information corresponding to the test file and the test file itself. The seventh determination submodule is used to generate training input based on the objective function and context information corresponding to the test file and the thought chain features, and to take the test file as the target output to obtain a second training sample. The second training sample set contains multiple second training samples.

[0111] Optionally, the fine-tuning module includes: The eighth determination submodule is used to determine the first subset and the second subset in the second training sample set, wherein the thought chain feature of the second training sample in the first subset is an explicit thought chain, and the thought chain feature of the second training sample in the second subset is a latent thought chain. The first fine-tuning submodule is used to fine-tune the unit test model based on the second training samples in the first subset to obtain the fine-tuned test model. The second fine-tuning submodule is used to fine-tune the fine-tuning test model based on the second training samples in the second subset, so as to obtain the fine-tuned unit test model.

[0112] Optionally, the first fine-tuning submodule is further configured to: The training input from the second training sample in the first subset is used as the input to the unit test model to obtain the predictive thought chain and predictive test file output by the unit test model. Based on the predicted thought chain, the predicted test file, the thought chain features, and the test file, a first loss of the unit test model is determined, and the unit test model is fine-tuned based on the first loss. The second fine-tuning submodule is further used for: The training input from the second training samples in the second subset is used as the input to the unit test model to obtain the output prediction test file of the unit test model; Based on the prediction test file and the test file, a second loss is determined for the fine-tuning test model, and the fine-tuning test model is fine-tuned based on the second loss.

[0113] Optionally, the device further includes: The third determining module is used to determine the test information corresponding to each test file, wherein the test information includes at least one of the code language of the test code in the test file, the test framework used by the test file, and the simulation framework. The seventh determining submodule is further used for: Training input is generated based on the objective function and context information corresponding to the test file, the test information, and the thought chain features.

[0114] Optionally, the device further includes: The second acquisition module is used to acquire a third training sample, wherein the third training sample contains an objective function for unit testing and context information of the objective function; The first processing module is used to input the third training sample into the unit test model and decode it based on multiple decoding strategies to obtain multiple candidate prediction files; The fourth determining module is used to determine positive and negative samples based on the candidate prediction file; The first optimization module is used to perform a first reinforcement learning optimization on the unit test model based on the positive samples and the negative samples to obtain an optimized unit test model.

[0115] Optionally, the fourth determining module is further configured to: The candidate prediction file is segmented using a sliding window to obtain a segmentation set; Determine the similarity between adjacent word segments in the word segmentation set; If adjacent word segments with similarity exceeding the second threshold are consecutive, and the number of consecutive word segments exceeds the third threshold, then the candidate prediction file is determined to be the negative sample. The candidate prediction files are detected based on preset structural rules, and the candidate prediction files that pass the detection of the structural rules are used as positive samples.

[0116] Optionally, the device further includes: The third acquisition module is used to acquire the fourth training sample, wherein the fourth training sample contains an objective function for unit testing and context information of the objective function; The second processing module is used to input the fourth training sample into the optimized unit test model to obtain multiple unit test files output by the optimized unit test model. The third processing module is used to compile and execute each unit test file based on a virtual isolation environment to obtain the execution metrics of each unit test file. The execution metrics include at least one of compilation metrics, execution metrics, and test coverage. The second optimization module is used to determine a target reward based on multiple execution metrics, and to perform a second reinforcement learning optimization on the optimized unit test model based on the target reward to obtain a new optimized unit test model.

[0117] The following is for reference. Figure 6 The diagram illustrates a structural schematic of an electronic device (e.g., a terminal device or a server) 600 suitable for implementing embodiments of the present disclosure. The terminal device in the embodiments of the present disclosure may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 6 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments disclosed herein.

[0118] like Figure 6 As shown, electronic device 600 may include a processing device (e.g., a central processing unit, a graphics processor, etc.) 601, which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 602 or a program loaded from storage device 608 into random access memory (RAM) 603. RAM 603 also stores various programs and data required for the operation of electronic device 600. Processing device 601, ROM 602, and RAM 603 are interconnected via bus 604. Input / output (I / O) interface 605 is also connected to bus 604.

[0119] Typically, the following devices can be connected to I / O interface 605: input devices 606 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 607 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 608 including, for example, magnetic tapes, hard disks, etc.; and communication devices 609. Communication device 609 allows electronic device 600 to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 6 An electronic device 600 with various devices is shown; however, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively.

[0120] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 609, or installed from a storage device 608, or installed from a ROM 602. When the computer program is executed by the processing device 601, it performs the functions defined in the methods of embodiments of this disclosure.

[0121] It should be noted that the computer-readable medium described in this disclosure can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this disclosure, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this disclosure, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.

[0122] In some implementations, clients and servers can communicate using any currently known or future-developed network protocol such as HTTP (Hypertext Transfer Protocol), and can interconnect with digital data communication (e.g., communication networks) of any form or medium. Examples of communication networks include local area networks ("LANs"), wide area networks ("WANs"), the Internet (e.g., the Internet), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future-developed networks.

[0123] The aforementioned computer-readable medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device.

[0124] The aforementioned computer-readable medium carries one or more programs, which, when executed by the electronic device, cause the electronic device to: acquire a test file for unit testing; determine a first dependency tree of test functions in the test file and determine a second dependency tree of a target function called by the test file, the test functions being used to perform unit testing on the target function; filter the test file based on the first dependency tree and the second dependency tree to determine candidate samples for generating training samples; generate a first training sample set for model training based on the candidate samples; and train a large language model based on the first training sample set to obtain a trained unit test model, wherein the unit test model is used to generate the target test file for unit testing.

[0125] Computer program code for performing the operations of this disclosure can be written in one or more programming languages ​​or a combination thereof, including but not limited to object-oriented programming languages ​​such as Java, Smalltalk, and C++, as well as conventional procedural programming languages ​​such as "C" or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0126] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0127] The modules described in the embodiments of this disclosure can be implemented in software or in hardware. The name of a module does not necessarily limit the module itself; for example, the first acquisition module can also be described as "a module for acquiring test files for unit testing".

[0128] The functions described above in this document can be performed at least in part by one or more hardware logic components. For example, exemplary types of hardware logic components that can be used, without limitation, include: field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), system-on-a-chip (SoCs), complex programmable logic devices (CPLDs), and so on.

[0129] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0130] According to one or more embodiments of this disclosure, Example 1 provides a model training method, the method comprising: Obtain the test files for unit testing; Determine the first dependency tree of the test functions in the test file, and determine the second dependency tree of the target function called by the test file, wherein the test functions are used to perform unit tests on the target function; The test files are filtered based on the first dependency tree and the second dependency tree to determine candidate samples for generating training samples; Based on the candidate samples, a first training sample set for model training is generated; The large language model is trained based on the first training sample set to obtain the trained unit test model, wherein the unit test model is used to generate the target test file for unit testing.

[0131] According to one or more embodiments of this disclosure, Example 2 provides the method of Example 1, wherein filtering the test file based on the first dependency tree and the second dependency tree to determine candidate samples for generating training samples includes: If the similarity between the first dependency tree and the second dependency tree of the test file exceeds a first threshold, then the test file is selected as a candidate file. The nodes in the second dependency tree corresponding to the candidate file are sorted, and the source code of the nodes is concatenated based on the obtained order as the context information of the target function corresponding to the candidate file; The objective function corresponding to the candidate file, the context information of the function, and the candidate file are determined as the candidate sample.

[0132] According to one or more embodiments of this disclosure, Example 3 provides the method of Example 1, wherein generating a first training sample set for model training based on the candidate samples includes: For each candidate sample, extract the code of the target item in the test file of the candidate sample, and delete the code of the target item in the test file to obtain an updated test file; The code of the target item is used as the target output, and the target function and context information corresponding to the test file in the candidate sample, as well as the updated test file, are used as inputs to obtain a first training sample. The first training sample set contains multiple first training samples. The target item includes the function body of the test function, and the target item also includes at least one of the following: Simulation items are used to create simulation objects in the test file; Test scenario items are used to determine the test logic of the unit test; Assertion terms are used to determine the target result of the unit test.

[0133] According to one or more embodiments of this disclosure, Example 4 provides the method of Example 3, wherein training a large language model based on the first training sample set to obtain a trained unit test model includes: For each of the first training samples, the input in the first training sample is used as the input of the large language model to obtain the prediction output of the large language model; Based on the predicted output, determine the predicted sub-output corresponding to the target item; Based on the code of the target item and the predicted sub-output in the first training sample, the target loss of the large language model is determined; The large language model is trained based on the target loss to obtain the unit test model.

[0134] According to one or more embodiments of this disclosure, Example 5 provides the method of Example 1, the method further comprising: Based on the candidate samples, a second training sample set for model fine-tuning is generated. The second training sample set contains multiple second training samples. The second training samples contain the thought chain features corresponding to the test file. The thought chain features are used to represent the generation logic of the test file. The unit test model is fine-tuned based on the second training sample set.

[0135] According to one or more embodiments of this disclosure, Example 6 provides the method of Example 5, wherein generating a second training sample set for model fine-tuning based on the candidate samples includes: Based on the objective function and context information corresponding to the test file, and the test file itself, determine the thought chain characteristics corresponding to the test file; Based on the objective function and context information corresponding to the test file and the thought chain features, a training input is generated, and the test file is used as the target output to obtain a second training sample. The second training sample set contains multiple second training samples.

[0136] According to one or more embodiments of this disclosure, Example 7 provides the method of Example 5, wherein fine-tuning the unit test model based on the second training sample set includes: Determine a first subset and a second subset in the second training sample set, wherein the thought chain feature of the second training sample in the first subset is an explicit thought chain, and the thought chain feature of the second training sample in the second subset is a latent thought chain. The unit test model is fine-tuned based on the second training samples in the first subset to obtain the fine-tuned test model. The fine-tuned test model is fine-tuned based on the second training samples in the second subset to obtain the fine-tuned unit test model.

[0137] According to one or more embodiments of this disclosure, Example 8 provides the method of Example 7, wherein fine-tuning the unit test model based on a second training sample in the first subset includes: The training input from the second training sample in the first subset is used as the input to the unit test model to obtain the predictive thought chain and predictive test file output by the unit test model. Based on the predicted thought chain, the predicted test file, the thought chain features, and the test file, a first loss of the unit test model is determined, and the unit test model is fine-tuned based on the first loss. The fine-tuning of the test model based on the second training samples in the second subset includes: The training input from the second training samples in the second subset is used as the input to the unit test model to obtain the output prediction test file of the unit test model; Based on the prediction test file and the test file, a second loss is determined for the fine-tuning test model, and the fine-tuning test model is fine-tuned based on the second loss.

[0138] According to one or more embodiments of this disclosure, Example 9 provides the method of Example 5, the method further comprising: For each test file, determine the test information corresponding to the test file. The test information includes at least one of the code language of the test code in the test file, the test framework used by the test file, and the simulation framework. The step of generating training input based on the objective function and context information corresponding to the test file and the thought chain features includes: Training input is generated based on the objective function and context information corresponding to the test file, the test information, and the thought chain features.

[0139] According to one or more embodiments of this disclosure, Example 10 provides a method of any of Examples 1-8, the method further comprising: Obtain a third training sample, wherein the third training sample contains an objective function for unit testing and context information of the objective function; The third training sample is input into the unit test model and decoded based on multiple decoding strategies to obtain multiple candidate prediction files; Positive and negative samples are determined based on the candidate prediction file; The unit test model is optimized by first reinforcement learning based on the positive and negative samples to obtain the optimized unit test model.

[0140] According to one or more embodiments of this disclosure, Example 11 provides the method of Example 10, wherein determining positive and negative samples based on the candidate prediction file includes: The candidate prediction file is segmented using a sliding window to obtain a segmentation set; Determine the similarity between adjacent word segments in the word segmentation set; If adjacent word segments with similarity exceeding the second threshold are consecutive, and the number of consecutive word segments exceeds the third threshold, then the candidate prediction file is determined to be the negative sample. The candidate prediction files are detected based on preset structural rules, and the candidate prediction files that pass the detection of the structural rules are used as positive samples.

[0141] According to one or more embodiments of this disclosure, Example 12 provides the method of Example 10, the method further comprising: Obtain a fourth training sample, wherein the fourth training sample contains an objective function for unit testing and context information of the objective function; The fourth training sample is input into the optimized unit test model to obtain multiple unit test files output by the optimized unit test model; Each unit test file is compiled and executed in a virtual isolation environment to obtain the execution metrics of each unit test file. The execution metrics include at least one of compilation metrics, execution metrics, and test coverage. The target reward is determined based on multiple performance metrics, and the optimized unit test model is then optimized using a second reinforcement learning method based on the target reward to obtain a new optimized unit test model.

[0142] According to one or more embodiments of this disclosure, Example 13 provides a model training apparatus, the apparatus comprising: The first acquisition module is used to acquire test files for unit testing; The first determining module is used to determine the first dependency tree of the test functions in the test file and to determine the second dependency tree of the target function called by the test file, wherein the test functions are used to perform unit tests on the target function; The second determining module is used to filter the test files based on the first dependency tree and the second dependency tree to determine candidate samples for generating training samples; The first generation module is used to generate a first training sample set for model training based on the candidate samples; The training module is used to train the large language model based on the first training sample set to obtain a trained unit test model, wherein the unit test model is used to generate target test files for unit testing. According to one or more embodiments of the present disclosure, Example 14 provides a computer-readable medium having a computer program stored thereon that, when executed by a processing device, implements the steps of the method described in any one of Examples 1-12.

[0143] According to one or more embodiments of this disclosure, Example 15 provides an electronic device, including: A storage device on which computer programs are stored; A processing device for executing the computer program in the storage device to implement the steps of any one of the methods in Examples 1-12.

[0144] According to one or more embodiments of the present disclosure, Example 16 provides a computer program product including a computer program that, when executed by a processor, implements the steps of the method described in any one of Examples 1-12.

[0145] The above description is merely a preferred embodiment of this disclosure and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of this disclosure is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features disclosed in this disclosure that have similar functions.

[0146] Furthermore, while the operations are described in a specific order, this should not be construed as requiring these operations to be performed in the specific order shown or in a sequential order. In certain environments, multitasking and parallel processing may be advantageous. Similarly, while several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of this disclosure. Certain features described in the context of individual embodiments may also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment may also be implemented individually or in any suitable sub-combination in multiple embodiments.

[0147] Although the subject matter has been described using language specific to structural features and / or methodological logic, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. Rather, the specific features and actions described above are merely illustrative forms of implementing the claims. Regarding the apparatus in the above embodiments, the specific manner in which the various modules perform their operations has been described in detail in the embodiments relating to the method, and will not be elaborated upon here.< / test> < / context>

Claims

1. A model training method, characterized in that, The method comprises: obtaining a test file for unit testing; determining a first dependency tree of a test function in the test file, and determining a second dependency tree of a target function called by the test file, the test function being used for unit testing of the target function; screening the test file based on the first dependency tree and the second dependency tree, and determining a candidate sample for generating a training sample; based on the candidate sample, generating a first training sample set for model training; training a large language model based on the first training sample set to obtain a trained unit test model, wherein the unit test model is used to generate a target test file for unit testing.

2. The method of claim 1, wherein, The method further comprises: if the similarity between the first dependency tree and the second dependency tree of the test file exceeds a first threshold, the test file is used as a candidate file; sorting the nodes in the second dependency tree corresponding to the candidate file, and splicing the source code of the nodes based on the obtained order to obtain context information of the target function corresponding to the candidate file; determining the target function corresponding to the candidate file, the context information of the function, and the candidate file as the candidate sample.

3. The method of claim 1, wherein, The method further comprises: for each candidate sample, extracting the code of a target item in the test file in the candidate sample, and deleting the code of the target item in the test file to obtain an updated test file; using the code of the target item as the target output, and using the target function and the context information corresponding to the test file in the candidate sample and the updated test file as the input to obtain a first training sample, the first training sample set comprising a plurality of first training samples; wherein the target item comprises a function body of a test function, and the target item further comprises at least one of the following: a simulation item for creating a simulation object in the test file; a test scenario item for determining a test logic of the unit test; an assertion item for determining a target result of the unit test.

4. The method of claim 3, wherein, The method further comprises: for each first training sample, using the input in the first training sample as the input of the large language model to obtain a predicted output of the large language model; based on the predicted output, determining a predicted sub-output corresponding to the target item; based on the code of the target item in the first training sample and the predicted sub-output, determining a target loss of the large language model; training the large language model based on the target loss to obtain the unit test model.

5. The method of claim 1, wherein, The method further comprises: generating, based on the candidate samples, a second training sample set for model fine-tuning, the second training sample set containing a plurality of second training samples, the second training samples containing a thought chain feature corresponding to the test file, the thought chain feature being used to represent the generation logic of the test file; fine-tuning the unit test model based on the second training sample set.

6. The method of claim 5, wherein, The method further comprises: determining a thought chain feature corresponding to the test file based on the target function and context information corresponding to the test file and the test file; generating a training input based on the target function and context information corresponding to the test file and the thought chain feature, taking the test file as a target output, and obtaining a second training sample, the second training sample set containing a plurality of second training samples.

7. The method of claim 5, wherein, The method further comprises: determining a first subset and a second subset in the second training sample set, wherein the thought chain feature of the second training sample in the first subset is a displayed thought chain, and the thought chain feature of the second training sample in the second subset is a latent thought chain; fine-tuning the unit test model based on the second training sample in the first subset to obtain a fine-tuned test model; fine-tuning the fine-tuned test model based on the second training sample in the second subset to obtain a fine-tuned unit test model.

8. The method of claim 7, wherein, The method further comprises: taking the training input in the second training sample in the first subset as the input of the unit test model to obtain a predicted thought chain and a predicted test file output by the unit test model; determining a first loss of the unit test model based on the predicted thought chain and the predicted test file, the thought chain feature, and the test file, and fine-tuning the unit test model based on the first loss; The method further comprises: taking the training input in the second training sample in the second subset as the input of the unit test model to obtain a predicted test file output by the unit test model; determining a second loss of the fine-tuned test model based on the predicted test file and the test file, and fine-tuning the fine-tuned test model based on the second loss.

9. The method of claim 6, wherein, The method further comprises: for each test file, determining test information corresponding to the test file, the test information containing at least one of the code language of the test code in the test file, the test framework used by the test file, and the simulation framework; The method further comprises: generating a training input based on the target function and context information corresponding to the test file, the test information, and the thought chain feature.

10. The method according to any one of claims 1-8, characterized in that, The method further comprises: obtaining a third training sample, wherein the third training sample contains a target function for unit testing and context information of the target function; inputting the third training sample into the unit testing model and decoding based on multiple decoding strategies to obtain multiple candidate prediction files; determining positive samples and negative samples based on the candidate prediction files; performing first reinforcement learning optimization on the unit testing model based on the positive samples and the negative samples to obtain an optimized unit testing model.

11. The method of claim 10, wherein, The method further comprises: obtaining a fourth training sample, wherein the fourth training sample contains a target function for unit testing and context information of the target function; inputting the fourth training sample into the optimized unit testing model to obtain multiple unit testing files output by the optimized unit testing model; compiling and executing each unit testing file based on a virtual isolated environment to obtain execution indicators of each unit testing file, the execution indicators containing at least one of a compilation indicator, an execution indicator, and a test coverage; determining a target reward based on multiple execution indicators, performing second reinforcement learning optimization on the optimized unit testing model based on the target reward to obtain a new optimized unit testing model.

12. The method of claim 10, wherein, The device comprises: a first obtaining module configured to obtain a test file for unit testing; a first determining module configured to determine a first dependency tree of a test function in the test file and a second dependency tree of a target function called by the test file, the test function being used for unit testing of the target function; a second determining module configured to filter the test file based on the first dependency tree and the second dependency tree to determine a candidate sample for generating a training sample; a first generating module configured to generate a first training sample set for model training based on the candidate sample; 13. A model training apparatus, comprising: a training module configured to train a large language model based on the first training sample set to obtain a trained unit testing model, wherein the unit testing model is used to generate a target test file for unit testing. The computer program, when executed by a processing device, implements the steps of the method of any one of claims 1-12. comprises: a storage device having a computer program stored thereon; a processing device configured to execute the computer program in the storage device to implement the steps of the method of any one of claims 1-12. The computer program, when executed by a processor, implements the steps of the method of any one of claims 1-12.

14. A computer readable medium having stored thereon a computer program, characterized in that, ​ 15. An electronic device, comprising: ​ ​ ​ 16. A computer program product comprising a computer program, characterized in that, ​