Inference engine creation method, product, device and computer readable storage medium

By dividing and quantifying the network layer weights of large language models, combined with operator fusion operations, the computational complexity and accuracy problems caused by the increase in the number of parameters of large language models are solved, and efficient deployment and accurate inference on computing devices are achieved.

CN118469024BActive Publication Date: 2024-10-15LANGCHAO ELECTRONIC INFORMATION IND CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410924977.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-11
Publication Date
2024-10-15
Estimated Expiration
2044-07-11

AI Technical Summary

Technical Problem

As the number of parameters of large language models (LLM) increases, the amount of calculation increases rapidly, resulting in inference performance that cannot meet application needs. When the model is converted to an inference engine, parameter compression leads to loss of accuracy, affecting the accuracy of the inference results, and after conversion The inference engine requires more cache and is not easy to deploy on computing devices.

Method used

By obtaining the network layer weight of the initial model, it is divided into primary weight and secondary weight. The primary weight is quantified first, and the compensation parameters of the quantization operation are calculated. Combined with the operator fusion operation, the model can be compressed to the greatest extent while maintaining the initial state to the greatest extent. accuracy and reduce the storage space occupied by computing devices.

Benefits of technology

The inference accuracy of the inference engine is improved, the storage space occupied by the computing device is reduced, and the inference engine is conveniently deployed on the computing device.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118469024B_ABST
    Figure CN118469024B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, product, device and computer-readable storage medium for creating an inference engine, which relates to the field of inference. To solve the problem that the inference engine is not convenient to deploy on the device, the method includes obtaining the weights of each network layer of the initial model; determining the influence parameter of the weight change of each network layer on the model loss after the target weight is determined, and determining the weight of each network layer as the main weight or the secondary weight based on each influence parameter; performing a first quantization operation on the main weight according to the quantization accuracy requirement to obtain the first weight, and obtaining the first compensation parameter corresponding to the first quantization operation; performing an operator fusion operation on the network layer corresponding to the main weight to obtain the inference engine corresponding to the initial model. The present invention can achieve the maximum compression of the model while maintaining the original accuracy of the initial model to the maximum extent, reduce the occupation of the storage space of the computing device, facilitate deployment on the computing device, and improve the inference accuracy of the inference engine.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of reasoning, and in particular to a reasoning engine creation method, product, device and computer-readable storage medium. Background Art

[0002] In order to improve the model performance of LLM (Large Language Model), the number of parameters has gradually increased from the initial 100M level to the 1000M level, 10B level, 100B level, and even 1000B level. As the number of LLM parameters increases, the amount of calculation also increases sharply, resulting in the inference performance of LLM being unable to meet the current application requirements of large models. In order to optimize, the common solution is to convert the initial model into an inference engine through the developed large model inference framework. However, during the conversion process, the relevant parameters of the model need to be compressed, resulting in a certain loss of accuracy of the converted inference engine relative to the initial model, affecting the accuracy of the inference results. In addition, the converted inference engine needs to pre-allocate more cache, which is not convenient for deployment on computing devices.

[0003] Therefore, how to provide a solution to the above technical problems is a problem that those skilled in the art need to solve at present. Summary of the invention

[0004] The purpose of the present invention is to provide a method, product, device and computer-readable storage medium for creating an inference engine, which can achieve maximum compression of the model while maintaining the original accuracy of the initial model to the greatest extent, thereby improving the reasoning accuracy of the inference engine.

[0005] In order to solve the above technical problems, the present invention provides a method for creating an inference engine, comprising:

[0006] Get the weights of each network layer of the initial model;

[0007] Determine the influence parameter of the weight change of each network layer on the model loss after the weight is changed to the target weight, and determine the weight of each network layer as the main weight or the secondary weight based on each of the influence parameters;

[0008] Performing a first quantization operation on the main weight according to the quantization accuracy requirement to obtain a first weight, and obtaining a first compensation parameter corresponding to the first quantization operation;

[0009] An operator fusion operation is performed on the network layer corresponding to the main weight to obtain an inference engine corresponding to the initial model, so that the inference engine can be deployed on a computing device to perform inference operations.

[0010] The process of obtaining the weights of each network layer of the initial model includes:

[0011] Get the configuration file of the initial model;

[0012] The weights of each network layer are obtained according to the configuration file of the initial model.

[0013] The process of determining the parameters affecting the model loss after the weight of each network layer is changed to the target weight includes:

[0014] A matrix multiplication operation is performed on the weight of each of the network layers to obtain an impact parameter on the model loss after the weight of each of the network layers is changed to the target weight.

[0015] The process of determining the weight of each network layer as a primary weight or a secondary weight based on each of the influencing parameters includes:

[0016] Determining whether each of the influencing parameters is less than a critical value;

[0017] If so, determining the weight of the network layer corresponding to the influencing parameter as a secondary weight;

[0018] If not, the weight of the network layer corresponding to the influencing parameter is determined as the main weight.

[0019] Before performing a first quantization operation on the main weight according to the quantization accuracy requirement to obtain the first weight, the inference engine creation method further includes:

[0020] Determine the structure of the network layer corresponding to the main weight;

[0021] Determine a quantization algorithm corresponding to the main weight based on the structure;

[0022] The process of performing a first quantization operation on the main weight according to the quantization accuracy requirement to obtain the first weight includes:

