Model reasoning method and device, electronic equipment and storage medium

In the inference process of large language models, the first quantization method is used in the pre-filling stage, the second quantization method is used in the decoding stage, and smooth quantization offline calibration is performed, which solves the problem of storage resources and inference efficiency of large language models and achieves high efficiency. Taking into account both storage resource utilization and inference performance.

CN118657219APending Publication Date: 2024-09-17SHANGHAI BIREN TECH CO LTD
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202410980678.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-19
Publication Date
2024-09-17

AI Technical Summary

Technical Problem

Large language models have challenges in terms of storage resource requirements and inference efficiency. It is difficult for existing technology to effectively utilize storage resources and ensure the inference performance and inference speed of the model.

Method used

The activation of the previous layer output and the weight of the current layer are calculated based on the first quantization method in the pre-filling stage of model inference, and the calculation is based on the second quantization method in the decoding stage. The weight quantization accuracy is the same but the activation quantization accuracy is different. Smooth quantization is used for offline calibration to reduce storage space and improve inference performance.

Benefits of technology

It realizes the rational use of storage resources in large language models, improves memory utilization, takes into account inference speed and performance, reduces storage space occupation, and improves efficient deployment and optimization of models.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118657219A
    Figure CN118657219A
Patent Text Reader

Abstract

The invention provides a model reasoning method and device, electronic equipment and a storage medium, and relates to the technical field of artificial intelligence, and the method comprises the steps: in a pre-filling stage of model reasoning, calculating the activation output by a previous layer and the weight of a current layer based on a first quantification mode; in the decoding stage of model reasoning, the activation output by the previous layer and the weight of the current layer are calculated based on a second quantization mode; wherein the weight quantization precision of the first quantization mode is the same as that of the second quantization mode, and the activation quantization precision of the first quantization mode is different from that of the second quantization mode. According to the method and the device provided by the invention, storage resources can be reasonably utilized to improve the utilization rate of the video memory, the reasoning performance and the reasoning speed of the model can be ensured, and efficient deployment and optimization of the large language model are realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a model reasoning method, device, electronic device and storage medium. Background Art

[0002] Large Language Models (LLMs) are an important branch of artificial intelligence. Large language models understand and generate natural language by learning from large amounts of text data. These models are capable of handling complex language tasks such as text generation, translation, question answering, etc.

[0003] As the model size continues to expand, large language models require more and more storage resources and their inference efficiency becomes lower and lower.

[0004] Therefore, how to rationally utilize storage resources to ensure the model's reasoning performance and speed has become a technical problem that needs to be urgently solved in the industry. Summary of the invention

[0005] The present application provides a model reasoning method, device, electronic device and storage medium for solving the technical problem of how to reasonably utilize storage resources and ensure the reasoning performance and reasoning speed of the model.

[0006] This application provides a model reasoning method, including: In the pre-filling phase of model inference, the activation of the previous layer output and the weight of the current layer are calculated based on the first quantization method; In the decoding phase of model inference, the activation of the previous layer output and the weight of the current layer are calculated based on the second quantization method; The first quantization method and the second quantization method have the same weight quantization precision and different activation quantization precision.

[0007] In some embodiments, the method further comprises: Before model inference, the model is calibrated offline based on the smoothing quantization method to obtain the smoothed weights, smoothing parameters, and channel-by-channel scaling parameters.

[0008] In some embodiments, in the pre-filling stage of model inference, the activation of the previous layer output and the weight of the current layer are calculated based on the first quantization method, including: Get the activation of the previous layer output; determining a first quotient between the activation of the previous layer output and the smoothing parameter; Linearly transforming the first quotient to an activation quantization accuracy of the first quantization mode; The calculation is performed based on the linear transformation result of the first quotient, the channel-by-channel scaling parameter and the weight of the current layer.

[0009] In some embodiments, in the decoding stage of model inference, the activation of the previous layer output and the weight of the current layer are calculated based on the second quantization method, including: Get the activation of the previous layer output; determining a second quotient between the activation of the previous layer output and the smoothing parameter; The calculation is performed based on the second quotient, the channel-by-channel scaling parameter and the weight of the current layer.

[0010] In some embodiments, the previous layer is an attention layer, and the current layer is a projection layer.

