Token processing method for large language model
By using a speculative model with a smaller number of parameters for autoregressive decoding and comparative verification, the reasoning process of the large language model is optimized, which solves the problem of low computational efficiency of the large language model when decoding text output tokens, and achieves an increase in reasoning speed and Cost reduction.
Patent Information
- Application Number
- CN202410554276.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-07
- Publication Date
- 2024-08-23
AI Technical Summary
During the autoregressive decoding process of large language models, each output token needs to be decoded sequentially, resulting in low computational efficiency and increased computational costs, especially in delay-sensitive scenarios.
Use a speculative model with a smaller number of parameters to perform autoregressive decoding reasoning, generate a speculative output Token sequence, and verify the similarity with the original model output through comparison, gradually replace the Tokens at different positions until they are verified to be the same, and generate the final output Token sequence, which greatly optimizes The inference process of language models.
It significantly improves the inference speed of large language models, reduces computational costs, and improves model efficiency without sacrificing output quality.
Smart Images

Figure CN118535693A
Abstract
Description
Technical Field
[0001] The invention discloses a method, which relates to the field of artificial intelligence, and in particular to a Token processing method for a large language model. Background Art
[0002] Transformer-based large language models, such as GPT-3 / 4 and Llama, have been widely adopted in various practical applications. However, as model parameters become larger and larger, the inference cost of large language models has caused serious concerns, especially for latency-sensitive scenarios.
[0003] Currently, in the inference process of autoregressive decoding, large language models need to decode each output Token in sequence. However, the decoding of each Token is usually limited by memory bandwidth, resulting in low computational efficiency and increased computational cost. Summary of the invention
[0004] In view of the problems in the prior art, the present invention provides a Token processing method for a large language model, which accelerates the reasoning process of the large language model when the large language model outputs Tokens in decoded text, improves the efficiency of the large language model outputting Tokens and reduces the computing cost.
[0005] The specific scheme proposed by the present invention is:
[0006] The present invention provides a Token processing method for a large language model, comprising:
[0007] Step 1: Take the large language model with a large number of parameters as the original model, and the large language model with a small number of parameters corresponding to the original model as the inferred model.
[0008] Step 2: Convert the question input by the user into a Token sequence of the question, use the inference model to perform autoregressive decoding inference based on the Token sequence of the question, and generate an inferred output Token sequence.
[0009] Step 3: Concatenate the problem’s Token sequence and the inferred output Token sequence into the input Token sequence of the original model, and use the original model to perform an inference based on the input Token sequence.
[0010] Generate an output Token sequence through inference of the original model, and compare and verify the output Token sequence with the inferred output Token sequence. If the Token sequences are the same, the inferred output Token sequence is used as the final output Token sequence, otherwise proceed to step 4.
[0011] Step 4: If the output Token sequence is different from the inferred output Token sequence, replace the inferred output Token sequence at the corresponding position with the output Token sequence of the original model, and then input the replaced Token sequence into the inference model for autoregressive decoding reasoning to obtain the inferred output Token sequence and input it into the original model. Perform a reasoning with the original model to obtain the output Token sequence, and then compare and verify the output Token sequence with the inferred output Token sequence. If the Token sequences are the same, the inferred output Token sequence is used as the final output Token sequence. Otherwise, repeat step 4 until the compared and verified Token sequences are the same, and use the inferred output Token sequence as the final output Token sequence.
[0012] Construct the answer to the user's question based on the final output Token sequence.
[0013] Furthermore, in the Token processing method of a large language model, in step 1, the Llama-2-70b model with a larger parameter amount is used as the original model, and the Llama-2-7b model with a smaller parameter amount corresponding to the original model is used as the inferred model.
[0014] Furthermore, in the Token processing method of a large language model, step 1: taking the Llama-2-70b model with a larger number of parameters as the original model, and taking the Llama-2-7b model with a smaller number of parameters corresponding to the original model as the inferred model,
[0015] Step 2: Use Tokenizer to convert the question input by the user into a Token sequence of the question. Use the inference model to perform autoregressive decoding inference based on the Token sequence of the question to generate an inferred output Token sequence containing k Tokens, where the k value is a hyperparameter. The k value is determined based on the similarity between the inferred model output and the original model output.
[0016] Step 3: Concatenate the problem’s Token sequence and the inferred output Token sequence into the input Token sequence of the original model, and use the original model to perform an inference based on the input Token sequence.
[0017] Generate an output Token sequence through inference of the original model, and compare and verify the output Token sequence with the inferred output Token sequence. If the Token sequences are the same, the inferred output Token sequence is used as the final output Token sequence, otherwise proceed to step 4.
[0018] Step 4: If the output Token sequence is different from the inferred output Token sequence, replace the inferred output Token sequence at the corresponding position with the output Token sequence of the original model at different positions, and then input the replaced Token sequence into the inference model for autoregressive decoding reasoning to obtain an inferred output Token sequence containing k Tokens. Input the inferred output Token sequence into the original model, perform reasoning through the original model to obtain the output Token sequence, and then compare and verify the output Token sequence with the inferred output Token sequence. If the Token sequences are the same, the inferred output Token sequence is used as the final output Token sequence. Otherwise, repeat step 4 until the compared and verified Token sequences are the same, and use the inferred output Token sequence as the final output Token sequence.
[0019] Construct the answer to the user's question based on the final output Token sequence.
[0020] Furthermore, in the token processing method of a large language model, the k value is determined according to the similarity between the output of the inferred model and the output of the original model in step 2, including: if the probability that the first i tokens generated by the original model are the same as the first i tokens generated by the inferred model is higher than the probability value in other cases, then i is used as the k value.
[0021] The present invention also provides a Token processing device for a large language model, including a model selection module, an inference model inference module, an original model inference module, a verification module and an answer generation module.
[0022] The model selection module uses the large language model with a large number of parameters as the original model, and the large language model with a small number of parameters corresponding to the original model as the inferred model.
[0023] The inference model inference module converts the question input by the user into a Token sequence of the question, and uses the inference model to perform autoregressive decoding reasoning based on the Token sequence of the question to generate an inference output Token sequence.
[0024] The original model inference module concatenates the problem's Token sequence and the inferred output Token sequence into the input Token sequence of the original model, uses the original model to perform an inference based on the input Token sequence, and generates an output Token sequence through the original model inference. The verification module compares and verifies the output Token sequence with the inferred output Token sequence. If the Token sequences are the same, the inferred output Token sequence is used as the final output Token sequence. Otherwise, if the output Token sequence is different from the inferred output Token sequence, the output Token sequence of the original model is replaced with the inferred output Token sequence at the corresponding position at different positions, and the replaced Token sequence is input into the inference model. The inference model inference module performs autoregressive decoding inference to obtain the inferred output Token sequence and input it into the original model. The original model inference module performs an inference through the original model to obtain the output Token sequence. The verification module compares and verifies the output Token sequence with the inferred output Token sequence. If the Token sequences are the same, the inferred output Token sequence is used as the final output Token sequence. Otherwise, the inference and verification process is repeated until the compared and verified Token sequences are the same, and the inferred output Token sequence is used as the final output Token sequence.
[0025] The answer generation module constructs the answer result of the user's question based on the final output Token sequence.
[0026] Furthermore, in the Token processing device of the large language model, the model selection module uses the Llama-2-70b model with a larger parameter amount as the original model, and uses the Llama-2-7b model with a smaller parameter amount corresponding to the original model as the inferred model.
[0027] Furthermore, in the Token processing device of a large language model, the model selection module uses the Llama-2-70b model with a larger parameter amount as the original model, and uses the Llama-2-7b model with a smaller parameter amount corresponding to the original model as the inferred model.
[0028] The inference model inference module uses Tokenizer to convert the user input question into a Token sequence of the question. According to the Token sequence of the question, the inference model is used to perform autoregressive decoding inference to generate an inference output Token sequence containing k Tokens, where the k value is a hyperparameter. The k value is determined according to the similarity between the inference model output and the original model output.
[0029] The original model inference module concatenates the problem's Token sequence and the inferred output Token sequence into the original model's input Token sequence, uses the original model to perform an inference based on the input Token sequence, and generates an output Token sequence through the original model inference.
[0030] The verification module compares and verifies the output Token sequence with the inferred output Token sequence. If the Token sequences are the same, the inferred output Token sequence is used as the final output Token sequence. Otherwise, if the output Token sequence is different from the inferred output Token sequence, the output Token sequence of the original model is replaced with the inferred output Token sequence at the corresponding position at different positions, and then the replaced Token sequence is input into the inference model. The inference module of the inference model performs autoregressive decoding reasoning to obtain the inferred output Token sequence containing k Tokens, and inputs the inferred output Token sequence into the original model. The original model inference module performs an inference through the original model to obtain the output Token sequence. The verification module then compares and verifies the output Token sequence with the inferred output Token sequence. If the Token sequences are the same, the inferred output Token sequence is used as the final output Token sequence. Otherwise, repeat step 4 until the compared and verified Token sequences are the same, and the inferred output Token sequence is used as the final output Token sequence.
[0031] The answer generation module constructs the answer result of the user's question based on the final output Token sequence.
[0032] Furthermore, in the Token processing device of a large language model, the inference model inference module determines the k value based on the similarity between the inference model output and the original model output, including: if the probability that the first i Tokens generated by the original model are the same as the first i Tokens generated by the inference model is higher than the probability value in other cases, then i is used as the k value.
[0033] The benefits of the present invention are:
[0034] The present invention accelerates the reasoning process of the large language model when the large language model outputs tokens during text decoding, improves the efficiency of the large language model outputting tokens and reduces the computational cost. The present invention optimizes the autoregressive decoding process based on predictive reasoning, which can significantly improve the reasoning speed of the model without sacrificing output quality. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 It is a schematic diagram of the application process of the method of the present invention. DETAILED DESCRIPTION
[0036] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it, but the embodiments are not intended to limit the present invention.
[0037] Example 1
[0038] The present invention provides a Token processing method for a large language model, comprising:
[0039] Step 1: Take the large language model with a large number of parameters as the original model, and the large language model with a small number of parameters corresponding to the original model as the inferred model.
[0040] Step 2: Convert the question input by the user into a Token sequence of the question, use the inference model to perform autoregressive decoding inference based on the Token sequence of the question, and generate an inferred output Token sequence.
[0041] Step 3: Concatenate the problem’s Token sequence and the inferred output Token sequence into the input Token sequence of the original model, and use the original model to perform an inference based on the input Token sequence.
[0042] Generate an output Token sequence through inference of the original model, and compare and verify the output Token sequence with the inferred output Token sequence. If the Token sequences are the same, the inferred output Token sequence is used as the final output Token sequence, otherwise proceed to step 4.
[0043] Step 4: If the output Token sequence is different from the inferred output Token sequence, replace the inferred output Token sequence at the corresponding position with the output Token sequence of the original model, and then input the replaced Token sequence into the inference model for autoregressive decoding reasoning to obtain the inferred output Token sequence and input it into the original model. Perform a reasoning with the original model to obtain the output Token sequence, and then compare and verify the output Token sequence with the inferred output Token sequence. If the Token sequences are the same, the inferred output Token sequence is used as the final output Token sequence. Otherwise, repeat step 4 until the compared and verified Token sequences are the same, and use the inferred output Token sequence as the final output Token sequence.
[0044] Construct the answer to the user's question based on the final output Token sequence.
[0045] The main efficiency bottleneck of large language model reasoning is the autoregressive decoding process, which converts the input question into multiple tokens, first performs a reasoning on the input model, and then generates output tokens one by one. However, the generation delay of a token is similar to the delay of reasoning multiple tokens at a time. The present invention converts autoregressive decoding into a single reasoning of multiple tokens, which can accelerate the reasoning process of large language models.
[0046] Example 2
[0047] In another embodiment of the present invention, step 1: use the Llama-2-70b model with a larger number of parameters as the original model, and use the Llama-2-7b model with a smaller number of parameters corresponding to the original model as the inference model. Take the Llama-2-70b model as an example and use it as the original model. Select the Llama-2-7b model of the same series as the original model, with the same model architecture, the same training method and training data, and a smaller number of parameters as the inference model. Although the present invention introduces an additional model into the reasoning scheme of the original model, the benefits brought by the original model's autoregressive decoding conversion scheme of multiple tokens at a time can cover
[0048] Remove the load of additional models.
[0049] Step 2: Use Tokenizer to convert the question input by the user into a token sequence of the question. Use the inference model to perform autoregressive decoding inference based on the token sequence of the question to generate an inference output token sequence containing k tokens, where the k value is a hyperparameter and is determined based on the similarity between the output of the inference model and the output of the original model. Furthermore, if the probability that the first i tokens generated by the original model are the same as the first i tokens generated by the inference model is higher than the probability value in other cases, then i can be used as the k value.
[0050] Step 3: Concatenate the problem’s Token sequence and the inferred output Token sequence into the input Token sequence of the original model, and use the original model to perform an inference based on the input Token sequence.
[0051] Generate an output Token sequence through inference of the original model, and compare and verify the output Token sequence with the inferred output Token sequence. If the Token sequences are the same, the inferred output Token sequence is used as the final output Token sequence, otherwise proceed to step 4.
[0052] Step 4: If the output Token sequence is different from the inferred output Token sequence, replace the inferred output Token sequence at the corresponding position with the output Token sequence of the original model at different positions, and then input the replaced Token sequence into the inference model for autoregressive decoding reasoning to obtain an inferred output Token sequence containing k Tokens. Input the inferred output Token sequence into the original model, perform reasoning through the original model to obtain the output Token sequence, and then compare and verify the output Token sequence with the inferred output Token sequence. If the Token sequences are the same, the inferred output Token sequence is used as the final output Token sequence. Otherwise, repeat step 4 until the compared and verified Token sequences are the same, and use the inferred output Token sequence as the final output Token sequence.
[0053] Construct the answer to the user's question based on the final output Token sequence.
[0054] The inference method of the large language model based on inference of the present invention can obtain the same output result as the greedy decoding method. By converting the autoregressive decoding process into a one-time inference process, the Transformer structure can be called in parallel, thereby achieving the effect of inference acceleration.
[0055] Example 3
[0056] The present invention also provides a Token processing device for a large language model, including a model selection module, an inference model inference module, an original model inference module, a verification module and an answer generation module.
[0057] The model selection module uses the large language model with a large number of parameters as the original model, and the large language model with a small number of parameters corresponding to the original model as the inferred model.
[0058] The inference model inference module converts the question input by the user into a Token sequence of the question, and uses the inference model to perform autoregressive decoding reasoning based on the Token sequence of the question to generate an inference output Token sequence.
[0059] The original model inference module concatenates the problem's Token sequence and the inferred output Token sequence into the input Token sequence of the original model, uses the original model to perform an inference based on the input Token sequence, and generates an output Token sequence through the original model inference. The verification module compares and verifies the output Token sequence with the inferred output Token sequence. If the Token sequences are the same, the inferred output Token sequence is used as the final output Token sequence. Otherwise, if the output Token sequence is different from the inferred output Token sequence, the output Token sequence of the original model is replaced with the inferred output Token sequence at the corresponding position at different positions, and the replaced Token sequence is input into the inference model. The inference model inference module performs autoregressive decoding inference to obtain the inferred output Token sequence and input it into the original model. The original model inference module performs an inference through the original model to obtain the output Token sequence. The verification module compares and verifies the output Token sequence with the inferred output Token sequence. If the Token sequences are the same, the inferred output Token sequence is used as the final output Token sequence. Otherwise, the inference and verification process is repeated until the compared and verified Token sequences are the same, and the inferred output Token sequence is used as the final output Token sequence.
[0060] The answer generation module constructs the answer result of the user's question based on the final output Token sequence.
[0061] As the information interaction, execution process and other contents between the modules in the above-mentioned device are based on the same concept as the embodiment of the method of the present invention, the specific contents can be found in the description of the embodiment of the method of the present invention and will not be repeated here.
[0062] Similarly, the device of the present invention accelerates the reasoning process of the large language model when decoding text and outputting Tokens, improves the efficiency of the large language model outputting Tokens and reduces the computational cost. The present invention optimizes the autoregressive decoding process based on predictive reasoning, which can significantly improve the reasoning speed of the model without sacrificing output quality.
[0063] It should be noted that not all steps and modules in the above-mentioned processes and device structures are necessary, and some steps or modules can be ignored according to actual needs. The execution order of each step is not fixed and can be adjusted as needed. The system structure described in the above-mentioned embodiments can be a physical structure or a logical structure, that is, some modules may be implemented by the same physical entity, or some modules may be implemented by multiple physical entities, or some components in multiple independent devices may be implemented together.
[0064] The above-described embodiments are only preferred embodiments for fully illustrating the present invention, and the protection scope of the present invention is not limited thereto. Equivalent substitutions or changes made by those skilled in the art based on the present invention are within the protection scope of the present invention. The protection scope of the present invention shall be subject to the claims.
Claims
1. A Token processing method for a large language model, characterized by include: Step 1: Take the large language model with a large number of parameters as the original model, and the large language model with a small number of parameters corresponding to the original model as the inferred model. Step 2: Convert the question input by the user into a Token sequence of the question, use the inference model to perform autoregressive decoding inference based on the Token sequence of the question, and generate an inferred output Token sequence. Step 3: Concatenate the problem’s Token sequence and the inferred output Token sequence into the input Token sequence of the original model, and use the original model to perform an inference based on the input Token sequence. Generate an output Token sequence through inference of the original model, and compare and verify the output Token sequence with the inferred output Token sequence. If the Token sequences are the same, the inferred output Token sequence is used as the final output Token sequence, otherwise proceed to step 4. Step 4: If the output Token sequence is different from the inferred output Token sequence, replace the inferred output Token sequence at the corresponding position with the output Token sequence of the original model, and then input the replaced Token sequence into the inference model for autoregressive decoding reasoning to obtain the inferred output Token sequence and input it into the original model. Perform a reasoning with the original model to obtain the output Token sequence, and then compare and verify the output Token sequence with the inferred output Token sequence. If the Token sequences are the same, the inferred output Token sequence is used as the final output Token sequence. Otherwise, repeat step 4 until the compared and verified Token sequences are the same, and use the inferred output Token sequence as the final output Token sequence. Construct the answer to the user's question based on the final output Token sequence.
2. According to the Token processing method of a large language model described in claim 1, it is characterized in that in step 1, the Llama-2-70b model with a larger parameter amount is used as the original model, and the Llama-2-7b model with a smaller parameter amount corresponding to the original model is used as the inferred model.
3. The token processing method of a large language model according to claim 1 or 2, characterized in that step 1: taking the Llama-2-70b model with a larger parameter amount as the original model, and taking the Llama-2-7b model with a smaller parameter amount corresponding to the original model as the inferred model, Step 2: Use Tokenizer to convert the question input by the user into a Token sequence of the question. Use the inference model to perform autoregressive decoding inference based on the Token sequence of the question to generate an inferred output Token sequence containing k Tokens, where the k value is a hyperparameter. The k value is determined based on the similarity between the inferred model output and the original model output. Step 3: Concatenate the problem’s Token sequence and the inferred output Token sequence into the input Token sequence of the original model, and use the original model to perform an inference based on the input Token sequence. Generate an output Token sequence through inference of the original model, and compare and verify the output Token sequence with the inferred output Token sequence. If the Token sequences are the same, the inferred output Token sequence is used as the final output Token sequence, otherwise proceed to step 4. Step 4: If the output Token sequence is different from the inferred output Token sequence, replace the inferred output Token sequence at the corresponding position with the output Token sequence of the original model at different positions, and then input the replaced Token sequence into the inference model for autoregressive decoding reasoning to obtain an inferred output Token sequence containing k Tokens. Input the inferred output Token sequence into the original model, perform reasoning through the original model to obtain the output Token sequence, and then compare and verify the output Token sequence with the inferred output Token sequence. If the Token sequences are the same, the inferred output Token sequence is used as the final output Token sequence. Otherwise, repeat step 4 until the compared and verified Token sequences are the same, and use the inferred output Token sequence as the final output Token sequence. Construct the answer to the user's question based on the final output Token sequence.
4. The Token processing method for a large language model according to claim 3, characterized in that In step 2, the k value is determined according to the similarity between the output of the inferred model and the output of the original model, including: if the probability that the first i tokens generated by the original model are the same as the first i tokens generated by the inferred model is higher than the probability value in other cases, then i is used as the k value.
5. A Token processing device for a large language model, characterized in that It includes model selection module, inference model inference module, original model inference module, verification module and answer generation module. The model selection module uses the large language model with a large number of parameters as the original model, and the large language model with a small number of parameters corresponding to the original model as the inferred model. The inference model inference module converts the question input by the user into a Token sequence of the question, and uses the inference model to perform autoregressive decoding reasoning based on the Token sequence of the question to generate an inference output Token sequence. The original model inference module concatenates the problem's Token sequence and the inferred output Token sequence into the input Token sequence of the original model, uses the original model to perform an inference based on the input Token sequence, and generates an output Token sequence through the original model inference. The verification module compares and verifies the output Token sequence with the inferred output Token sequence. If the Token sequences are the same, the inferred output Token sequence is used as the final output Token sequence. Otherwise, if the output Token sequence is different from the inferred output Token sequence, the output Token sequence of the original model is replaced with the inferred output Token sequence at the corresponding position at different positions, and the replaced Token sequence is input into the inference model. The inference model inference module performs autoregressive decoding inference to obtain the inferred output Token sequence and input it into the original model. The original model inference module performs an inference through the original model to obtain the output Token sequence. The verification module compares and verifies the output Token sequence with the inferred output Token sequence. If the Token sequences are the same, the inferred output Token sequence is used as the final output Token sequence. Otherwise, step 4 is repeated until the compared and verified Token sequences are the same, and the inferred output Token sequence is used as the final output Token sequence. The answer generation module constructs the answer result of the user's question based on the final output Token sequence.
6. The Token processing device for a large language model according to claim 5, characterized in that the model The selection module uses the Llama-2-70b model with a larger number of parameters as the original model, and uses the Llama-2-7b model with a smaller number of parameters corresponding to the original model as the inferred model.
7. The Token processing device for a large language model according to claim 6, wherein the model The selection module uses the Llama-2-70b model with a larger number of parameters as the original model, and the Llama-2-7b model with a smaller number of parameters corresponding to the original model as the inferred model. The inference model inference module uses Tokenizer to convert the user input question into a Token sequence of the question. According to the Token sequence of the question, the inference model is used to perform autoregressive decoding inference to generate an inference output Token sequence containing k Tokens, where the k value is a hyperparameter. The k value is determined according to the similarity between the inference model output and the original model output. The original model inference module concatenates the problem's Token sequence and the inferred output Token sequence into the original model's input Token sequence, uses the original model to perform an inference based on the input Token sequence, and generates an output Token sequence through the original model inference. The verification module compares and verifies the output Token sequence with the inferred output Token sequence. If the Token sequences are the same, the inferred output Token sequence is used as the final output Token sequence. Otherwise, if the output Token sequence is different from the inferred output Token sequence, the output Token sequence of the original model is replaced with the inferred output Token sequence at the corresponding position at different positions, and then the replaced Token sequence is input into the inference model. The inference module of the inference model performs autoregressive decoding reasoning to obtain the inferred output Token sequence containing k tokens, and the inferred output Token sequence is input into the original model. The original model inference module performs an inference through the original model to obtain the output Token sequence. The verification module then compares and verifies the output Token sequence with the inferred output Token sequence. If the Token sequences are the same, the inferred output Token sequence is used as the final output Token sequence. Otherwise, the inference and verification process is repeated until the compared and verified Token sequences are the same, and the inferred output Token sequence is used as the final output Token sequence. The answer generation module constructs the answer result of the user's question based on the final output Token sequence.
8. The Token processing device for a large language model according to claim 7, characterized in that The model inference module determines the k value according to the similarity between the inferred model output and the original model output, including: if the probability that the first i tokens generated by the original model are the same as the first i tokens generated by the inferred model is higher than the probability value in other cases, then i is used as the k value.
Citation Information
Patent Citations
Model processing method and device
CN115563238A
Cross-language question answering system construction method and device based on generative multi-language model
CN115795009A
MT5 language model optimization method and device, medium and equipment
CN116579385A
Natural language question answering method and device based on small language model cluster and medium
CN116910217A
Open domain natural language reasoning question-answering system and method driven by large language model
CN116932708A
Cited By
Speculation decoding method and device based on large model, equipment and storage medium
CN119806649A
Large model-based speculative decoding method and device, equipment and storage medium
CN119806649B