[0023] A first quantization operation is performed on the main weight according to the quantization accuracy requirement and the quantization algorithm to obtain a first weight.

[0024] Wherein, after performing a first quantization operation on the main weight according to the quantization accuracy requirement to obtain a first weight, and obtaining a first compensation parameter corresponding to the first quantization operation, the inference engine creation method further includes:

[0025] Determining a target network layer among the network layers corresponding to the main weights;

[0026] The target network layer is quantized and trained to compensate for a first quantization operation of the target network layer.

[0027] The process of obtaining the first compensation parameter corresponding to the first quantization operation includes:

[0028] Creating a compensation relationship based on the main weight, target weight, preset matrix and preset coefficient;

[0029] A first compensation parameter corresponding to the first quantization operation is obtained using the compensation relationship.

[0030] After determining that the weight of each network layer is a primary weight or a secondary weight based on each of the influencing parameters, the inference engine creation method further includes:

[0031] determining a weight to be quantified among all the secondary weights;

[0032] A second quantization operation is performed on the weight to be quantized according to the quantization accuracy requirement of the weight to be quantized to obtain a second weight, and a second compensation parameter corresponding to the second quantization operation is obtained.

[0033] The process of performing a second quantization operation on the weight to be quantized according to the quantization accuracy requirement of the weight to be quantized to obtain the second weight includes:

[0034] Determining a quantization algorithm according to the quantization accuracy requirement of the weight to be quantized;

[0035] Based on the quantization accuracy requirement and the quantization algorithm, a second quantization operation is performed on the weight to be quantized to obtain a second weight.

[0036] The process of performing operator fusion operation on the network layer corresponding to the main weight includes:

[0037] Determine the structure of the network layer corresponding to the main weight;

[0038] When it is determined based on the structure that the network layer corresponding to the main weight is an attention layer, a normalization operation is performed on the input data of the attention layer to obtain a query vector, a value vector and a key vector;

[0039] Obtaining an attention value based on the transpose of the query vector and the transpose of the key vector;

[0040] The output data of the attention layer is obtained according to the attention value, the transpose of the value vector, and the first activation function of the attention layer.

[0041] The process of performing operator fusion operation on the network layer corresponding to the main weight includes:

[0042] Determine the structure of the network layer corresponding to the main weight;

[0043] When it is determined based on the structure that the network layer corresponding to the main weight is a feedforward layer, judging whether the initial model is a hybrid expert structure;

[0044] If yes, perform a first operator fusion operation on the feedforward layer; the first operator fusion operation includes normalizing the input data of the feedforward layer to obtain a first linear layer name of a hybrid expert structure, obtaining a second linear layer name of the hybrid expert structure based on the first linear layer name and a second activation function, and obtaining output data of the feedforward layer according to the second linear layer name;

[0045] If not, perform a second operator fusion operation on the feedforward layer; the second operator fusion operation includes normalizing the input data of the feedforward layer to obtain the name of the third linear layer of the multilayer perceptron structure, obtaining the name of the fourth linear layer of the multilayer perceptron structure based on the third linear layer name and the second activation function, and obtaining the output data of the feedforward layer according to the fourth linear layer name.

[0046] Wherein, after performing an operator fusion operation on the network layer corresponding to the main weight to obtain an inference engine corresponding to the initial model, the inference engine creation method further includes:

[0047] determining a plurality of preset sequence lengths;

[0048] Physical storage blocks corresponding to a plurality of preset sequence lengths are allocated to the inference engine so that when user input data is received, a target storage block is selected based on the user input data and the preset sequence length corresponding to the inference result.

[0049] In order to solve the above technical problems, the present invention also provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the steps of any of the above-mentioned inference engine creation methods.

[0050] In order to solve the above technical problems, the present invention further provides an electronic device, comprising:

[0051] Memory for storing computer programs;

[0052] A processor is used to implement the steps of the inference engine creation method as described in any one of the above when executing the computer program.

[0053] In order to solve the above technical problems, the present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the inference engine creation method as described in any one of the above are implemented.

[0054] The present invention provides a method for creating an inference engine. First, the weights of each network layer of the initial model are obtained. The weights are divided into primary weights and secondary weights based on the influence of the weights of each network layer on the model loss. During the conversion process, the present invention preferentially quantizes the primary weights and calculates the compensation parameters of the quantization operation. When the converted inference engine is used later, the quantized weights are compensated based on the compensation parameters to achieve maximum compression of the model while maintaining the original accuracy of the initial model to the maximum extent. The network layer corresponding to the primary weights is subjected to operator fusion operations, and the encapsulation of the inference engine is realized. Since the inference engine can maintain the original accuracy of the initial model to the maximum extent, the accuracy of the inference results when the inference is performed through the inference engine is guaranteed, and the storage space occupied by the computing device is reduced, which is convenient for deployment on the computing device. The present invention also provides a computer program product, an electronic device, and a computer-readable storage medium, which have the above-mentioned beneficial effects. BRIEF DESCRIPTION OF THE DRAWINGS

[0055] In order to more clearly illustrate the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0056] Figure 1 A flowchart of the steps of a method for creating an inference engine provided by the present invention;

[0057] Figure 2 A schematic diagram of operator fusion for the attention layer provided by the present invention;

[0058] Figure 3 A schematic diagram of operator fusion for a feedforward layer provided by the present invention;

