Method, device, system, equipment, cluster, product and medium for preventing generation of redundant codes

By introducing an early warning module into the large code model, which predicts the probability of redundant code based on semantic vectors and sends a stop notification, the problem of redundant code generation in the large code model is solved, and the generation efficiency is improved.

CN121541852APending Publication Date: 2026-02-17HUAWEI CLOUD COMPUTING TECHNOLOGIES CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411110685.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-13
Publication Date
2026-02-17

AI Technical Summary

Technical Problem

Existing large code models are prone to generating redundant code during code generation, leading to reduced generation efficiency.

Method used

By using an independent early warning module to obtain the semantic vector of the target code unit during the inference process of the code big model, predicting the probability of generating redundant code, and sending a stop notification to prevent the generation of redundant code when the probability exceeds a threshold.

Benefits of technology

It effectively prevents the generation of redundant code, improves the generation efficiency of large code models, and does not require modification of existing large code models, thus possessing high compatibility.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121541852A_ABST
    Figure CN121541852A_ABST
Patent Text Reader

Abstract

The invention provides a method, a device, a system and equipment for preventing generation of redundant codes, a cluster, a product and a medium. The method is applied to an early warning module, the early warning module is externally connected to a large code model, and the method comprises the steps that in the reasoning process of the large code model, a semantic vector of a target code unit output by the large code model is obtained, the target code unit comprises one or more code units, and the semantic vector is stored in the target code unit; the code unit is a basic grammar unit in a code; on the basis of the semantic vector of the target code unit, predicting the probability that the code large model currently generates redundant codes; under the condition that the probability is larger than a preset probability threshold value, a stop notice is sent to the code large model, and the stop notice is used for indicating the code large model to conduct reasoning. According to the scheme, generation of redundant codes can be effectively prevented, and the code generation efficiency of the code large model is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of artificial intelligence, and in particular to a method, device, system, equipment, cluster, product and medium for preventing redundant code generation. BACKGROUND

[0002] With the development of code technology, code writing gradually tends to be automated. For example, a code large model can automatically generate a large amount of code according to user needs or prompts, thereby reducing the workload of programmers. In the code large model, a code unit (token) is the smallest language unit. The code large model divides natural language text into a code unit sequence composed of multiple code units. The mainstream decoding mechanism of the current code large model is the autoregressive decoding strategy: after inputting the code unit sequence, the code large model predicts the next code unit and merges it into the original code unit sequence. The process is repeated until an end code unit appears.

[0003] The code large model adopts the autoregressive decoding strategy, which may result in redundant code generation. After inputting the prompt word, the code large model generates code programs that meet the code requirements and does not stop the generation process, but continues to generate some code unrelated to the code requirements until the maximum generation length is reached. As shown in the following table, first, the prompt word (lines 1-5) is input into the code large model, which contains the signature of the target generation function and the description of the target function requirements, providing the context information needed by the code large model to complete the task. After receiving the prompt word, the code large model generates the target generation content in line 6. This line of code can well complete the code requirements. However, the code large model does not terminate the generation process as expected, but continues to generate content unrelated to solving the code task until the maximum generation length is reached, and stops generating at line 12, resulting in redundant code generation from line 7 to line 12, which reduces the code generation efficiency of the code large model. Figure 1 SUMMARY

[0004] The present application provides a method, device, system, equipment, cluster, product and medium for preventing redundant code generation, which can effectively prevent the generation of redundant code and improve the efficiency of code generation by the code large model.

[0005] In a first aspect, a method for preventing redundant code generation is provided, which is applied to a pre-warning module and is externally connected to a code large model. The method comprises the following steps:

[0006] ​In the inference process of the code large model, a semantic vector of a target code unit output by the code large model is obtained. Based on the semantic vector of the target code unit, a probability that the code large model currently generates redundant code is predicted. In a case where the probability is greater than a preset probability threshold, a stop notification is sent to the code large model. The target code unit includes one or more code units, and the code unit is a basic syntax unit in the code. The stop notification is used to instruct the code large model to stop inference.

[0007] The present application can improve the code generation efficiency of the code large model by warning the code large model to stop generating redundant code in time when the code large model generates redundant code. Moreover, the warning module is independent of the code large model and does not need to modify the code large model, so it can be compatible with the existing code large model.

[0008] In some possible designs, the target code unit includes a plurality of code units in a target code line. Based on the semantic vector of the target code unit, the probability that the code large model currently generates redundant code is predicted in the following manner:

[0009] The semantic vectors of the plurality of code units are used to determine a redundant code probability of each of the plurality of code units, where the redundant code probability is used to indicate a probability that the corresponding code is redundant code.

[0010] In a case where a proportion of code units with a redundant code probability greater than a probability threshold in the plurality of code units is greater than a proportion threshold, the inference process of the code large model is stopped.

[0011] In the above scheme, the probability of generating redundant code is predicted based on the plurality of code units in the target code line, which is more accurate than predicting the probability of generating redundant code based on a single code unit (for example, the last output code unit).

[0012] In some possible designs, the warning module includes a linear layer. Based on the semantic vector of the target code unit, the probability that the code large model currently generates redundant code is predicted in the following manner: the semantic vector of the target code unit is mapped to a two-dimensional vector through the linear layer, and the probability that the code large model currently generates redundant code is calculated based on the two-dimensional vector.

[0013] In some possible designs, the warning module needs to be trained before being used. Training the warning module includes the following steps: obtaining historical code generated by the code large model, labeling the historical code to obtain labeled historical code, and training the warning module based on the labeled historical code.

[0014] In some possible designs, the history code is labeled to obtain the labeled history code, which can include at least the following two manners:

[0015] In the first manner, an abstract syntax tree of the history code is constructed. A target function node in the abstract syntax tree is extracted based on a function word in the prompt for generating the history code. A plurality of relationship nodes having a direct calling relationship or an indirect calling relationship with the target function node are obtained from the abstract syntax tree. An ideal generation code is obtained by truncating the last line of code of each relationship node, and a continue generation label is labeled on the ideal generation code, where the ideal generation code is a part of the history code except redundant code, and the continue generation label is used to instruct the code large model to continue generating code. The code of the history code except the ideal generation code is taken as redundant generation code, and a stop generation label is labeled on the redundant generation code to obtain the labeled history code, where the stop generation label is used to instruct the code large model to stop generating code.