[0011] In some embodiments, the weight quantization precision of the first quantization method is an 8-bit integer, and the activation quantization precision is an 8-bit integer.

[0012] In some embodiments, the weight quantization precision of the second quantization method is an 8-bit integer, and the activation quantization precision is a 16-bit floating point number.

[0013] The present application provides a model reasoning device, comprising: A pre-filling module, used to calculate the activation of the previous layer output and the weight of the current layer based on the first quantization method during the pre-filling stage of model inference; A decoding module is used to calculate the activation of the previous layer output and the weight of the current layer based on the second quantization method during the decoding stage of model inference; The first quantization method and the second quantization method have the same weight quantization precision and different activation quantization precision.

[0014] The present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the model reasoning method when executing the computer program.

[0015] The present application provides a non-transitory computer-readable storage medium having a computer program stored thereon, and the computer program implements the model reasoning method when executed by a processor.

[0016] The model inference method, device, electronic device and storage medium provided in the present application calculate the activation of the previous layer output and the weight of the current layer based on the first quantization method in the pre-filling stage of model inference; calculate the activation of the previous layer output and the weight of the current layer based on the second quantization method in the decoding stage of model inference; since the weight quantization accuracy of the first quantization method and the second quantization method is the same, only one set of parameters needs to be saved in the two stages of model inference, reducing the occupied storage space; since the activation quantization accuracy of the first quantization method and the second quantization method is different, the inference speed and inference performance can be taken into account in the two stages of model inference; by mixing two different quantization methods in model inference, it is possible to reasonably use storage resources to improve the utilization rate of video memory, and to ensure the inference performance and inference speed of the model, thereby realizing efficient deployment and optimization of large language models. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0018] In order to more clearly illustrate the technical solutions in the present application or the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0019] Figure 1 It is a flowchart of the model reasoning method provided in this application.

[0020] Figure 2 This is a schematic diagram of offline calibration of a model based on smooth quantization provided in this application.

[0021] Figure 3 It is a schematic diagram of the pre-filling stage model reasoning optimization provided in this application.

[0022] Figure 4 It is a schematic diagram of the model inference optimization in the decoding stage provided by this application.

[0023] Figure 5 It is a structural diagram of the model reasoning device provided in this application.

[0024] Figure 6 It is a structural schematic diagram of the electronic device provided by this application. DETAILED DESCRIPTION

[0025] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.

[0026] It should be noted that the terms "first", "second" etc. in the present application are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable in appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, the process, method, system, product or equipment comprising a series of steps or units or modules need not be limited to those steps or units or modules clearly listed, but may include other steps or units or modules that are not clearly listed or inherent to these processes, methods, products or equipment.

[0027] The large language model (abbreviated as the large model) is a pre-trained language model based on the Transformer architecture. The large language model can be divided into two stages when performing inference: the prefill stage (Prefill) and the decoding stage (Decode). The prefill stage is to preprocess the prompt words that the user inputs into the large voice model. Since the prompt words entered by the user are usually long texts, more computing power is required, and the operators in this stage are computationally intensive operators. The decoding stage is the process of generating tokens one by one in the large language model. Since one token is generated at a time, the computing resources consumed are relatively small, and it is a bandwidth-intensive operator.

[0028] Model quantization refers to the process of approximating continuous floating-point weights to a finite number of discrete values ​​at a lower loss of inference accuracy. By representing floating-point numbers with fewer bits, model quantization can reduce the model size, thereby reducing memory and other resource consumption during inference, and can increase inference speed on some processors with faster low-precision operations.

[0029] Quantized objects usually include weights (Weight, W) and activations (Activation, A). Weights refer to the parameters that connect neurons in a neural network and are used to adjust the influence of input signals. In each layer of a neural network, each connection between two neurons has a corresponding weight. These weights determine the importance of the input signal transmitted from the previous layer of neurons to the current layer of neurons. Activation refers to the result of the output of a neuron after receiving the input, also known as the activation value of the neuron.

[0030] The quantization methods used in related technologies include W8A8 (the precision of weight quantization and the precision of activation quantization are both 8-bit integers), W8A16 (the precision of weight quantization is 8-bit integers, and the precision of activation quantization is 16-bit floating point numbers) and W16A16 (the precision of weight quantization and the precision of activation quantization are both 16-bit floating point numbers).