[0059] Figure 4 A structural schematic diagram of an inference engine creation system provided by the present invention;

[0060] Figure 5 A schematic diagram of the structure of an electronic device provided by the present invention;

[0061] Figure 6 This is a schematic diagram of the structure of a computer-readable storage medium provided by the present invention. DETAILED DESCRIPTION

[0062] The core of the present invention is to provide a method, product, device and computer-readable storage medium for creating an inference engine, which can achieve maximum compression of the model while maintaining the original accuracy of the initial model to the greatest extent, thereby improving the reasoning accuracy of the inference engine.

[0063] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0064] First, please refer to Figure 1 The present invention provides a method for creating an inference engine, comprising:

[0065] S101: Obtain the weights of each network layer of the initial model;

[0066] The initial model in this embodiment is a model to be converted into an inference engine. Specifically, the information of each network layer can be obtained by obtaining the configuration file config of the initial model. The information of the network layer includes but is not limited to the weight of the network layer.

[0067] S102: Determine an influencing parameter of the model loss after the weight of each network layer changes to the target weight, and determine the weight of each network layer as a primary weight or a secondary weight based on each influencing parameter;

[0068] This embodiment includes but is not limited to compressing the initial model by quantizing the weights of the network layer. First, the weights are classified. Specifically, the weights W of the Nth network layer can be N Change to the target weight W M The influence of the model loss of the initial model on the weight W of the Nth network layer N Classify them and determine those with greater impact as primary weights and those with smaller impact as secondary weights.

[0069] S103: performing a first quantization operation on the main weight according to the quantization accuracy requirement to obtain a first weight, and obtaining a first compensation parameter corresponding to the first quantization operation;

[0070] In this embodiment, a first quantization operation is performed on the main weight according to the quantization accuracy requirement of each main weight to obtain a first weight. Exemplarily, the accuracy of the main weight can be FP32, and the accuracy of the first weight obtained after the main weight is quantized can be int4 or int8.

[0071] Furthermore, considering that the quantization of the main weights will cause a certain loss in the accuracy of the initial model, the present embodiment also obtains a first compensation parameter corresponding to the first quantization operation. When the converted inference engine is subsequently used, compensation can be performed using the first compensation parameter to maintain the original accuracy of the initial model to the greatest extent.

[0072] S104: Performing operator fusion operations on the network layers corresponding to the main weights to obtain an inference engine corresponding to the initial model, so as to deploy the inference engine on a computing device to perform inference operations.

[0073] In this embodiment, the matrix multiplication process of the network layer corresponding to the main weights is optimized and the operators are fused, which overall realizes the encapsulation of the inference engine integrating multiple optimization technologies, and high-performance reasoning and deployment can be achieved based on the inference engine in the future.

[0074] The present invention provides a method for creating an inference engine. First, the weights of each network layer of an initial model are obtained, and the weights are divided into main weights and secondary weights based on the influence of the weights of each network layer on the model loss. During the conversion process, the present invention preferentially quantizes the main weights and calculates compensation parameters of the quantization operation. When the converted inference engine is subsequently used, the quantized weights are compensated based on the compensation parameters to achieve maximum compression of the model while maintaining the original accuracy of the initial model to the maximum extent. Operator fusion operations are performed on the network layers corresponding to the main weights, thereby realizing the encapsulation of the inference engine. Since the inference engine can maintain the original accuracy of the initial model to the maximum extent, the accuracy of the inference results when reasoning is performed through the inference engine is guaranteed, the storage space occupied by the computing device is reduced, and it is convenient to deploy on the computing device.

[0075] Based on the above embodiments:

[0076] In an exemplary embodiment, the process of determining the influencing parameters of the model loss after the weight of each network layer is changed to the target weight includes:

[0077] Perform matrix multiplication on the weights of each network layer to obtain the parameters that affect the model loss after the weights of each network layer are changed to the target weights.

[0078] In this embodiment, the weight W of the Nth network layer can be specifically N Perform matrix multiplication to obtain the weight W of the Nth network layer N The influencing parameters of the model loss improve the accuracy of the obtained influencing parameters. Among them, the weight W of the Nth network layer N Perform matrix multiplication operation, that is, the influencing parameter is W N GEMM, where GEMM is a matrix multiplication calculation.

[0079] As an optional embodiment, the Hessian matrix algorithm can be used to determine the optimal order of performing quantization operations on the weights of each network layer. When the quantization operation is performed subsequently, the weights of each network layer are quantized in the optimal order. Specifically, the optimal order of performing quantization operations on the weights of each network layer can be determined by the first relational expression. The first relational expression is: , where W M is the target weight, H is the Hessian matrix, [H -1 ] is the inverse matrix of the Hessian matrix, is the value of the inverse matrix of the Hessian matrix in the Nth row and Nth column; the target weight is the quantized weight, and argmin is the minimum value calculation, which is equivalent to selecting the minimum value of the following formula from all the weights (that is, the weight with the least influence). It can be understood that the execution order of the weight with the least influence is the earlier, so as to give priority to quantizing the weights of the network layers that have less impact on the accuracy of the initial model, thereby maintaining the original accuracy of the initial model to the greatest extent.

[0080] In an exemplary embodiment, the process of determining the weight of each network layer as a primary weight or a secondary weight based on each impact parameter includes:

[0081] Determine whether each influencing parameter is less than a critical value;

