Model quantization method, apparatus, device, and storage medium

By quantizing multiple operators of the Transformer model using integer algorithms, the deployment challenge on FPGA chips was solved, achieving efficient model quantization and improved inference speed.

CN114936619BActive Publication Date: 2026-03-17SHANGHAI WESTWELL INFORMATION & TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-21
Publication Date
2026-03-17

AI Technical Summary

Technical Problem

Existing technologies make it difficult to effectively quantize the Transformer model, enabling its practical application on resource-constrained FPGA chips.

Method used

The Transformer model employs integer algorithms to execute multiple operators, including linear and nonlinear operators. Floating-point values ​​are quantized into integer values ​​through methods such as symmetric quantization and polynomial fitting, specifically including matrix multiplication, activation functions, and layer normalization operators.

Benefits of technology

It realizes quantized inference of Transformer models, can be deployed and run on FPGA chips, the model accuracy is close to that of floating-point models, and the inference speed is improved by 4 times.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114936619B_ABST
    Figure CN114936619B_ABST
Patent Text Reader

Abstract

The application provides a model quantification method, device and equipment and storage medium, the method comprises: using integer algorithm to execute a plurality of operators of transformer model for image processing, the plurality of operators of the transformer model comprises linear operator and nonlinear operator, wherein the linear operator comprises matrix multiplication operator, the matrix multiplication operator adopts symmetric quantization to quantize floating point value to integer value;The nonlinear operator comprises an activation function operator and a layer normalization operator, the activation function operator adopts polynomial fitting to quantize floating point value to integer value, and the layer normalization operator adopts the mean and standard deviation of input data in the channel dimension to quantize floating point value to integer value.The transformer operator is quantified, so that the inference work of the transformer model for natural language is based on integer operation, so that it can be truly deployed on FPAG chip for practical application.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image processing technology, and in particular to a model quantization method, apparatus, device, and storage medium. Background Technology

[0002] Artificial intelligence (AI) models are commonly used for image processing and semantic analysis. These models are typically deployed on chips, and AI chips can be optimized in three ways: algorithm optimization, compiler optimization, and hardware optimization. Algorithm optimization reduces the computational power of AI models, such as neural network models, and sets the upper limit on the efficiency of network model deployment. The resource consumption difference between floating-point calculations (addition or multiplication) and fixed-point calculations is significant, especially for chips with limited logic resources, such as FPGAs (Field-Programmable Gate Arrays). Fixed-point calculations are more efficient and can improve performance several times over compared to floating-point calculations.

[0003] In addition, the Transformer model has made groundbreaking progress in many NLP (Neuro-Linguistic Programming) tasks, and has since been extended to image and video processing.

[0004] Therefore, how to quantize the transformer operator so that the inference work of the transformer model used for natural language processing is based on integer operations, and thus enable it to be truly deployed on FPAG chips for practical applications, is a technical problem that urgently needs to be solved by those skilled in the art. Summary of the Invention

[0005] To address the problems in the prior art, the present invention aims to provide a model quantization method, apparatus, device, and storage medium that quantizes transformer operators, enabling inference operations of transformer models used for natural language processing to be based on integer operations, thus making it truly feasible to deploy on FPAG chips for practical applications.

[0006] This invention provides a model quantization method, comprising:

[0007] Multiple operators of a transformer model for image processing are executed using integer algorithms. These operators include both linear and nonlinear operators.

[0008] The linear operator includes a matrix multiplication operator, which uses symmetric quantization to quantize floating-point values ​​into integer values.

[0009] The nonlinear operator includes an activation function operator and a layer normalization operator. The activation function operator uses polynomial fitting to quantize floating-point values ​​into integer values, and the layer normalization operator uses the mean and standard deviation of the input data in the channel dimension to quantize floating-point values ​​into integer values.

[0010] In some embodiments of this application, the symmetry quantization is implemented according to the following formula:

[0011]