[0016] In the second manner, a redundant generation code background knowledge history code and a prompt for generating the history code are sent to a large language model semantic analyzer. The ideal generation code is extracted from the history code by the large language model semantic analyzer according to the redundant generation code background knowledge, the history code and the prompt, and a continue generation label is labeled on the ideal generation code. The code of the history code except the ideal generation code is taken as redundant generation code, and a stop generation label is labeled on the redundant generation code to obtain the labeled history code.

[0017] In the above manners, the first manner does not need to use the large language model semantic analyzer, effectively reducing the size of the system, and the second manner uses the large language model semantic analyzer, effectively improving the convenience and accuracy of use.

[0018] In some possible designs, the specific implementation of the pre-warning module is obtained by training based on the labeled history code.

[0019] A plurality of code unit sequences are constructed based on the labeled history code. Each code unit sequence is input into the code large model to obtain a training semantic vector corresponding to the code unit sequence output by the code large model, under a condition that parameters of the code large model are frozen. When the pre-warning module is trained under the condition that the parameters of the code large model are frozen, the parameters of the code large model are not updated, each training semantic vector is input into the pre-warning module to obtain a predicted redundant generation probability, and the training of the pre-warning module is completed.

[0020] In a second aspect, a device for preventing redundant code generation is provided. The device is external to a large code model, and includes:

[0021] a obtaining module configured to obtain semantic vectors of target code units output by the large code model during an inference process of the large code model, the target code units including one or more code units, the code units being basic syntax units in code;

[0022] a predicting module configured to predict a probability that the large code model currently generates redundant code based on the semantic vectors of the target code units;

[0023] a stopping module configured to send a stop notification to the large code model if the probability is greater than a preset probability threshold, wherein the stop notification is used to instruct the large code model to stop the inference.

[0024] In a third aspect, a system for preventing redundant code generation is provided. The system includes:

[0025] a client configured to send a code generation instruction;

[0026] a large code model configured to generate target code units based on the code generation instruction;

[0027] a device for preventing redundant code generation configured to obtain semantic vectors of target code units output by the large code model during an inference process of the large code model, the target code units including one or more code units, the code units being basic syntax units in code, predict a probability that the large code model currently generates redundant code based on the semantic vectors of the target code units, and send a stop notification to the large code model if the probability is greater than a preset probability threshold, wherein the stop notification is used to instruct the large code model to perform the inference.

[0028] In a fourth aspect, a chip system is provided. The chip system includes a processor and a power supply circuit configured to supply power to the processor. The processor is configured to perform the operation steps of the method according to any one of the first aspect.

[0029] In a fifth aspect, a computing device is provided. The computing device includes a processor and a memory.

[0030] The processor is configured to execute instructions stored in the memory to cause the computing device to perform the operation steps of the method according to any one of the first aspect.

[0031] In a sixth aspect, a computing device cluster is provided. The computing device cluster includes at least one computing device, and each computing device includes a processor and a memory.

[0032] The processor of the at least one computing device is configured to execute instructions stored in the memory of the at least one computing device to cause the cluster of computing devices to perform the operational steps of the method as described in any of the first aspects.

[0033] In a seventh aspect, a computer program product comprising instructions is provided, which, when executed by a cluster of computing devices, cause the cluster of computing devices to perform the operational steps of the method described in any of the first aspects.

[0034] Eighthly, a computer-readable storage medium is provided, including computer program instructions that, when executed by a cluster of computing devices, perform operational steps as described in any of the first aspects. Attached Figure Description

[0035] Figure 1 This is a schematic diagram illustrating a method for generating redundant code as described in this application;

[0036] Figure 2 A schematic diagram of a system for preventing redundant code generation is provided in this application;

[0037] Figure 3 A flowchart illustrating a method for preventing redundant code generation provided in this application;

[0038] Figure 4 A flowchart illustrating another method for preventing redundant code generation provided in this application;

[0039] Figure 5 A flowchart illustrating a training method for an early warning module provided in this application;

[0040] Figure 6 This application provides a code implementation diagram with automatic code annotation for the code portion;

[0041] Figure 7 A schematic diagram of a device for preventing redundant code generation is provided in this application;

[0042] Figure 8 A schematic diagram of a system for preventing redundant code generation is provided in this application;

[0043] Figure 9 A schematic diagram of the structure of a computing device provided in this application;

[0044] Figure 10 This application provides a schematic diagram of the structure of a computing device cluster;

[0045] Figure 11 This is a schematic diagram of another computing device cluster provided in this application. Detailed Implementation

[0046] See Figure 2 , Figure 2 This is a schematic diagram of the structure of a system for preventing redundant code generation provided in this application. For example... Figure 2 As shown, the redundant code generation prevention system of this application includes a client 110 and a redundant code generation prevention device 120. The number of clients 110 in this architecture can be one or more, and this application does not impose a specific limitation. The client 110 and the redundant code generation prevention device 120 establish a communication connection through a network. This communication connection can be a wired connection or a wireless connection. The network can be the public Internet, a local area network (LAN), a virtual private network (VPN), a dedicated line such as fiber optic lines, copper wires, satellite connections, etc., or a wireless network such as wireless LAN (Wi-Fi), cellular networks, etc., and this application does not impose a specific limitation.

[0047] Client 110 is deployed on terminal devices or computing devices to enable human-computer interaction. Terminal devices include personal computers, smartphones, wearable devices, handheld processing devices, tablets, mobile laptops, augmented reality (AR) devices, virtual reality (VR) devices, smart conferencing devices, etc., and are not specifically limited here. The description of computing devices can be found above and will not be repeated here. Client 110 can also be deployed on physical servers, such as ARM servers or x86 servers, and this application does not specifically limit its deployment.

[0048] In specific implementation, client 110 can be software or application running on a terminal device or computing device controlled by the user, such as a personal computer (PC) client, a World Wide Web (web) client accessed through a browser, an application (APP) client running on a mobile terminal, or a console of a cloud platform. This application does not make any specific limitations.

[0049] Optionally, client 110 can be a client specifically designed to prevent the generation of redundant code, which can be used when a user needs to prevent the generation of redundant code.

[0050] Optionally, client 110 may also be a comprehensive client that includes the above-mentioned function of preventing the generation of redundant code, such as a code generation client. These comprehensive drawing clients may include not only the function of preventing the generation of redundant code, but also other functions, such as the function of generating code. The above examples are for illustration only and are not specifically limited in this application.