[0082] If so, the weight of the network layer corresponding to the influencing parameter is determined as the secondary weight;

[0083] If not, the weight of the network layer corresponding to the influencing parameter is determined as the main weight.

[0084] In this embodiment, the critical value β is first obtained, and then the influencing parameter W N GEMM compares with the critical value β. If the influencing parameter is less than the critical value, the weight W of the Nth network layer N is a secondary weight, otherwise it is a primary weight.

[0085] In an exemplary embodiment, before performing a first quantization operation on the main weight according to the quantization accuracy requirement to obtain the first weight, the inference engine creation method further includes:

[0086] Determine the structure of the network layer corresponding to the main weights;

[0087] A quantitative algorithm corresponding to the main weights is determined based on the structure;

[0088] The process of performing a first quantization operation on the main weight according to the quantization accuracy requirement to obtain the first weight includes:

[0089] A first quantization operation is performed on the main weight according to the quantization accuracy requirement and the quantization algorithm to obtain the first weight.

[0090] Taking into account that the structure of the network layer of the main weights will also be different, for example, the attention layer and the feedforward layer, different network layer structures will affect the selection of the quantization algorithm. Therefore, in this embodiment, the structure of the network layer is first determined, and then the corresponding quantization algorithm is selected based on the structure of the network layer. Then, the first quantization operation is performed on the main weights together with the quantization accuracy requirements and the quantization algorithm to obtain a better compression effect.

[0091] In an exemplary embodiment, after performing a first quantization operation on the main weight according to the quantization accuracy requirement to obtain the first weight and obtaining the first compensation parameter corresponding to the first quantization operation, the inference engine creation method further includes:

[0092] Determine the target network layer among the network layers corresponding to the main weights;

[0093] The target network layer is quantized and trained to compensate for the first quantization operation of the target network layer.

[0094] Considering that the main weights have a greater impact on maintaining the accuracy of the model, this embodiment also performs quantization training compensation on specific network layers in the network layers corresponding to the main weights to maintain the accuracy of the initial model.

[0095] In an exemplary embodiment, the process of obtaining a first compensation parameter corresponding to the first quantization operation includes:

[0096] Creating compensation relationships based on primary weights, target weights, preset matrices, and preset coefficients;

[0097] A first compensation parameter corresponding to the first quantization operation is obtained using the compensation relationship.

[0098] In this embodiment, compensation is performed according to the error that may be generated by the quantization operation. Specifically, the first compensation parameter corresponding to the first quantization operation can be obtained through a compensation relationship. The compensation relationship is: ; Among them, [H -1 ] NN is the value of the inverse matrix of the Hessian matrix in row N and column N, [H -1 ] :,N Indicates H -1 The Nth column of is the first compensation parameter, and γ is a specific coefficient calculated according to the size of the weight influence (there is a certain difference in the size of each weight).

[0099] In an exemplary embodiment, after determining the weight of each network layer as a primary weight or a secondary weight based on each influencing parameter, the inference engine creation method further includes:

[0100] Determine the weight to be quantified among all the secondary weights;

[0101] A second quantization operation is performed on the weight to be quantized according to the quantization accuracy requirement of the weight to be quantized to obtain a second weight, and a second compensation parameter corresponding to the second quantization operation is obtained.

[0102] In this embodiment, for the network layer corresponding to the secondary weight, quantization with selectable precision is performed, such as quantization or non-quantization, so as to reduce the occupation of computing resources. It can be understood that after the quantization operation, there will be quantization errors. Therefore, the second compensation parameter is also calculated for the secondary weight that performs the second quantization operation, which can be specifically calculated by the following formula:

[0103] ; is the second compensation parameter.

[0104] In an exemplary embodiment, the process of performing a second quantization operation on the weight to be quantized according to the quantization accuracy requirement of the weight to be quantized to obtain the second weight includes:

[0105] Determine the quantization algorithm according to the quantization accuracy requirement of the weight to be quantized;

[0106] A second quantization operation is performed on the weight to be quantized based on the quantization accuracy requirement and the quantization algorithm to obtain a second weight.

[0107] In this embodiment, when the quantization accuracy requirements for the weights to be quantized are different, the selectable quantization algorithms are also different. First, the quantization algorithm is determined according to the quantization accuracy requirements, and then the quantization algorithm is used to quantize the weights to be quantized so that the quantized second weights meet the quantization accuracy requirements. For example, assuming that the quantization accuracy requirement is int4 or below, the second quantization operation can be performed based on the GPTQ (Generative Pre-trained Transformer Quantization) or AWQ (Activation-aware Weight Quantization) algorithm. If you want to perform int8 precision quantization, you can perform the second quantization operation based on SmoothQuant (smoothing quantization method).

[0108] As an optional embodiment, information of the network layer corresponding to the secondary weight can be displayed on the interactive interface, the information including the structure of the network layer, optional quantization algorithm, optional quantization accuracy requirement, etc., so that the user can output corresponding selection instructions based on the above information and the deployment hardware and acceleration requirements of the inference engine. The selection instructions are used to select the weights to be quantized and the quantization algorithm. The second quantization operation is performed on the weights to be quantized according to the quantization algorithm and quantization accuracy requirement determined by the user selection instruction, thereby improving the construction flexibility of the inference engine to meet its inference acceleration and deployment needs.

