A code generation method, apparatus, device, and storage medium
By generating feature vectors to select suitable data generation modules and verifying candidate sequences, the problems of poor domain adaptability and inference latency in code generation of large language models are solved, and efficient code generation is achieved.
Patent Information
- Application Number
- CN202511254893.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-04
- Publication Date
- 2026-02-13
- Estimated Expiration
- 2045-09-04
AI Technical Summary
Existing large language models suffer from poor domain adaptability, low reliability of output results, and slow data processing during code generation.
By acquiring task data to generate feature vectors, selecting suitable data generation modules, and using the main model to verify candidate sequences, including dynamic routing units, parallel verification units, and online adaptive units, task adaptability and inference latency are reduced.
It achieves precise adaptation of code generation across multiple domains and styles, reduces inference latency and computational costs, and improves generation efficiency.
Smart Images

Figure CN120743244B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence technology, and in particular to a code generation method, apparatus, device, and storage medium. Background Technology
[0002] Autoregressive models, especially LLM (Large Language Model), have become a core technology in the field of natural language processing. Their working principle involves generating sequences one "token" (such as a word or character) at a time.
[0003] Currently, in natural language processing using large language models, such as code generation, a small-parameter "draft model" is used to pre-generate a candidate sequence, which is then validated by the main model. Since the draft model is static, it is typically used in specific technical fields. For example, a draft model that excels at writing poetry might experience a sharp drop in prediction accuracy when generating code, causing the main model to frequently reject its drafts, thus failing to achieve effective acceleration. Therefore, this approach suffers from poor domain adaptability, low reliability of output results, and slow data processing. Summary of the Invention
[0004] In view of this, the purpose of this invention is to provide a code generation method, apparatus, device, and storage medium that can select a data generation module based on feature vectors and verify candidate sequences using a main model, thereby ensuring task adaptability and reducing inference latency. The specific solution is as follows:
[0005] Firstly, this application provides a code generation method applied to a target data reasoning system, comprising:
[0006] Obtain current task data and generate a current feature vector corresponding to the target encoding task based on the current task data; wherein, the current task data includes the current token sequence, task metadata, and user metadata of the target user corresponding to the target encoding task;
[0007] The target data generation module corresponding to the target encoding task is determined from several initial data generation modules locally using the current feature vector, and the current data packet is generated using the target data generation module; wherein, the current data packet includes a new token sequence corresponding to the target encoding task, and different initial data generation modules are used to generate different types of data content;
[0008] splicing the current token sequence and the new token sequence into a first token sequence, and predicting a probability distribution of a next token corresponding to any one token in the first token sequence by using a preset main model to obtain a corresponding prediction result;
[0009] determining whether there is a divergence point between each prediction result and the first token sequence, and if there is no divergence point between each prediction result and the first token sequence, generating a current code snippet based on the first token sequence, and determining whether a new code snippet needs to be generated according to the current code snippet, and if a new code snippet does not need to be generated, determining the current code snippet as a target code corresponding to the target coding task.
[0010] Optionally, the determining of the target data generation module corresponding to the target coding task from the plurality of initial data generation modules locally by using the current feature vector comprises:
[0011] projecting the current feature vector to a target multi-dimensional vector space by using a preset feedforward network, wherein a dimension of the target multi-dimensional vector space is the same as a number of the initial data generation modules;
[0012] determining an adaptation degree score of the target coding task and each initial data generation module based on the target multi-dimensional vector space, and determining the target data generation module corresponding to the target coding task from each initial data generation module locally according to each adaptation degree score.
[0013] Optionally, the code generation method further comprises:
[0014] determining a target priority corresponding to each initial data generation module according to a frequency of use of each initial data generation module, wherein the target priority represents a priority of eliminating each initial data generation module from a target cache space;
[0015] determining a target weight corresponding to each initial data generation module as each adaptation degree score, and adjusting each target priority according to each target weight.
[0016] Optionally, the code generation method further comprises:
[0017] if the first token sequence and each prediction result have a divergence point, generating a second token sequence based on each prediction result, generating the current code snippet based on the second token sequence, and jumping to the step of determining whether a new code snippet needs to be generated according to the current code snippet.
[0018] Optionally, the code generation method further comprises:
[0019] If the first token sequence and each of the prediction results exist a divergence point, a target position and a target probability distribution of a target divergence point are determined, wherein the target divergence point is a first divergence point of the first token sequence and each of the prediction results, and the target probability distribution is a probability distribution corresponding to the prediction result of the preset main model at the target position;
[0020] A Shannon entropy corresponding to the target probability distribution is determined, and a target feedback signal is generated based on the Shannon entropy, so that a new code snippet is generated according to the target feedback signal.
[0021] Optionally, the code generation method further comprises:
[0022] If each of the prediction results and the first token sequence do not exist a divergence point, and a new code snippet needs to be generated, the first token sequence is determined as the current token sequence, and the step of obtaining the current task data is jumped to, so as to generate a new code snippet;
[0023] The current code snippet and the new code snippet are combined to obtain the target code corresponding to the target coding task.
[0024] Optionally, the code generation method further comprises:
[0025] If each of the prediction results and the first token sequence exist a divergence point, each of the prediction results and the first token sequence are integrated into a mismatch sequence pair;
[0026] A parameter update gradient corresponding to the target data generation module is obtained by using the mismatch sequence pair, and a low-rank matrix corresponding to the target data generation module is updated based on the parameter update gradient and the LoRA technology.
[0027] In a second aspect, the present application provides a code generation device applied to a target data reasoning system, comprising:
[0028] A feature vector generation module is configured to obtain current task data, and generate a current feature vector corresponding to a target coding task based on the current task data, wherein the current task data comprises a current token sequence corresponding to the target coding task, task metadata, and user metadata of a target user.
[0029] The data packet generation module is configured to determine a target data generation module corresponding to the target coding task from a plurality of initial data generation modules locally by using the current feature vector, and generate a current data packet by using the target data generation module; wherein the current data packet comprises a new token sequence corresponding to the target coding task, and different initial data generation modules are respectively configured to generate different types of data content.
[0030] The probability distribution prediction module is configured to concatenate the current token sequence and the new token sequence into a first token sequence, and predict a probability distribution of a next token corresponding to any token in the first token sequence by using a preset main model to obtain a corresponding prediction result.
[0031] The code acquisition module is configured to determine whether there is a divergence point between each prediction result and the first token sequence, and if there is no divergence point between each prediction result and the first token sequence, generate a current code snippet based on the first token sequence, and determine whether a new code snippet needs to be generated according to the current code snippet, and if a new code snippet does not need to be generated, determine the current code snippet as a target code corresponding to the target coding task.
[0032] In a third aspect, the present application provides an electronic device, comprising:
[0033] A memory configured to save a computer program;
[0034] A processor configured to execute the computer program to implement the code generation method described above.
[0035] In a fourth aspect, the present application provides a computer readable storage medium configured to save a computer program, and the computer program is executed by a processor to implement the code generation method described above.
[0036] The application first acquires current task data, and generates a current feature vector corresponding to a target coding task based on the current task data; wherein the current task data includes a current token sequence corresponding to the target coding task, task metadata, and user metadata of a target user, then determines a target data generation module corresponding to the target coding task from a plurality of initial data generation modules locally using the current feature vector, and generates a current data packet using the target data generation module; wherein the current data packet includes a new token sequence corresponding to the target coding task, different initial data generation modules are used to generate different types of data content, then the current token sequence and the new token sequence are spliced into a first token sequence, and the probability distribution of the next token corresponding to any one token in the first token sequence is predicted using a preset main model to obtain a corresponding prediction result, finally it is judged whether there is a divergence point between each prediction result and the first token sequence, if there is no divergence point between each prediction result and the first token sequence, a current code snippet is generated based on the first token sequence, and it is judged whether a new code snippet needs to be generated according to the current code snippet, if a new code snippet does not need to be generated, the current code snippet is determined as a target code corresponding to the target coding task. As can be seen, the application generates a feature vector corresponding to a coding task, and selects a target data generation module most suitable for the coding task from initial data generation modules responsible for different technical fields according to the feature vector, thereby realizing precise adaptation of multi-field and multi-style generation tasks, solving the problem of poor adaptability of general draft models; by using the target data generation module to generate a candidate sequence containing a confidence score and verifying the sequence by the main model, the speculation and verification of long sequence fragments are realized, breaking through the sequence dependence bottleneck of token-by-token generation, and significantly reducing the inference delay. BRIEF DESCRIPTION OF DRAWINGS
[0037] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or prior art description. Obviously, the drawings in the following description are only embodiments of the present application, and for those skilled in the art, other drawings can be obtained without creative labor based on the provided drawings.
[0038] Figure 1 A code generation method flowchart disclosed by the present application;
[0039] Figure 2 A data reasoning system structure schematic diagram disclosed by the present application;
[0040] Figure 3A dynamic routing unit structure diagram disclosed by the present application;
[0041] Figure 4 A specific code generation method flow diagram disclosed by the present application;
[0042] Figure 5 A code generation device structure diagram disclosed by the present application;
[0043] Figure 6 An electronic device structure diagram disclosed by the present application. DETAILED DESCRIPTION
[0044] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative labor fall within the scope of protection of the present application.
[0045] At present, when a large language model is used for natural language processing, such as code generation, there are problems of poor field adaptability, low output result reliability, and slow data processing. Therefore, the present application provides a code generation method, which selects a data generation module according to a feature vector, and verifies a candidate sequence using a main model, thereby ensuring task adaptability and reducing inference delay.
[0046] Referring to Figure 1 The embodiments of the present application disclose a code generation method applied to a target data inference system, which comprises the following steps:
[0047] In step S11, current task data is obtained, and a current feature vector corresponding to a target coding task is generated based on the current task data; wherein the current task data comprises a current token sequence corresponding to the target coding task, task metadata, and user metadata of a target user.
[0048] To solve the core problems of high inference delay, high computational cost, poor field adaptability, rigid strategy, and inability to learn online in the prior art code generation method, the present embodiment designs a predictive generation and verification system (i.e. a target data inference system), wherein the data generation module is an autoregressive model, and the structure of the system is as shown in Figure 2 The system comprises the following parts:
[0049] 1. A main generation model, which serves as a quality benchmark and verification core for the final generated content.
[0050] 2. A module pool comprising a plurality of heterogeneous specialized generation modules, each optimized to efficiently process content of a specific domain or style, for generating candidate token sequences according to instructions.
[0051] 3. A dynamic routing unit, as shown in Figure 3 configured to:
[0052] 1) receive and process multi-dimensional context information comprising current text context, task metadata, and user metadata;
[0053] 2) integrate a context analysis engine to convert the multi-dimensional context information into a standardized context feature vector;
[0054] 3) integrate a module selection engine to calculate an adaptation score for each specialized generation module based on the context feature vector, and select one or more modules to perform the subsequent candidate sequence generation task accordingly.
[0055] 4. A parallel verification unit, configured to:
[0056] 1) receive a candidate sequence data package comprising a candidate sequence and a confidence score generated by the selected specialized generation module;
[0057] 2) perform a one-time, non-token-by-token parallelized verification of the candidate sequence using the master generation model, and determine the divergence point in the sequence;
[0058] 3) output the final confirmed token sequence based on the verification result;
[0059] 4) further, the unit is configured to generate an uncertainty feedback signal comprising the location information of the divergence point and the uncertainty quantization value of the master model at that point, and return it to the dynamic routing unit to assist subsequent decision-making.
[0060] 5. An online adaptive unit, configured to:
[0061] 1) receive a pair of mismatched sequences provided by the verification unit when the parallel verification unit determines that the candidate sequence does not match the final confirmed sequence;
[0062] 2) calculate the parameter update gradient for the specialized generation module that caused the error based on the pair of mismatched sequences;
[0063] 3) perform online fine-tuning of the specialized generation module in a parameter-efficient manner (e.g., only update the adapter weights), so as to realize continuous self-optimization of the system, and the fine-tuning process can be configured to be executed asynchronously to not block the main generation process.
[0064] Further, embodiments can also include a module management unit that works in conjunction with the dynamic routing unit to manage the loading and unloading of specialized generation modules between cache and low-speed storage based on a cache replacement algorithm with priority weights (e.g., the fitness scores provided by the routing unit as weights) to optimize system memory footprint and module invocation latency.
[0065] In one specific implementation, as shown in Figure 4 def calculate_average(numbers).
[0066] Routing: The routing unit receives the text context, as well as the metadata {"task_source": "IDE_plugin", "user_profile": ["Python_dev"]}. The context analysis engine outputs a strong "code" leaning feature vector. The module selection engine accordingly gives the "code generation module" the highest fitness score of 0.95.
[0067] Generation: The module management unit ensures the code module is in cache. The module predicts that the following is likely to be the function body, and confidently generates a long candidate sequence, packaged into a data packet.
[0068] Verification: The parallel verifier concatenates the function header and the candidate sequence and feeds it into the main model. The main model verifies that it is correct with no disagreement points. The final confirmed sequence is output to the editor. At this point, the uncertainty quantifier can output a low uncertainty signal (or not), further enhancing the routing unit's trust in the code module.
[0069] Adaptation: Since there is no disagreement, the online adaptation unit does not work this round.
[0070] Iteration: The process ends, and the user sees the complete function body completed instantaneously.
[0071] In another specific implementation, suppose the candidate sequence is "\n total = sum(nums)\n..." (variable name error).
[0072] Verification: The verifier finds a disagreement point at nums. The main model will correct it to numbers and generate the following.
[0073] Adaptation: The online adaptation unit receives a mismatched sequence pair. It computes the gradient and fine-tunes the LoRA (Low-Rank Adaptation of Large Language Models) weights of the code module so that it is more likely to use the variable name "numbers" when it encounters a similar context in the future.
[0074] In this embodiment, the process of obtaining task data is responsible for the context analysis engine in the dynamic routing unit described above. Specifically, the dynamic routing unit is the intelligent decision-making hub of the system. It is further divided into a context analysis engine and a module selection engine:
[0075] Contextual Analysis Engine:
[0076] Input:
[0077] Receive three types of information (i.e. current task data): a) Text context (generated token sequence, i.e. current token sequence); b) Context metadata (i.e. task metadata and user metadata) (a data structure containing key-value pairs, such as {"task_source": "IDE_plugin", "user_id": "U785", "user_profile": ["Python_dev", "English_speaker"]} ); c) Uncertainty feedback signal from the verification unit.
[0078] Processing:
[0079] A lightweight neural network such as BERT (Bidirectional Encoder Representations from Transformers, a pre-trained language model) or a small Transformer encoder can be used inside the engine to encode and fuse the three types of heterogeneous information into a high-dimensional, standardized context feature vector V_context (i.e. current feature vector). This vector comprehensively represents the current generation context.
[0080] By integrating the three types of heterogeneous information and generating the context feature vector, the corresponding data generation module for the task can be selected from the local according to the feature vector, ensuring the adaptability of the task and the module.
[0081] Step S12, determining the target data generation module corresponding to the target coding task from the plurality of initial data generation modules locally using the current feature vector, and generating a current data packet using the target data generation module; wherein the current data packet includes a new token sequence corresponding to the target coding task, and different initial data generation modules are respectively used to generate different types of data content.
[0082] In this embodiment, the process of determining the target data generation module corresponding to the target coding task from the plurality of initial data generation modules locally using the current feature vector can specifically include: projecting the current feature vector to a target multi-dimensional vector space using a preset feedforward network; wherein the dimension of the target multi-dimensional vector space is the same as the number of initial data generation modules; determining the adaptation degree score of the target coding task and each initial data generation module based on the target multi-dimensional vector space, and determining the target data generation module corresponding to the target coding task from the local initial data generation modules according to each adaptation degree score.
[0083] The above process is responsible for the module selection engine in the aforementioned dynamic routing unit:
[0084] Module Selection Engine:
[0085] Input: Context Feature Vector V_context.
[0086] Processing: An engine internally maintains a learnable projection matrix or a small feedforward network (i.e., a preset feedforward network). The feedforward network projects V_context into a dimensional space (i.e., a target multi-dimensional vector space) with the same number of specialized generation modules, thereby calculating an adaptation degree score S for each specialized generation module (i.e., an initial data generation module). S = {s1, s2,..., sN}.
[0087] Output: Based on the score S, the engine outputs a routing directive. The directive not only includes the highest scoring module ID, but also can include one or more alternative module IDs (Identity document, i.e., identity identifier), or even a module combination weighting scheme. The directive is sent to the module management unit.
[0088] That is, in this embodiment, each task can not correspond to only one data generation module. In a specific embodiment, the current code generation task can need to use A module and B module to cooperatively generate data.
[0089] Specialized Generation Module:
[0090] The activated module (i.e., the target data generation module), such as the code generation module, performs its generation task, and outputs a structured candidate sequence data packet (i.e., the current data packet). The data packet is a tuple containing multiple fields: [candidate_sequence, sequence_length, confidence_score, module_id].
[0091] The confidence_score is calculated as follows: the module outputs a probability distribution when generating each token. The score can be the average log probability of the entire sequence, or the probability value of the lowest probability token in the sequence, which quantifies its "confidence level". This score will determine the sequence_length, achieving flexible "variable length prediction".
[0092] In addition, the use frequency of each initial data generation module is determined in the embodiment, and the target priority corresponding to each initial data generation module is determined; wherein the target priority represents the priority of eliminating each initial data generation module from the target cache space; the adaptation score is determined as the target weight corresponding to each initial data generation module, and each target priority is adjusted according to the target weight.
[0093] Specifically, after receiving the routing instruction, the module management unit adopts a LRU (Least Recently Used) cache algorithm with priority weight. The adaptation score S in the routing instruction is used as the weight. The priority of the module with a high score being replaced out of the cache will be reduced even if it has not been used recently. This ensures the constant residence of "key" modules and greatly reduces the call delay.
[0094] Step S13, splicing the current token sequence and the new token sequence into a first token sequence, and using a preset main model to predict the probability distribution of the next token corresponding to any token in the first token sequence to obtain a corresponding prediction result.
[0095] In the embodiment, the process of predicting the probability distribution of the next token corresponding to any token in the first token sequence by using the preset main model is responsible for the parallel verifier unit, which is the core of the acceleration effect implementation. It is further divided into a parallel verifier and an uncertainty quantifier inside:
[0096] Parallel Validator:
[0097] Input: new token sequence in the candidate sequence data packet and the current text context (i.e. the current token sequence).
[0098] Process: concatenate the text context with the candidate sequence to form a complete input sequence (i.e. the first token sequence), and then invoke the main generation model to perform a complete forward propagation on the complete sequence. In this propagation, for each position in the sequence, the main model will predict the probability distribution (logits) of the next token. The verifier will compare the main model's prediction with the actual token in the candidate token sequence (i.e. the current token sequence part in the first token sequence) bit by bit. The first mismatched position is marked as the divergence point.
[0099] Output: if there is no divergence point, the candidate sequence is completely accepted. If there is, the part before the divergence point is adopted, and the main model generates the subsequent content from the divergence point in its own autoregressive manner to form the final confirmed sequence.
[0100] By verifying the tokens in the candidate token sequence using the prediction results of the main model, parallel speculation and verification of long sequence fragments are achieved, breaking the sequence dependency bottleneck of token-by-token generation, and significantly reducing inference delay and computational cost.
[0101] Step S14, determine whether there is a divergence point between each prediction result and the first token sequence. If there is no divergence point between each prediction result and the first token sequence, generate a current code fragment based on the first token sequence, and determine whether a new code fragment needs to be generated according to the current code fragment. If a new code fragment does not need to be generated, the current code fragment is determined as the target code corresponding to the target coding task.
[0102] In a specific embodiment, if the first token sequence and each prediction result have a divergence point, generate a second token sequence based on each prediction result, generate a current code fragment based on the second token sequence, and jump to the step of determining whether a new code fragment needs to be generated according to the current code fragment. That is, in this embodiment, if there is no divergence point, the candidate sequence is completely accepted.
[0103] In another specific embodiment, if the first token sequence and each prediction result have a divergence point, a target position of a target divergence point and a target probability distribution are determined; the target divergence point is the first divergence point of the first token sequence and each prediction result, and the target probability distribution is a probability distribution corresponding to the prediction result of the preset main model at the target position; a Shannon entropy corresponding to the target probability distribution is determined, and a target feedback signal is generated based on the Shannon entropy, so that a new code segment is generated according to the target feedback signal.
[0104] The above process is responsible for the uncertainty quantifier, specifically:
[0105] Input: the position of the divergence point and the complete probability distribution output by the main model at the divergence point position.
[0106] Processing: use a clear mathematical formula to calculate the uncertainty, such as Shannon Entropy. The higher the entropy value, the more uncertain the main model's prediction here.
[0107] Output: Generate a structured uncertainty feedback signal (i.e., target feedback signal) in the format: [divergence_point_index, uncertainty_value, corrective_token_id]. This signal is sent back to the routing unit, forming an accurate and fast feedback loop.
[0108] In a third specific embodiment, if each prediction result does not have a divergence point with the first token sequence, and a new code segment needs to be generated, the first token sequence is determined as the current token sequence, and the step of obtaining the current task data is jumped to to generate a new code segment; the current code segment and the new code segment are combined to obtain a target code corresponding to a target coding task.
[0109] That is, for a code generation task, this embodiment does not generate an entire code segment in the process of one round of data processing, but generates code segments in segments. In this way, the amount of data processing in each cycle can be reduced, thereby ensuring the accuracy of code generation.
[0110] In addition, if each prediction result has a divergence point with the first token sequence, each prediction result and the first token sequence are integrated into a mismatch sequence pair; a parameter update gradient corresponding to the target data generation module is obtained using the mismatch sequence pair, and the low-rank matrix corresponding to the target data generation module is updated based on the parameter update gradient and the LoRA technology.
[0111] The above process of updating the low-rank matrix is responsible for the online adaptive unit in the system, which is the key to the self-evolution of the system, specifically:
[0112] Input: When inconsistency occurs, receive the pair of mismatched sequences generated by the verification unit. This pair of data is structured: (input_context, erroneous_sequence, correct_sequence, erroneous_module_id).
[0113] Processing: Gradient calculation: the unit takes this pair of data as a high-quality training sample, calculates a loss function (for example, cross-entropy loss on erroneous_sequence), and back-propagates to calculate the update gradient of the parameters of the module corresponding to erroneous_module_id.
[0114] Efficient parameter update: for efficiency and stability, the update does not act on all parameters of the module. Instead, a parameter-efficient fine-tuning technique (such as LoRA) is used. The unit only retrieves and updates the small low-rank adaptation matrix (LoRA weights) associated with the module. The backbone network parameters remain frozen.
[0115] Asynchronous execution: the entire fine-tuning process is executed asynchronously in a separate computing thread or queue, ensuring that it does not increase the inference delay of the main process.
[0116] As can be seen, the present application generates a feature vector corresponding to the coding task, and selects the target data generation module most suitable for the coding task from the initial data generation modules responsible for different technical fields according to the feature vector, thereby realizing precise adaptation for multi-field and multi-style generation tasks, and solving the problem of poor adaptability of general draft models; by using the target data generation module to generate candidate sequences with confidence scores and verifying the sequences by the main model, the speculation and verification of long sequence fragments are realized, breaking through the sequence dependency bottleneck of token-by-token generation, and significantly reducing the inference delay.
[0117] Referring to Figure 5 The embodiment of the present application discloses a code generation device, applied to a target data inference system, comprising:
[0118] A feature vector generation module 11 is configured to obtain current task data and generate a current feature vector corresponding to a target coding task based on the current task data; wherein the current task data includes a current token sequence corresponding to the target coding task, task metadata, and user metadata of a target user.
[0119] The data packet generation module 12 is configured to determine a target data generation module corresponding to the target coding task from a plurality of initial data generation modules locally using the current feature vector, and generate a current data packet using the target data generation module; wherein the current data packet comprises a new token sequence corresponding to the target coding task, and different initial data generation modules are respectively configured to generate different types of data content.
[0120] The probability distribution prediction module 13 is configured to concatenate the current token sequence and the new token sequence into a first token sequence, and predict a probability distribution of a next token corresponding to any token in the first token sequence using a preset main model to obtain a corresponding prediction result.
[0121] The code generation module 14 is configured to determine whether there is a divergence point between each prediction result and the first token sequence, and if there is no divergence point between each prediction result and the first token sequence, generate a current code snippet based on the first token sequence, and determine whether a new code snippet needs to be generated according to the current code snippet, and if a new code snippet does not need to be generated, determine the current code snippet as a target code corresponding to the target coding task.
[0122] In some embodiments, the data packet generation module 12 can specifically include:
[0123] The vector projection unit is configured to project the current feature vector to a target multi-dimensional vector space using a preset feedforward network; wherein the dimension of the target multi-dimensional vector space is the same as the number of the initial data generation modules.
[0124] The score determination unit is configured to determine an adaptation degree score of the target coding task and each initial data generation module based on the target multi-dimensional vector space, and determine the target data generation module corresponding to the target coding task from each initial data generation module locally according to each adaptation degree score.
[0125] In some embodiments, the code generation apparatus further includes:
[0126] The priority determination module is configured to determine a target priority corresponding to each initial data generation module according to a usage frequency of each initial data generation module; wherein the target priority represents a priority of eliminating each initial data generation module from a target cache space.
[0127] The priority adjustment module is configured to determine the adaptation degree score as a target weight corresponding to the initial data generation module, and adjust the target priority according to the target weight.
[0128] In some embodiments, the code generation apparatus further comprises:
[0129] The first step jump module is configured to generate a second token sequence based on the prediction results if the first token sequence and the prediction results have a divergence point, generate the current code snippet based on the second token sequence, and jump to the step of determining whether a new code snippet needs to be generated according to the current code snippet.
[0130] In some embodiments, the code generation apparatus further comprises:
[0131] The probability distribution determination module is configured to determine a target position of a target divergence point and a target probability distribution if the first token sequence and the prediction results have a divergence point, wherein the target divergence point is the first divergence point of the first token sequence and the prediction results, and the target probability distribution is a probability distribution corresponding to the prediction result of the preset main model at the target position.
[0132] The feedback signal generation module is configured to determine a Shannon entropy corresponding to the target probability distribution, and generate a target feedback signal based on the Shannon entropy, so as to generate a new code snippet according to the target feedback signal.
[0133] In some embodiments, the code generation apparatus further comprises:
[0134] The second step jump module is configured to determine the first token sequence as the current token sequence if the prediction results and the first token sequence do not have a divergence point and a new code snippet needs to be generated, and jump to the step of obtaining the current task data to generate the new code snippet.
[0135] The code snippet combination module is configured to combine the current code snippet and the new code snippet to obtain the target code corresponding to the target coding task.
[0136] In some embodiments, the code generation apparatus further comprises:
[0137] The data integration module is configured to integrate the prediction results and the first token sequence into a mismatch sequence pair if the prediction results and the first token sequence have a divergence point.
[0138] The low-rank matrix updating module is configured to obtain a parameter updating gradient of the target data generation module by using the mismatch sequence, and update a low-rank matrix of the target data generation module based on the parameter updating gradient and the LoRA technology.
[0139] Further, the embodiment of the present application further discloses an electronic device, Figure 6 The electronic device 20 is shown in a structural diagram according to an exemplary embodiment, and the content in the diagram should not be considered as any limitation on the use range of the present application.
[0140] Figure 6 The electronic device 20 is shown in a structural diagram according to an exemplary embodiment, and the content in the diagram should not be considered as any limitation on the use range of the present application.
[0141] In the embodiment, the power supply 23 is configured to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol followed by the communication interface 24 can be any communication protocol applicable to the technical solution of the present application, which is not limited here; the input and output interface 25 is configured to obtain external input data or output data to the outside, and the specific interface type can be selected according to the specific application needs, which is not limited here.
[0142] In addition, the memory 22 as a carrier for resource storage can be a read-only memory, a random access memory, a magnetic disk or an optical disk, etc., and the resources stored thereon can include an operating system 221, a computer program 222, etc., and the storage mode can be temporary storage or permanent storage.
[0143] The operating system 221 is configured to manage and control each hardware device on the electronic device 20 and the computer program 222, and can be Windows Server, Netware, Unix, Linux, etc. In addition to the computer program capable of completing the code generation method executed by the electronic device 20 disclosed in any of the foregoing embodiments, the computer program 222 can further include a computer program capable of completing other specific work.
[0144] Further, the present application also discloses a computer readable storage medium for storing a computer program, wherein the computer program is executed by a processor to implement the code generation method disclosed above. For the specific steps of the method, refer to the corresponding content disclosed in the foregoing embodiments, which will not be repeated here.
[0145] The various embodiments are described in the present specification in progressive order, and each embodiment focuses on the difference from other embodiments. For the same or similar parts among the various embodiments, refer to each other. For the device disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple, and refer to the method part for the relevant content.
[0146] The skilled person can further realize that the units and algorithm steps of the examples described in combination with the embodiments disclosed herein can be realized by electronic hardware, computer software or a combination of both. In order to clearly illustrate the interchangeability of hardware and software, the components and steps of the examples have been described in the above description in general terms. Whether the functions are realized in hardware or software depends on the specific application and design constraints of the technical solution. The skilled person can use different methods to realize the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.
[0147] The steps of the method or algorithm described in combination with the embodiments disclosed herein can be directly implemented by hardware, a software module executed by a processor, or a combination of both. The software module can be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0148] Finally, it should be noted that, in this document, the relationship terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between the entities or operations. Moreover, the terms "include", "contain" or any other variants thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, method, article or device. Without more limitations, the element defined by the statement "including a" does not exclude the presence of other identical elements in the process, method, article or device including the element.
[0149] The technical solutions provided by the present application are described in detail above, and the principles and implementation manners of the present application are described by using specific examples. The above description of the examples is only used to help understand the method of the present application and its core idea; meanwhile, for those skilled in the art, according to the idea of the present application, the specific implementation manners and application ranges will be changed, and the above description of the content of the specification should not be understood as a limitation on the present application.
Claims
1. A code generation method characterized by, The application is applied to a target data inference system, comprising: obtaining current task data, and generating a current feature vector corresponding to a target coding task based on the current task data; wherein the current task data comprises a current token sequence corresponding to the target coding task, task metadata, and user metadata of a target user; determining a target data generation module corresponding to the target coding task from a plurality of initial data generation modules locally using the current feature vector, and generating a current data packet using the target data generation module; wherein the current data packet comprises a new token sequence corresponding to the target coding task, and different initial data generation modules are used to generate different types of data content; splicing the current token sequence and the new token sequence into a first token sequence, and predicting a probability distribution of a next token corresponding to any token in the first token sequence using a preset main model to obtain a corresponding prediction result; determining whether there is a divergence point between each prediction result and the first token sequence, and if there is no divergence point between each prediction result and the first token sequence, generating a current code snippet based on the first token sequence, and determining whether a new code snippet needs to be generated according to the current code snippet, and if a new code snippet does not need to be generated, determining the current code snippet as a target code corresponding to the target coding task; wherein the determination of the target data generation module corresponding to the target coding task from the plurality of initial data generation modules locally using the current feature vector comprises: projecting the current feature vector to a target multi-dimensional vector space using a preset feedforward network; wherein the dimension of the target multi-dimensional vector space is the same as the number of the initial data generation modules; determining an adaptation degree score of the target coding task and each initial data generation module based on the target multi-dimensional vector space, and determining the target data generation module corresponding to the target coding task from each initial data generation module locally according to each adaptation degree score.
2. The code generation method of claim 1, wherein, Further comprising: determining a target priority corresponding to each initial data generation module according to the usage frequency of each initial data generation module; wherein the target priority represents the priority of eliminating each initial data generation module from a target cache space; determining a target weight corresponding to each initial data generation module as each adaptation degree score, and adjusting each target priority according to each target weight.
3. The code generation method of claim 1, wherein, Further comprising: if the first token sequence and each prediction result have a divergence point, generating a second token sequence based on each prediction result, generating the current code snippet based on the second token sequence, and jumping to the step of determining whether a new code snippet needs to be generated according to the current code snippet.
4. The code generation method of claim 1, wherein, Further comprising: If the first token sequence and each of the prediction results exist a divergence point, a target position and a target probability distribution of a target divergence point are determined; the target divergence point is a first divergence point of the first token sequence and each of the prediction results, and the target probability distribution is a probability distribution corresponding to the prediction result of the preset main model at the target position; A Shannon entropy corresponding to the target probability distribution is determined, and a target feedback signal is generated based on the Shannon entropy, so that a new code snippet is generated according to the target feedback signal.
5. The code generation method of claim 1, wherein, Further comprising: If each of the prediction results and the first token sequence do not exist a divergence point, and a new code snippet needs to be generated, the first token sequence is determined as the current token sequence, and the step of obtaining the current task data is jumped to, so as to generate a new code snippet; The current code snippet and the new code snippet are combined to obtain the target code corresponding to the target coding task.
6. The code generation method according to any one of claims 1 to 5, characterized in that, Further comprising: If each of the prediction results and the first token sequence exist a divergence point, each of the prediction results and the first token sequence is integrated into a mismatch sequence pair; The parameter update gradient corresponding to the target data generation module is obtained by using the mismatch sequence pair, and the low-rank matrix corresponding to the target data generation module is updated based on the parameter update gradient and the LoRA technology.
7. A code generation apparatus characterized by comprising: Applied to a target data reasoning system, comprising: A feature vector generation module is configured to obtain current task data and generate a current feature vector corresponding to a target coding task based on the current task data; wherein the current task data includes a current token sequence corresponding to the target coding task, task metadata, and user metadata of a target user; A data packet generation module is configured to determine a target data generation module corresponding to the target coding task from a plurality of initial data generation modules locally using the current feature vector, and generate a current data packet using the target data generation module; wherein the current data packet includes a new token sequence corresponding to the target coding task, and different initial data generation modules are respectively configured to generate different types of data content; A probability distribution prediction module is configured to concatenate the current token sequence and the new token sequence into a first token sequence, and predict the probability distribution of a next token corresponding to any one token in the first token sequence using a preset main model to obtain a corresponding prediction result; A code acquisition module is configured to determine whether each of the prediction results and the first token sequence exist a divergence point, and if each of the prediction results and the first token sequence do not exist a divergence point, generate a current code snippet based on the first token sequence, and determine whether a new code snippet needs to be generated according to the current code snippet, and if a new code snippet does not need to be generated, determine the current code snippet as a target code corresponding to the target coding task. The data packet generation module comprises: a vector projection unit configured to project the current feature vector to a target multi-dimensional vector space by using a preset feedforward network, wherein a dimension of the target multi-dimensional vector space is the same as a number of the initial data generation modules; a score determination unit configured to determine an adaptation score of the target coding task and each of the initial data generation modules based on the target multi-dimensional vector space, and determine the target data generation module corresponding to the target coding task from each of the initial data generation modules locally according to each of the adaptation scores.
8. An electronic device, comprising: comprising: a memory configured to save a computer program; a processor configured to execute the computer program to implement the code generation method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, a computer program configured to be executed by a processor to implement the code generation method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Large language model reasoning acceleration method and device based on predictive decoding
CN118886511A
Speculation decoding method and device for large language model and medium
CN119150848A