[0051] Optionally, client 110 can also be a client of a cloud platform, used for users to purchase and rent various cloud services. The solution for preventing redundant code generation provided in this application can be one of these cloud services, and users can purchase this cloud service separately to prevent redundant code generation; or, the cloud platform provides users with a comprehensive service, and the above-mentioned function of preventing redundant code generation can be a sub-service of this comprehensive cloud service. For example, if a user purchases a code generation service, the above-mentioned function of preventing redundant code generation can be a sub-service of this cloud service. This application does not make any specific limitations.

[0052] The redundant code generation prevention device 120 can be deployed on computing devices, or on a cluster of computing devices consisting of multiple computing devices. The computing devices can be bare metal servers (BMS), virtual machines, containers, or storage devices. A BMS refers to a general-purpose physical server, such as an ARM server or an x86 server; a virtual machine refers to a complete computer system simulated by software, possessing full hardware system functionality and running in a completely isolated environment. Any task that can be performed on a physical computer can also be performed in a virtual machine. When creating a virtual machine on a computing device, a portion of the physical machine's hard drive and memory capacity is used as the virtual machine's hard drive and memory capacity. Each virtual machine has an independent basic input / output system (BIOS), hard drive, and operating system, and can be operated like a physical machine. A container is a portable software unit that can combine an application and all its dependencies into a single software package. This package is not limited by the underlying host operating system, thus eliminating the need to build complex environments and simplifying the application development and deployment process. In practice, the computing device cluster can be a cloud data center, an enterprise private cluster, or a hybrid cloud environment, which is a deployment mode that uses both public and private clouds. This application does not impose any specific limitations.

[0053] In the above examples, the redundant code generation prevention system only exemplifies the client 110 and the redundant code generation prevention device 120. In practical applications, the redundant code generation prevention system may also include one or more of the following: a large code model and a large language model.

[0054] See Figure 3 , Figure 3This application provides a flowchart illustrating a method for preventing redundant code generation. For example... Figure 3 As shown, the method for preventing redundant code generation in this application includes the following steps:

[0055] S110: During the reasoning process of the large code model, obtain the semantic vector of the target code unit output by the large code model.

[0056] Large-scale code models are artificial intelligence models that utilize deep learning techniques, particularly large-scale language models, to assist in programming and software development. Large-scale code models can include CodeGeeX4-ALL-9B, Yuan2.0, LLaMA, LLaVA, Mistral, Mixtral-MoE, Qwen, Yi, Gemma, Baichuan, ChatGLM, Phi, Mathstral 7B, Mamba2 architecture code models, Tongyi Lingma, Huawei Cloud Pangu, SenseTime Xiaohuanxiong, Zhipu Codegeex, and many more.

[0057] During inference, the large code model will output one or more lines of code, each line of code can include one or more code units (tokens). A code unit is a basic syntactic unit in the code. Each code unit can be one of the following types:

[0058] (1) Keywords. Keywords can be words with specific meanings, such as if, while, class, etc.

[0059] (2) Identifiers. Identifiers are used to represent objects in a program, such as variable names and function names.

[0060] (3) Literals. Literals can be specific values ​​such as numbers and strings.

[0061] (4) Operators. Operators can be symbols used to perform calculations, such as +, -, *, / , etc.

[0062] (5) Separators. Separators can be used to separate different parts of the code, such as commas, semicolons, parentheses, etc.

[0063] (6) Comments. Comments have no effect during program execution, but they are still recognized as specific units of code.

[0064] A target code unit may include one or more code units. For example, a target code unit may be the latest code unit output by the large code model, or it may be one or more of the latest lines of code units output by the large code model. In the following description, we will use the example of the latest code unit output by the large code model as the target code unit.

[0065] Specifically, prompt words can be input into the code big model so that the code big model can obtain the function signature and function requirement description of the prompt words, then automatically infer and generate code, and determine the semantic vector of the latest output code unit of the code big model.

[0066] The code-big model can be a multi-layer attention layer architecture. At time t, the code-big model is fed a sequence of text units X = {x_1, x_2, ..., x_t}. The code-big model models the relationships between these text units based on an attention mechanism. After processing through multiple attention layers, the code-big model outputs a high-dimensional vector h_t. The layer from which the code-big model outputs this high-dimensional vector is not fixed; for example, the last layer might output the high-dimensional vector, representing the semantic information of the input text sequence at time t. This high-dimensional vector is the semantic vector.

[0067] Furthermore, the code-big model inputs the semantic vector h_t into a linear classifier to predict the probability distribution of code units appearing in the next time step. The code-big model typically includes a linear layer W_LM, which maps the semantic vector h_t to the vocabulary dimension, and then the probability distribution of code units in the next time step can be calculated using a prediction formula:

[0068]

[0069] Where, x n+1 Let P(x) be the sequence number of the code unit at the next moment. n+1 ) represents the probability distribution of the code unit at the next time step, and softmax() is one of the prediction formulas, such as the softmax function, etc. t For the semantic vector of the target code unit, These are the weights of the linear layer.

[0070] Understandably, during the reasoning process of code generation, whenever the large code model generates a new code unit, the early warning module obtains the semantic vector output by the large code model.

[0071] S120: Based on the semantic vector of the target code unit, predict the probability that the code big model currently generates redundant code.

[0072] Specifically, while the code big model outputs the probability distribution of code units at the next time step, the early warning module can use semantic vectors as input to predict the probability that the code big model will generate redundant code at the current time.

[0073] The early warning module may include one or more neural networks. The neural networks may include one or more types of deep neural networks, convolutional neural networks, etc.

[0074] S130: If the probability is greater than the preset probability threshold, send a stop notification to the code model.

[0075] The preset probability threshold can be set manually based on experience. When high accuracy is required, the preset probability threshold can be set higher; when high omission rate is required, the preset probability threshold can be set lower. Users can set it according to their experience.

[0076] The stop notification is used to instruct the large code model to stop inference.

[0077] Specifically, when the warning module predicts that the probability of generating extra data is greater than the preset probability threshold stop_threshold, the warning module will predict and stop the current inference process.

[0078] For example, at time n, given the sequence of code units: X_n={x_1,x_2,...,x_n}, inputting it into the code big model yields the predicted code unit token x_(n+1) and semantic vector for the next time step. The semantic vector is then input into the warning module to obtain the probability p_stop of the current occurrence of redundant generation. When the probability p_stop of the current occurrence of redundant generation exceeds the preset probability threshold θ_stop, a stop notification is sent to the code big model to stop the inference process of the code big model.