[0109] For the network layer with main weights, after the above customized quantization operation, matrix multiplication optimization is performed for specific network layers. Currently, the main calculation of the Transformer model is in the Attention layer, followed by the feedforward layer. This embodiment describes the process of optimizing the matrix multiplication process of the attention layer and the feedforward layer and the process of operator fusion.

[0110] In an exemplary embodiment, the process of performing operator fusion operation on the network layer corresponding to the main weight includes:

[0111] Determine the structure of the network layer corresponding to the main weights;

[0112] When the network layer corresponding to the main weight is determined to be the attention layer based on the structure, the input data of the attention layer is normalized to obtain the query vector, value vector and key vector;

[0113] Get the attention value based on the transpose of the query vector and the transpose of the key vector;

[0114] The output data of the attention layer is obtained according to the attention value, the transpose of the value vector, and the first activation function of the attention layer.

[0115] In this embodiment, with the help of the kernel optimization idea in DeepSpeed ​​Inference, the Attention part is further divided into QKV (Query, Key, Value) kernel and Attention Kernel, and then the operators are fused separately; in addition, we also group the attention heads, and each group shares the KV parameters (Grouped-Query Attention idea) to further reduce the possible required calculation process, refer to Figure 2 As shown in Figure 1, the operator fusion process includes normalizing the input data to obtain the query vector, value vector and key vector. Figure 2 In the example, the query vector, value vector, and key vector are represented by Q, V, and K respectively. The transpose of the query vector, value vector, and key vector are obtained respectively. Figure 2 China-Israel Q T 、V T and K T According to Q T , K T Get the attention value, input the attention value into the first activation function Softmax, based on the output of the first activation function Softmax and V T Get the output data of the attention layer.

[0116] In an exemplary embodiment, the process of performing operator fusion operation on the network layer corresponding to the main weight includes:

[0117] Determine the structure of the network layer corresponding to the main weights;

[0118] When the network layer corresponding to the main weight is determined to be a feedforward layer based on the structure, it is determined whether the initial model is a mixed expert structure;

[0119] If yes, perform a first operator fusion operation on the feedforward layer; the first operator fusion operation includes normalizing the input data of the feedforward layer to obtain the first linear layer name of the hybrid expert structure, obtaining the second linear layer name of the hybrid expert structure based on the first linear layer name and the second activation function, and obtaining the output data of the feedforward layer according to the second linear layer name;

[0120] If not, perform a second operator fusion operation on the feedforward layer; the second operator fusion operation includes normalizing the input data of the feedforward layer to obtain the name of the third linear layer of the multilayer perceptron structure, obtaining the name of the fourth linear layer of the multilayer perceptron structure based on the third linear layer name and the second activation function, and obtaining the output data of the feedforward layer according to the fourth linear layer name.

[0121] In this embodiment, for the feedforward layer, a judgment is made first to determine whether the initial model is a MOE (Mixture of Experts) structure. Figure 3 As shown, if it is an MOE structure, Variable Sized Grouped GEMM (Grouped GEMM if the number of tokens of each expert is the same) is performed and then fused with activation functions, normalization operations Norm and other processes, including normalizing the input data of the feedforward layer to obtain the first linear layer name W1 of the hybrid expert structure, obtaining the second linear layer name W2 of the hybrid expert structure based on the first linear layer name W1 and the second activation function GELU, and obtaining the output data of the feedforward layer according to the second linear layer name W2; if it is not an MOE structure, the operator fusion strategy is directly applied, including normalizing the input data of the feedforward layer to obtain the third linear layer name U_g_p of the multilayer perceptron (MLP) structure, obtaining the fourth linear layer name D_p of the multilayer perceptron structure based on the third linear layer name U_g_p and the second activation function GELU, and obtaining the output data of the feedforward layer according to the fourth linear layer name D_p.

[0122] Based on the above process and related algorithms, the calculation process of the initial model is optimized according to the network structure of the read initial model. At the same time, the optimization kernel based on CUDA (Compute Unified Device Architecture, a general parallel computing architecture) within the TensorRT-LLM (TensorRT-LLM is an open source library for defining, optimizing and executing reasoning of large language models (LLM) in production environments) and vLLM (Virtual Large Language Model) reasoning framework is adopted to realize the construction of the inference engine Optimized Engine.

[0123] In an exemplary embodiment, after performing an operator fusion operation on the network layer corresponding to the main weight to obtain an inference engine corresponding to the initial model, the inference engine creation method further includes:

[0124] determining a plurality of preset sequence lengths;

[0125] Physical storage blocks corresponding to a plurality of preset sequence lengths are allocated to the inference engine so that when user input data is received, a target storage block is selected based on the user input data and the preset sequence length corresponding to the inference result.

[0126] In this embodiment, considering that PagedAttention (virtual memory paging management technology) in vLLM has certain advantages in processing long sequences, it can process nearly 40 requests at the same time. However, if a short sequence is processed, the video memory occupancy will inevitably be high. In addition, the paging management strategy is a method of evenly dividing the sequence into pages of a fixed size, which has limitations in processing the diversity of tasks. In order to dynamically adjust the position and size of the page according to the importance and relevance of different parts of the sequence, on the one hand, it can further reduce memory waste and reduce the complexity of calculation. This embodiment proposes a more flexible paging strategy. When mapping from logical blocks to physical blocks, a more flexible Block table is used. It can allocate physical blocks (i.e., storage blocks) of appropriate sizes according to preset sequence lengths and task types. Specifically, a first storage block adapted to long sequences and a second storage block adapted to short sequences can be allocated. When user input data is received, a target storage block is selected from the first storage block and the second storage block based on the preset sequence length corresponding to the user input data and the inference result. In addition, when more space needs to be allocated, a memory request can be further sent to the machine and memory space can be allocated, thereby reducing resource waste caused by the block division process. Requests can also be sent more flexibly to divide the memory into blocks on demand.

