OPTIMIZATION METHOD FOR DEEP LEARNING NETWORKS, COMPUTER APPARATUS, AND COMPUTER-READABLE STORAGE MEDIUM
By segmenting parameter distributions in deep learning networks with breakpoints and applying varied quantization parameters, the method improves prediction accuracy and compression efficiency in deep learning networks.
Patent Information
- Application Number
- JP2022199034
- Authority / Receiving Office
- JP · JP
- Patent Type
- Patents
- Current Assignee / Owner
- Priority Date
- 2022-05-26
- Filing Date
- 2022-12-14
- Publication Date
- 2024-08-26
- Estimated Expiration
- 2042-12-14
Smart Images

Figure 0007539959000015 
Figure 0007539959000016 
Figure 0007539959000017
Abstract
Description
[Technical field]
[0001] The present invention relates to machine learning technology, and in particular to an optimization method and computer device for deep learning networks, and a computer-readable storage medium. [Background technology]
[0002] In recent years, with the increasing update of artificial intelligence (AI) technology, the number of parameters and the computational complexity of neural network models are also increasing. As a result, compression techniques for deep learning networks are also becoming more and more popular. It is worth noting that quantization is an important technique for compressing models. However, the prediction accuracy and compression rate of traditional quantized models need to be further improved. Summary of the Invention [Problem to be solved by the invention]
[0003] Technical issues The present invention provides an optimization method and computer device, and a computer-readable storage medium for deep learning networks, which can ensure prediction accuracy and compression rate using multi-scale dynamic quantization. [Means for solving the problem]
[0004] Solutions to the challenges An optimization method for a deep learning network according to a preferred embodiment of the present invention includes, but is not limited to, the following steps: obtaining a value distribution from a pre-trained model; determining one or more breakpoints within the value distribution; quantizing a portion of values of a parameter type in a first one of a plurality of sections with a first quantization parameter and quantizing another portion of values of the parameter type in a second one of the sections with a second quantization parameter; the value distribution being a statistical distribution of values of the parameter type in the deep learning network; and dividing the range into the sections by one or more breakpoints, the first quantization parameter being different from the second quantization parameter.
[0005] A computer device for a deep learning network according to an embodiment of the present invention includes, but is not limited to, a memory and a processor. The memory stores code. The processor is coupled to the memory. The processor loads and executes the code to obtain a value distribution from a trained model, determine one or more breakpoints within the value distribution, and quantize a portion of values of a parameter type in a first section of a plurality of sections with a first quantization parameter and quantize another portion of values of the parameter type in a second section of the sections with a second quantization parameter. The value distribution is a statistical distribution of values of the parameter type in the deep learning network. The range is divided into the sections by one or more breakpoints. The first quantization parameter is different from the second quantization parameter.
[0006] A non-transitory computer readable storage medium according to a preferred embodiment of the present invention is used to store code. The code is used by a processor to perform the following steps: obtain a value distribution from a pre-trained model; determine one or more breakpoints within the value distribution; perform quantization of a portion of values of a parameter type in a first section of a plurality of sections with a first quantization parameter and perform quantization of another portion of values of the parameter type in a second section of the sections with a second quantization parameter. The value distribution is a statistical distribution of values of the parameter type in the deep learning network. The range is divided into the sections by one or more breakpoints. The first quantization parameter is different from the second quantization parameter. Effect of the Invention
[0007] Based on the above, the optimization method and computer device for deep learning networks, and the computer-readable storage medium, divide the value distribution into multiple sections by breakpoints, and use different quantization parameters for the values in each section. In this way, the quantized distribution can more closely approximate the original value distribution, thereby improving the prediction accuracy of the model.
[0008] In order to make the features and advantages of the present invention more easily understandable, specific embodiments of the present invention will be described in detail below in conjunction with the drawings. [Brief description of the drawings]
[0009] [Figure 1] FIG. 2 is a block diagram of elements of a computing device according to one embodiment of the present invention. [Diagram 2] 1 is a flowchart of an optimization method for a deep learning network, according to one embodiment of the present invention. [Diagram 3] FIG. 2 is a schematic diagram of a value distribution according to an embodiment of the present invention; [Figure 4] 4 is a flowchart of a breakpoint search according to one embodiment of the present invention. [Diagram 5] 4 is a flowchart of a breakpoint search according to one embodiment of the present invention. [Figure 6] FIG. 2 is a schematic diagram of a first stage search according to an embodiment of the present invention. [Figure 7] FIG. 2 is a schematic diagram of a second stage search according to an embodiment of the present invention. [Figure 8] FIG. 2 is a schematic diagram of multi-scale dynamic fixed-point quantization according to an embodiment of the present invention; [Figure 9] FIG. 4 is a schematic diagram of quantization parameters according to an embodiment of the present invention; [Figure 10] FIG. 2 is a schematic diagram of progressive quantization according to an embodiment of the present invention; [Figure 11] FIG. 1 is a schematic diagram of a bound-constrained straight-through estimator (STE) according to one embodiment of the present invention. [Figure 12] 4 is a flowchart of model correction according to an embodiment of the present invention. [Figure 13] 4 is a flow chart of layer by layer level quantization according to one embodiment of the present invention. [Figure 14] 1 is a flow chart of layer-wise post-learning quantization according to one embodiment of the present invention. [Figure 15] 1 is a flowchart of model fine-tuning according to one embodiment of the present invention. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS
[0010] DETAILED DESCRIPTION OF THE DISCLOSED EMBODIMENTS Please refer to Figure 1, which is a block diagram of elements of a computing device 100 according to one embodiment of the present invention. The computing device 100 includes, but is not limited to, a memory 110 and a processor 150. The computing device 100 may be a desktop computer, a notebook computer, a smart phone, a tablet computer, a server, or other electronic device.
[0011] Memory 100 can be any type of fixed or removable random access memory (RAM), read only memory (ROM), flash memory, a conventional hard disk drive (HDD), a solid state drive (SSD), or similar device. In one embodiment, memory 110 is used to store code, software modules, configuration data, or files (e.g., samples, model parameters, value distributions, or breakpoints).
[0012] The processor 150 is coupled to the memory 110. The processor 150 may be a central processing unit (CPU), a graphics processing unit (GPU), other programmable general-purpose or special-purpose microprocessor, a digital signal processor (DSP), a programmable controller, a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a neural network accelerator, other similar devices, or a combination of the above devices. In one embodiment, the processor 150 is used to perform all or a portion of the operations of the computing device 100, and the processor 150 may load and execute the respective codes, software modules, files, and data stored in the memory 110.
[0013] Hereinafter, a method according to an embodiment of the present invention will be described in relation to various devices, elements, and modules in the computer apparatus 100. Each process of the method can be adjusted according to the implementation situation, and is not limited to these processes.
[0014] FIG. 2 is a flowchart of an optimization method for a deep learning network according to an embodiment of the present invention. Please refer to FIG. 2. The processor 150 obtains one or more value distributions from a pre-trained model (step S210). Specifically, the pre-trained model is based on a deep learning network (e.g., you only look once (YORO), AlexNet, ResNet, region based convolutional neural network (R-CNN), or Fast R-CNN). In other words, the pre-trained model is a model trained by inputting training samples into a deep learning network. Note that the pre-trained model can be used for image classification, object detection, or other inference, and the embodiment of the present invention does not limit the use of the pre-trained model. The trained pre-trained model satisfies a preset accuracy criterion.
[0015] It is worth noting that the pre-trained model has corresponding parameters (e.g., weights, input activation values / feature values / output activation values / feature values) for each layer. Too many parameters may require higher computation and storage requirements, and the higher the complexity of the parameters, the greater the amount of computation. Quantization is one technique to reduce the complexity of neural networks. Quantization can reduce the number of bits to represent activation values / feature values or weights. There are many kinds of quantization models, such as symmetric quantization, asymmetric quantization, and clipping methods.
[0016] On the other hand, a value distribution is a statistical distribution of multiple values of one or more parameter types in a deep learning network. The parameter types can be weights, input activation values / feature values, and / or output activation values / feature values. A statistical distribution represents the distribution of statistics (e.g., total count) of each value. For example, FIG. 3 is a schematic diagram of a value distribution according to an embodiment of the present invention. Please refer to FIG. 3. The value distribution of weights or input activation values / feature values / output activation values / feature values in a pre-trained model is a Gaussian (normal) distribution, a Laplace distribution, or a bell-shaped distribution. As shown in FIG. 3, it is worth noting that the majority of the values are located within the central section of the value distribution. If uniform quantization is used for these values, the values in the central section may all be quantized to 0, which may reduce the accuracy of model prediction. Therefore, quantization needs to be improved for parameter type values for deep learning networks.
[0017] In one embodiment, processor 150 can generate values using the validation data. For example, processor 150 can perform inference on the validation data with a pre-trained floating-point model (i.e., the pre-trained model), collect parameters (e.g., weights, input activations / feature values, or output activations / feature values) for each layer, and count values for that parameter type to generate a value distribution for that parameter type.
[0018] Please refer to FIG. 2. The processor 150 determines one or more breakpoints within the range of the value distribution (step S220). Specifically, as shown in FIG. 3, the total number of values in different sections may vary significantly. For example, the total number of values in the middle section is significantly larger than the total number of values in the two terminal / end sections. Instead, the breakpoints are used to divide the range into multiple sections. That is, the range is divided into multiple sections by one or more breakpoints. For example, the breakpoint p (real number) in the value domain in FIG. 3 divides the value distribution in the range [-m, m] into two symmetrical sections, where m (real number) represents the maximum absolute value in the value distribution. These two symmetrical sections include the middle section and the end section. The middle section is in the range [-p, p], and the end section is the other section in the range [-m, m].
[0019] Taking FIG. 3 as an example and assuming that the values are floating point, when dividing the above range into a middle section and an end section, the values in the middle section may require a larger bit width to represent the fractional part so as to prevent too many values from being quantized to 0. Also, for the end sections, the values may require a larger bit width to represent the integer part so as to provide sufficient capacity to quantize larger values. From this, it can be seen that the breakpoints are the basis for classifying values into different quantization conditions. Also, finding breakpoints suitable for the value distribution is helpful for quantization.
[0020] FIG. 4 is a flow chart of searching for a breakpoint according to an embodiment of the present invention. Please refer to FIG. 4. The first search points are used to evaluate whether a breakpoint exists (step S410). The first search points are located within the range. In one embodiment, the distance between any two adjacent first search points is the same as the distance between any two other adjacent first search points. In other embodiments, the distances between adjacent first search points may be different.
[0021] The processor 150 may divide the range by each first search point to form a plurality of evaluation sections (step S420), each evaluation section corresponding to a respective first search point. In other words, every search point divides the range into an evaluation section, or every evaluation section is located between two adjacent search points. In one embodiment, the processor 150 may determine a first search space within the value distribution. The first search points may divide the first search space into evaluation sections. The processor 150 may define the first search space and the first search points using a breakpoint ratio. Each of the plurality of breakpoint ratios is a ratio of the first search point to the maximum absolute value in the value distribution, and the mathematical expression (1) is as follows: breakpoint ratio=break point / abs max...(1) Here, breakpoint ratio is the breakpoint ratio, break point is any first search point or other search point, and abs max is the maximum absolute value in the value distribution. For example, the first search space is [0.1, 0.9], and the distance is 0.1. In other words, the breakpoint ratios of the first search points are 0.1, 0.2, 0.3, etc., respectively up to 0.9, and the first search points can be backtracked according to the mathematical expression.
[0022] The processor 150 performs quantization on the evaluation section corresponding to each first search point with different quantization parameters to obtain a quantized value corresponding to each first search point (step S430). In other words, different quantization parameters are used for different evaluation sections of any search point. Taking dynamic fixed-point quantization as an example, the quantization parameters include a bit width (BW), an integer length (IL), and a fraction length (FL). These different quantization parameters are, for example, different integer lengths and / or different fraction lengths. It should be noted that different quantization methods may use different quantization parameters. In one embodiment, under the same bit width, a section with a value close to 0 uses a longer fraction length, and a section with a larger value uses a longer integer length.
[0023] The processor 150 compares the difference measures of the first search points to obtain one or more breakpoints (step S440). Each difference measure corresponding to the first search points is a difference between a quantized value and its corresponding unquantized value (i.e., a value before quantization). For example, the difference measure is a mean squared error (MSE), a root mean squared error (RMSE), or a mean absolute error. Taking MSE as an example, the mathematical expression 2 is as follows:
number
number
[0024] In one embodiment, the processor 150 can use one or more of the first search points having a smaller difference amount as one or more breakpoints. A smaller difference amount means that the difference amount is smaller than the others. Taking one breakpoint as an example, the processor 150 can select one of the first search points having a smaller difference amount as the breakpoint. Taking two breakpoints as an example, the processor 150 selects two of the first search points having a smaller difference amount and a second smaller difference amount as the breakpoints.
[0025] Taking the selection of a small difference amount as an example, FIG. 5 is a flow chart of a breakpoint search according to an embodiment of the present invention. Please refer to FIG. 5. The processor 150 can determine a search space to obtain the quantized value of the current first search point (step S510). For example, the maximum and minimum values in the value distribution are used as the upper and lower limits of the search space. In addition, quantization is performed with different quantization parameters for the two sections divided by the first search point. The processor 150 determines the difference amount, for example, the mean square error, between the quantized value and the unquantized value of the current first search point (step S520). The processor 150 judges whether the difference amount of the current first search point is smaller than the previous difference amount (step S530). The previous difference amount is the difference amount of another first search point previously calculated. If the current difference amount is smaller than the previous difference amount, the processor 150 can update the breakpoint ratio using the current first search point (step S540). For example, the breakpoint ratio can be obtained by substituting the first search point into the formula expression (1). If the current difference amount is not smaller than the previous difference amount, the processor 150 can disable / ignore / not update the breakpoint. Then, the processor 150 can determine whether the current first search point is the last search point in the search space (step S550), i.e., ensure that the difference amounts of all the first search points have been compared. If there are other difference amounts that have not been compared among the difference amounts of the first search points, the processor 150 can determine the quantization value of the next first search point (step S510). If all the first search points have been compared, the processor 150 can output the final breakpoint ratio, and the breakpoint can be determined by the breakpoint ratio (step S560).
[0026] FIG. 6 is a schematic diagram of a first stage search according to an embodiment of the present invention. Please refer to FIG. 6. There is a distance ES between two adjacent ones of the multiple first search points FSP. In one embodiment, the first stage search can be used as a rough search, and a second stage of the search can be additionally provided. For example, the second stage defines a second search point, and the distance between two adjacent second search points is smaller than the distance between two adjacent first search points. The second search point is also used to evaluate whether a breakpoint exists, and the second search point is located within the range of the value distribution.
[0027] In one embodiment, the processor 150 can determine the second search space by one or more of the first search points having a smaller difference amount. The second search space is smaller than the first search space. As defined by the breakpoint ratio, in one embodiment, the processor 150 can determine the breakpoint ratio by one of the first search points having a smaller difference amount. The breakpoint ratio is the ratio of the first search points having the above-mentioned small difference amount to the maximum absolute value in the value distribution, and the explanation related to the formula expression (1) can be referred to, and the explanation will not be repeated here. The processor 150 can determine the second search space according to the breakpoint ratio. The small difference amount can be located in the center of the second search space. For example, when the breakpoint ratio is 0.5, the range of the second search space can be [0.4, 0.6], and the distance between two adjacent second search points can be 0.01 (assuming that the distance between the first search points is 0.1). Note that the breakpoint ratio having a small difference amount in the first stage is not necessarily located in the center of the second search space.
[0028] Fig. 7 is a schematic diagram of the second stage search according to an embodiment of the present invention. Please refer to Fig. 7, which is a partial enlarged view of value distribution. Compared with Fig. 6, the distance between two adjacent second search points SSP in Fig. 7 is much smaller than the distance ES in Fig. 6. In addition, the second search space is evenly divided by the second search points SSP, and divides the corresponding multiple evaluation sections accordingly.
[0029] Similarly, for the second stage, the processor 150 can perform quantization with different quantization parameters on the value of the evaluation section divided by each second search point to obtain a quantized value corresponding to each second search point. Then, the processor 150 can compare the difference amounts of the second search points to obtain one or more breakpoints. Each difference amount corresponding to the second search point includes the difference between the quantized value and the corresponding non-quantized value. For example, the difference amount is MSE, RMSE, or MAE. In addition, the processor 150 can use one or more of the second search points with smaller difference amounts as one or more breakpoints. Take one breakpoint as an example, the processor 150 can select one of the second search points with smaller difference amounts as a breakpoint.
[0030] See Fig. 2. The processor 150 performs quantization of a part of the values of the parameter type in a first one of the sections with a first quantization parameter, and performs quantization of another part of the values of the parameter type in a second one of the sections with a second quantization parameter (step S230). Specifically, as described in step S220, the breakpoint is used to divide the value distribution into sections with different quantization conditions. Therefore, the embodiment of the present invention provides different quantization parameters for different sections. For example, Fig. 8 is a schematic diagram of multi-scale dynamic fixed-point quantization. See Fig. 8. A pair of breakpoints BP divide the value distribution into a central section and an end section. The dotted lines are schematic lines for quantizing a certain quantization parameter, where the values in the central section are denser and the values in the end section are more sparse, and quantization is performed with different quantization parameters for the two sections.
[0031] For the central section where the value distribution is denser, the processor 150 can allocate a larger bit width to the fractional part length (FL); for the end section where the value distribution is more sparse, the processor 150 can allocate a larger bit width to the integer part length (IL). Figure 9 is a schematic diagram of quantization parameters according to an embodiment of the present invention. Please refer to Figure 9. Taking dynamic fixed-point quantization as an example, in addition to an additional bit 901, a sign bit 902, in the 12 bits representing a value, the mantissa 903 includes an integer part 904 and a fractional part 905. If the fractional part length is 3 (i.e., fl=3), the fractional part 905 occupies 3 bits as shown in the figure. In some application scenarios, dynamic fixed-point quantization is more suitable for hardware realization than symmetric quantization. For example, in addition to adders and multipliers, a neural network accelerator only needs additional support for transform calculation. However, in other embodiments, asymmetric quantization or other quantization methods can also be adopted.
[0032] Also, if more than two breakpoints are obtained, we are not limited to applying two quantization parameters to different sections.
[0033] In one embodiment, the processor 150 can perform dynamic fixed-point quantization in combination with a clipping method. The processor 150 can determine the length of the integer part of the first quantization parameter, the second quantization parameter, or other quantization parameter according to the maximum and minimum absolute values in the value distribution. The clipping method is exemplified by percentile clipping. There are only a few values far from the center in the bell-shaped distribution shown in FIG. 3, and percentile clipping can reduce the effect of these off-peak values. The processor 150 can select the value located at the 99.99th percentile in the value distribution as the maximum value W. max The value at the 0.01 percentile in the value distribution can be used as the minimum value W min The processor 150 may use, for example, an integer value of the weight IL Wcan be determined by equation (5): IL W =log2(max(|W max |, |W min |))+1...(5) Here, max represents the maximum value of the values in ().
[0034] It should be noted that the maximum and minimum values are not limited to 99.99% and 0.01%, the quantization is not limited to being combined with percentile clipping, and the quantization method is not limited to dynamic fixed-point quantization. In addition, input activation values / feature values, output activation values / feature values, or other parameter types can also be applied. Taking the maximum absolute value as an example, the processor 150 can use some of the training samples as calibration samples, and estimate these calibration samples to obtain a value distribution of the activation values / feature values. The maximum value in the value distribution can be used as the maximum value for the clipping method. Also, the formula (5) can determine the length of the integer part of the input activation values / feature values / output activation values / feature values, for example, as follows: IL I =log2(max(|I max |, |I min |))+1...(6) IL O =log2(max(|O max |, |O min |))+1...(7) Here, I.L. I is the length of the integer part of the input activation / feature value, and IL O is the length of the integer part of the output activation value / feature value, and I max is the maximum value in the value distribution of the input activation value / feature value, and O max is the maximum value in the value distribution of the output activation value / feature value, and I min is the minimum value in the distribution of input activations / feature values, and O min is the minimum value in the value distribution of the output activation values / feature values.
[0035] Meanwhile, Fig. 10 is a schematic diagram of stepwise quantization according to an embodiment of the present invention. Please refer to Fig. 10. The quantization formula is usually stepwise. The values at the same level between the maximum value x_max and the minimum value x_min are quantized to the same value. However, in the neural network learning of stepwise quantization, the parameters may not be updated due to zero gradient, which makes it difficult to learn. Therefore, there is a need to improve the gradient of the quantization formula.
[0036] A straight through estimator (STE) can be used to approximate the gradient of the quantization equation. In one embodiment, the processor 150 can use a straight through estimator (STE) with boundary constraint to further reduce gradient noise. FIG. 11 is a schematic diagram of a straight through estimator with boundary constraint (STEBC) according to one embodiment of the present invention. See FIG. 11. This STEBC can prevent differentiation in the quantization equation and define a quantization equation where the input gradient is equal to the output gradient. Equation (8) can be expressed as STEBC:
number
number
[0037] FIG. 12 is a flow chart of model correction according to an embodiment of the present invention. Please refer to FIG. 12. The quantized model can be obtained after quantizing parameters in the pre-trained model. For example, the weights, input activation / feature values, and / or output activation / feature values of each layer in the deep learning network are quantized. In one embodiment, in addition to using different quantization parameters for different sections of the same parameter type, the processor 150 can use different quantization parameters for different parameter types. Taking AlexNet as an example, the weight range of the above parameter types is [2 -11 , 2 -3 ] and the activation / feature values of the above parameter types are in the range of [2 -2 , 2 8 If a single quantization parameter were used to cover these two ranges, a larger bit width would be required to represent these values. Therefore, different quantization parameters can be assigned to the ranges of different parameter types.
[0038] In one embodiment, multiple quantization layers are added to the deep learning network. These quantization layers can be divided into three parts: for weights, for input activations / feature values, and for output activations / feature values. In addition, different bit widths and / or fractional lengths or the same bit widths and / or fractional lengths can be provided to represent the three parts of the quantization layers. This allows for a layer-by-layer level of quantization layers.
[0039] FIG. 13 is a flow chart of a quantization layer of a level per layer according to an embodiment of the present invention. Please refer to FIG. 13. The processor 150 can obtain input activation values / feature values and weights (floating point is taken as an example) of a certain parameter type (steps S101 and S102), and quantize (e.g., dynamic fixed-point quantization, symmetric quantization, or other quantization) each of the weights or input activation values / feature values (steps S103 and S104) to obtain quantized input activation values / feature values and quantized weights (steps S105 and S106). The processor 150 can input these quantized values to a calculation layer (step S107). The calculation layer can perform, for example, convolution calculation, full connection calculation, or other calculation. Next, the processor 150 obtains the output activation / feature values of the above parameter types output by the computation layer (step S108), and quantizes the output activation / feature values (step S109) to obtain the quantized output activation / feature values (step S110). The quantization steps S103, S104, and S109 can be considered as being in one quantization layer. This mechanism can tie this quantization layer to one general floating-point layer or a customized layer. In addition, in some embodiments, the processor 150 can accelerate the learning and inference process using a floating-point general matrix multiplication (GEMM) library (e.g., compute unified device architecture (GUDA®: a general-purpose parallel computing platform for GPUs by NVIDIA)).
[0040] The processor 150 can post-train the quantization model (step S121). For example, the quantization model is trained using training samples with labeled results. FIG. 14 is a flowchart of layer-by-layer post-training quantization according to an embodiment of the present invention. Please refer to FIG. 14. The processor 150 can determine the length of the integer part of the weight of each quantization layer in the quantization model (steps S141-S143), for example, using percentile clipping or multi-scale quantization method on the trained weights. For an example of percentile clipping, the description related to Equation (5) can be referred to, and the description will not be repeated here. Next, the processor 150 can estimate a number of calibration samples according to the quantization model, determine the value distribution of the input activation value / feature value / output activation value / feature value in each quantization layer in the quantization model, and select the maximum value for the clipping method accordingly. The processor 150 can determine the length of the integer part of the activation / feature values in each quantization layer in the quantization model, for example, using the maximum absolute value or a multi-scale quantization method for the trained input / output activation / feature values (steps S142 and S143). For an example of the maximum absolute value, reference can be made to the description related to equations (6) and (7), and the description will not be repeated here.
[0041] Next, the processor 150 can determine the length of the fractional part of each quantization layer weight / activation value / feature value according to the bit width limit of each quantization layer (step S144). Using equation (11), the fractional part length is determined as follows: FL=BW-IL...(11) where FL is the length of the fractional part, BW is a predetermined bit width limit, and IL is the length of the integer part. Under some application scenarios, the length of the integer part obtained from equation (11) can be smaller than the length of the integer part obtained from equations (5) to (7), for example by 1 bit. (Fine-)adjusting the length of the integer part helps to improve the prediction accuracy of the model. Finally, the processor 150 can obtain the post-trained quantization model (step S145).
[0042] See FIG. 12. The processor 150 may retrain / (fine)tune the trained quantization model (step S122). Under some application scenarios, post-training the trained model may reduce prediction accuracy. Thus, (fine) tuning may improve accuracy. In one embodiment, the processor 150 may determine the gradient of the weight quantization by using a bound-constrained straight-through estimator (STEBC). The straight-through estimator is configured such that the input gradient between the upper and lower bounds is equal to the output gradient. As previously explained, the bound-constrained straight-through estimator may improve the gradient approximation. The above embodiment of the present invention introduces a bound-constrained straight-through estimator for a single layer in a deep learning network to provide layer-by-layer level (fine) tuning. In other words, in addition to providing layer-by-layer quantization for forward propagation, layer-by-layer (fine) tuning may also be provided in backward propagation. For the layer-by-layer quantization of forward propagation, reference can be made to the explanation related to FIG. 13, and the explanation will not be repeated here.
[0043] FIG. 15 is a flow chart of model fine-tuning according to an embodiment of the present invention. Please refer to FIG. 15. For a trained quantized model, in backpropagation, the processor 150 obtains gradients from the next layer (step S151), and uses a bounded straight-through estimator to (fine-)adjust the gradients of the output activation values / feature values (step S152) to obtain the gradients of the output of the quantized layer (step S153). Note that, taking neural network inference as an example, forward propagation starts from the input layer of a neural network and goes to its output layer in order. For adjacent layers, the layer closer to the input layer is the previous layer, and the layer closer to the output layer is the next layer before and after one layer. In addition, the processor 150 can determine the corresponding gradient from the weights and input activation values / feature values of the learned quantization model using floating-point calculation (step S154), (fine-)adjust the weights and input activation values / feature values, respectively, using a bound-constrained straight-through estimator (steps S155 and S156), and determine the gradient of the weights and the gradient for the previous layer accordingly (steps S157 and S158). Then, the processor 150 can update the weights using gradient descent (step S159). The weights can be used in step S102 of FIG. 13. It is worth noting that the updated gradient can be further applied to floating-point quantization. Finally, the processor 150 can obtain the (fine-)adjusted quantization model (step S123). This can further improve the prediction accuracy.
[0044] An embodiment of the present invention provides a non-transitory computer-readable storage medium (e.g., a hard disk drive, an optical disk, a flash memory, a solid-state drive (SSD), and other storage media) that is used to store code. The processor 150 of the computer device 100 or other processors can load the code and execute corresponding processes of one or more optimization methods according to an embodiment of the present invention. For these processes, reference can be made to the above description, and the description will not be repeated here.
[0045] In summary, in the optimization method and computer device for deep learning networks, and the computer-readable storage medium according to the embodiments of the present invention, the value distribution of the parameters of the pre-trained model is analyzed to determine the range to be divided into breakpoints with different quantization conditions. The breakpoints can divide the value distribution of different parameter types into multiple sections, and / or the value distribution of a single parameter type into multiple sections. Different quantization parameters can be used for different sections. A percentile clipping method is used to determine the length of the integer part of the weights, and a maximum absolute value method is used to determine the length of the integer part of the input feature value / activation value / output feature value / activation value. In addition, a bound-constrained straight-through estimator is introduced to improve the gradient approximation. In this way, the accuracy loss can be reduced and acceptable compression can be achieved.
[0046] Although the present invention has been disclosed in the above embodiments, these embodiments are not intended to limit the present invention. Those skilled in the art can make certain changes and modifications without departing from the spirit and scope of the present invention. Therefore, the protection scope of the present invention is defined by the appended claims. [Industrial Applicability]
[0047] The optimization method for deep learning networks, the computer device, and the computer-readable storage medium of the present invention can be applied to the computer device and its calculation method. [Explanation of symbols]
[0048] 100: Computer equipment 110:Memory 150: Processor S210~S130, S410~S440, S510~S560, S121~S123, S101~S110, S141~S145, S151~S159: Step m, -m: maximum absolute value ES: Distance FSP: 1st search point SSP: 2nd search point p, BP: breakpoint 901: Additional bits 902: Sign bit 903: Mantissa 904: Integer part 905: Decimal part fl:fraction length x_max:Maximum value x_min:minimum value
Claims
1. 1. An optimization method for a deep learning network, comprising: obtaining a value distribution from a pre-trained model, the value distribution being a statistical distribution of values of a parameter type in the deep learning network; determining at least one breakpoint within a range of said value distribution, said range being divided into a plurality of sections by said at least one breakpoint; performing quantization of a portion of the values of the parameter type in a first section of the plurality of sections with a first quantization parameter and performing quantization of another portion of the values of the parameter type in a second section of the plurality of sections with a second quantization parameter, the first quantization parameter being different from the second quantization parameter; quantizing the quantization step by: performing dynamic fixed-point quantization in combination with a clipping technique, the length of the integer part of the first quantization parameter being determined in response to a maximum and a minimum absolute value in the value distribution; The optimization method for a deep learning network comprises: Post-training the quantization model to obtain a trained quantization model; and adjusting the learned quantization model. The step of adjusting the trained quantization model includes:
1. A method of optimization for deep learning networks, comprising: determining gradients of quantization of weights of the parameter types using a bound-constrained straight-through estimator (STEBC), the bound-constrained straight-through estimator being configured such that an input gradient between an upper bound and a lower bound is equal to an output gradient.
2. determining at least one breakpoint within said distribution of values, determining a plurality of first search points within the range; dividing the range by each of the first search points to form a plurality of evaluation sections, each of the evaluation sections corresponding to a respective one of the first search points; performing quantization on the evaluation sections corresponding to each of the first search points with different quantization parameters to obtain quantized values corresponding to each of the first search points; comparing a plurality of difference measures of the first search points to obtain the at least one break point, each of the difference measures corresponding to one of the first search points and comprising a difference between a quantized value and a corresponding unquantized value; Including, The step of determining the first plurality of search points comprises: determining a first search space within the range, the first search space being evenly divided into the evaluation section by the first search points; comparing a plurality of difference measures of the first search points to obtain the at least one break point; using one of the first search points having a smaller amount of difference as the at least one break point; determining a second search space by one of the first search points having a smaller difference amount, the second search space being smaller than the first search space; determining a plurality of second search points in the second search space, wherein a distance between two adjacent second search points is smaller than a distance between two adjacent first search points; comparing difference measures of the second search points to obtain the at least one break point, each difference measure corresponding to one of the second search points and comprising a difference between a quantized value and a corresponding unquantized value; determining the second search space by the one first search point having the small difference amount among the first search points, determining a breakpoint ratio from the one of the first search points having the small difference amount, the breakpoint ratio being a ratio of the one of the first search points having the small difference amount to a maximum absolute value in the value distribution; 2. The method of claim 1, further comprising: determining the second search space according to the breakpoint ratio, the small difference amount being located within the second search space.
3. The step of post-learning the quantization model comprises: determining a length of an integer portion of a weight for each of a plurality of quantization layers in the quantization model; estimating a plurality of calibration samples using the quantization model to determine the length of the integer part of the activation values / feature values of each of the quantization layers in the quantization model; determining a length of a fractional portion of each of the quantization layers according to a bit width limit of each of the quantization layers; 3. The optimization method for a deep learning network according to claim 1 or 2, comprising:
4. The optimization method for a deep learning network comprises: quantizing the parameter type weight values or input activation values; inputting the quantized values obtained by the quantization into a computational layer in the quantization model; quantizing the output activation values of the parameter types output from the computational layer; The optimization method for a deep learning network according to claim 1 or 2, further comprising:
5. A memory for storing a code; and a processor coupled to the memory, the processor loading and executing the code to: obtaining a value distribution from a pre-trained model, the value distribution being a statistical distribution of values of a parameter type in the deep learning network; determining at least one breakpoint within a range of the value distribution, the range being divided into a plurality of sections by the at least one breakpoint; performing quantization of a portion of the values of the parameter type within a first section of the plurality of sections using a first quantization parameter and performing quantization of another portion of the values of the parameter type within a second section of the plurality of sections using a second quantization parameter, the first quantization parameter being different from the second quantization parameter; The processor further comprises: Combining dynamic fixed-point quantization with a clipping method, the length of the integer part of the first quantization parameter being determined in response to a maximum and a minimum absolute value in the value distribution; The processor further comprises: Post-training the quantization model to obtain a trained quantization model; and adjusting the trained quantization model. Adjusting the trained quantization model, determining gradients of quantization of weights of the parameter types using a bounded constrained straight-through estimator (STEBC), the bounded straight-through estimator being configured such that an input gradient between an upper bound and a lower bound is equal to an output gradient.
6. A non-transitory computer readable storage medium storing code, comprising: A processor loads and executes the code, obtaining a value distribution from a pre-trained model, the value distribution being a statistical distribution of values of a parameter type in the deep learning network; determining at least one breakpoint within a range of the value distribution, the range being divided into a plurality of sections by the at least one breakpoint; performing quantization of a portion of the values of the parameter type within a first section of the plurality of sections using a first quantization parameter and performing quantization of another portion of the values of the parameter type within a second section of the plurality of sections using a second quantization parameter, the first quantization parameter being different from the second quantization parameter; The processor further comprises: Combining dynamic fixed-point quantization with a clipping method, the length of the integer part of the first quantization parameter being determined in response to a maximum and a minimum absolute value in the value distribution; The processor further comprises: Post-training the quantization model to obtain a trained quantization model; and adjusting the trained quantization model. Adjusting the trained quantization model, determining gradients of quantization of weights of the parameter types using a bound-constrained straight-through estimator (STEBC), the bound-constrained straight-through estimator being configured such that an input gradient between an upper bound and a lower bound is equal to an output gradient.
Citation Information
Patent Citations
Information processing device, information processing method, and information processing program
JP2021056734A
Method of quantizing artificial neural network, and system and artificial neural network device therefor
JP2021072103A
Methods, apparatus, and related products for processing data
JP2022501670A
Method and apparatus for processing weight of artificial neural network
KR1020210093648A
Look-up table based neural networks
US20200234126A1
