Large code model training method and device, computer equipment and storage medium
By dynamic parameter adjustment of the code model, the problem of mutual interference between tasks in the existing technology is solved, and the output effect and adaptability of the model are improved.
Patent Information
- Application Number
- CN202411058253.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-02
- Publication Date
- 2024-12-03
AI Technical Summary
The existing pre-trained code model has the problem of interfering tasks between tasks in diversified downstream tasks, resulting in poor model output.
By obtaining multiple types of sample instruction data sets, performing data cleaning and clustering analysis, using the KCenterGreedy algorithm to generate sample instruction data sets, and preset dynamic parameters in the code model to base the actual code data and predict the code data. Parameter adjustment is performed differently to reduce dynamic parameter interference of different types of sample instruction data.
It effectively avoids mutual interference between tasks, improves the output effect of the code large model, and enhances the adaptability and generalization ability of the model.
Smart Images

Figure CN119066419A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of natural language processing, and in particular to a method, apparatus, computer equipment, computer-readable storage medium and computer program product for training a large code model. Background Art
[0002] With the development of the field of natural language processing, pre-training models have emerged. In the early days, pre-training models were mainly targeted at text data, and their ability to understand and generate code was relatively limited.
[0003] With the deep integration of software engineering and artificial intelligence, pre-trained code large models have emerged. Pre-trained code large models perform well in code understanding and generation, but they are often fine-tuned for a single task and are difficult to adapt to diverse downstream task requirements. Existing multi-task fine-tuning methods such as hard parameter sharing and soft parameter sharing have problems such as mutual interference between tasks and poor model output effects. Summary of the invention
[0004] Based on this, it is necessary to provide a training method, device, computer equipment, computer-readable storage medium and computer program product for a large code model that can avoid mutual interference between tasks in order to solve the above-mentioned technical problems.
[0005] In a first aspect, the present application provides a method for training a large code model, comprising:
[0006] Obtain a sample instruction data set; the sample instruction data set includes multiple types of sample instruction data, there is type overlap between the types of sample instruction data, and each type of sample instruction data is obtained based on actual code data of the corresponding type;
[0007] Input the sample instruction data set into the code big model to be trained to obtain the predicted code data of each type of sample instruction data;
[0008] Determine the dynamic parameters preset for each type of sample instruction data in the code model to be trained, and adjust the dynamic parameters of the corresponding type according to the difference between each type of predicted code data and the actual code data of the corresponding type, so as to reduce the adjustment interference of the dynamic parameters corresponding to different types of sample instruction data, and obtain the trained code model.
[0009] In one embodiment, obtaining a sample instruction data set includes:
[0010] Get the original code dataset;
[0011] Removing original code data whose data length is not within a preset data length range and repeated original code data in the original code data set to obtain a cleaned original code data set;
[0012] The KCenterGreedy algorithm is used to perform cluster analysis on the cleaned original code data set to obtain the actual code data set; the actual code data set contains actual code data of multiple programming languages, and the amount of actual code data of each programming language is balanced;
[0013] The actual code data set is input into a preset benchmark code large model, and the actual code data set is converted into a corresponding sample instruction data set through the benchmark code large model.
[0014] In one of the embodiments, the benchmark code large model includes an instruction data set generation model and an instruction data set filtering model;
[0015] Inputting the actual code data set and the generated instruction into the instruction data set generation model to generate the corresponding instruction data set; the generated instruction includes indicating the dependency relationship between the instruction data and the actual code data, indicating the data format and data content of the generated instruction data, and indicating the dependent actual code data;
[0016] The instruction data set and filtering instructions are input into the instruction data set filtering model to generate a sample instruction data set; the filtering instructions include judging whether the instruction data meets the data format and data content, judging whether the data content relationship of the instruction data matches, and judging whether the instruction data is retained.
[0017] In an exemplary embodiment, generating a sample instruction data set includes:
[0018] When the data format of the instruction data simultaneously contains the task name, task information, task type and task solution && the task name in the data content of the instruction data matches the task type && the task name in the data content of the instruction data matches the task solution && the task information in the data content of the instruction data matches the task solution, the instruction data is retained and a sample instruction data set is generated based on the instruction data.
[0019] In one embodiment, generating a sample instruction data set based on the instruction data includes:
[0020] Get the number of valid basic units of each instruction data;
[0021] Each instruction data is divided into groups according to the number of valid basic units to obtain a plurality of instruction data groups; the difference between the number of valid basic units of the instruction data in the instruction data group satisfies a preset difference interval; the instruction data group includes all types of instruction data;
[0022] A plurality of instruction data groups are randomly sorted to obtain a sample instruction data set.
[0023] In one embodiment, according to the difference between each type of predicted code data and the corresponding type of actual code data, the dynamic parameters of the corresponding type are adjusted, including:
[0024] Determine the loss function preset for each type of sample instruction data in the code model to be trained;
[0025] According to the differences between the types and the corresponding loss functions, the task loss values of the sample instruction data of each type are obtained;
[0026] The corresponding type of dynamic parameters to be adjusted are determined according to the loss values of each type of tasks, and the parameters of the corresponding type of dynamic parameters to be adjusted are adjusted.
[0027] In an exemplary embodiment, determining the corresponding type of dynamic parameters to be adjusted according to the loss values of each type of tasks, and adjusting the corresponding type of dynamic parameters to be adjusted includes:
[0028] When the difference between the loss values of each type of task is less than the preset difference threshold, a corresponding task loss value change curve is obtained based on the loss value of each type of task, and a first dynamic parameter of the corresponding type to be adjusted is determined according to the task loss value change curve, and the first dynamic parameter of the corresponding type to be adjusted is reduced;
[0029] When the difference between the task loss values of each type is greater than a preset difference threshold, the corresponding type of second dynamic parameter to be adjusted is determined according to the task loss value, and the corresponding type of second dynamic parameter to be adjusted is reduced.
[0030] In a second aspect, the present application also provides a training device for a large code model, comprising:
[0031] The data set acquisition module is used to acquire a sample instruction data set; the sample instruction data set includes multiple types of sample instruction data, and there is type overlap between the types of sample instruction data. Each type of sample instruction data is obtained based on the actual code data of the corresponding type;
[0032] A data set input module is used to input the sample instruction data set into the code model to be trained to obtain predicted code data of each type of sample instruction data;
[0033] The large model training module is used to determine the dynamic parameters preset for each type of sample instruction data in the code large model to be trained, and adjust the dynamic parameters of the corresponding type according to the difference between each type of predicted code data and the actual code data of the corresponding type, so as to reduce the adjustment interference of the dynamic parameters corresponding to different types of sample instruction data, and obtain a trained code large model.
[0034] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0035] Obtain a sample instruction data set; the sample instruction data set includes multiple types of sample instruction data, there is type overlap between the types of sample instruction data, and each type of sample instruction data is obtained based on actual code data of the corresponding type;
[0036] Input the sample instruction data set into the code big model to be trained to obtain the predicted code data of each type of sample instruction data;
[0037] Determine the dynamic parameters preset for each type of sample instruction data in the code model to be trained, and adjust the dynamic parameters of the corresponding type according to the difference between each type of predicted code data and the actual code data of the corresponding type, so as to reduce the adjustment interference of the dynamic parameters corresponding to different types of sample instruction data, and obtain the trained code model.
[0038] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the following steps are implemented:
[0039] Obtain a sample instruction data set; the sample instruction data set includes multiple types of sample instruction data, there is type overlap between the types of sample instruction data, and each type of sample instruction data is obtained based on actual code data of the corresponding type;
[0040] Input the sample instruction data set into the code big model to be trained to obtain the predicted code data of each type of sample instruction data;
[0041] Determine the dynamic parameters preset for each type of sample instruction data in the code model to be trained, and adjust the dynamic parameters of the corresponding type according to the difference between each type of predicted code data and the actual code data of the corresponding type, so as to reduce the adjustment interference of the dynamic parameters corresponding to different types of sample instruction data, and obtain the trained code model.
[0042] In a fifth aspect, the present application further provides a computer program product, including a computer program, which implements the following steps when executed by a processor:
[0043] Obtain a sample instruction data set; the sample instruction data set includes multiple types of sample instruction data, there is type overlap between the types of sample instruction data, and each type of sample instruction data is obtained based on actual code data of the corresponding type;
[0044] Input the sample instruction data set into the code big model to be trained to obtain the predicted code data of each type of sample instruction data;
[0045] Determine the dynamic parameters preset for each type of sample instruction data in the code model to be trained, and adjust the dynamic parameters of the corresponding type according to the difference between each type of predicted code data and the actual code data of the corresponding type, so as to reduce the adjustment interference of the dynamic parameters corresponding to different types of sample instruction data, and obtain the trained code model.
[0046] The training method, device, computer equipment, computer-readable storage medium and computer program product of the above-mentioned code big model, the sample instruction data set contains multiple types of sample instruction data, there is type overlap between the types of sample instruction data, each type of sample instruction data is obtained based on the actual code data of the corresponding type, the server obtains the above-mentioned sample instruction data set and inputs it into the code big model to be trained, obtains the predicted code data of each type of sample instruction data, determines the dynamic parameters preset for each type of sample instruction data in the code big model to be trained, and according to the difference between each type of predicted code data and the corresponding type of actual code data, adjusts the parameters of the corresponding type of dynamic parameters to reduce the adjustment interference of the dynamic parameters corresponding to the different types of sample instruction data, and obtains the trained code big model. Since there are multiple types of sample instruction data and there is type overlap between types, each instruction data may interfere with each other when using the code big model for code prediction. The present application presets the corresponding dynamic parameters for each type of sample instruction data, adjusts the dynamic parameters during the training process to reduce the mutual interference between tasks, and improves the output effect of the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0048] Figure 1 An application environment diagram of a method for training a large code model in an embodiment;
[0049] Figure 2 A schematic diagram of a flow chart of a method for training a large code model in one embodiment;
[0050] Figure 3 A schematic diagram of a process for generating a sample instruction data set in one embodiment;
[0051] Figure 4 A schematic diagram of a process for adjusting dynamic parameters in one embodiment;
[0052] Figure 5 A schematic diagram of a process for training a large code model in another embodiment;
[0053] Figure 6 A structural block diagram of a training device for a large code model in an embodiment;
[0054] Figure 7 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0055] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0056] The code model training method provided in the embodiment of the present application can be applied to Figure 1In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. The data storage system pre-stores multiple types of sample instruction data and large code models to be trained. There is type overlap between each type of sample instruction data, and each type of sample instruction data is obtained based on the actual code data of the corresponding type obtained from the terminal 102. The server 104 obtains a sample instruction data set from the data storage system, and then inputs the sample instruction data set into the large code model to be trained to obtain the predicted code data of each type of sample instruction data, and determines the dynamic parameters preset for each type of sample instruction data in the large code model to be trained. Then, according to the difference between each type of predicted code data and the corresponding type of actual code data, the dynamic parameters of the corresponding type are adjusted to reduce the adjustment interference of the dynamic parameters corresponding to the different types of sample instruction data, and obtain the trained large code model. The terminal 102 may be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, IoT devices, and portable wearable devices. The IoT devices may be smart speakers, smart TVs, smart air conditioners, smart car devices, projection devices, etc. Portable wearable devices may be smart watches, smart bracelets, head-mounted devices, etc. Head-mounted devices may be virtual reality (VR) devices, augmented reality (AR) devices, smart glasses, etc. The server 104 may be an independent physical server, a server cluster or distributed system consisting of multiple physical servers, or a cloud server that provides cloud computing services.
[0057] In an exemplary embodiment, Figure 2 As shown, a method for training a large code model is provided, and the method is applied to Figure 1 The server 104 in the example is used as an example to illustrate the method, which includes the following steps S201 to S203. Among them:
[0058] Step S201, obtaining a sample instruction data set; the sample instruction data set includes multiple types of sample instruction data, and there is type overlap between the types of sample instruction data. Each type of sample instruction data is obtained based on actual code data of the corresponding type.
[0059] Among them, sample instruction data can be understood as input data used to help the model understand the code data and train the model to output corresponding code data; type overlap can be understood as the overlapping information between different types of instruction data; actual code data can be understood as code data that correctly corresponds to the instruction data.
[0060] Exemplarily, a sample instruction data set containing multiple types of sample instruction data is pre-stored in the data storage system, and type information overlaps between the types of sample instruction data. Each type of sample instruction data is obtained based on actual code data of the corresponding type, and the server 104 obtains the sample instruction data set from the data storage system. This lays a data foundation for subsequent model training of the large code model to be trained.
[0061] Step S202, input the sample instruction data set into the code model to be trained to obtain predicted code data for each type of sample instruction data.
[0062] Step S203, determine the dynamic parameters preset for each type of sample instruction data in the code model to be trained, and adjust the dynamic parameters of the corresponding type according to the difference between each type of predicted code data and the actual code data of the corresponding type, so as to reduce the adjustment interference of the dynamic parameters corresponding to different types of sample instruction data, and obtain a trained code model.
[0063] Among them, the code big model can be understood as a deep learning model trained with a large amount of code data, which aims to generate, understand, or complete the code; the predicted code data can be understood as the code data generated by the code big model based on the sample instruction data; the dynamic parameters can be understood as the parameters dynamically determined according to the specific situation when the program or function is executed. It changes according to conditions, inputs or other factors at runtime.
[0064] In an exemplary embodiment, the server 104 inputs the sample instruction data set into the code big model to be trained, obtains the predicted code data of each type of sample instruction data, and determines the dynamic parameters preset for each type of sample instruction data in the code big model to be trained, and then adjusts the dynamic parameters of the corresponding type according to the difference between each type of predicted code data and the corresponding type of actual code data, so as to reduce the adjustment interference of the dynamic parameters corresponding to the different types of sample instruction data, and obtains the trained code big model. By presetting the corresponding dynamic parameters for each type of sample instruction data and adaptively adjusting the dynamic parameters during model training, the mutual interference between multiple tasks during the internal processing of the model is avoided, thereby enhancing the output effect of the model.
[0065] In the training method of the above-mentioned code big model, the sample instruction data set contains multiple types of sample instruction data, and there is type overlap between the types of sample instruction data. Each type of sample instruction data is obtained based on the actual code data of the corresponding type. The server obtains the above-mentioned sample instruction data set and inputs it into the code big model to be trained to obtain the predicted code data of each type of sample instruction data, determine the dynamic parameters preset for each type of sample instruction data in the code big model to be trained, and adjust the dynamic parameters of the corresponding type according to the difference between each type of predicted code data and the actual code data of the corresponding type, so as to reduce the adjustment interference of the dynamic parameters corresponding to the different types of sample instruction data, and obtain the trained code big model. Since there are multiple types of sample instruction data and there is type overlap between types, each instruction data may interfere with each other when using the code big model for code prediction. The present application presets the corresponding dynamic parameters for each type of sample instruction data, adjusts the dynamic parameters during the training process to reduce the mutual interference between tasks, and improves the output effect of the model.
[0066] In one embodiment, obtaining a sample instruction data set includes: obtaining an original code data set; removing original code data whose data length is not within a preset data length interval and repeated original code data in the original code data set to obtain a cleaned original code data set; performing cluster analysis on the cleaned original code data set using a KCenterGreedy algorithm to obtain an actual code data set; the actual code data set includes actual code data of multiple programming languages, and the amount of actual code data of each programming language is balanced; the actual code data set is input into a preset benchmark code macro model, and the actual code data set is converted into a corresponding sample instruction data set through the benchmark code macro model.
[0067] Among them, the KCenterGreedy algorithm is a K-center greedy algorithm, which is a greedy algorithm used for clustering and approximate solution of the k-center problem. The goal of the k-center problem is to select k center points from a set of points so that the distances from all other points to their nearest center points are as small as possible. This problem can be stated as: given a point set, find k points so that the maximum distance from each point in the point set to its nearest center point is minimized; the benchmark code large model can be understood as a code large model used to convert actual code data into sample instruction data.
[0068] Optionally, the server 104 obtains the original code data set from the data storage system, removes the original code data whose data length is not within the preset data length interval and the repeated original code data in the original code data set, obtains the cleaned original code data set, and then uses the KCenterGreedy algorithm to perform cluster analysis processing on the original code data in the cleaned original code data set to obtain an actual code data set containing multiple programming languages and with a balanced amount of actual code data for each programming language, and finally inputs the actual code data set into a preset benchmark code large model, and converts the actual code data set into a corresponding sample instruction data set through the benchmark code large model. Through data cleaning and cluster analysis processing of the original code data, the availability and effectiveness of the original code data are improved, thereby improving the training effect of model training.
[0069] In one embodiment, the benchmark code big model includes an instruction data set generation model and an instruction data set filtering model; inputting the actual code data set into the preset benchmark code big model, and converting the actual code data set into a corresponding sample instruction data set through the benchmark code big model, including:
[0070] Inputting the actual code data set and the generated instruction into the instruction data set generation model to generate the corresponding instruction data set; the generated instruction includes indicating the dependency relationship between the instruction data and the actual code data, indicating the data format and data content of the generated instruction data, and indicating the dependent actual code data;
[0071] The instruction data set and filtering instructions are input into the instruction data set filtering model to generate a sample instruction data set; the filtering instructions include judging whether the instruction data meets the data format and data content, judging whether the data content relationship of the instruction data matches, and judging whether the instruction data is retained.
[0072] For example, the benchmark code big model includes an instruction data set generation model and an instruction data set filtering model, and the server 104 inputs the actual code data set and the generation instruction into the instruction data set generation model, wherein the generation instruction includes indicating the dependency relationship between the instruction data and the actual code data, indicating the data format and data content of the generated instruction data, and indicating the actual code data that is dependent, and the instruction data set generation model generates the instruction to convert the actual code data in the actual code data set into corresponding instruction data according to the content indicated by the instruction, so as to form an instruction data set; then the instruction data set and the filtering instruction are input into the instruction data set filtering model, wherein the filtering instruction includes judging whether the instruction data meets the data format and data content, judging whether the data content relationship of the instruction data matches, judging whether the instruction data is retained, filtering the instruction data in the instruction data set according to the filtering instruction, retaining the instruction data that meets the requirements, and forming the sample instruction data. The data quality of the generated sample instruction data is guaranteed by designing the generation instruction and the filtering instruction, and the steps of obtaining the sample instruction data are simplified by using the big model tool, thereby accelerating the efficiency of the model.
[0073] In one embodiment, generating a sample instruction data set includes: retaining the instruction data and generating a sample instruction data set based on the instruction data when the data format of the instruction data simultaneously includes a task name, task information, a task type, and a task solution && the task name in the data content of the instruction data matches the task type && the task name in the data content of the instruction data matches the task solution && the task information in the data content of the instruction data matches the task solution.
[0074] Among them, the task name can be understood as the title or logo of a specific task, which is usually used to concisely describe the main content or goal of the task; the task information can be understood as the relevant information of the sample instruction data, such as detailed information and description of the task to be performed in a specific context; the task type can be understood as a classification based on the nature, goal, or execution method of the task, such as project tasks, daily tasks, emergency tasks, cooperative tasks, and test tasks; the task solution can be understood as the specific method, strategy or step formulated for a specific task or problem, which is used to effectively achieve the goal or solve the problem.
[0075] In an exemplary embodiment, when the data format of the instruction data includes the task name, task information, task type and task solution at the same time, and the content under each part is correct, and further, the task name matches the task type, the task name matches the task solution, and the task information matches the task solution, the data quality of the instruction data generated at this time meets the data quality requirements for subsequent model training, and can be retained, and sample instruction data is generated based on the retained instruction data. By filtering the generated instruction data, the rationality and effectiveness of the data format and data content of the instruction data are further guaranteed, and the data quality of the sample instruction data in the sample instruction data set is improved.
[0076] In an exemplary embodiment, Figure 3 As shown, generating a sample instruction data set based on instruction data includes steps S301 to S303. Among them:
[0077] Step S301, obtaining the number of valid basic units of each instruction data.
[0078] Step S302, grouping each instruction data according to the number of valid basic units to obtain multiple instruction data groups; the difference between the number of valid basic units of the instruction data in the instruction data group meets the preset difference range; the instruction data group contains all types of instruction data.
[0079] Step S303: randomly sort the multiple instruction data groups to obtain a sample instruction data set.
[0080] Among them, the number of valid basic units is the number of valid tokens, which can be understood as the number of words or symbols that can be effectively used for calculation or analysis in natural language processing (NLP) or machine learning models.
[0081] For example, the server 104 obtains the number of effective basic units of each instruction data, and divides each instruction data into groups according to the number of effective basic units, to obtain multiple instruction data groups, wherein the difference between the number of effective basic units of instruction data in the instruction data group satisfies the preset difference interval, and the instruction data group contains all types of instruction data, and finally randomly sorts the multiple instruction data groups in groups to obtain sample instruction data sets. By obtaining the number of effective basic units of each instruction data and dividing the groups according to the number of effective basic units, the number of effective basic units in each group is similar and each group contains all types of instruction data, and random sorting is performed in groups, so that the model is trained in groups, thereby enhancing the generalization ability of the model.
[0082] In an exemplary embodiment, Figure 4As shown, according to the difference between each type of predicted code data and the corresponding type of actual code data, the dynamic parameters of the corresponding type are adjusted, including steps S401 to S403. Among them:
[0083] Step S401, determining the loss function preset for each type of sample instruction data in the code model to be trained.
[0084] Among them, the loss function can be understood as an important criterion for measuring the difference between the output results of the model and the actual results.
[0085] Exemplarily, the server 104 determines the loss function preset for each type of sample instruction data in the code big model to be trained, laying a data foundation for the subsequent acquisition of the task loss value of each type of sample instruction data.
[0086] Step S402, obtaining the task loss value of each type of sample instruction data according to the difference of each type and the corresponding type loss function.
[0087] Step S403: determining the corresponding type of dynamic parameters to be adjusted according to the loss values of each type of tasks, and adjusting the corresponding type of dynamic parameters to be adjusted.
[0088] Among them, the task loss value can be understood as visual data that expresses the difference between the model-predicted code data and the actual code data. This data can more intuitively observe the gap between the two.
[0089] In an exemplary embodiment, according to the difference of each type and the corresponding type loss function, the task loss value of each type of sample instruction data is obtained, and then the corresponding type of dynamic parameters to be adjusted are determined according to the task loss value of each type, and the corresponding type of dynamic parameters to be adjusted are adjusted. By obtaining the task loss value of each type of sample instruction data, and determining the dynamic parameters to be adjusted according to the task loss value, the parameters are adjusted in a targeted manner, which avoids the unnecessary cost consumption caused by adjusting all dynamic parameters, and also improves the training speed of model training.
[0090] In one embodiment, dynamic parameters of the corresponding type to be adjusted are determined based on the loss values of each type of tasks, and parameter adjustment is performed on the dynamic parameters of the corresponding type to be adjusted, including: when the difference between the loss values of each type of tasks is less than a preset difference threshold, a task loss value change curve is obtained based on the loss values of each type of tasks, and a first dynamic parameter of the corresponding type to be adjusted is determined based on the task loss value change curve, and the first dynamic parameter of the corresponding type to be adjusted is reduced; when the difference between the loss values of each type of tasks is greater than the preset difference threshold, a second dynamic parameter of the corresponding type to be adjusted is determined based on the loss values of each type of tasks, and the second dynamic parameter of the corresponding type to be adjusted is reduced.
[0091] Among them, the task loss value change curve can be understood as a task loss value-time change curve composed of the task loss values of each type of sample instruction data, or it can be a task loss value-time change curve formed by weighted averaging the task loss values of various types of sample instruction data, which is not limited in this application; the first dynamic parameter of the corresponding type can be understood as the dynamic parameter of the corresponding type with the largest curve change trend within the same time period; the second dynamic parameter of the corresponding type can be understood as the dynamic parameter corresponding to the sample instruction data with the largest task loss value.
[0092] Optionally, the dynamic parameter adjustment of the present application is divided into two cases, which are specifically described as follows:
[0093] Case 1: When the difference between the loss values of each type of task is less than the preset difference threshold, a task loss value change curve is obtained based on the loss value of each type of task, and the corresponding type of task loss value with the fastest change trend is determined according to the task loss value change curve. The dynamic parameter corresponding to the task loss value of this type is used as the first dynamic parameter of the corresponding type to be adjusted, and the first dynamic parameter of the corresponding type to be adjusted is reduced to reduce the adjustment interference of the dynamic parameters corresponding to different types of sample instruction data.
[0094] Case 2: When the difference between the loss values of each type of task is greater than the preset difference threshold, the maximum value among the task loss values is determined, and the dynamic parameter corresponding to the maximum task loss value is used as the second dynamic parameter of the corresponding type to be adjusted, and the second dynamic parameter of the corresponding type to be adjusted is reduced to reduce the adjustment interference of the dynamic parameters corresponding to different types of sample instruction data.
[0095] Regardless of whether the difference between the task loss values is large or small, the dynamic parameters need to be adjusted. In other words, this process is dynamic. The above-mentioned dynamic parameter adjustment method can reduce the adjustment interference of the dynamic parameters corresponding to different types of sample instruction data, thereby improving the output effect of the model.
[0096] In an exemplary embodiment, Figure 5 As shown, a specific implementation method of a method for training a large code model is provided, including steps S501 to S505. Among them:
[0097] Step S501, original code data collection:
[0098] First, we select an existing open source code database as the basic database. Each data in the database contains comment-code pair information. To ensure the quality of the code dataset, we set filtering conditions to filter out overlong, overshort, and duplicate data in the basic dataset. To ensure the diversity of code languages, we use the KCenterGreedy algorithm to construct an original code dataset with reasonable distribution of languages from the basic dataset.
[0099] Step S502: Generate a large model input data set:
[0100] Select an existing large model with strong coding capabilities as the instruction dataset generator. Input instructions to the generator, requiring the generator to complete the conversion from the original code dataset data to the instruction dataset data. The specific input includes the following three functions: (1) Indicate the dependency relationship between the output instruction data and the original data; (2) Indicate that the output instruction data should contain four parts: task name, task information, task type, and task solution, and put forward specific requirements for the four parts; (3) Indicate the original data that this output depends on. The three functions can be implemented in the three sections of the input respectively. The first two parts are general parts, the third part key is general, and the value is the specific original data. In this way, the input dataset can be generated from the original code dataset.
[0101] Step S503, generating an instruction data set:
[0102] Select an existing large model with strong coding capabilities as the instruction data set filter. Input instructions to the filter, requiring the filter to complete the invalid information screening of the instruction data set data generated in the previous step. The specific input includes the following three functions: (1) Determine whether the instruction data format is presented in accordance with the above requirements; (2) Determine whether the content relationship of the instruction data is reasonable, and whether the task name matches the task classification, and whether the task name and task information match the task solution; (3) Determine whether the instruction data is retained, based on whether the instruction data is positively judged in the previous two judgments. Finally, the instruction data set with the third positive judgment is retained.
[0103] Step S504, balance the number of valid tokens of each training task (the number of valid tokens is a valid basic unit):
[0104] Calculate the number of tokens lost in a single instruction data and record it as the number of valid tokens for the instruction data. Calculate the number of valid tokens for the instruction data set. (1) The instruction data set is randomly arranged in groups; (2) Each group contains all required task type data; (3) The number of valid tokens for each task type data in each group is close. When training batches, use sequential batch processing to make the training of various tasks relatively balanced during the training process.
[0105] Step S505, dynamically adjust the training loss:
[0106] Introduce a dynamic parameter for each type of task , is the task type number, and the dynamic parameter is calculated by the following formula:
[0107]
[0108] in, For training groups, is the total number of tasks, express wheel The weighted average of the tasks' recent rounds. The more recent the round, the greater the weight. for The average loss of each task in each round, for wheel Mission loss value, is an empirical constant. During the training process, when the loss gap is small, the main influencing factor is the dynamic trend of the training loss of various tasks. The dynamic parameters with faster learning loss decrease are smaller to slow down the learning speed; when the loss gap is large, the main influencing factor is the size of the loss value of various tasks. The dynamic parameters with significantly larger losses are smaller to slow down the learning speed.
[0109] Compared with the prior art, this application has the following advantages:
[0110] 1. By designing input instructions and using large model tools to generate and verify sample instruction data sets that meet quality requirements, the computing power cost consumed in obtaining sample instruction data sets is greatly reduced.
[0111] 2. By pre-designing dynamic parameters for each type of sample instruction data, during the training process of the large model, the corresponding dynamic parameters are dynamically adjusted based on the difference between the actual code data and the predicted code data to avoid adjustment interference between various types of sample instruction data during the operation of the model, thereby improving the output effect of the model.
[0112] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0113] Based on the same inventive concept, the embodiment of the present application also provides a device for training a large code model for implementing the method for training a large code model involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in the embodiments of the training device for one or more large code models provided below can refer to the limitations of the training method for the large code model above, and will not be repeated here.
[0114] In an exemplary embodiment, Figure 6 As shown, a training device for a large code model is provided, including: a data set acquisition module 601, a data set input module 602 and a large model training module 603, wherein:
[0115] The data set acquisition module 601 is used to acquire a sample instruction data set; the sample instruction data set includes multiple types of sample instruction data, and there is type overlap between the types of sample instruction data. Each type of sample instruction data is obtained based on the actual code data of the corresponding type;
[0116] The data set input module 602 is used to input the sample instruction data set into the code big model to be trained to obtain the predicted code data of each type of sample instruction data;
[0117] The large model training module 603 is used to determine the dynamic parameters preset for each type of sample instruction data in the code large model to be trained, and adjust the dynamic parameters of the corresponding type according to the difference between each type of predicted code data and the actual code data of the corresponding type, so as to reduce the adjustment interference of the dynamic parameters corresponding to different types of sample instruction data, and obtain a trained code large model.
[0118] In one embodiment, the data set acquisition module 601 further includes:
[0119] Get submodule to get the original code dataset.
[0120] The cleaning submodule is used to remove the original code data whose data length is not within the preset data length range and the repeated original code data in the original code data set to obtain a cleaned original code data set.
[0121] The clustering submodule uses the KCenterGreedy algorithm to perform cluster analysis on the cleaned original code data set to obtain the actual code data set; the actual code data set contains actual code data of multiple programming languages, and the amount of actual code data of each programming language is balanced.
[0122] The conversion submodule inputs the actual code data set into a preset benchmark code large model, and converts the actual code data set into a corresponding sample instruction data set through the benchmark code large model.
[0123] In one embodiment, the benchmark code model includes an instruction data set generation model and an instruction data set filtering model, and the conversion submodule further includes:
[0124] The instruction data set generation unit is used to input the actual code data set and the generated instructions into the instruction data set generation model to generate the corresponding instruction data set; the generated instructions include indicating the dependency relationship between the instruction data and the actual code data, indicating the data format and data content of the generated instruction data, and indicating the dependent actual code data.
[0125] The sample instruction data set generation unit is used to input the instruction data set and filtering instructions into the instruction data set filtering model to generate a sample instruction data set; the filtering instructions include judging whether the instruction data meets the data format and data content, judging whether the data content relationship of the instruction data matches, and judging whether the instruction data is retained.
[0126] In an exemplary embodiment, the sample instruction data set generation unit is also used to retain the instruction data and generate a sample instruction data set based on the instruction data when the data format of the instruction data simultaneously contains a task name, task information, a task type and a task solution && the task name in the data content of the instruction data matches the task type && the task name in the data content of the instruction data matches the task solution && the task information in the data content of the instruction data matches the task solution.
[0127] In one embodiment, the number of valid basic units of each instruction data is obtained; each instruction data is divided into groups according to the number of valid basic units to obtain multiple instruction data groups; the difference between the number of valid basic units of the instruction data in the instruction data group satisfies a preset difference range; the instruction data group contains all types of instruction data; and the multiple instruction data groups are randomly sorted to obtain a sample instruction data set.
[0128] In one embodiment, the large model training module 603 further includes:
[0129] The function determination submodule is used to determine the loss function preset for each type of sample instruction data in the code model to be trained.
[0130] The loss value acquisition submodule is used to obtain the task loss value of each type of sample instruction data based on the differences between each type and the corresponding type loss function.
[0131] The parameter adjustment submodule is used to determine the corresponding type of dynamic parameters to be adjusted according to the loss values of each type of tasks, and to adjust the parameters of the corresponding type of dynamic parameters to be adjusted.
[0132] In an exemplary embodiment, the parameter adjustment submodule is also used to obtain a task loss value change curve based on each type of task loss value when the difference between each type of task loss value is less than a preset difference threshold, and determine the corresponding type of first dynamic parameter to be adjusted according to the task loss value change curve, and reduce the corresponding type of first dynamic parameter to be adjusted; when the difference between each type of task loss value is greater than the preset difference threshold, determine the corresponding type of second dynamic parameter to be adjusted according to each type of task loss value, and reduce the corresponding type of second dynamic parameter to be adjusted.
[0133] Each module in the training device of the above code model can be implemented in whole or in part by software, hardware and their combination. Each module can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to each module above.
[0134] In an exemplary embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as shown in FIG. Figure 7As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store original code data, instruction data, and sample instruction data. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a method for training a large code model is implemented.
[0135] Those skilled in the art will understand that Figure 7 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0136] In an exemplary embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the method for training the code model of the above embodiment is implemented.
[0137] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the training method of the code big model of the above embodiment is implemented.
[0138] In one embodiment, a computer program product is provided, including a computer program, which implements the code big model training method of the above embodiment when the computer program is executed by a processor.
[0139] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0140] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.
[0141] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0142] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A training method for a large code model, It is characterized in that The method comprises: Acquire a sample instruction data set; the sample instruction data set includes multiple types of sample instruction data, there is type overlap between the types of sample instruction data, and each type of sample instruction data is obtained based on actual code data of the corresponding type; Inputting the sample instruction data set into the code big model to be trained to obtain predicted code data of each type of the sample instruction data; Determine the dynamic parameters preset for each type of sample instruction data in the code model to be trained, and adjust the dynamic parameters of the corresponding type according to the difference between the predicted code data of each type and the actual code data of the corresponding type, so as to reduce the adjustment interference of the dynamic parameters corresponding to different types of sample instruction data, and obtain a trained code model.
2. The method according to claim 1, It is characterized in that The step of obtaining a sample instruction data set includes: Get the original code dataset; Removing original code data whose data length is not within a preset data length interval and repeated original code data in the original code data set to obtain a cleaned original code data set; Performing cluster analysis on the cleaned original code data set using the KCenterGreedy algorithm to obtain an actual code data set; the actual code data set contains actual code data of multiple programming languages, and the amount of actual code data of each programming language is balanced; The actual code data set is input into a preset benchmark code large model, and the actual code data set is converted into a corresponding sample instruction data set through the benchmark code large model.
3. The method according to claim 2, It is characterized in that The benchmark code large model includes an instruction data set generation model and an instruction data set filtering model; The step of inputting the actual code data set into a preset benchmark code large model and converting the actual code data set into a corresponding sample instruction data set through the benchmark code large model includes: Inputting the actual code data set and the generation instruction into the instruction data set generation model to generate a corresponding instruction data set; the generation instruction includes indicating the dependency relationship between the instruction data and the actual code data, indicating the data format and data content of the generation instruction data, and indicating the actual code data on which it depends; The instruction data set and filtering instructions are input into the instruction data set filtering model to generate a sample instruction data set; the filtering instructions include determining whether the instruction data satisfies the data format and the data content, determining whether the data content relationship of the instruction data matches, and determining whether the instruction data is retained.
4. The method according to claim 3, It is characterized in that The generating of the sample instruction data set comprises: In the case where the data format of the instruction data simultaneously includes a task name, task information, a task type, and a task solution&& the task name in the data content of the instruction data matches the task type&& the task name in the data content of the instruction data matches the task solution&& the task information in the data content of the instruction data matches the task solution, the instruction data is retained and the sample instruction data set is generated based on the instruction data.
5. The method according to claim 4, It is characterized in that The generating the sample instruction data set based on the instruction data comprises: Obtaining the number of valid basic units of each of the instruction data; The instruction data are divided into groups according to the effective basic unit numbers to obtain a plurality of instruction data groups; the difference between the effective basic unit numbers of the instruction data in the instruction data groups satisfies a preset difference interval; the instruction data groups contain all types of instruction data; The plurality of instruction data groups are randomly sorted to obtain the sample instruction data set.
6. The method according to claim 1, It is characterized in that The step of adjusting the dynamic parameters of the corresponding type according to the difference between the predicted code data of each type and the actual code data of the corresponding type includes: Determine a loss function preset for each type of sample instruction data in the code macro model to be trained; According to the differences of each type and the loss function of the corresponding type, obtaining the task loss value of the sample instruction data of each type; The corresponding type of dynamic parameters to be adjusted are determined according to the task loss values of each type, and the corresponding type of dynamic parameters to be adjusted are adjusted.
7. The method according to claim 6, It is characterized in that The determining of the dynamic parameters of the corresponding type to be adjusted according to the task loss values of each type, and adjusting the dynamic parameters of the corresponding type to be adjusted includes: When the difference between the task loss values of each type is less than a preset difference threshold, a task loss value change curve is obtained based on the task loss values of each type, and a first dynamic parameter of a corresponding type to be adjusted is determined according to the task loss value change curve, and the first dynamic parameter of the corresponding type to be adjusted is reduced; When the difference between the task loss values of each type is greater than a preset difference threshold, the corresponding type of second dynamic parameter to be adjusted is determined according to the task loss value of each type, and the corresponding type of second dynamic parameter to be adjusted is reduced.
8. A training device for a large code model, It is characterized in that The device comprises: A data set acquisition module is used to acquire a sample instruction data set; the sample instruction data set includes multiple types of sample instruction data, there is type overlap between the types of sample instruction data, and each type of sample instruction data is obtained based on actual code data of the corresponding type; A data set input module, used for inputting the sample instruction data set into the code big model to be trained, and obtaining predicted code data of each type of the sample instruction data; The large model training module is used to determine the dynamic parameters preset for each type of sample instruction data in the code large model to be trained, and adjust the dynamic parameters of the corresponding type according to the difference between the predicted code data of each type and the actual code data of the corresponding type, so as to reduce the adjustment interference of the dynamic parameters corresponding to different types of sample instruction data, and obtain a trained code large model.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program. It is characterized in that When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