[0127] In summary, the present invention provides a solution for classifying and marking the degree of influence of model weights, and performs customized quantization methods according to accuracy requirements, thereby achieving maximum compression of the model while maintaining the original accuracy of the model to the greatest extent through quantization compensation. The present invention provides a more efficient and more widely applicable fusion matrix multiplication algorithm, which optimizes the matrix multiplication process and operator fusion of a specific layer according to the structure of the model, and ultimately realizes the encapsulation of an Optimized Engine that integrates multiple optimization technologies. The present invention also provides a more flexible and intelligent paging memory management solution, which allocates memory on demand according to the sequence requirements of input and output, thereby reducing resource waste and improving efficient memory management.

[0128] Second, please refer to Figure 4 The present invention also provides a reasoning engine creation system, comprising:

[0129] An acquisition module 11 is used to obtain the weights of each network layer of the initial model;

[0130] A first determination module 12 is used to determine the influence parameter of the weight change of each network layer on the model loss after the weight is changed to the target weight, and determine the weight of each network layer as the main weight or the secondary weight based on each influence parameter;

[0131] A quantization module 13, configured to perform a first quantization operation on the main weight according to the quantization accuracy requirement to obtain a first weight, and obtain a first compensation parameter corresponding to the first quantization operation;

[0132] The fusion module 14 is used to perform operator fusion operations on the network layers corresponding to the main weights to obtain an inference engine corresponding to the initial model, so as to deploy the inference engine on a computing device to perform inference operations.

[0133] It can be seen that in this embodiment, the weights of each network layer of the initial model are first obtained, and the weights are divided into main weights and secondary weights based on the influence of the weights of each network layer on the model loss. During the conversion process, the present invention gives priority to quantizing the main weights, and at the same time calculates the compensation parameters of the quantization operation. When the converted inference engine is subsequently used, the quantized weights are compensated based on the compensation parameters to achieve maximum compression of the model while maintaining the original accuracy of the initial model to the greatest extent, and perform operator fusion operations on the network layers corresponding to the main weights, thereby realizing the encapsulation of the inference engine. Since the inference engine can maintain the original accuracy of the initial model to the greatest extent, the accuracy of the inference results when reasoning is performed through the inference engine is guaranteed, and the storage space occupied by the computing device is reduced, which is convenient for deployment on the computing device.

[0134] In an exemplary embodiment, the process of obtaining the weights of each network layer of the initial model includes:

[0135] Get the configuration file of the initial model;

[0136] Get the weights of each network layer according to the configuration file of the initial model.

[0137] In an exemplary embodiment, the process of determining the influencing parameters of the model loss after the weight of each network layer is changed to the target weight includes:

[0138] Perform matrix multiplication on the weights of each network layer to obtain the parameters that affect the model loss after the weights of each network layer are changed to the target weights.

[0139] In an exemplary embodiment, the process of determining the weight of each network layer as a primary weight or a secondary weight based on each impact parameter includes:

[0140] Determine whether each influencing parameter is less than a critical value;

[0141] If so, the weight of the network layer corresponding to the influencing parameter is determined as the secondary weight;

[0142] If not, the weight of the network layer corresponding to the influencing parameter is determined as the main weight.

[0143] In an exemplary embodiment, the inference engine creation system further includes:

[0144] A second determination module is used to determine the structure of the network layer corresponding to the main weight before performing a first quantization operation on the main weight according to the quantization accuracy requirement to obtain the first weight;

[0145] A third determination module is used to determine the quantization algorithm corresponding to the main weights based on the structure;

[0146] The process of performing a first quantization operation on the main weight according to the quantization accuracy requirement to obtain the first weight includes:

[0147] A first quantization operation is performed on the main weight according to the quantization accuracy requirement and the quantization algorithm to obtain the first weight.

[0148] In an exemplary embodiment, the inference engine creation system further includes:

[0149] A fourth determination module is used to determine a target network layer in the network layer corresponding to the main weight after performing a first quantization operation on the main weight according to the quantization accuracy requirement to obtain a first weight and obtaining a first compensation parameter corresponding to the first quantization operation;

[0150] The quantization module is also used to perform quantization training on the target network layer to compensate for the first quantization operation of the target network layer.

[0151] In an exemplary embodiment, the process of obtaining a first compensation parameter corresponding to the first quantization operation includes:

[0152] Creating compensation relationships based on primary weights, target weights, preset matrices, and preset coefficients;

[0153] A first compensation parameter corresponding to the first quantization operation is obtained using the compensation relationship.

[0154] In an exemplary embodiment, the inference engine creation system further includes:

[0155] a fifth determination module, configured to determine a weight to be quantized among all the secondary weights after determining the weight of each network layer as a primary weight or a secondary weight based on each influencing parameter;