[0079] This application improves the code generation efficiency of a large code model by having an early warning module promptly interrupt the model when redundant code is generated during inference, thus preventing further generation of unnecessary code. Furthermore, the early warning module is independent of the large code model, requiring no modification and ensuring compatibility with existing large code models.

[0080] To further improve the accuracy of preventing redundant code generation, the target code unit can be made to include multiple code units within the target line of code. See also Figure 4 , Figure 4 This is a flowchart illustrating another method for preventing redundant code generation provided in this application. For example... Figure 4 As shown, the method for preventing redundant code generation in this application includes:

[0081] S210: Obtain the semantic vector of each code unit in the latest output line of code during the inference process of the large code model.

[0082] For example, the code big model includes the following sequence of code units for the latest output of the prompt word:

[0083] A n =(a1,a2,...,a n );

[0084] Among them, A n Let n be a sequence of code units, where n is the number of code units in a line of code, a1 is the first code unit, a2 is the second code unit, ..., a n Let n be the nth code unit. After determining the sequence of code units for the latest output line of code, the semantic vector for each code unit in the sequence can be determined separately.

[0085] It is understood that this explanation uses the example of a target code unit including the latest line of code. In practical applications, the target code unit can also include the latest two, three, or even more lines of code, or it can include the last few code units in the latest line (not enough for one line), etc. No specific limitation is made here.

[0086] S220: Determine the probability of redundant code in the semantic vector of each code unit in the latest output code line.