[0031] Since the parameters of large language models occupy a particularly large storage space, usually between tens of gigabytes (GB) and hundreds of gigabytes, in related technologies, when large language models are inferred, the same quantization method is used in the pre-filling stage and the decoding stage to avoid saving two sets of parameters (weights). Since the same quantization method is used, the resource requirements of large language models in the pre-filling stage and the decoding stage cannot be met.

[0032] In order to solve the shortcomings of related technologies, Figure 1 It is a flowchart of the model reasoning method provided in this application, such as Figure 1 As shown, the method includes step 110 and step 120.

[0033] Step 110: In the pre-filling stage of model inference, the activation of the previous layer output and the weight of the current layer are calculated based on the first quantization method.

[0034] Step 120: In the decoding stage of model inference, the activation of the previous layer output and the weight of the current layer are calculated based on the second quantization method.

[0035] The first quantization method and the second quantization method have the same weight quantization precision and different activation quantization precision.

[0036] Specifically, the model inference method provided in the embodiment of the present application is applicable to various large-scale language models. The embodiment of the present application does not specifically limit the model structure of the large-scale language model.

[0037] The execution subject of the model reasoning method provided in the embodiment of the present application is a model reasoning device. The device can be implemented by software, such as a model reasoning program or a model reasoning optimization program; it can also be a device for executing the model reasoning method, such as an artificial intelligence chip for executing the model reasoning method, and a mobile terminal, tablet computer, desktop computer or server containing these artificial intelligence chips. Artificial intelligence chips can include various graphics processing units (GPUs), various general-purpose computing on graphics processing units (GPGPUs), etc.

[0038] Large language models belong to neural network models. Neural network models are usually composed of various layers, each of which can be regarded as a specific mathematical operation or transformation. Therefore, in the neural network model, the layers in the neural network can also be called operators.

[0039] In each layer, the parameters involved in the operation include weight (Weight, W) and activation (Activation, A).

[0040] Weight quantization accuracy refers to the representation accuracy of weights after quantization. For example, weights are quantized from floating-point data to integer data with fewer bits. Generally, W16 can indicate that the quantization accuracy of weights is a floating-point number represented by 16 bits (Float16, FP16 or Bfloat16, BF16), and W8 can indicate that the quantization accuracy of weights is an integer represented by 8 bits (INT8).

[0041] The activation quantization precision refers to the representation precision of the activation after quantization. For example, the activation is quantized from floating point data to integer data with fewer bits. Generally, A16 can represent the activation quantization precision as a 16-bit floating point number (FP16 or BF16), and A8 can represent the activation quantization precision as an 8-bit integer (INT8).

[0042] By using different quantization precisions for weights and activations, different quantization methods can be obtained. For example, W8A8 means quantizing weights to 8-bit integers and activations to 8-bit integers; W8A16 means quantizing weights to 8-bit integers and activations to 16-bit floating-point numbers; W16A16 means quantizing weights to 16-bit floating-point numbers and activations to 16-bit floating-point numbers.

[0043] When performing inference on large language models, a hybrid quantization approach can be used, that is, different quantization methods are used in different inference stages to meet the resource requirements of the pre-filling stage and the decoding stage.

[0044] In the pre-filling stage of model inference, the activation of the previous layer output and the weight of the current layer can be converted according to the first quantization method before calculation; in the decoding stage of model inference, the activation of the previous layer output and the weight of the current layer can be converted according to the second quantization method before calculation.

[0045] The weight quantization precision of the first quantization method and the second quantization method is the same, so that a large language model only needs to save one set of parameters (weights) in the two stages of reasoning. Compared with using different weight quantization precisions in the two stages, it can reduce the storage space occupied. For example, the weight quantization precision of both quantization methods can be selected as W8.

[0046] The activation quantization precision of the first quantization method and the second quantization method is different, so that large language models can flexibly choose precision in the two stages of reasoning to balance the reasoning speed and model performance. For example, a lower precision can be selected in the pre-filling stage to reduce the consumption of storage resources for activation and improve the reasoning speed; a higher precision can be selected in the decoding stage to improve the accuracy of the reasoning calculation and enhance the reasoning performance of the model. For example, the activation quantization precision of the first quantization method can be A8, and the activation quantization precision of the second quantization method can be A16.