[0012] Where q is the quantized integer value, and q∈[-2] f-1 ,2 f-1 ], x is the floating-point value before quantization, S is the scaling factor, and S=α / (2 f-1 -1), where α is the quantization range and f is the quantization bit width.

[0013] In some embodiments of this application, the activation function operator includes a Gaussian error linear operator, which quantizes floating-point values ​​into integer values ​​according to the following polynomial fitting formula:

[0014]

[0015] Where i-GELU(x) is the quantized integer value, x is the unquantized floating-point value, and L(x) = sgn(x)[a(clip(|x|,max=-b)+b)] 2 +1], where sgn is the sign function, and a and b are second-order polynomial parameters obtained by fitting the curve of the activation function of the Gaussian error linear operator.

[0016] In some embodiments of this application, a is -0.2 to -0.3 and b is -1.7 to -1.8.

[0017] In some embodiments of this application, the activation function operator includes a softmax operator, which quantizes floating-point values ​​into integer values ​​according to the following polynomial fitting formula:

[0018]

[0019] in, The quantized integer value. Let L(p) be (-ln2)z+p, where z is a non-negative integer, p is a real number, and the range of p is (-ln2, 0]. Let L(p) be c(p+g). 2 +d, c, d, and g are the second-order polynomial parameters obtained by fitting the curve of exp(p).

[0020] In some embodiments of this application, c is 0.3 to 0.4, g is 1.3 to 1.4, and d is 0.3 to 0.4.

[0021] In some embodiments of this application, the layer normalization operator quantizes floating-point values ​​into integer values ​​according to the following formula:

[0022]

[0023] in, is the quantized integer value, x is the unquantized integer value, and μ and σ are the mean and standard deviation of x in the channel dimension.

[0024] According to another aspect of this application, a model quantization apparatus is also provided, comprising:

[0025] The quantization module is used to execute multiple operators of a transformer model for image processing using integer algorithms. These operators include both linear and nonlinear operators.

[0026] The linear operator includes a matrix multiplication operator, which uses symmetric quantization to quantize floating-point values ​​into integer values.

[0027] The nonlinear operator includes an activation function operator and a layer normalization operator. The activation function operator uses polynomial fitting to quantize floating-point values ​​into integer values, and the layer normalization operator uses the mean and standard deviation of the input data in the channel dimension to quantize floating-point values ​​into integer values.

[0028] This invention also provides an electronic device, comprising:

[0029] processor;

[0030] A memory in which executable instructions of the processor are stored;

[0031] The processor is configured to perform the steps of the model quantization method by executing the executable instructions.

[0032] This invention also provides a computer-readable storage medium for storing a program that, when executed by a processor, implements the steps of the model quantization method.

[0033] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure.

[0034] The model quantization method, apparatus, device, and storage medium of the present invention have the following beneficial effects:

[0035] This application uses integer algorithms to execute multiple operators for a transformer model used in natural language processing. These operators include linear and nonlinear operators. The linear operators include matrix multiplication, which uses symmetric quantization to convert floating-point values ​​to integer values. The nonlinear operators include activation function operators and layer normalization operators. The activation function operators use polynomial fitting to convert floating-point values ​​to integer values, and the layer normalization operators use the mean and standard deviation of the input data along the channel dimension to convert floating-point values ​​to integer values. This enables quantized inference of the transformer model, allowing it to be deployed and run on a chip. Simulation tests on various tasks in a dataset using activation function operators such as GELU (Gaussian Error Linear Unit) show that the accuracy of the quantized model is approximately the same as the floating-point model; and based on the tests, the inference speed of the quantized model is four times that of the floating-point model. Attached Figure Description

[0036] Other features, objects, and advantages of the invention will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings.

[0037] Figure 1 This is a flowchart of a model quantization method according to an embodiment of the present invention;

[0038] Figure 2 This is a model architecture diagram of natural language processing using the transformer model according to an embodiment of the present invention;

[0039] Figure 3 This is the quantization process of a transformer model according to an embodiment of the present invention;

[0040] Figure 4 This is a schematic diagram of the structure of a model quantization device according to an embodiment of the present invention;