[0087] Determine the redundant code probability of the semantic vector for each code unit in the latest output code line. Continue with code unit sequence A. n =(a1,a2,…,a n For example, the probability p1 of generating the semantic vector of code unit a1 based on code unit a1, the probability p2 of generating the semantic vector of code unit a2 based on code unit a2, and so on, based on code unit a... n Generate code unit a n The probability p of redundant code in semantic vectors n .

[0088] S230: Define code units with a redundancy probability greater than a preset probability threshold as redundancy code units, and determine the proportion of redundancy code units in each code unit in the latest output code line.

[0089] Continue with code unit sequence A n =(a1,a2,…,a n For example, when the probability of redundant code p1 is greater than a preset probability threshold, code unit a1 is identified as a redundant code unit; when the probability of redundant code p1 is less than or equal to the preset probability threshold, code unit a1 is not identified as a redundant code unit. Similarly, when the probability of redundant code p2 is greater than the preset probability threshold, code unit a2 is identified as a redundant code unit; when the probability of redundant code p2 is less than or equal to the preset probability threshold, code unit a2 is not identified as a redundant code unit. And so on. n When the probability exceeds a preset threshold, code unit a will be... n If a code is identified as a redundant code unit, and the probability of the redundant code is pn When the probability is less than or equal to a preset probability threshold, code unit a will not be set. n It has been identified as a redundant code unit.

[0090] Then, by dividing the number of redundant code units by the number of code units in the code unit sequence, we can obtain the proportion of the redundant code units in each code unit in the latest output code line.

[0091] S240: If the proportion of code units with a redundant code probability greater than the probability threshold among the multiple code units is greater than the proportion threshold, stop the reasoning process of the large code model.

[0092] The specificity threshold can be set manually based on experience. When high accuracy is required, the specificity threshold can be set higher; when the omission rate is required to be lower, the specificity threshold can be set lower. Users can set it according to their experience.

[0093] The method for preventing redundant code generation provided in this embodiment calculates the probability of redundant generation for each code unit of the latest line of code output by the large code model, and judges the probability of the current output of redundant code by the proportion of redundant code units in each line of code. This can optimize the robustness of preventing code generation and improve the accuracy of preventing code generation.

[0094] In some embodiments of this application, the early warning module mentioned in the above embodiments is further described. This early warning module may include a linear layer. Based on this, the process of step S120—predicting the probability of the large code model generating redundant code based on the semantic vector of the target code unit—is described. This process may include:

[0095] S1: The semantic vector of the latest output code unit is mapped to a two-dimensional vector through a linear layer.

[0096] A linear layer is a fundamental component of a neural network. It performs matrix multiplication between the input vector and the weight matrix, plus a bias vector. Therefore, a linear layer can consist of a weight matrix and a bias vector. The weight matrix is ​​a two-dimensional matrix with dimensions equal to the output vector dimension (2 in this example) multiplied by the input vector dimension. Each element in the weight matrix represents a model parameter, which is updated during training using optimization algorithms (such as stochastic gradient descent). The bias vector is a one-dimensional vector with dimensions equal to the output vector dimension, and it is also updated during training.

[0097] S2: Calculate the probability of the current generation of redundant code in the large code model based on the two-dimensional vector.

[0098] Specifically, as shown in the following formula:

[0099]

[0100] Among them, h t Code unit a for input to the early warning module t The semantic vector, where t is any index in the code unit sequence, t is greater than or equal to 1, and less than or equal to n, W GenGuard For linear layers, For linear layer parameters, p is a two-dimensional vector obtained by mapping semantic vectors through a linear layer. continue p is the probability of non-redundant generation. stop The probability of generating an extra one.

[0101] In some embodiments of this application, the training process of the early warning module mentioned in the foregoing embodiments is described, such as... Figure 5 As shown, the process may include:

[0102] Step S310: Obtain historical code that has been generated by the large code model and contains redundant code.

[0103] Specifically, task prompts can be generated based on code from various programming languages, and code containing redundant code can be sampled from a large code model to serve as the generated historical code.

[0104] The redundancy generation problem varies across different large code models. Therefore, to better obtain data consistent with the large code model, prompt words can be used to sample historically generated code from the large code model. In this process, only prompt words containing function signatures and comments are required from the user. Furthermore, prompt words can be used to sample historical code containing redundant generated code from the large code model. Simultaneously, to ensure that the GenGuard warning module has the ability to predict redundant generated code across different programming languages, prompt words for code generation tasks in multiple programming languages ​​can be used to sample historical code containing redundant code from the large code model in various programming languages. For the sampling method in the large code model, greedy decoding, temperature sampling, and other methods can be used.

[0105] S320: Annotate historical codes to obtain the annotated historical codes.

[0106] Understandably, after sampling historical code from a large code model, the sampled historical code can be labeled to obtain training data for GenGuard. The purpose of the data labeling stage is to identify and distinguish between ideal generated code and redundant generated code in the original code.

[0107] Specifically, code analyzers based on syntax structure and those based on semantics can automatically annotate code units in historical code to indicate whether to continue generating tags or stop generating tags.

[0108] S330: Train the early warning module using previously labeled historical codes.

[0109] It is understandable that the warning module is trained using labeled historical code, enabling it to learn to determine whether the output at the next time step is redundant based on the input semantic vector.

[0110] For a single training iteration, because the output of the warning module should be as close as possible to the desired prediction, historical codes from a training sample can be input into the warning module to obtain predictions based on those historical codes. The annotations of these historical codes are then used as the target value. The difference between the current prediction and the target value is compared, and the weight vector of each layer of the warning module is updated based on this difference (of course, there is usually an initialization process before the first update, i.e., pre-configuring parameters for each layer in the warning module). This process is repeated until the difference between the predicted value and the target value output by the warning module is sufficiently small. Therefore, it is necessary to predefine "how to compare the difference between the predicted value and the true value," which is the loss function or objective function. These are important equations used to measure the difference between the current predicted value and the true value. Taking the loss function as an example, a higher output value (loss) indicates a greater difference, so training the warning module becomes a process of minimizing this loss as much as possible.

[0111] The method for preventing redundant code generation provided in this embodiment only requires training a lightweight model warning block (GenGuard), without needing to train the parameters of a large code model with a huge number of parameters. On the one hand, this reduces the computational resources required by the method and makes it easy to expand. On the other hand, since no training is required, it will not affect the knowledge of the large code model itself, thus affecting the quality of the generated results of the large code model.

[0112] In some embodiments of this application, the process of annotating historical codes in step S320 above to obtain annotated historical codes is described. This process may include the following two cases:

[0113] The first method involves annotation using a code analyzer based on syntax structure.

[0114] S11. Constructing the Abstract Syntax Tree (AST) of historical code. The Abstract Syntax Tree (AST) is a crucial data structure in the compilation and parsing process of programming languages. It represents the abstract syntactic structure of source code and is a tree-like structure generated by the compiler or interpreter after analyzing the source code. An AST consists of nodes (e.g., root node, leaf nodes, and intermediate nodes), each node representing a syntactic structure or operator in the source code. The root node typically represents the entire program or code block. Leaf nodes represent basic elements such as variables, constants, and operators. Intermediate nodes represent more complex syntactic structures, such as function calls, conditional statements, and loops.

[0115] S12. Determine the function words in the prompts of the historical code, and extract the target function node in the abstract syntax tree through the function words. The target function node is the node corresponding to the function word.

[0116] S13. Obtain multiple relation nodes from the abstract syntax tree that have a direct or indirect calling relationship with the target function node.

[0117] S14. Truncate the last line of code in each relation node to obtain the truncated code.

[0118] S15. Treat all truncated code as ideal generated code, and label the ideal generated code with a "continue generation" tag. The ideal generated code is the portion of the historical code excluding redundant code, and the "continue generation" tag indicates that the large code model should continue generating code.

[0119] S16. All code in the historical code other than the ideal generated code is considered redundant generated code, and a "stop generating" label is added to this redundant generated code to obtain the labeled historical code. The "stop generating" label is used to indicate that the large code model should stop generating code.

[0120] Understandably, the core idea of ​​a syntax-based code analyzer is to extract the ideal generated code from the generated results by analyzing the syntax structure of the code. Specifically, a syntax-based code analyzer will extract all functions that generate `diamagnetic` that have dependencies and call relationships with the target function. This part will be considered ideal generated code, while the rest, since it is unrelated to the target function, will be considered redundant generated code.

[0121] The second method involves automatic annotation using a semantic code analyzer.

[0122] Understandably, the core idea of ​​semantic-based code analyzers is to leverage large language models with strong code understanding capabilities, such as ChatGPT, to analyze sampled code and extract ideal generated code. This type of code analyzer is typically used when syntax-based code analyzers fail, such as when the code generated by a large code model contains multiple lines of comments.

[0123] S21. Send redundant generated code background knowledge history code, as well as prompt words for generating history code, to the large language model semantic analyzer.

[0124] S22. Using a large language model semantic analyzer, extract ideal generated code from historical code based on background knowledge of redundant generated code, historical code, and prompt words, and label the ideal generated code with a "continue generating" tag.

[0125] After receiving context learning guidance, the large language model semantic analyzer sends an instruction to extract the ideal generated code, in order to obtain the ideal generated code of the historical code, and to mark the ideal generated code with a "continue generation" label.

[0126] S23. Take the code in the historical code other than the ideal generated code as redundant generated code, and mark the redundant generated code with a stop generating label to obtain the labeled historical code.

[0127] Specifically, a large language model can be used as a semantic analyzer, guided by prompts to complete code analysis tasks. The prompts first introduce the background of redundant generation to the large language model; second, they detail the task instructions, requiring the model to extract the ideal portion of the generated content; and finally, multiple examples are used to guide the model to correctly complete the task through contextual learning. After extracting the ideal generated code, the remaining portion is considered redundant and marked accordingly.

[0128] For example Figure 6 , Figure 6 The code implementation diagram with automatic annotations is shown.

[0129] The method for preventing redundant code generation provided in this embodiment automatically annotates the data using a syntax-based code analyzer and a semantic-based code analyzer, thus avoiding manual annotation and reducing annotation costs.

[0130] In some embodiments of this application, the process of training the early warning module through annotated historical code in step S330 is described. This process may include:

[0131] S1. Construct multiple code unit sequences based on the labeled historical code.

[0132] S2. With the parameters of the large code model frozen, each code unit sequence is input into the large code model to obtain the training semantic vector corresponding to that code unit sequence output by the large code model. Note that when training the early warning module while the parameters of the large code model are frozen, the parameters of the large code model are not updated.

[0133] Specifically, at time n, given a sequence of code units: X_n = (x_1, x_2, ..., x_n) and the label y_n of the prediction result of the warning module at time n, the token sequence is first input into the code big model to obtain the semantic vector h_n at time t, h_n = LLM(X_n), where LLM(·) represents the code big model.

[0134] S3. Input each training semantic vector into the early warning module so that the early warning module can predict the excess generation probability using the softmax probability prediction formula, thereby completing the training of the early warning module.

[0135] The softmax probability prediction formula is as follows:

[0136]

[0137] Among them, h n For this training semantic vector, Here, p represents the linear layer parameters of the early warning module, softmax() is the softmax probability calculation function, and p represents the linear layer parameters of the early warning module. continue p represents the probability distribution of generating labels for the code unit corresponding to the given training semantic vector. stop p represents the probability distribution of stopping label generation for the code unit corresponding to this training semantic vector. stop This is the redundant generation probability predicted by the early warning module for this training semantic vector.

[0138] Furthermore, during the training of the prediction module GenGuard, cross-entropy loss can be used to optimize the parameters of the prediction module GenGuard.

[0139] Specifically, the early warning module can be trained using the cross-entropy loss optimization formula.

[0140] The cross-entropy loss optimization formula is as follows:

[0141] Loss = -[y n log(p stop )+(1-y n log(1-p) stop )];

[0142] Where Loss is the training loss of the early warning module, yn The label value y is the label value of the code unit. When the code unit stops generating labels, the label value y is... n When the value is 1, the expected label value y of the code unit is... n It is 0.

[0143] This application also provides a device for preventing the generation of redundant code, such as Figure 7 As shown, it includes:

[0144] The acquisition module 210 is used to acquire the semantic vector of the target code unit output by the code big model during the reasoning process of the code big model. The target code unit includes one or more code units, and the code unit is a basic syntactic unit in the code.

[0145] The prediction module 220 is used to predict the probability that the code big model currently generates redundant code based on the semantic vector of the target code unit;

[0146] The stop module 230 is used to send a stop notification to the code big model when the probability is greater than a preset probability threshold, wherein the stop notification is used to instruct the code big model to stop inference.

[0147] The acquisition module 210, prediction module 220, and stopping module 230 can all be implemented in software or in hardware. For example, the implementation of the prediction module will be described below. Similarly, the implementation methods of the prediction module and the stopping module can be found in the implementation method of the prediction module.

[0148] As an example of a software functional unit, a prediction module may include code running on a compute instance. A compute instance may include at least one of a physical host (computing device), a virtual machine, or a container. Furthermore, the aforementioned compute instance may be one or more. For example, a prediction module may include code running on multiple hosts / virtual machines / containers. It should be noted that the multiple hosts / virtual machines / containers used to run the code may be distributed within the same region or in different regions. Further, the multiple hosts / virtual machines / containers used to run the code may be distributed within the same availability zone (AZ) or in different AZs, each AZ comprising one or more geographically proximate data centers. Typically, a region may include multiple AZs.

[0149] Similarly, multiple hosts / virtual machines / containers used to run this code can be distributed within the same Virtual Private Cloud (VPC) or across multiple VPCs. Typically, a VPC is set up within a region. Communication between two VPCs within the same region, as well as between VPCs in different regions, requires a communication gateway to be set up within each VPC to enable interconnection between VPCs.

[0150] As an example of a hardware functional unit, a prediction module may include at least one computing device, such as a server. Alternatively, the prediction module may be implemented using a central processing unit (CPU), an application-specific integrated circuit (ASIC), or a programmable logic device (PLD). The PLD can be implemented using a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), a data processing unit (DPU), a neural network processing unit (NPU), a system-on-chip (SoC), an offload card, an accelerator card, or any combination thereof.

[0151] The prediction module includes multiple computing devices that can be distributed within the same region or in different regions. Similarly, the prediction module can be distributed within the same Availability Zone (AZ) or in different AZs. Likewise, the prediction module can be distributed within the same Virtual Private Cloud (VPC) or multiple VPCs. These multiple computing devices can be any combination of computing devices such as servers, ASICs, PLDs, CPLDs, FPGAs, GALs, DPUs, NPUs, SoCs, offloading cards, and accelerator cards.

[0152] It should be noted that, in other embodiments, the prediction module can be used to execute any step in the method for preventing redundant code generation, the acquisition module can be used to execute any step in the method for preventing redundant code generation, and the stop module can be used to execute any step in the method for preventing redundant code generation. The steps implemented by the prediction module, the acquisition module, and the stop module can be specified as needed. By implementing different steps in the method for preventing redundant code generation through the prediction module, the acquisition module, and the stop module, all functions of the device for preventing redundant code generation can be realized.

[0153] This application also provides a system for preventing the generation of redundant code, such as Figure 8 As shown, it includes:

[0154] Client 310 is used to send code generation instructions;

[0155] Code Model 320 is used to generate target code units based on code generation instructions.

[0156] The early warning module 330 is used to acquire the semantic vector of the target code unit output by the large code model during the inference process. The target code unit includes one or more code units, which are basic syntactic units in the code. Based on the semantic vector of the target code unit, the module predicts the probability that the large code model is currently generating redundant code. If the probability is greater than a preset probability threshold, the module sends a stop notification to the large code model, wherein the stop notification is used to instruct the large code model to continue inference. Both the large code model 320 and the early warning module 330 can be implemented in software or in hardware. For example, the implementation of the early warning module 330 will be described below. Similarly, the implementation of the early warning module 330 can refer to the implementation method of the early warning module 330. The early warning module can be the aforementioned device for preventing redundant code generation.

[0157] As an example of a software functional unit, the alerting module 330 may include code running on a computing instance. The computing instance can be at least one of a physical host (computing device), a virtual machine, a container, or other computing devices. Furthermore, the aforementioned computing device can be one or more. For example, the alerting module 330 may include code running on multiple hosts / virtual machines / containers. It should be noted that the multiple hosts / virtual machines / containers used to run the application can be distributed in the same region or in different regions. The multiple hosts / virtual machines / containers used to run the code can be distributed in the same Availability Zone (AZ) or in different AZs, each AZ including one data center or multiple geographically proximate data centers. Typically, a region may include multiple AZs.

[0158] Similarly, multiple hosts / virtual machines / containers used to run this code can be distributed within the same VPC or across multiple VPCs. Typically, a VPC is set up within a single region. Communication between two VPCs within the same region, and between VPCs in different regions, requires a communication gateway to be set up within each VPC to enable interconnection between VPCs.

[0159] As an example of a hardware functional unit, the early warning module 330 may include at least one computing device, such as a server. Alternatively, the early warning module 330 may also be a device implemented using a CPU, ASIC, PLD, CPLD, FPGA, GAL, DPU, NPU, SoC, offload card, accelerator card, etc. The aforementioned PLD may be implemented using a CPLD, FPGA, GAL, or any combination thereof.

[0160] The multiple computing devices included in the early warning module 330 can be distributed in the same region or in different regions. Similarly, the multiple computing devices included in the early warning module 330 can be distributed in the same Availability Zone (AZ) or in different AZs. Likewise, the multiple computing devices included in the early warning module 330 can be distributed in the same Virtual Private Cloud (VPC) or in multiple VPCs. These multiple computing devices can be any combination of computing devices such as servers, ASICs, PLDs, CPLDs, FPGAs, GALs, DPUs, NPUs, SoCs, offloading cards, and accelerator cards.

[0161] Optionally, the system for preventing redundant code generation may also include a large language model 340. The large language model 340 may be implemented in a similar manner to the large code model 320, which will not be elaborated here.

[0162] This application also provides a chip system including a processor and a power supply circuit. The power supply circuit supplies power to the processor, and the processor executes the operation steps corresponding to the method of preventing redundant code generation. For simplicity, further details are omitted here. The processor can be implemented using a GPU, or it can be implemented using computing devices such as a DPU, NPU, XPU, SoC, offload card, or accelerator card.

[0163] This application also provides a computing device 400. For example... Figure 9 As shown, the computing device 400 includes a bus 402, a processor 404, a memory 406, and a communication interface 408. The processor 404, the memory 406, and the communication interface 408 communicate with each other via the bus 402. The computing device 400 can be a server or a terminal device. It should be understood that this application does not limit the number of processors and memories in the computing device 400.

[0164] Bus 402 can be a Peripheral Component Interconnect Express (PCIe) bus, an Extended Industry Standard Architecture (EISA) bus, a Unified Bus (Ubus or UB), a Compute Express Link (CXL) bus, a Cache Coherent Interconnect for Accelerators (CCIX) bus, etc. The Unified Bus is also known as the Lingqu Bus. Buses can be divided into address buses, data buses, control buses, etc. For ease of representation, Figure 9 The bus 402 is represented by only one line, but this does not mean that there is only one bus or one type of bus. Bus 402 may include a path for transmitting information between various components of computing device 400 (e.g., memory 406, processor 404, communication interface 408). The unified bus may also be called the Lingqu bus.

[0165] Processor 404 may include any one or more of the following computing devices: central processing unit (CPU), graphics processing unit (GPU), microprocessor (MP) or digital signal processor (DSP), ASIC, FPGA, CPLD, NPU, SoC, offload card, accelerator card, etc.

[0166] Memory 406 may include volatile memory, such as random access memory (RAM). Processor 404 may also include non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid state drive (SSD). Furthermore, memory 406 may also be implemented using storage class memory (SCM), phase change memory (PCM), or other types of storage media.

[0167] It is worth noting that the same type of storage medium can be configured in the same computing device to realize the function of memory 406, or two or more types of storage media can be configured to realize the function of memory 406. This application does not limit this.

[0168] The memory 406 stores executable program code, which the processor 404 executes to implement the functions of the aforementioned prediction module, acquisition module, and stop module, thereby preventing the generation of redundant code. In other words, the memory 406 stores instructions for executing the method to prevent the generation of redundant code.

[0169] Alternatively, the memory 406 stores executable code, which the processor 404 executes to implement the aforementioned early warning module 330 and code big model 320, thereby preventing the generation of redundant code. In other words, the memory 406 stores instructions for executing methods to prevent the generation of redundant code.

[0170] The communication interface 408 uses transceiver modules such as, but not limited to, network interface cards and transceivers to enable communication between the computing device 400 and other devices or communication networks.

[0171] As one possible implementation, the computing device 400 may also include a chip system, which includes a processor and a power supply circuit. The power supply circuit supplies power to the processor, and the processor executes the operation steps corresponding to the method of preventing redundant code generation. For simplicity, further details are omitted here. The processor can be implemented using a GPU, or it can be implemented using computing devices or AI chips such as a DPU, NPU, XPU, SoC, offloading card, or accelerator card.

[0172] As one possible implementation, the computing device 400 may include multiple types of processors 404, meaning the computing device 400 is a heterogeneous device. For example, the computing device 400 may include a CPU and a GPU, and at least one of the processors 404 may execute the operation steps corresponding to the method of preventing redundant code generation. For the sake of brevity, further details will not be elaborated here.

[0173] This application also provides a computing device cluster. The computing device cluster includes at least one computing device. The computing device can be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device can also be a terminal device such as a desktop computer, a laptop computer, or a smartphone.

[0174] like Figure 10As shown, the computing device cluster includes at least one computing device 400. The memory 406 of one or more computing devices 400 in the computing device cluster may store the same instructions for executing methods to prevent redundant code generation.

[0175] In some possible implementations, the memory 406 of one or more computing devices 400 in the computing device cluster may also store partial instructions for executing methods to prevent redundant code generation. In other words, a combination of one or more computing devices 400 can jointly execute instructions for executing methods to prevent redundant code generation.

[0176] It should be noted that the memory 406 in different computing devices 400 within the computing device cluster can store different instructions, each used to execute a portion of the functions of the early warning module 330. That is, the instructions stored in the memory 406 of different computing devices 400 can implement the functions of one or more modules among the prediction module, acquisition module, and stop module.

[0177] In some possible implementations, one or more computing devices in a computing device cluster can be connected via a network. This network can be a wide area network (WAN) or a local area network (LAN), etc. Figure 11 One possible implementation is shown. For example... Figure 11 As shown, the two computing devices 400A and 400B are connected via a network. Specifically, they are connected to the network through communication interfaces in each computing device. In this possible implementation, the memory 406 in computing device 400A stores instructions for executing the prediction module. Meanwhile, the memory 406 in computing device 400B stores instructions for executing the acquisition and stop modules.

[0178] Figure 11 The connection method between the computing device clusters shown can be such that, considering the method for preventing redundant code generation provided in this application requires a large amount of data storage and computation, the functions implemented by the acquisition module and the stop module are delegated to the computing device 400B.

[0179] It should be understood that Figure 11 The functions of the computing device 400A shown can also be performed by multiple computing devices 400. Similarly, the functions of the computing device 400B can also be performed by multiple computing devices 400.

[0180] This application also provides another computing device cluster. The connection relationships between the computing devices in this computing device cluster can be similarly referred to... Figure 10 and Figure 11The connection method of the computing device cluster is different in that the memory 406 of one or more computing devices 400 in the computing device cluster can store the same instructions for executing methods to prevent redundant code generation.

[0181] In some possible implementations, the memory 406 of one or more computing devices 400 in the computing device cluster may also store partial instructions for executing methods to prevent redundant code generation. In other words, a combination of one or more computing devices 400 can jointly execute instructions for executing methods to prevent redundant code generation.

[0182] It should be noted that the memory 406 in different computing devices 400 within the computing device cluster can store different instructions for executing certain functions of the system that prevents redundant code generation. That is, the instructions stored in the memory 406 of different computing devices 400 can implement the functions of one or more devices in the early warning module 330 and the code big model 320.

[0183] This application also provides a computer program product containing instructions. The computer program product may be a software or program product containing instructions capable of running on a computing device or stored on any usable medium. When the computer program product is run on at least one computing device, it causes the at least one computing device to execute a method to prevent the generation of redundant code.

[0184] This application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium that a computing device can store, or a data storage device such as a data center containing one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive). The computer-readable storage medium includes instructions that instruct the computing device to execute a method to prevent the generation of redundant code.