[0156] A second quantization operation is performed on the weight to be quantized according to the quantization accuracy requirement of the weight to be quantized to obtain a second weight, and a second compensation parameter corresponding to the second quantization operation is obtained.

[0157] In an exemplary embodiment, the process of performing a second quantization operation on the weight to be quantized according to the quantization accuracy requirement of the weight to be quantized to obtain the second weight includes:

[0158] Determine the quantization algorithm according to the quantization accuracy requirement of the weight to be quantized;

[0159] A second quantization operation is performed on the weight to be quantized based on the quantization accuracy requirement and the quantization algorithm to obtain a second weight.

[0160] In an exemplary embodiment, the process of performing operator fusion operation on the network layer corresponding to the main weight includes:

[0161] Determine the structure of the network layer corresponding to the main weights;

[0162] When the network layer corresponding to the main weight is determined to be the attention layer based on the structure, the input data of the attention layer is normalized to obtain the query vector, value vector and key vector;

[0163] Get the attention value based on the transpose of the query vector and the transpose of the key vector;

[0164] The output data of the attention layer is obtained according to the attention value, the transpose of the value vector, and the first activation function of the attention layer.

[0165] In an exemplary embodiment, the process of performing operator fusion operation on the network layer corresponding to the main weight includes:

[0166] Determine the structure of the network layer corresponding to the main weights;

[0167] When the network layer corresponding to the main weight is determined to be a feedforward layer based on the structure, it is determined whether the initial model is a mixed expert structure;

[0168] If yes, perform a first operator fusion operation on the feedforward layer; the first operator fusion operation includes normalizing the input data of the feedforward layer to obtain the first linear layer name of the hybrid expert structure, obtaining the second linear layer name of the hybrid expert structure based on the first linear layer name and the second activation function, and obtaining the output data of the feedforward layer according to the second linear layer name;

[0169] If not, perform a second operator fusion operation on the feedforward layer; the second operator fusion operation includes normalizing the input data of the feedforward layer to obtain the name of the third linear layer of the multilayer perceptron structure, obtaining the name of the fourth linear layer of the multilayer perceptron structure based on the third linear layer name and the second activation function, and obtaining the output data of the feedforward layer according to the fourth linear layer name.

[0170] In an exemplary embodiment, after performing an operator fusion operation on the network layer corresponding to the main weight to obtain an inference engine corresponding to the initial model, the inference engine creation system further includes:

[0171] determining a plurality of preset sequence lengths;

[0172] Physical storage blocks corresponding to a plurality of preset sequence lengths are allocated to the inference engine so that when user input data is received, a target storage block is selected based on the user input data and the preset sequence length corresponding to the inference result.

[0173] In a third aspect, the present invention further provides a computer program product, comprising a computer program / instruction, which, when executed by a processor, implements the steps of the inference engine creation method described in any of the above embodiments.

[0174] For an introduction to a computer program product provided by the present invention, please refer to the above embodiments, and the present invention will not be described in detail here.

[0175] A computer program product provided by the present invention has the same beneficial effects as the above-mentioned reasoning engine creation method.

[0176] Fourth, please refer to Figure 5 The present invention also provides an electronic device, comprising:

[0177] A memory 21, used for storing computer programs;

[0178] The processor 22 is used to implement the steps of the method for creating an inference engine as described in any one of the embodiments above when executing a computer program.

[0179] The electronic device also includes:

[0180] The input interface 23 is connected to the processor 22 via the communication bus 26, and is used to obtain the computer programs, parameters and instructions imported from the outside, and save them in the memory 21 under the control of the processor 22. The input interface can be connected to an input device to receive parameters or instructions manually input by the user. The input device can be a touch layer covered on the display screen, or a key, trackball or touchpad set on the terminal housing.

[0181] The display unit 24 is connected to the processor 22 via the communication bus 26 and is used to display the data sent by the processor 22. The display unit can be a liquid crystal display or an electronic ink display.

[0182] The network port 25 is connected to the processor 22 via the communication bus 26, and is used to communicate with various external terminal devices. The communication technology used in the communication connection can be a wired communication technology or a wireless communication technology, such as mobile high-definition link technology, universal serial bus, high-definition multimedia interface, wireless fidelity technology, Bluetooth communication technology, low-power Bluetooth communication technology, communication technology based on IEEE802.11s, etc.

[0183] For an introduction to an electronic device provided by the present invention, please refer to the above embodiments, and the present invention will not be described in detail here.

[0184] The electronic device provided by the present invention has the same beneficial effects as the above-mentioned inference engine creation method.

[0185] Fifth, please refer to Figure 6 The present invention further provides a computer-readable storage medium 30, on which a computer program 31 is stored. When the computer program 31 is executed by a processor, the steps of the inference engine creation method described in any of the above embodiments are implemented.

[0186] The computer storage medium 30 may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.

[0187] For an introduction to a computer-readable storage medium provided by the present invention, please refer to the above embodiments, and the present invention will not be described in detail here.

[0188] A computer-readable storage medium provided by the present invention has the same beneficial effects as the above-mentioned inference engine creation method.

[0189] It should also be noted that, in this specification, relational terms such as first and second, etc. 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 these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.