[0041] Figure 5 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present invention;

[0042] Figure 6 This is a schematic diagram of the structure of a computer-readable storage medium according to an embodiment of the present invention. Detailed Implementation

[0043] Exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, these exemplary embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein; rather, they are provided so that this disclosure will be more comprehensive and complete, and will fully convey the concept of the exemplary embodiments to those skilled in the art. The described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments.

[0044] Furthermore, the accompanying drawings are merely illustrative of this disclosure and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and therefore repeated descriptions of them will be omitted. Some block diagrams shown in the drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities may be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.

[0045] The flowchart shown in the attached diagram is merely an illustrative example and does not necessarily include all steps. For example, some steps may be broken down, while others may be combined or partially combined. Therefore, the actual execution order may change depending on the specific circumstances.

[0046] like Figure 1 As shown in the figure, an embodiment of the present invention provides a model quantization method, the method comprising the following steps:

[0047] Step S110: Execute multiple operators of a transformer model for image processing using an integer algorithm, wherein the multiple operators of the transformer model include linear operators and nonlinear operators.

[0048] The linear operators include matrix multiplication operators, which use symmetric quantization to quantize floating-point values ​​into integer values; the nonlinear operators include activation function operators and layer normalization operators, which use polynomial fitting to quantize floating-point values ​​into integer values, and layer normalization operators use the mean and standard deviation of the input data in the channel dimension to quantize floating-point values ​​into integer values.

[0049] Specifically, the key to model quantization is to perform all operations using integer algorithms, without any floating-point calculations. Operators in the Transformer model mainly include: Embedding (instantiation operator), Linear operator, bmm (matrix multiplication operator), LayerNorm (layer normalization operator), GELU (Gaussian error linear operator), and Softmax operator. Among these, the matrix multiplication operator is a linear operation; based on its linearity, MatMul(Sq) (MatMul is the matrix multiplication function) is equivalent to S*MatMul(q), thus allowing symmetric quantization to convert floating-point values ​​to integer values. Other activation function operators, such as the Gaussian error linear operator and the Softmax operator, are non-linear operations and cannot be directly quantized using symmetric quantization. In this application, polynomials can be used to approximate the non-linear operations of activation function operators; these polynomials can be operated on using pure integers. Considering that higher-order polynomials have higher computational and memory overhead, and that overflow may occur when using low-precision integers, second-order polynomials are preferably used for fitting quantization for GELU and Softmax approximations.

[0050] This application uses integer algorithms to execute multiple operators of a transformer model for natural language processing. These operators include linear and nonlinear operators. The linear operators include matrix multiplication, which uses symmetric quantization to convert floating-point values ​​to integer values. The nonlinear operators include activation function operators and layer normalization operators. The activation function operators use polynomial fitting to convert floating-point values ​​to integer values, and the layer normalization operators use the mean and standard deviation of the input data along the channel dimension to convert floating-point values ​​to integer values. This enables quantized inference of the transformer model, allowing it to be deployed and run on a chip. Simulation tests on various tasks in a dataset using activation function operators such as GELU (Gaussian Error Linear Unit) show that the accuracy of the quantized model is approximately the same as the floating-point model; and based on the tests, the inference speed of the quantized model is four times that of the floating-point model.

[0051] Specifically, the symmetric quantization is implemented according to the following formula:

[0052]

[0053] Where q is the quantized integer value, and q∈[-2] f-1 ,2 f-1 ], x is the floating-point value before quantization, S is the scaling factor, and S=α / (2 f-1 -1), where α is the quantization range and f is the quantization bit width.

[0054] Therefore, the inverse transform formula for symmetric quantization is:

[0055]

[0056] Where DQ is the inverse quantization function.

[0057] Specifically, the activation function operator includes the Gaussian error linear operator, which is a nonlinear activation function, and its formula is:

[0058]

[0059] Wherein, error function The error function can be used to represent the cumulative distribution function of the standard normal distribution.