[0047] The model inference method provided in the embodiment of the present application calculates the activation of the previous layer output and the weight of the current layer based on the first quantization method in the pre-filling stage of model inference; calculates the activation of the previous layer output and the weight of the current layer based on the second quantization method in the decoding stage of model inference; since the weight quantization accuracy of the first quantization method and the second quantization method is the same, only one set of parameters needs to be saved in the two stages of model inference, reducing the occupied storage space; since the activation quantization accuracy of the first quantization method and the second quantization method is different, the inference speed and inference performance can be taken into account in the two stages of model inference; by mixing two different quantization methods in model inference, it is possible to reasonably use storage resources to improve the utilization rate of video memory, and to ensure the inference performance and inference speed of the model, thereby realizing efficient deployment and optimization of large language models.

[0048] It should be noted that each implementation method of the present application can be freely combined, the order can be changed, or it can be executed separately, and does not need to rely on or depend on a fixed execution order.

[0049] In some embodiments, the weight quantization precision of the first quantization method is an 8-bit integer, and the activation quantization precision is an 8-bit integer; the weight quantization precision of the second quantization method is an 8-bit integer, and the activation quantization precision is a 16-bit floating point number.

[0050] Specifically, the first quantization mode may be W8A8, that is, the weight quantization precision is an 8-bit integer (INT8), and the activation quantization precision is an 8-bit integer (INT8). The second quantization mode may be W8A16, that is, the weight quantization precision is an 8-bit integer (INT8), and the activation quantization precision is a 16-bit floating point number (FP16).

[0051] When not quantized, the activations in the model can be expressed in 16-bit floating point (FP16) precision.

[0052] From the above, we can see that the first quantization method will quantize the activation and quantize the accuracy from FP16 to INT8; the second quantization method will not quantize the activation.

[0053] In some embodiments, the method further comprises: Before model inference, the model is calibrated offline based on the smoothing quantization method to obtain the smoothed weights, smoothing parameters, and channel-by-channel scaling parameters.

[0054] Specifically, the reasons why large language models are difficult to quantize usually include: weights are easy to quantize, while activations are more difficult to quantize; there are outliers in the activations, which have larger numerical differences than normal values, making activation quantization more difficult; outliers in the activations persist in fixed channels (such as each output channel in the convolutional layer).

[0055] SmoothQuant can be used to transfer the difficulty of quantization from activation to weight through a mathematically equivalent transformation. SmoothQuant proposes a mathematically equivalent per-channel scaling transformation (where the channel is the input channel), which can significantly smooth the amplitude between channels, making the model easy to quantize, ensuring accuracy while improving inference speed.

[0056] The smoothing quantization method requires offline calibration of the model through calibration samples before model inference to determine the smoothed weights, smoothing parameters, and channel-by-channel scaling parameters.

[0057] Figure 2 This is a schematic diagram of offline calibration of a model based on smooth quantization provided by the present application, such as Figure 2 As shown, A represents activation, W represents weight, smoother represents smoothing parameter, and per channel scales represents channel-by-channel scaling parameter (this channel is the output channel).

[0058] The smoothing parameter (smoother), also known as the smoothing factor, indicates the degree of smoothing outliers in the activation, which is used to reduce quantization errors. By adjusting the smoothing parameter, the accuracy of quantization and the performance of the model can be balanced. The perchannel scale parameter (perchannel scales), also known as the perchannel scale factor, is used to indicate the degree of scaling of the weights corresponding to each channel.

[0059] The model inference method provided in the embodiment of the present application uses a smoothing quantization method to perform offline calibration on the model before model inference, so that the model is easy to quantize, which is conducive to ensuring the model performance of the model and improving the inference speed.

[0060] In some embodiments, in the pre-filling stage of model inference, the activation of the previous layer output and the weight of the current layer are calculated based on the first quantization method, including: Get the activation of the previous layer output; Determine the first quotient between the activation of the previous layer output and the smoothing parameter; Linearly transforming the first quotient to an activation quantization precision of a first quantization mode; The calculation is based on the linear transformation result of the first quotient, the channel-by-channel scaling parameter and the weight of the current layer.