[0185] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the protection scope of the technical solutions of the embodiments of this application.

Claims

1. A method for preventing the generation of redundant code, characterized in that, Applied to an early warning module, which is external to a large code model, the method includes: During the reasoning process of the large code model, the semantic vector of the target code unit output by the large code model is obtained. The target code unit includes one or more code units, and the code unit is the basic syntactic unit in the code. Based on the semantic vector of the target code unit, predict the probability that the large code model currently generates redundant code; If the probability is greater than a preset probability threshold, a stop notification is sent to the large code model, wherein the stop notification is used to instruct the large code model to stop inference.

2. The method according to claim 1, characterized in that, The target code unit includes multiple code units in the target code line; Based on the semantic vector of the target code unit, predict the probability that the large code model currently generates redundant code, including: The redundant code probability of the multiple code units is determined based on the semantic vectors of the multiple code units, wherein the redundant code probability is used to indicate the probability that the corresponding code is redundant code; If the proportion of code units with a redundant code probability greater than a probability threshold among the multiple code units is greater than a proportion threshold, the reasoning process of the large code model is stopped.

3. The method according to claim 1, characterized in that, The early warning module includes a linear layer that, based on the semantic vector of the target code unit, predicts the probability that the large code model currently generates redundant code, including: The semantic vector of the target code unit is mapped to a two-dimensional vector through the linear layer; The probability of the current generation of redundant code in the code big model is calculated based on the two-dimensional vector.