[0060] The activation function operator can be approximated by a binomial polynomial, and its optimization formula is as follows:

[0061]

[0062] Here, L(x) is a binomial polynomial used to fit the error function erf(x). Since the domain of the error function erf(x) is the entire real number, directly using the above formula for fitting may lead to a poor approximation. To solve this problem, L(x) can be optimized within a finite range, and the parity of the error function erf(x) can be utilized. Thus, the Gaussian error linear operator can quantize floating-point values ​​into integer values ​​according to the following polynomial fitting formula:

[0063]

[0064] Where i-GELU(x) is the quantized integer value, x is the unquantized floating-point value, and L(x) = sgn(x)[a(clip(|x|,max=-b)+b)] 2 +1], where sgn is the sign function, and a and b are the second-order polynomial parameters obtained by fitting the curve of the activation function of the Gaussian error linear operator. The values ​​of the second-order polynomial parameters a and b can be obtained by approximating the curve of the activation function using a second-order polynomial, where a is -0.2 to -0.3 and b is -1.7 to -1.8. Preferably, a = -0.2888 and b = -1.769.

[0065] Specifically, the activation function operator includes the softmax operator, which is used to normalize the input vector and map it to a probability distribution. The softmax operator is a non-linear activation function, and its formula is:

[0066]

[0067] Where x = [x1, ..., x2] k[k], where k is the number of values ​​x can take. Similar to GELU, quantized softmax can be approximated using a lower-order quantization within a certain finite range. First, for numerical stability, the maximum exponent is subtracted from the input, as shown in the following formula:

[0068]

[0069] The input to the exponential function is now... Non-positive real numbers can Decomposition is represented as Where z is a non-negative integer, and p is a real number in the range (-ln2, 0). Therefore:

[0070]

[0071] According to the above formula, we only need to approximate the exponent within the compact interval (-ln2, 0] of p. Using the minimum L2 distance formula, the softmax operator can quantize the floating-point value into an integer value according to the following polynomial fitting formula:

[0072]

[0073] in, The quantized integer value. Let L(p) be (-ln2)z+p, where z is a non-negative integer, p is a real number, and the range of p is (-ln2, 0]. Let L(p) be c(p+g). 2 +d, c, d, and g are the second-order polynomial parameters obtained by fitting the curve of exp(p). The values ​​of the second-order polynomial parameters c, g, and d can be obtained by approximating the curve of the activation function using a second-order polynomial, where c is 0.3 to 0.4, g is 1.3 to 1.4, and d is 0.3 to 0.4. Preferably, c is 0.3585, g is 1.353, and d is 0.344.

[0074] Specifically, the layer normalization operator typically normalizes the input data along the channel dimension, and its operation includes multiple nonlinear operations such as division, squaring, and square root. The layer normalization operator quantizes floating-point values ​​into integer values ​​according to the following formula:

[0075]

[0076] in, is the quantized integer value, x is the unquantized integer value, and μ and σ are the mean and standard deviation of x in the channel dimension.

[0077] To efficiently compute the square root using pure integers, this application employs Newton's method to iteratively search for the exact value. The pseudocode for calculating the integer square root using Newton's method is as follows:

[0078]

[0079] The algorithm described above is computationally lightweight because it converges in at most four iterations for any int32 input, and each iteration consists of only one integer division, one integer addition, and one bit shift operation.

[0080] See below. Figure 2 , Figure 2 This is a model architecture diagram for natural language processing using the transformer model, according to an embodiment of the present invention. Figure 2 As shown, the iBert-Base model 210 and the transformer model 220 are combined to perform natural language processing (e.g., semantic analysis) on the input vector (input text vector). After the input vector is input into model 210, it is instantiated by the instantiation layer and processed by layer normalization. Based on Dropout, certain neurons are deactivated with a certain probability before being input into model 220. After passing through a multi-head attention layer, Dropout, a fully connected layer, GELU, another fully connected layer, and Dropout again, it undergoes layer normalization before returning to model 210. The semantic recognition result is then output through Dropout, a fully connected layer, the Tanh activation function, Dropout again, and a fully connected layer. Specifically, Dropout, during forward propagation, deactivates certain neurons with a certain probability, which improves the model's generalization ability because it doesn't rely too heavily on local features. Dropout also helps avoid overfitting caused by too many model parameters and too few training samples.