[0190] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for creating an inference engine, characterized in that: include: Get the weights of each network layer of the initial model; Determine the influence parameter of the weight change of each network layer on the model loss after the weight is changed to the target weight, and determine the weight of each network layer as the main weight or the secondary weight based on each of the influence parameters; Performing a first quantization operation on the main weight according to the quantization accuracy requirement to obtain a first weight, and obtaining a first compensation parameter corresponding to the first quantization operation; Performing an operator fusion operation on the network layer corresponding to the main weight to obtain an inference engine corresponding to the initial model, so as to deploy the inference engine on a computing device to perform an inference operation; The inference engine creation method also includes: determining a plurality of preset sequence lengths; Allocating physical storage blocks corresponding to a plurality of preset sequence lengths to the inference engine in the memory of the computing device, so that when receiving user input data, a target storage block is selected based on the user input data and the preset sequence length corresponding to the inference result; The process of performing operator fusion operation on the network layer corresponding to the main weights includes: Determine the structure of the network layer corresponding to the main weight; When it is determined based on the structure that the network layer corresponding to the main weight is an attention layer, a normalization operation is performed on the input data of the attention layer to obtain a query vector, a value vector and a key vector; Obtaining an attention value based on the transpose of the query vector and the transpose of the key vector; The output data of the attention layer is obtained according to the attention value, the transpose of the value vector, and the first activation function of the attention layer.

2. The method for creating an inference engine according to claim 1, characterized in that: The process of obtaining the weights of each network layer of the initial model includes: Get the configuration file of the initial model; The weights of each network layer are obtained according to the configuration file of the initial model.

3. The method for creating an inference engine according to claim 1, characterized in that: The process of determining the parameters affecting the model loss after the weight of each network layer is changed to the target weight includes: A matrix multiplication operation is performed on the weight of each of the network layers to obtain an impact parameter on the model loss after the weight of each of the network layers is changed to the target weight.

4. The method for creating an inference engine according to claim 3, characterized in that: The process of determining the weight of each network layer as a primary weight or a secondary weight based on each of the influencing parameters includes: Determining whether each of the influencing parameters is less than a critical value; If so, determining the weight of the network layer corresponding to the influencing parameter as a secondary weight; If not, the weight of the network layer corresponding to the influencing parameter is determined as the main weight.

5. The method for creating an inference engine according to claim 1, characterized in that: Before performing a first quantization operation on the main weight according to the quantization accuracy requirement to obtain the first weight, the inference engine creation method further includes: Determine the structure of the network layer corresponding to the main weight; Determine a quantization algorithm corresponding to the main weight based on the structure; The process of performing a first quantization operation on the main weight according to the quantization accuracy requirement to obtain the first weight includes: A first quantization operation is performed on the main weight according to the quantization accuracy requirement and the quantization algorithm to obtain a first weight.

6. The method for creating an inference engine according to claim 1, characterized in that: After performing a first quantization operation on the main weight according to the quantization accuracy requirement to obtain a first weight and obtaining a first compensation parameter corresponding to the first quantization operation, the inference engine creation method further includes: Determining a target network layer among the network layers corresponding to the main weights; The target network layer is quantized and trained to compensate for a first quantization operation of the target network layer.

7. The method for creating an inference engine according to claim 1, characterized in that: The process of obtaining the first compensation parameter corresponding to the first quantization operation includes: Creating a compensation relationship based on the main weight, target weight, preset matrix and preset coefficient; A first compensation parameter corresponding to the first quantization operation is obtained using the compensation relationship.

8. The method for creating an inference engine according to claim 1, characterized in that: After determining the weight of each network layer as a primary weight or a secondary weight based on each of the influencing parameters, the inference engine creation method further includes: determining a weight to be quantified among all the secondary weights; A second quantization operation is performed on the weight to be quantized according to the quantization accuracy requirement of the weight to be quantized to obtain a second weight, and a second compensation parameter corresponding to the second quantization operation is obtained.

9. The method for creating an inference engine according to claim 8, characterized in that: The process of performing a second quantization operation on the weight to be quantized according to the quantization accuracy requirement of the weight to be quantized to obtain a second weight includes: Determining a quantization algorithm according to the quantization accuracy requirement of the weight to be quantized; Based on the quantization accuracy requirement and the quantization algorithm, a second quantization operation is performed on the weight to be quantized to obtain a second weight.

10. The method for creating an inference engine according to claim 1, characterized in that: The process of performing operator fusion operation on the network layer corresponding to the main weights also includes: When it is determined based on the structure that the network layer corresponding to the main weight is a feedforward layer, judging whether the initial model is a hybrid expert structure; If yes, perform a first operator fusion operation on the feedforward layer; the first operator fusion operation includes normalizing the input data of the feedforward layer to obtain a first linear layer name of a hybrid expert structure, obtaining a second linear layer name of the hybrid expert structure based on the first linear layer name and a second activation function, and obtaining output data of the feedforward layer according to the second linear layer name; If not, perform a second operator fusion operation on the feedforward layer; the second operator fusion operation includes normalizing the input data of the feedforward layer to obtain the name of the third linear layer of the multilayer perceptron structure, obtaining the name of the fourth linear layer of the multilayer perceptron structure based on the third linear layer name and the second activation function, and obtaining the output data of the feedforward layer according to the fourth linear layer name.

11. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the method for creating an inference engine according to any one of claims 1 to 10 are implemented.

12. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the inference engine creation method as described in any one of claims 1 to 10 when executing the computer program.

13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the inference engine creation method according to any one of claims 1 to 11 are implemented.