[0061] Specifically, Figure 3 is a schematic diagram of the model reasoning optimization in the pre-filling stage provided by this application, such as Figure 3 As shown in the figure, the previous layer in the model is the attention layer (attn) and the current layer is the projection layer (proj). The solid line in the figure represents the model inference stage, and the dotted line represents the offline calibration stage.

[0062] The attention layer is mainly used in the neural network to improve the model's attention to the input data and its learning ability by dynamically allocating the model's attention. The projection layer is mainly used in the neural network to map the input data to a lower-dimensional space layer, perform feature dimensionality reduction or feature space transformation, in order to reduce computational complexity, reduce the number of parameters, improve computational efficiency or improve model performance.

[0063] In the pre-filling stage, the activation of the previous layer output is obtained, and the activation of the previous layer output is divided by the smoothing parameter to obtain the first quotient. The precision of the first quotient is the same as the precision of the activation of the previous layer output, and the first quotient can be linearly transformed to the activation quantization precision of the first quantization method. Since the precision of the activation of the previous layer output is greater than the activation quantization precision of the first quantization method (for example, the precision of the activation of the previous layer output is FP16, and the activation quantization precision of the first quantization method is INT8), after adopting the first quantization method, the linear transformation result of the first quotient can use fewer bits and precision to represent the activation of the previous layer output, which can reduce storage space consumption. The linear transformation can specifically be a linear transformation of FP16 to INT8. Then, according to the linear transformation result of the first quotient, the channel-by-channel scaling parameter and the weight of the current layer, calculation can be performed to improve the inference speed.

[0064] The above process can be achieved by adding an online quantization layer (PerTokenQuantize, also known as an online quantization operator) between the previous layer and the current layer. The online quantization layer uses channel-by-channel quantization, with each quantization channel of a layer of the network as the unit. For weights, each column in the weight matrix uses a separate set of quantization parameters (i.e., per channelscales); for activations, each row in the activation matrix uses a separate set of quantization parameters (i.e., per token scales), which can be determined based on the linear transformation process of the first quotient.

[0065] The model inference method provided in the embodiment of the present application calculates the activation of the previous layer output and the weight of the current layer based on the first quantization method during the pre-filling stage of model inference, thereby reducing the storage space required for activation and improving the inference speed of the model.

[0066] In some embodiments, in the decoding stage of model inference, the activation of the previous layer output and the weight of the current layer are calculated based on the second quantization method, including: Get the activation of the previous layer output; Determine the second quotient between the activation of the previous layer output and the smoothing parameter; The calculation is based on the second quotient, the channel-by-channel scaling parameter and the weights of the current layer.

[0067] Specifically, Figure 4 This is a schematic diagram of the model inference optimization in the decoding stage provided by this application, such as Figure 4 As shown in the figure, the previous layer in the model is the attention layer (attn) and the current layer is the projection layer (proj). The solid line in the figure represents the model inference stage, and the dotted line represents the offline calibration stage.

[0068] In the decoding stage, the activation of the previous layer output is obtained, and the activation of the previous layer output is divided by the smoothing parameter to obtain the second quotient. In this way, the modification of the weight by the smoothing quantization method (SmoothQuant) can be offset.

[0069] Then, the calculation is performed based on the second quotient, the channel-by-channel scaling parameter, and the weight of the current layer. Since the activation accuracy of the previous layer output is the same as the activation quantization accuracy of the second quantization method, no linear transformation is required. Since the activation accuracy is not reduced, the inference performance of the model can be guaranteed.

[0070] The model inference method provided in the embodiment of the present application calculates the activation of the previous layer output and the weight of the current layer based on the second quantization method during the decoding stage of model inference, so that the activation can be calculated with higher precision, thereby ensuring the inference performance of the model.

[0071] In the above embodiment, the model reasoning method provided by the present application is described by taking the previous layer as the attention layer and the current layer as the projection layer as an example. Since the model reasoning method provided by the present application does not limit the function and structure of each layer in the model, the previous layer and the current layer mentioned in the model reasoning method provided by the present application are also applicable to other types of layers.