4. The method according to any one of claims 1-3, characterized in that, The method further includes: Obtain the historical code generated by the aforementioned large code model; The historical codes are annotated to obtain the annotated historical codes; The early warning module is trained using the labeled historical codes.

5. The method according to claim 4, characterized in that, The historical code is annotated to obtain the annotated historical code, including: constructing an abstract syntax tree of the historical code; The target function node in the abstract syntax tree is extracted based on the function words in the prompt words used to generate the historical code; Obtain multiple relation nodes from the abstract syntax tree that have a direct or indirect calling relationship with the target function node; The last line of code at each relation node is truncated to obtain the ideal generated code, and the ideal generated code is labeled with a "continue generation" tag. The ideal generated code is the part of the historical code excluding the redundant code, and the "continue generation" tag is used to indicate that the code model continues to generate code. The code in the historical code other than the ideal generated code is regarded as redundant generated code, and the redundant generated code is marked with a stop generation label to obtain the labeled historical code. The stop generation label is used to indicate that the code model stops generating code.

6. The method according to claim 4, characterized in that, The historical codes are annotated to obtain the annotated historical codes, including: Send redundant generated code background knowledge historical code to the large language model semantic analyzer, and prompt words for generating the historical code; The large language model semantic analyzer extracts the ideal generated code from the historical code based on the background knowledge of the redundant generated code, the historical code, and the prompt words, and marks the ideal generated code with a "continue to generate" tag; The code in the historical code other than the ideal generated code is regarded as redundant generated code, and the redundant generated code is marked with a stop generation label to obtain the labeled historical code.

