A data normalization processing method, a storage medium and a computer device
By calculating a scaling factor to scale the input data proportionally, the problem of data overflow in deep learning neural network models is solved, and the accuracy and performance of normalization processing are improved.
Patent Information
- Application Number
- CN202010709417.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-07-22
- Publication Date
- 2026-01-16
- Estimated Expiration
- 2040-10-10
AI Technical Summary
During the forward propagation of a deep learning neural network model, the sum of squares of the input data can easily exceed the expression range of integer and floating-point data types, leading to data overflow and affecting model computation.
By calculating the maximum value of the data type after quantization and the maximum value of the input data, a scaling factor is calculated, and the input data is scaled proportionally using the scaling factor to perform normalization processing and avoid data overflow.
It effectively prevents data overflow, improves the computational accuracy and performance of normalization processing, simplifies the normalization operation process, and reduces the amount of computation.
Smart Images

Figure CN113971453B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of artificial intelligence, in particular to a data normalization processing method, a data normalization processing device, a computer readable storage medium and a computer device. BACKGROUND
[0002] In order to accelerate the convergence speed of the deep learning neural network model and improve the precision of the model, the normalization layer is widely used in the training process of the deep learning neural network. In order to ensure the precision of the model, the normalization layer will also be retained in the forward propagation process, that is, the inference process. In order to improve the performance of the deep learning neural network model, normalization of the input data, that is, floating-point number to integer number, is often required in the forward propagation process.
[0003] In actual situations, the total number of input data is usually large. At this time, when the L2Normalization operator is used for calculation, the square sum of the input data is easy to exceed the expression range of the integer data type, even the floating-point data type, that is, the data overflow phenomenon occurs, resulting in abnormal operation of the model.
[0004] Therefore, in the forward propagation process of the deep learning neural network model, it is necessary to prevent data overflow of the normalization layer. SUMMARY
[0005] Therefore, it is necessary to provide a data normalization processing method for the above technical problems. The method is suitable for the normalization layer in the deep learning neural network, and the method comprises:
[0006] According to the maximum value of the quantized data type of the input data and the maximum value of the input data, a scaling factor of the input data is calculated;
[0007] The first product of the scaling factor and the input data is calculated, and the normalization result of the input data in the normalization layer is calculated according to the first product.
[0008] The present application also provides a data normalization processing device suitable for the normalization layer in the deep learning neural network, and the device comprises:
[0009] The scaling factor calculation unit calculates the scaling factor of the input data according to the maximum value of the quantized data type of the input data and the maximum value of the input data;
[0010] The normalization calculation unit calculates the first product of the scaling factor and the input data, and calculates the normalization result of the input data in the normalization layer according to the first product.
[0011] The application further provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the data normalization processing method to normalize data.
[0012] The application further provides a computer device, which comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the data normalization processing method when executing the computer program.
[0013] Advantages of the present disclosure are as follows:
[0014] The technical solution in the present disclosure introduces the maximum value of the quantized input data and the maximum value of the input data as the basis for calculating the scaling factor, and uses the calculated scaling factor to scale the input data, which can effectively prevent data overflow in the data processing process, improve the calculation accuracy of input data normalization (quantization), and improve the performance of data normalization processing.
[0015] The present disclosure simplifies the calculation process of the normalization operation by performing data scaling operation inside the Normalizaion layer or operator, reduces the calculation amount in the calculation process, and makes the normalization operation more concise compared with the existing normalization operation, without the need for additional user operations.
[0016] Furthermore, the present disclosure uses a basic operator splicing method to complete the function of the L2Normalization operator when performing normalization operation, especially on an ai chip. The operator splicing method in the present disclosure has the same calculation effect as the L2Normalization operator, while reducing the complexity of normalization operation on the ai chip, avoiding additional workload caused by new operator development, and helping to improve the performance of the overall ai chip. BRIEF DESCRIPTION OF DRAWINGS
[0017] The advantages of the above and / or additional aspects of the present disclosure will become apparent and easy to understand in connection with the following description of the embodiments, in conjunction with the accompanying drawings, in which:
[0018] Figure 1 is a schematic diagram of a processor for a data normalization processing method according to an embodiment of the present disclosure;
[0019] Figure 2 is a schematic flowchart of a data normalization processing method according to an embodiment of the present disclosure;
[0020] Figure 3 is a schematic flowchart of an operator splicing process according to an embodiment of the present disclosure;
[0021] Figure 4A schematic block diagram of a data normalization processing apparatus according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0022] The technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are part of, rather than all of, the embodiments of the present disclosure. Based on the embodiments in the present disclosure, all other embodiments obtained by a person of ordinary skill in the art without creative effort fall within the protection scope of the present disclosure.
[0023] It should also be understood that the terminology used herein in the specification presents a description for the particular embodiments only and should not be construed to limit the present disclosure. As used in the specification and in the claims, the singular forms "a," "an" and "the" include plural references unless the context clearly dictates otherwise. It should also be further understood that the term "and / or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items, as well as the lack of combinations when interpreted in the alternative.
[0024] As used in the specification and claims, the term "if' can be construed to mean "when" or "once," or "in response to a determination" or "in response to a detection" of, as appropriate, depending on the context. Similarly, the phrase "if it is determined" or "if [a described condition or event] is detected" can be construed to mean "once it is determined" or "in response to a determination," or "once [the described condition or event] is detected" or "in response to a detection [of the described condition or event]," depending on the context.
[0025] The data processing method according to the embodiments of the present disclosure can be applied to a first processing device such as a processor, which can be a general-purpose processor such as a CPU (Central Processing Unit) or an artificial intelligence processor (IPU) for performing artificial intelligence operations. The artificial intelligence operations can include machine learning operations, brain-like operations, and the like. The machine learning operations include neural network operations, k-means operations, support vector machine operations, and the like. The artificial intelligence processor can include one or a combination of a GPU (Graphics Processing Unit), a NPU (Neural-Network Processing Unit), a DSP (Digital Signal Process), and an FPGA (Field-Programmable Gate Array) chip, for example. The present disclosure does not limit the specific type of processor.
[0026] In a possible implementation, the processor mentioned in the disclosure can include a plurality of processing units, each of which can independently run an assigned task, such as a scaling factor calculation task, a data normalization calculation task, etc. The disclosure does not limit the processing units and the tasks run by the processing units.
[0027] Figure 1 A schematic diagram of a processor for a data normalization processing method according to an embodiment of the disclosure is shown, which is suitable for normalization operation of a normalization layer in a deep learning neural network. As shown in the figure, Figure 1 The processor 100 includes a plurality of processing units 101 for executing instruction sequences and a storage unit 102 for storing data, which can include a random access memory and a register stack. The plurality of processing units 101 in the processor 100 can share part of the storage space, such as a shared part of the RAM storage space and the register stack, or can have their own storage space at the same time. After the processing units 101 in the processor 100 execute the assigned tasks, the calculation amount in the normalization operation process can be reduced while preventing data overflow, and the overall performance of the device is improved.
[0028] When the processor 100 performs normalization operation, the normalization operation method is as shown in the figure Figure 2 According to the maximum value of the quantized (normalized) data type of the input data and the maximum value of the input data, the processing unit 101 calculates the scaling factor of the input data.
[0029] Optionally, the input data can be one-dimensional data, two-dimensional data, or multi-dimensional data, which is not limited in the present application.
[0030] Optionally, the input data is floating-point data, which can be 32-bit floating-point data, 16-bit floating-point data, 64-bit floating-point data, etc. The quantized data is fixed-point data, including 8-bit fixed-point data, 16-bit fixed-point data, etc. The present application does not make any limitation. The maximum value of the quantized data type refers to the maximum value of the numerical range represented by the data type, for example, the range represented by 8-bit fixed-point data is [-128, 127], and the maximum value of the quantized data type is 127.
[0031] In one possible embodiment, the calculation formula of the scaling factor is:
[0032]
[0033] In the formula, β is the scaling factor, Max is the maximum value of the quantized data type of the input data, x max is the maximum value of the input data, and n is the total number of the input data, n is a positive integer greater than 1.
[0034] In one possible embodiment, the calculation formula of the scaling factor can also be Max / x max .
[0035] The scaling factor of the present application is determined according to the maximum value of the data type after quantization and the maximum value of the input data, and the specific calculation formula of the scaling factor is not limited.
[0036] By setting the scaling factor, the maximum value of the data type after data quantization is introduced, which can improve the calculation accuracy of the scaling factor, reduce the calculation amount of the scaling factor, and improve the data overflow prevention effect.
[0037] The processing unit 101 calculates the first product of the scaling factor and the input data, and calculates the normalization result of the input data in the L2Normalization operator in the normalization layer according to the first product.
[0038] Specifically, in the normalization layer of the deep learning neural network model, the L2Normalization operator is usually used to normalize the input data to improve the performance of the deep learning neural network model.
[0039] The processing unit 101 scales the input data by the same proportion by using the calculated scaling factor before performing the normalization operation, that is, the scaling factor is multiplied by the input data one by one.
[0040] The product of the two is then brought into the L2Normalization operator to perform the normalization operation. At this time, the calculation formula of the L2Normalization operator normalization is:
[0041]
[0042] In the formula, x i is the i-th data in the input data, i=1, 2, …, n, n is the total number of input data, y i is the corresponding normalized result of the input data x i .
[0043] As can be seen from the above formula, when normalizing, the numerator and denominator are scaled by the same multiple, so the corresponding normalization result remains unchanged. However, by scaling the numerator and denominator, data overflow can be effectively prevented and the calculation accuracy in the normalization process can be improved.
[0044] According to the calculation formula of the L2Normalization operator, it can be known that, when performing the normalization calculation, first, the input data needs to be squared, then the cumulative sum is calculated, the square root of the cumulative sum is calculated, the reciprocal of the square root is calculated, and then the input data is multiplied to complete the normalization operation.
[0045] The above calculation process is relatively complicated, especially the calculation process involves squaring, cumulative sum, and square root operations, and the calculation amount is large, therefore, in the present disclosure, the normalization calculation process is replaced by operator splicing to reduce the calculation amount in the calculation process, and further improve the performance of the deep learning neural network model.
[0046] The operator splicing method in the present disclosure is suitable for the normalization operation of the L2Normalization operator in instance mode, channel mode and other operation modes, and is described by taking the instance mode operation of the L2Normalization operator as an example.
[0047] Specifically, the instance mode refers to when the input data is in the NCHW format, then the instance refers to the operation on each batch, or the operation on the N direction of the input data, and the operation mode at this time is recorded as the instance mode.
[0048] The channel mode refers to that the input data is the channel of the RGB picture, and it is also the operation on the C direction of the data format NCHW, and the operation mode at this time is recorded as the channel mode.
[0049] When the input data is in the NCHW format, the L2Normalization operator performs the instance mode operation, and takes the picture data processing as an example, and the processing sequence is generally: N direction—>H direction—>W direction—>C direction, wherein, N is usually referred to as instance or batch, H is usually referred to as the height of the picture, W is the width of the picture, and C is the channel of the picture.
[0050] Those skilled in the art can understand that, when the input data is in the NCHW format, it means that the operation is performed on 1, 2, 3, or 4-dimensional data, that is, when any one of the data in the four directions is greater than 1, and the remaining three directions of the data are equal to 1, it means that the operation is performed on 1-dimensional data; when any two of the data in the four directions are greater than 1, and the remaining two directions of the data are equal to 1, it means that the operation is performed on 2-dimensional data; when any three of the data in the four directions are greater than 1, and the remaining one direction of the data is equal to 1, it means that the operation is performed on 3-dimensional data; and when all the data in the four directions are greater than 1, it means that the operation is performed on 4-dimensional data.
[0051] The present disclosure only takes N-direction data as an example, i.e., uses 1-dimensional data to illustrate the operator splicing method.
[0052] As shown in FIG. 1, the processing unit 101 uses the operator splicing method to calculate the specific process of the normalization result of the input data in the L2Normalization operator in the normalization layer. Figure 3
[0053] After normalizing the N-direction data, the first product βx i As data A1, first use the square (multiplication) operation (NCHW) x (NCHW) to calculate the first square value of data A1, and obtain data A2;
[0054] Sum the data A1 and data A2 in the N-direction data, at this time, the dimension of the N-direction data is changed to 1, and the remaining dimensions remain unchanged, i.e., NCHW -> 1CHW, and the sum of the two is recorded as data A3;
[0055] Then use the square root operation on data A3 and take the reciprocal, i.e., 1 Obtain the square root reciprocal of data A3, recorded as data A4, wherein data A4 is three-dimensional data, and A1 is four-dimensional data, which has one less dimension than data A1.
[0056] Therefore, multiply data A4 and data A1 in different dimensions, i.e., broadcast multiplication broadcast_mult, to obtain the second product corresponding to the input data, and record the second product as the normalization result of the L2Normalization operator.
[0057] Now the broadcast multiplication is described: the broadcast multiplication is a multiplication operation between a small matrix and a large matrix, wherein the "small" and "large" are relative to the dimensions of the data, and the dimension of the small matrix is smaller than that of the large matrix. The large matrix is divided into at least two sub-matrices according to the dimension of the small matrix, and the at least two sub-matrices are operated with the small matrix respectively to obtain a product recorded as a sub-matrix product, and the sum of the sub-matrix products is calculated by using addition operation, which is the final result of the small matrix and the large matrix. In the present disclosure, the reciprocal of the square root is a three-dimensional matrix, which is a small matrix, and the first product is a four-dimensional matrix, which is a large matrix.
[0058] In the present disclosure, the specific method for calculating the second product using broadcast multiplication includes:
[0059] According to the dimension of the reciprocal of the square root, the first product is divided into at least two sub-matrices, wherein the dimension of the reciprocal of the square root is smaller than that of the first product, and the dimension of the divided sub-matrix is equal to that of the reciprocal of the square root, i.e., the broadcast multiplication is performed on the reciprocal of the square root;
[0060] The inverse of the square root is calculated in sequence and multiplied with the sub-matrix, and the product is recorded as the sub-matrix product;
[0061] The sum of the sub-matrix products is calculated by using addition operation, and the sum is recorded as the second product.
[0062] Specifically, the data A1 is four-dimensional data, and the data format is NCHW, and the data A4 is three-dimensional data, and the data format is CHW. Therefore, when the broadcast multiplication is performed, the data A1 is first split into N three-dimensional data according to the N direction according to the dimension of the data A4, and N sub-matrices are obtained.
[0063] Then, the N sub-matrices are multiplied with the data A4 in sequence to obtain N sub-matrix products.
[0064] Finally, the N sub-matrix products are added to obtain the sum of the sub-matrix products, and the broadcast multiplication is completed to realize the calculation of the second product.
[0065] The above calculation process can be described as: mult->sumpool->rsqrt->broadcast_mult.
[0066] It should be noted that when the input data is in the RGB picture format, the L2Normalization operator performs channel mode operation at this time, that is, the input data at this time is the channel of the RGB picture, which is equivalent to the C direction under the data format NHWC. At this time, the processing unit 101 replaces the specific process of the L2Normalization operator by using the operator splicing method, and the execution example mode operation is the same as described above, which can be described as: mult->sumpool->rsqrt->broadcast_mult.
[0067] Through the above calculation process of operator splicing, the basic operators are spliced to avoid the square, cumulative summation and square root operations in the calculation process of the conventional L2Normalization operator. The operator splicing method in the present disclosure has the same calculation effect as the conventional L2Normalization operator. At the same time, the operator splicing method also reduces the complexity in the data normalization process, simplifies the normalization operation of the Normalization layer in the deep learning neural network model, and avoids the additional workload caused by the development of new operators.
[0068] On the basis of the above disclosure, as Figure 4The disclosure also provides a data normalization processing device, which comprises a scaling factor calculation unit 10 and a normalization calculation unit 20. The scaling factor calculation unit 10 and the normalization calculation unit 20 perform normalization operations of a normalization layer in a deep learning neural network, reduce the amount of calculation in the normalization operation, and improve the overall performance of the device while preventing data overflow.
[0069] The scaling factor calculation unit 10 is configured to calculate a scaling factor of the input data according to a maximum value of a data type of the quantized (normalized) input data and a maximum value of the input data.
[0070] Optionally, the input data can be one-dimensional data, two-dimensional data, or multi-dimensional data, and the present application does not make any limitation in this regard.
[0071] Optionally, the input data can be floating-point data, such as 32-bit floating-point data, 16-bit floating-point data, 64-bit floating-point data, etc., and the quantized data can be fixed-point data, such as 8-bit fixed-point data, 16-bit fixed-point data, etc., and the present application does not make any limitation in this regard. The maximum value of the quantized data type refers to the maximum value of the numerical range represented by the data type, for example, the range represented by 8-bit fixed-point data is [-128, 127], and the maximum value of the quantized data type is 127.
[0072] In one possible embodiment, the calculation formula of the scaling factor is:
[0073]
[0074] In the formula, β is the scaling factor, Max is the maximum value of the data type of the quantized input data, x max is the maximum value of the input data, and n is the total number of the input data, and n is a positive integer greater than 1.
[0075] In one possible embodiment, the calculation formula of the scaling factor can also be Max / x max .
[0076] The scaling factor of the present disclosure is determined according to the maximum value of the quantized data type and the maximum value of the input data, and the specific calculation formula of the scaling factor is not limited.
[0077] By setting the scaling factor, the maximum value of the data type after data quantization is introduced, which can improve the calculation accuracy of the scaling factor, reduce the calculation amount of the scaling factor, and improve the effect of data overflow prevention.
[0078] The normalization calculation unit 20 is configured to calculate a first product of the scaling factor and the input data, and calculate a normalization result of the input data in an L2Normalization operator in the normalization layer according to the first product.
[0079] Specifically, in the normalization layer of the deep learning neural network model, an L2 normalization operator is usually used to normalize the input data, so as to improve the performance of the deep learning neural network model.
[0080] Before performing the normalization operation, the normalization calculation unit 20 scales the input data by the calculated scaling factor, i.e., multiplies the scaling factor with the input data.
[0081] The product is then input into the L2 normalization operator to perform the normalization operation. At this time, the calculation formula of the L2 normalization operator is:
[0082]
[0083] In the formula, x i is the i-th data in the input data, i = 1, 2, …, n, n is the total number of input data, y i is the corresponding normalized result of the input data x i .
[0084] As can be seen from the above formula, when performing normalization, the numerator and denominator are scaled by the same multiple, so the corresponding normalization result remains unchanged. However, by scaling the numerator and denominator, data overflow can be effectively prevented and the calculation accuracy in the normalization process can be improved.
[0085] According to the calculation formula of the L2 normalization operator, it can be known that when performing normalization calculation, the input data needs to be squared first, then the cumulative sum is calculated, the square root of the cumulative sum is calculated, the reciprocal of the square root is calculated, and then the input data is multiplied to complete the normalization operation.
[0086] The above calculation process is relatively complicated, especially the calculation process involves squaring, cumulative sum, and square root operations, and the calculation amount is large. Therefore, in the present disclosure, the normalization calculation process is replaced by operator splicing to reduce the calculation amount in the calculation process and further improve the performance of the deep learning neural network model.
[0087] The operator splicing method in the present disclosure is suitable for the normalization operation of the L2 normalization operator in instance mode, channel mode, etc. Taking the execution of the instance mode operation of the L2 normalization operator as an example for illustration.
[0088] Specifically, the instance mode refers to that when the input data is in the NCHW format, the instance refers to performing operation on each batch or on the N direction of the input data, and the operation mode is recorded as the instance mode.
[0089] The channel mode refers to that the input data is the channel of the RGB picture, and the operation is performed on the C direction of the data in the NCHW format, and the operation mode is recorded as the channel mode.
[0090] When the input data is in the NCHW format, the L2Normalization operator performs the instance mode operation. Taking picture data processing as an example, the processing order is generally: N direction -> H direction -> W direction -> C direction according to the set dimension, wherein N is usually referred to as instance or batch, H is usually referred to as the height of the picture, W is the width of the picture, and C is the channel of the picture.
[0091] Those skilled in the art can understand that when the input data is in the NCHW format, it means that the operation is performed on 1, 2, 3 or 4-dimensional data, that is, when any one of the data in the four directions is greater than 1 and the data in the remaining three directions is equal to 1, it means that the operation is performed on 1-dimensional data; when any two of the data in the four directions are greater than 1 and the data in the remaining two directions is equal to 1, it means that the operation is performed on 2-dimensional data; when any three of the data in the four directions are greater than 1 and the data in the remaining one direction is equal to 1, it means that the operation is performed on 3-dimensional data; and when the data in the four directions are all greater than 1, it means that the operation is performed on 4-dimensional data.
[0092] The present disclosure only takes the N direction data as an example to illustrate the operator splicing method.
[0093] The normalization calculation unit 20 adopts the operator splicing method, and the specific process of calculating the normalization result of the L2Normalization operator in the normalization layer of the input data is as follows:
[0094] After normalizing the N direction data, the first product βx i As data A1, first, a square (multiplication) operation (NCHW) x (NCHW) is used to calculate the first square value of data A1, and data A2 is obtained;
[0095] The sum operation is performed on data A1 and data A2 in the N direction data, at this time, the dimension of the N direction data is changed to 1, and the remaining dimensions remain unchanged, that is, NCHW -> 1CHW, and the sum value of the two is recorded as data A3;
[0096] Then, the square root operation is used on data A3 and the reciprocal is taken, that is, 1 The square root reciprocal of the data A3 is obtained, denoted as data A4, wherein the data A4 is three-dimensional data, and the data A1 is four-dimensional data, and the dimension of the data A4 is one less than that of the data A1.
[0097] Therefore, the data A4 and the data A1 are subjected to a multiplication operation of different dimensions, that is, a broadcast multiplication, to obtain a second product corresponding to the input data, and the second product is denoted as a normalization result of the L2Normalization operator.
[0098] The broadcast multiplication will be described as follows: the broadcast multiplication is a multiplication operation between a small matrix and a large matrix, wherein the "small" and "large" are relative to the dimensions of the data, and the dimension of the small matrix is less than that of the large matrix. The large matrix is divided into at least two sub-matrices according to the dimension of the small matrix, and the at least two sub-matrices are respectively operated with the small matrix to obtain a sub-matrix product. The sum of the sub-matrix products is calculated by using an addition operation, and the sum is the final result of the small matrix and the large matrix. In the present disclosure, the square root reciprocal is a three-dimensional matrix, which is a small matrix, and the first product is a four-dimensional matrix, which is a large matrix.
[0099] In the present disclosure, the specific method for calculating the second product by using the broadcast multiplication includes the following steps:
[0100] According to the dimension of the square root reciprocal, the first product is divided into at least two sub-matrices, wherein the dimension of the square root reciprocal is less than that of the first product, and the dimension of the divided sub-matrix is equal to that of the square root reciprocal, that is, the square root reciprocal is subjected to the broadcast multiplication;
[0101] The square root reciprocal is sequentially multiplied with the sub-matrices to obtain a sub-matrix product.
[0102] The sum of the sub-matrix products is calculated by using an addition operation, and the sum is denoted as the second product.
[0103] Specifically, the data A1 is four-dimensional data, and the data format is NCHW. The data A4 is three-dimensional data, and the data format is CHW. Therefore, when the broadcast multiplication is performed on the two data, the data A1 is first split into N three-dimensional data according to the dimension of the data A4 in the N direction to obtain N sub-matrices.
[0104] Then, the N sub-matrices are sequentially multiplied with the data A4 to obtain N sub-matrix products.
[0105] Finally, the N sub-matrix products are added to obtain the sum of the sub-matrix products, and the broadcast multiplication is completed to realize the calculation of the second product.
[0106] The above calculation process can be described as: mult->sumpool->rsqrt->broadcast_mult.
[0107] It should be noted that when the input data is in the RGB picture format, the L2Normalization operator performs channel mode operation at this time, that is, the input data at this time is the channel of the RGB picture, which is equivalent to the C direction under the data format NHWC, at this time, the processing unit 101 replaces the specific process of the L2Normalization operator by the operator splicing method, which is the same as the execution example mode operation described above, which can be described as: mult->sumpool->rsqrt->broadcast_mult.
[0108] In a possible implementation manner, the data normalization processing method of the embodiment of the disclosure is stored in the form of a computer program in a computer readable storage medium, when the computer readable storage medium is run by a computer device, a plurality of processing units in the computer device can run various tasks allocated to them, such as: calculating a scaling factor task, operator splicing task, etc. The processing unit run by the disclosure is not limited. The processing unit can be any appropriate hardware processor, such as CPU, GPU, FPGA, DSP, and ASIC, etc., and can also be an artificial intelligence processor (IPU) for performing artificial intelligence operation.
[0109] It should be noted that for the above-mentioned method embodiments, in order to simply describe, they are all expressed as a series of action combinations, but those skilled in the art should know that the disclosure is not limited by the order of the described actions, because according to the disclosure, certain steps can be performed in other order or simultaneously. Secondly, those skilled in the art should know that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily necessary for the disclosure.
[0110] It should be further noted that although Figure 2 and Figure 3 the steps in the flowcharts are displayed in sequence according to the arrows, these steps are not necessarily executed in sequence according to the arrows. Unless otherwise specified in this article, the execution of these steps has no strict order limitation, and these steps can be executed in other order. Moreover, Figure 2 at least part of the steps in may include multiple sub-steps or multiple stages, which are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily sequential, but can be executed alternately or alternately with at least part of the other steps or other steps.
[0111] It should be understood that the above-mentioned apparatus embodiments are only illustrative, and the apparatus of the present disclosure can also be implemented in other manners. For example, the division of the units / modules described in the above-mentioned embodiments is only a logical function division, and actual implementation can be in another manner. For example, a plurality of units / modules or components can be combined, or can be integrated into another system, or some features can be omitted or not executed.
[0112] In addition, unless otherwise specified, each functional unit / module in each embodiment of the present disclosure can be integrated in one unit / module, or each unit / module can be physically present alone, or two or more units / modules can be integrated together. The integrated unit / module can be implemented in the form of hardware or in the form of a software program module.
[0113] If the integrated unit / module is implemented in the form of hardware, the hardware can be a digital circuit, an analog circuit, etc. The physical implementation of the hardware structure includes but is not limited to transistors, memristors, etc. Unless otherwise specified, the scaling factor calculation unit and the normalization calculation unit can be any appropriate hardware processor with data processing functions, such as a CPU, a GPU, an FPGA, a DSP, an ASIC, etc.
[0114] If the integrated unit / module is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the present disclosure, essentially or the part that contributes to the prior art, or all or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in each embodiment of the present disclosure. The aforementioned storage medium includes: a U disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a mobile hard disk, a magnetic disk or an optical disk, and various media that can store program codes.
[0115] In the above embodiments, the description of each embodiment has its own focus, and the parts not described in detail in a certain embodiment can be referred to the relevant description of other embodiments. Each technical feature of the above embodiments can be combined arbitrarily. In order to make the description concise, not all possible combinations of the technical features in the above embodiments are described, but as long as the combination of the technical features does not exist contradictory, it should be considered as the scope of the present disclosure.
[0116] The foregoing can be better understood in light of the following clauses:
[0117] Clause A1, a data normalization processing method, the method is suitable for a normalization layer in a deep learning neural network, the method comprises:
[0118] According to the maximum value of the input data quantization data type and the maximum value of the input data, the scaling factor of the input data is calculated;
[0119] The product of the scaling factor and the input data is calculated, and the normalization result of the input data in the normalization layer is calculated according to the product.
[0120] Clause A2, according to clause A1, the calculation formula of the scaling factor is:
[0121]
[0122] In the formula, β is the scaling factor, Max is the maximum value of the input data quantization data type, x max is the maximum value of the input data, and n is the total number of the input data.
[0123] Clause A3, according to clause A2, in step 2, the normalization result of the input data in the normalization layer is calculated, specifically comprising:
[0124] The first square value of the first product is calculated by sequentially performing square operation on the first product;
[0125] The sum value of the first square value and the first product is calculated by using addition operation, and the reciprocal of the square root of the sum value is calculated;
[0126] The second product of the reciprocal of the square root and the first product is calculated by using broadcast multiplication, and the second product is recorded as the normalization result of the L2Normalization operator.
[0127] Clause A4, according to clause A3, the data normalization processing method, the second product of the reciprocal of the square root and the first product is calculated by using broadcast multiplication, specifically comprising:
[0128] According to the dimension of the reciprocal of the square root, the first product is divided into at least two submatrices, wherein the dimension of the reciprocal of the square root is less than the dimension of the first product;
[0129] The product of the reciprocal of the square root and the submatrix is calculated in sequence, and the product is recorded as the submatrix product;
[0130] The sum value of the submatrix product is calculated by using addition operation, and the sum value is recorded as the second product.
[0131] Clause A5, the method according to any one of clauses A1 or A3, wherein the normalization result is a normalization result of an L2Normalization operator.
[0132] Clause A6, the method according to clause A5, wherein the operation mode of the L2Normalization operator comprises an instance mode and a channel mode.
[0133] Clause A7, the data normalization processing method according to clause A1, wherein the quantization of the input data specifically comprises:
[0134] According to the quantization type, the actual value represented by each quantized value is calculated in sequence to generate quantized initial data;
[0135] According to the fine-tuning parameter, the quantized initial data is fine-tuned to generate quantized data.
[0136] Clause A8, a data normalization processing device, the device comprising: a scaling factor calculation unit and a normalization calculation unit;
[0137] The scaling factor calculation unit is configured to calculate a scaling factor of the input data according to a maximum value of a data type after quantization of the input data and a maximum value of the input data;
[0138] The normalization calculation unit is configured to calculate a first product of the scaling factor and the input data, and calculate a normalization result of the input data in the normalization layer according to the first product.
[0139] Clause A9, the device according to clause A8, wherein the calculation formula of the scaling factor is:
[0140]
[0141] In the formula, β is the scaling factor, Max is the maximum value of the data type after quantization of the input data, x max is the maximum value of the input data, and n is the total number of the input data.
[0142] Clause A10, the device according to clause A9, wherein the normalization calculation unit calculates the normalization result of the input data in the normalization layer, specifically comprising:
[0143] The first product is squared to calculate a first square value of the first product;
[0144] The sum of the first square value and the first product is calculated by using addition operation, and the reciprocal of the square root of the sum is calculated;
[0145] A second product of the inverse of the square root and the first product is computed using a broadcast multiplication, the second product is denoted as the normalized result.
[0146] Clause A11. A computer readable storage medium, having stored thereon a computer program, which, when executed by a processor, implements the data normalization processing method according to any one of clauses A1 to A7 to perform normalization processing on data.
[0147] Clause A12. A computer device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor implements the data normalization processing method according to any one of clauses A1 to A7 when executing the computer program.
[0148] The above detailed description of the embodiments of the present disclosure is made with specific examples applied to the principles and implementation modes of the present disclosure. The above description of the embodiments is only used to help understand the method of the present disclosure and its core idea. Meanwhile, any changes or modifications made by those skilled in the art based on the specific implementation modes and application scope of the present disclosure are within the scope of protection of the present disclosure. In summary, the content of the specification should not be understood as a limitation of the present disclosure.
Claims
1. A data normalization processing method characterized by comprising: The method is suitable for a normalization layer in a deep learning neural network, and is run in a processor including a processing unit. The processing unit is configured to execute an instruction sequence. The method comprises: The processing unit calculates a scaling factor of the input data according to a maximum value of a data type after quantization of the input data and a maximum value of the input data; The maximum value of the data type refers to a maximum value of a numerical range represented by the data type; The processing unit calculates a first product of the scaling factor and the input data, and calculates a normalization result of the input data in the normalization layer according to the first product; The normalization result is a normalization result of an L2Normalization operator; The input data is a picture.
2. The data normalization processing method of claim 1, wherein, The scaling factor is calculated according to the following formula: where β is the scaling factor, Max is the maximum value of the input data after quantization, x max is the maximum value of the input data, and n is the total number of the input data.
3. The data normalization processing method of claim 2, wherein, The normalization result of the input data in the normalization layer is calculated, specifically including: performing a square operation on the first product to obtain a first square value of the first product; using an addition operation to calculate a sum value of the first square value and the first product, and calculating an inverse of a square root of the sum value; using broadcast multiplication to calculate a second product of the inverse of the square root and the first product, and recording the second product as the normalization result.
4. The data normalization processing method of claim 3, wherein, The second product of the inverse of the square root and the first product is calculated using broadcast multiplication, specifically including: dividing the first product into at least two sub-matrices according to a dimension of the inverse of the square root, wherein the dimension of the inverse of the square root is smaller than a dimension of the first product; calculating a product of the inverse of the square root and the sub-matrices, and recording the product as a sub-matrix product; using an addition operation to calculate a sum value of the sub-matrix product, and recording the sum value as the second product.
5. The data normalization method of claim 1, wherein, The operation mode of the L2Normalization operator includes an instance mode and a channel mode.
6. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the data normalization processing method according to any one of claims 1-5 to normalize data.
7. A computer device, characterized by The computer program is executed by the processor to implement the data normalization processing method according to any one of claims 1-5 to normalize data. The computer program is executed by the processor to implement the data normalization processing method according to any one of claims 1-5 to normalize data.
Citation Information
Patent Citations
Method, device for implementing LLR normalization, and electronic device
CN109525250A
Method and device for preventing data overflow, and chip
CN111258537A