[0081] See below. Figure 3 , Figure 3 This is the quantization process of a transformer model according to an embodiment of the present invention.

[0082] After the input vector is instantiated by the instantiation layer, the query matrix (Q), key matrix (K), and value matrix (V) are calculated (the query matrix (Q), key matrix (K), and value matrix (V) are part of the self-attention mechanism). The query matrix (Q) and key matrix (K) are multiplied by the matrix multiplication operator, and the intermediate matrix obtained by softmax processing is multiplied by the value matrix (V) by the matrix multiplication operator. Then, it is added to the instantiated features by the addition operator. Finally, it is output sequentially through the batch normalization operator, linear operator, GELU operator, linear operator, addition operator, and batch normalization operator. The above model uses the self-attention mechanism, thus having better parallel computing capabilities and greater advantages in training large-scale data models.

[0083] The above is merely an illustrative description of several implementations of this application. Each embodiment can be implemented individually or in combination, and this application is not intended to limit the scope of the application.

[0084] like Figure 4 As shown, this embodiment of the invention also provides a model quantization device for implementing the model quantization method described above. The model quantization device 400 includes:

[0085] The quantization module 410 is used to execute multiple operators of a transformer model for image processing using integer algorithms. The multiple operators of the transformer model include linear operators and nonlinear operators. The linear operators include a matrix multiplication operator, which uses symmetric quantization to quantize floating-point values ​​into integer values. The nonlinear operators include an activation function operator and a layer normalization operator. The activation function operator uses polynomial fitting to quantize floating-point values ​​into integer values, and the layer normalization operator uses the mean and standard deviation of the input data in the channel dimension to quantize floating-point values ​​into integer values.

[0086] The functions of each module in the model quantization device of the present invention can be implemented by the specific implementation methods of the above steps, which will not be repeated here.

[0087] This application uses integer algorithms to execute multiple operators of a transformer model for natural language processing. These operators include linear and nonlinear operators. The linear operators include matrix multiplication, which uses symmetric quantization to convert floating-point values ​​to integer values. The nonlinear operators include activation function operators and layer normalization operators. The activation function operators use polynomial fitting to convert floating-point values ​​to integer values, and the layer normalization operators use the mean and standard deviation of the input data along the channel dimension to convert floating-point values ​​to integer values. This enables quantized inference of the transformer model, allowing it to be deployed and run on a chip. Simulation tests on various tasks in a dataset using activation function operators such as GELU (Gaussian Error Linear Unit) show that the accuracy of the quantized model is approximately the same as the floating-point model; and based on the tests, the inference speed of the quantized model is four times that of the floating-point model.

[0088] Figure 4 The illustrations of the model quantization apparatus provided by this invention are merely schematic representations. Without departing from the inventive concept, the splitting, merging, and addition of modules are all within the scope of protection of this invention. The model quantization apparatus provided by this invention can be implemented by software, hardware, firmware, plugins, and any combination thereof; this invention is not limited thereto.

[0089] This invention also provides an electronic device, including a processor; a memory storing executable instructions of the processor; wherein the processor is configured to perform the steps of the model quantization method by executing the executable instructions.

[0090] Those skilled in the art will understand that various aspects of the present invention can be implemented as systems, methods, or program products. Therefore, various aspects of the present invention can be specifically implemented in the following forms: a completely hardware implementation, a completely software implementation (including firmware, microcode, etc.), or a combination of hardware and software aspects, collectively referred to herein as a "circuit," "module," or "platform."

[0091] The following reference Figure 5 To describe an electronic device 600 according to this embodiment of the present invention. Figure 5 The electronic device 600 shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of the present invention.