7. The method according to claim 6, characterized in that, The early warning module is trained using the labeled historical code and includes: Construct multiple code unit sequences based on the labeled historical code; With the parameters of the large code model frozen, each code unit sequence is input into the large code model to obtain the training semantic vector corresponding to the code unit sequence output by the large code model. When training the warning module with the parameters of the large code model frozen, the parameters of the large code model are not updated. Each trained semantic vector is input into the early warning module to obtain the predicted excess generation probability, thus completing the training of the early warning module.

8. A device for preventing redundant code generation, characterized in that, The device is externally connected to the large code model, and the device includes: The acquisition module is used to acquire the semantic vector of the target code unit output by the code big model during the reasoning process of the code big model. The target code unit includes one or more code units, and the code unit is a basic syntactic unit in the code. The prediction module is used to predict the probability that the large code model will generate redundant code based on the semantic vector of the target code unit. A stop module is used to send a stop notification to the code big model when the probability is greater than a preset probability threshold, wherein the stop notification is used to instruct the code big model to stop inference.

9. A system for preventing redundant code generation, characterized in that, The system includes: The client is used to send code generation instructions; Large code model, used to generate target code units based on code generation instructions; The early warning module is used to obtain the semantic vector of the target code unit output by the code big model during the inference process of the code big model. The target code unit includes one or more code units, which are basic syntactic units in the code. Based on the semantic vector of the target code unit, the module predicts the probability that the code big model is currently generating redundant code. If the probability is greater than a preset probability threshold, the module sends a stop notification to the code big model. The stop notification is used to instruct the code big model to continue inference.

10. A chip system, characterized in that, The chip system includes a processor and a power supply circuit, the power supply circuit being used to supply power to the processor, and the processor being used to perform the operation steps of the method as described in any one of claims 1 to 7.

11. A computing device, characterized in that, The computing device includes a processor and memory; The processor is configured to execute instructions stored in the memory to cause the computing device to perform the operational steps of the method as described in any one of claims 1 to 7.

12. A computing device cluster, characterized in that, It includes at least one computing device, each computing device including a processor and memory; The processor of the at least one computing device is configured to execute instructions stored in the memory of the at least one computing device to cause the cluster of computing devices to perform the operational steps of the method as described in any one of claims 1 to 7.

13. A computer program product containing instructions, characterized in that, When the instruction is executed by the computing device cluster, the computing device cluster causes the computing device cluster to perform the operation steps of the method as described in any one of claims 1 to 7.

14. A computer-readable storage medium, characterized in that, It includes computer program instructions, which, when executed by a cluster of computing devices, perform the operational steps of the method as described in any one of claims 1 to 7.