[0072] In some embodiments, the present application provides a model reasoning method combining quantization methods such as SmoothQuant, W8A8 and W8A16, including: Step 1: Offline calibration

[0073] Use SmoothQuant to calibrate and smooth the large model offline to obtain the quantized weight W, smoothing parameter (smoother) and per channel scale parameters (per channel scales).

[0074] Step 2: Online Reasoning

[0075] In the prefill stage of model inference, W8A8 quantization is used. When the previous operator outputs, an online quantization operator is added to convert the output from FP16 (float) precision to INT8 precision, and then the current operator uses the INT8 computing unit for calculation.

[0076] In the decoding stage (Prefill) of model inference, W8A16 quantization is used, and the output of the previous operator is no longer quantized. Instead, it is divided by the offline calibrated smoothing parameter to offset the modification of the weight by Smoothquant, and then calculated using the Float16 / Bfloat16 computing unit.

[0077] Through testing, we know that using W8A8 in the pre-filling stage can improve the performance by 40% compared with W8A16. W8A16 is still used in the decoding stage, but the performance loss is reduced to less than 1% compared with W8A8, and the accuracy is improved by about 0.3% compared with using W8A8 as a whole.

[0078] The model inference method provided in the embodiment of the present application uses only one set of weights and quantization parameters, and does not consume additional video memory. W8A8 is selected to be used in the pre-filling stage, and W8A16 is used in the decoding stage. The performance of the INT8 computing unit used in the pre-filling stage is optimal. If W8A8 is not used in the decoding stage, the activation value does not need to be quantized and dequantized, thereby improving performance.

[0079] The device provided in the embodiment of the present application is described below. The device described below and the method described above can be referenced to each other.

[0080] Figure 5 is a schematic diagram of the structure of the model reasoning device provided by this application, such as Figure 5 As shown, the device comprises: A pre-filling module 510, used to calculate the activation of the previous layer output and the weight of the current layer based on the first quantization method during the pre-filling stage of the model inference; A decoding module 520, used to calculate the activation of the previous layer output and the weight of the current layer based on the second quantization method during the decoding stage of the model inference; The first quantization method and the second quantization method have the same weight quantization precision and different activation quantization precision.

[0081] The model inference device provided in the embodiment of the present application calculates the activation of the previous layer output and the weight of the current layer based on the first quantization method in the pre-filling stage of model inference; calculates the activation of the previous layer output and the weight of the current layer based on the second quantization method in the decoding stage of model inference; since the weight quantization accuracy of the first quantization method and the second quantization method is the same, only one set of parameters needs to be saved in the two stages of model inference, reducing the occupied storage space; since the activation quantization accuracy of the first quantization method and the second quantization method is different, the inference speed and inference performance can be taken into account in the two stages of model inference; by mixing two different quantization methods in model inference, it is possible to reasonably use storage resources to improve the utilization rate of video memory, and to ensure the inference performance and inference speed of the model, thereby realizing efficient deployment and optimization of large language models.

[0082] In some embodiments, the apparatus further comprises: The offline calibration module is used to perform offline calibration on the model based on the smoothing quantization method before model inference to obtain smoothed weights, smoothing parameters, and channel-by-channel scaling parameters.

[0083] In some embodiments, the pre-fill module is used to: Get the activation of the previous layer output; Determine the first quotient between the activation of the previous layer output and the smoothing parameter; Linearly transforming the first quotient to a weight quantization accuracy of a first quantization method; The calculation is based on the linear transformation result of the first quotient, the channel-by-channel scaling parameter and the weight of the current layer.

[0084] In some embodiments, the decoding module is used to: Get the activation of the previous layer output; Determine the second quotient between the activation of the previous layer output and the smoothing parameter; The calculation is based on the second quotient, the channel-by-channel scaling parameter and the weights of the current layer.

[0085] In some embodiments, the previous layer is an attention layer and the current layer is a projection layer.

[0086] In some embodiments, the weight quantization precision of the first quantization mode is an 8-bit integer, and the activation quantization precision is an 8-bit integer.

[0087] In some embodiments, the weight quantization precision of the second quantization mode is an 8-bit integer, and the activation quantization precision is a 16-bit floating point number.