[0092] like Figure 5 As shown, the electronic device 600 is presented in the form of a general-purpose computing device. The components of the electronic device 600 may include, but are not limited to: at least one processing unit 610, at least one storage unit 620, a bus 630 connecting different system components (including storage unit 620 and processing unit 610), a display unit 640, etc.

[0093] The storage unit stores program code that can be executed by the processing unit 610, causing the processing unit 610 to perform the steps described in the model quantization method section of this specification, according to various exemplary embodiments of the present invention. For example, the processing unit 610 can perform, as follows: Figure 1 The steps are shown in the figure.

[0094] The storage unit 620 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 6201 and / or a cache storage unit 6202, and may further include a read-only memory unit (ROM) 6203.

[0095] The storage unit 620 may also include a program / utility 6204 having a set (at least one) program module 6205, such program module 6205 including but not limited to: an operating system, one or more application programs, other program modules and program data, each or some combination of these examples may include an implementation of a network environment.

[0096] Bus 630 can represent one or more of several types of bus structures, including a memory cell bus or memory cell controller, a peripheral bus, a graphics acceleration port, a processing unit, or a local bus using any of the various bus structures.

[0097] Electronic device 600 can also communicate with one or more external devices 700 (e.g., keyboard, pointing device, Bluetooth device, etc.), and with one or more devices that enable a user to interact with electronic device 600, and / or with any device that enables electronic device 600 to communicate with one or more other computing devices (e.g., router, modem, etc.). This communication can be performed via input / output (I / O) interface 650. Furthermore, electronic device 600 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via network adapter 660. Network adapter 660 can communicate with other modules of electronic device 600 via bus 630. It should be understood that, although not shown in the figures, other hardware and / or software modules can be used in conjunction with electronic device 600, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0098] In the electronic device, when the program in the memory is executed by the processor, it implements the steps of the model quantization method. Therefore, the device can also obtain the technical effects of the model quantization method.

[0099] This invention also provides a computer-readable storage medium for storing a program that, when executed by a processor, implements the steps of the model quantization method. In some possible implementations, various aspects of the invention can also be implemented as a program product comprising program code that, when executed on a terminal device, causes the terminal device to perform the steps described in the model quantization method section of this specification according to various exemplary embodiments of the invention.

[0100] refer to Figure 6 As shown, a program product 800 for implementing the above-described method according to an embodiment of the present invention is described. It may employ a portable compact disc read-only memory (CD-ROM) and include program code, and may be executed on a terminal device, such as a personal computer. However, the program product of the present invention is not limited thereto. In this document, the readable storage medium may be any tangible medium containing or storing a program that may be used by or in conjunction with an instruction execution system, apparatus, or device.

[0101] The program product may employ any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection having one or more wires, a portable disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.

[0102] The computer-readable storage medium may include data signals propagated in baseband or as part of a carrier wave, carrying readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. The readable storage medium may also be any readable medium other than a readable storage medium, capable of transmitting, propagating, or transmitting programs for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the readable storage medium may be transmitted using any suitable medium, including but not limited to wireless, wired, optical fiber, RF, etc., or any suitable combination thereof.

[0103] Program code for performing the operations of this invention can be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java and C++, and conventional procedural programming languages ​​such as C or similar languages. The program code can execute entirely on the user's computing device, partially on the user's device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).

[0104] When the program in the computer storage medium is executed by the processor, it implements the steps of the model quantization method described above. Therefore, the computer storage medium can also achieve the technical effects of the model quantization method described above.

[0105] The model quantization method, apparatus, device, and storage medium of the present invention have the following beneficial effects:

[0106] This application uses integer algorithms to execute multiple operators of a transformer model for natural language processing. These operators include linear and nonlinear operators. The linear operators include matrix multiplication, which uses symmetric quantization to convert floating-point values ​​to integer values. The nonlinear operators include activation function operators and layer normalization operators. The activation function operators use polynomial fitting to convert floating-point values ​​to integer values, and the layer normalization operators use the mean and standard deviation of the input data along the channel dimension to convert floating-point values ​​to integer values. This enables quantized inference of the transformer model, allowing it to be deployed and run on a chip. Simulation tests on various tasks in a dataset using activation function operators such as GELU (Gaussian Error Linear Unit) show that the accuracy of the quantized model is approximately the same as the floating-point model; and based on the tests, the inference speed of the quantized model is four times that of the floating-point model.

[0107] The above description, in conjunction with specific preferred embodiments, provides a further detailed explanation of the present invention. It should not be construed that the specific implementation of the present invention is limited to these descriptions. For those skilled in the art, various simple deductions or substitutions can be made without departing from the concept of the present invention, and all such modifications and substitutions should be considered within the scope of protection of the present invention.

Claims

1. A model quantization method, characterized in that, Comprising: performing a plurality of operators of a transformer model for image processing using integer arithmetic, the plurality of operators of the transformer model comprising linear operators and non-linear operators, wherein the linear operators comprise matrix multiplication operators that employ symmetric quantization to quantize floating point values to integer values; the non-linear operators comprise activation function operators that employ polynomial fitting to quantize floating point values to integer values, and layer normalization operators that employ mean and standard deviation of input data over channel dimension to quantize floating point values to integer values, the activation function operators comprising Gaussian error linear operators that quantize floating point values to integer values according to a polynomial fitting formula as follows: where i-GELU(x) is a quantized integer value, x is a floating point value before quantization, L(x) = sgn(x) [a(clip(|x|, max = -b) + b) 2 +1], where sgn is a sign function, a and b are second order polynomial parameters obtained by fitting a curve of an activation function of the Gaussian error linear operator, a is -0.2 to -0.3, b is -1.7 to -1.8, and the layer normalization operator quantizes a floating point value to an integer value according to the following equation: wherein is the quantized integer value, x is the integer value before quantization, and μ and σ are the mean and standard deviation of x in the channel dimension.

2. The model quantization method of claim 1, wherein, the symmetric quantization is implemented according to a formula as follows: where q is an integer value after quantization, and q ∈ [-2 f-1 , 2 f-1 ], x is a floating point value before quantization, S is a scaling factor, and S = a / (2 f-1 -1), a is a quantization range, and f is a quantization bit width.

3. A model quantization apparatus characterized by comprising: Comprising: a quantization module configured to perform a plurality of operators of a transformer model for image processing using integer arithmetic, the plurality of operators of the transformer model comprising linear operators and non-linear operators, wherein the linear operators comprise matrix multiplication operators that employ symmetric quantization to quantize floating point values to integer values; the non-linear operators comprise activation function operators that employ polynomial fitting to quantize floating point values to integer values, and layer normalization operators that employ mean and standard deviation of input data over channel dimension to quantize floating point values to integer values, the activation function operators comprising Gaussian error linear operators that quantize floating point values to integer values according to a polynomial fitting formula as follows: where i-GELU(x) is a quantized integer value, x is a floating point value before quantization, L(x) = sgn(x) [a(clip(|x|, max = -b) + b) 2 +1], where sgn is a sign function, a and b are second order polynomial parameters obtained by fitting a curve of an activation function of the Gaussian error linear operator, and the layer normalization operator quantizes a floating point value into an integer value according to the following equation: wherein is the quantized integer value, x is the integer value before quantization, and μ and σ are the mean and standard deviation of x in the channel dimension.

4. An electronic device, comprising: The electronic device comprises: a processor; a storage medium having stored thereon a computer program, the computer program being executable by the processor to execute the model quantization method of claim 1 or 2.

5. A storage medium, characterized by The storage medium has stored thereon a computer program, the computer program being executable by a processor to execute the model quantization method of claim 1 or 2.

Citation Information

Patent Citations

  • Quantization method, device and equipment of text feature extraction model and storage medium

    CN112686031A

  • Normalization quantification method and device, electronic equipment and storage medium

    CN114330655A

  • KR20220078950A