[0088] Figure 6 is a schematic diagram of the structure of the electronic device provided by this application, such as Figure 6 As shown, the electronic device may include: a processor (Processor) 610, a communication interface (Communications Interface) 620, a memory (Memory) 630 and a communication bus (Communications Bus) 640, wherein the processor 610, the communication interface 620, and the memory 630 communicate with each other through the communication bus 640. The processor 610 may call the logic command in the memory 630 to execute the method described in the above embodiment, for example: In the pre-filling stage of model inference, the activation of the previous layer output and the weight of the current layer are calculated based on the first quantization method; in the decoding stage of model inference, the activation of the previous layer output and the weight of the current layer are calculated based on the second quantization method; wherein the weight quantization accuracy of the first quantization method and the second quantization method is the same, and the activation quantization accuracy is different.

[0089] In addition, the logical commands in the above-mentioned memory can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several commands to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., which can store program code.

[0090] The processor in the electronic device provided in the embodiment of the present application can call the logic instructions in the memory to implement the above method. Its specific implementation method is consistent with the implementation method of the aforementioned method and can achieve the same beneficial effects, which will not be repeated here.

[0091] An embodiment of the present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the methods provided in the above embodiments are implemented.

[0092] Its specific implementation is consistent with the aforementioned method implementation and can achieve the same beneficial effects, so it will not be repeated here.

[0093] An embodiment of the present application provides a computer program product, including a computer program, which implements the above method when executed by a processor.

[0094] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0095] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0096] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A model reasoning method, characterized in that: include: In the pre-filling phase of model inference, the activation of the previous layer output and the weight of the current layer are calculated based on the first quantization method; In the decoding phase of model inference, the activation of the previous layer output and the weight of the current layer are calculated based on the second quantization method; The first quantization method and the second quantization method have the same weight quantization precision and different activation quantization precision.

2. The model reasoning method according to claim 1, characterized in that: The method further comprises: Before model inference, the model is calibrated offline based on the smoothing quantization method to obtain the smoothed weights, smoothing parameters, and channel-by-channel scaling parameters.

3. The model reasoning method according to claim 2, characterized in that: In the pre-filling stage of model inference, the activation of the previous layer output and the weight of the current layer are calculated based on the first quantization method, including: Get the activation of the previous layer output; determining a first quotient between the activation of the previous layer output and the smoothing parameter; Linearly transforming the first quotient to an activation quantization accuracy of the first quantization mode; The calculation is performed based on the linear transformation result of the first quotient, the channel-by-channel scaling parameter and the weight of the current layer.

4. The model reasoning method according to claim 2, characterized in that: In the decoding stage of the model inference, the activation of the previous layer output and the weight of the current layer are calculated based on the second quantization method, including: Get the activation of the previous layer output; determining a second quotient between the activation of the previous layer output and the smoothing parameter; The calculation is performed based on the second quotient, the channel-by-channel scaling parameter and the weight of the current layer.

5. The model reasoning method according to claim 1, characterized in that: The previous layer is an attention layer, and the current layer is a projection layer.

6. The model reasoning method according to any one of claims 1 to 5, characterized in that: The weight quantization precision of the first quantization method is an 8-bit integer, and the activation quantization precision is an 8-bit integer.

7. The model reasoning method according to any one of claims 1 to 5, characterized in that: The weight quantization precision of the second quantization method is an 8-bit integer, and the activation quantization precision is a 16-bit floating point number.

8. A model reasoning device, characterized in that: include: A pre-filling module, used to calculate the activation of the previous layer output and the weight of the current layer based on the first quantization method during the pre-filling stage of model inference; A decoding module is used to calculate the activation of the previous layer output and the weight of the current layer based on the second quantization method during the decoding stage of model inference; The first quantization method and the second quantization method have the same weight quantization precision and different activation quantization precision.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the model reasoning method according to any one of claims 1 to 7 is implemented.

10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the model reasoning method according to any one of claims 1 to 7 is implemented.

Citation Information

Cited By

  • Visual language model quantification method, device, equipment, medium and program

    CN122088707A

  • Quantization methods, devices, equipment, media, and programs for visual language models

    CN122088707B

  • Quantization method and inference method for large language model, and electronic device

    WO2026158311A1